function WildcardConfigActionsTest::testCreateForEachValidatesCreatedEntities

Tests that the createForEach action validates the config it creates.

File

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

Class

WildcardConfigActionsTest
Tests config actions targeting multiple entities using wildcards.

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testCreateForEachValidatesCreatedEntities() : void {
  $this->enableModules([
    'image',
  ]);
  // To prove that the validation runs, we need to disable strict schema
  // checking in this test. We need to explicitly unsubscribe it from events
  // because by this point in the test it has been fully wired up into the
  // container and can't be changed.
  $schema_checker = $this->container
    ->get('testing.config_schema_checker');
  $this->container
    ->get(EventDispatcherInterface::class)
    ->removeSubscriber($schema_checker);
  try {
    $this->container
      ->get('plugin.manager.config_action')
      ->applyAction('createForEach', 'node.type.*', [
      'image.style.node__%bundle' => [],
    ]);
    $this->fail('Expected an exception to be thrown but it was not.');
  } catch (InvalidConfigException $e) {
    $this->assertSame('image.style.node__one', $e->data
      ->getName());
    $this->assertCount(1, $e->violations);
    $this->assertSame('label', $e->violations[0]
      ->getPropertyPath());
    $this->assertSame(NotNull::IS_NULL_ERROR, $e->violations[0]
      ->getCode());
  }
}

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