function RecipeRunnerTest::testConfigActionsPreExistingConfig

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php \Drupal\KernelTests\Core\Recipe\RecipeRunnerTest::testConfigActionsPreExistingConfig()

File

core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php, line 182

Class

RecipeRunnerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Recipe%21RecipeRunner.php/class/RecipeRunner/11.x" title="Applies a recipe." class="local">\Drupal\Core\Recipe\RecipeRunner</a> @group Recipe

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testConfigActionsPreExistingConfig() : void {
    $this->enableModules([
        'config_test',
    ]);
    $this->installConfig([
        'config_test',
    ]);
    $this->assertSame('bar', $this->config('config_test.system')
        ->get('foo'));
    $storage = \Drupal::entityTypeManager()->getStorage('config_test');
    $config_test_entity = $storage->create([
        'id' => 'recipe',
        'label' => 'Created by test',
    ]);
    $this->assertInstanceOf(ConfigTest::class, $config_test_entity);
    $config_test_entity->setProtectedProperty('Set by test');
    $config_test_entity->save();
    $recipe = Recipe::createFromDirectory('core/tests/fixtures/recipes/config_actions');
    RecipeRunner::processRecipe($recipe);
    // Test the state after to applying the recipe.
    $config_test_entity = $storage->load('recipe');
    $this->assertInstanceOf(ConfigTest::class, $config_test_entity);
    $this->assertSame('Created by test', $config_test_entity->label());
    $this->assertSame('Set by recipe', $config_test_entity->getProtectedProperty());
    $this->assertSame('not bar', $this->config('config_test.system')
        ->get('foo'));
}

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