function WildcardConfigActionsTest::testTargetEntitiesByWildcards

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Recipe/WildcardConfigActionsTest.php \Drupal\KernelTests\Core\Recipe\WildcardConfigActionsTest::testTargetEntitiesByWildcards()

Tests targeting multiple config entities for an action, using wildcards.

@testWith ["field.field.node.one.*", ["node.one.body", "node.one.field_test"]] ["field.field.node.*.body", ["node.one.body", "node.two.body"]] ["field.field.*.one.field_test", ["entity_test_with_bundle.one.field_test", "node.one.field_test"]] ["field.field.node.*.*", ["node.one.body", "node.one.field_test", "node.two.body", "node.two.field_test"]] ["field.field.*.one.*", ["entity_test_with_bundle.one.field_test", "node.one.field_test", "node.one.body"]] ["field.field.*.*.field_test", ["entity_test_with_bundle.one.field_test", "entity_test_with_bundle.two.field_test", "node.one.field_test", "node.two.field_test"]] ["field.field.*.*.*", ["entity_test_with_bundle.one.field_test", "entity_test_with_bundle.two.field_test", "node.one.field_test", "node.two.field_test", "node.one.body", "node.two.body"]]

Parameters

string $expression: The expression the recipe will use to target multiple config entities.

string[] $expected_changed_entities: The IDs of the config entities that we expect the recipe to change.

File

core/tests/Drupal/KernelTests/Core/Recipe/WildcardConfigActionsTest.php, line 99

Class

WildcardConfigActionsTest
Tests config actions targeting multiple entities using wildcards.

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testTargetEntitiesByWildcards(string $expression, array $expected_changed_entities) : void {
    $contents = <<<YAML
name: 'Wildcards!'
config:
  actions:
    {<span class="php-variable">$expression</span>}:
      setLabel: 'Changed by config action'
YAML;
    $recipe = $this->createRecipe($contents);
    RecipeRunner::processRecipe($recipe);
    $changed = $this->container
        ->get(EntityTypeManagerInterface::class)
        ->getStorage('field_config')
        ->getQuery()
        ->condition('label', 'Changed by config action')
        ->execute();
    sort($expected_changed_entities);
    sort($changed);
    $this->assertSame($expected_changed_entities, array_values($changed));
}

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