class RecipeTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Recipe/RecipeTest.php \Drupal\KernelTests\Core\Recipe\RecipeTest

@coversDefaultClass \Drupal\Core\Recipe\Recipe
@group Recipe

Hierarchy

Expanded class hierarchy of RecipeTest

File

core/tests/Drupal/KernelTests/Core/Recipe/RecipeTest.php, line 18

Namespace

Drupal\KernelTests\Core\Recipe
View source
class RecipeTest extends KernelTestBase {
  use RecipeTestTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'user',
    'field',
  ];
  
  /**
   * @testWith ["no_extensions", "No extensions" , "Testing", [], "A recipe description"]
   *           ["install_two_modules", "Install two modules" , "Content type", ["filter", "text", "node"], ""]
   */
  public function testCreateFromDirectory2(string $recipe_name, string $expected_name, string $expected_type, array $expected_modules, string $expected_description) : void {
    $recipe = Recipe::createFromDirectory('core/tests/fixtures/recipes/' . $recipe_name);
    $this->assertSame($expected_name, $recipe->name);
    $this->assertSame($expected_type, $recipe->type);
    $this->assertSame($expected_modules, $recipe->install->modules);
    $this->assertSame($expected_description, $recipe->description);
  }
  public function testCreateFromDirectoryNoRecipe() : void {
    $dir = uniqid('public://');
    mkdir($dir);
    $this->expectException(RecipeFileException::class);
    $this->expectExceptionMessage('There is no ' . $dir . '/recipe.yml file');
    Recipe::createFromDirectory($dir);
  }
  public function testPreExistingDifferentConfiguration() : void {
    // Install the node module, its dependencies and configuration.
    $this->container
      ->get('module_installer')
      ->install([
      'node',
    ]);
    $this->assertFalse($this->config('node.settings')
      ->get('use_admin_theme'), 'The node.settings:use_admin_theme is set to FALSE');
    try {
      Recipe::createFromDirectory('core/tests/fixtures/recipes/install_node_with_config');
      $this->fail('Expected exception not thrown');
    } catch (RecipePreExistingConfigException $e) {
      $this->assertSame("The configuration 'node.settings' exists already and does not match the recipe's configuration", $e->getMessage());
      $this->assertSame('node.settings', $e->configName);
    }
  }
  public function testPreExistingMatchingConfiguration() : void {
    // Install the node module, its dependencies and configuration.
    $this->container
      ->get('module_installer')
      ->install([
      'node',
    ]);
    // Change the config to match the recipe's config to prevent the exception
    // being thrown.
    $this->config('node.settings')
      ->set('use_admin_theme', TRUE)
      ->save();
    $recipe = Recipe::createFromDirectory('core/tests/fixtures/recipes/install_node_with_config');
    $this->assertSame('core/tests/fixtures/recipes/install_node_with_config/config', $recipe->config->recipeConfigDirectory);
  }
  public function testExampleRecipe() : void {
    // The example recipe imports all the configurations from the node module
    // including optional configurations associated with the search and view
    // modules. So we have to install them before applying the example recipe.
    $this->container
      ->get('module_installer')
      ->install([
      'search',
      'views',
    ]);
    // Apply the example recipe.
    $recipe = Recipe::createFromDirectory('core/recipes/example');
    RecipeRunner::processRecipe($recipe);
    // Verify if the 'default_summary_length' value is updated.
    $this->assertSame($this->config('text.settings')
      ->get('default_summary_length'), 700);
  }
  public function testImplicitlyRequiredModule() : void {
    $this->disableModules([
      'user',
    ]);
    $recipe = $this->createRecipe([
      'name' => 'Actions on config from required module',
      'config' => [
        'actions' => [
          'user.role.authenticated' => [
            'grantPermission' => 'access administration pages',
          ],
        ],
      ],
    ]);
    $this->assertIsObject($recipe);
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
RecipeTest::$modules protected static property Modules to install.
RecipeTest::testCreateFromDirectory2 public function @testWith ["no_extensions", "No extensions" , "Testing", [], "A recipe description"][[api-linebreak]]
["install_two_modules", "Install two modules" , "Content type",…
RecipeTest::testCreateFromDirectoryNoRecipe public function
RecipeTest::testExampleRecipe public function
RecipeTest::testImplicitlyRequiredModule public function
RecipeTest::testPreExistingDifferentConfiguration public function
RecipeTest::testPreExistingMatchingConfiguration public function
RecipeTestTrait::applyRecipe protected function Applies a recipe to the site.
RecipeTestTrait::createRecipe protected function Creates a recipe in a temporary directory.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements Deprecated private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements Deprecated protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.