function InputTest::testInputInConfigEntityIds

Tests using input values in entity IDs for config actions.

File

core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php, line 256

Class

InputTest
@group Recipe @covers \Drupal\Core\Recipe\InputConfigurator[[api-linebreak]]

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testInputInConfigEntityIds() : void {
  $this->assertFalse(\Drupal::moduleHandler()->moduleExists('node'));
  $collector = new class  implements InputCollectorInterface {
    
    /**
     * {@inheritdoc}
     */
    public function collectValue(string $name, DataDefinitionInterface $definition, mixed $default_value) : mixed {
      return $default_value;
    }

};
  $recipe = Recipe::createFromDirectory('core/tests/fixtures/recipes/input_test');
  $recipe->input
    ->collectAll($collector);
  RecipeRunner::processRecipe($recipe);
  $this->assertInstanceOf(NodeType::class, NodeType::load('test'));
  // Using an input placeholder in a non-identifying part of the config entity
  // ID should cause an exception.
  $recipe = $this->createRecipe([
    'name' => 'Invalid use of an input in config entity ID',
    'config' => [
      'actions' => [
        'node.${anything}.test' => [
          'createIfNotExists' => [
            'id' => 'test',
          ],
        ],
      ],
    ],
  ]);
  $recipe->input
    ->collectAll($collector);
  $this->expectException(ConfigActionException::class);
  $this->expectExceptionMessage("The entity type for the config name 'node.\${anything}.test' could not be identified.");
  RecipeRunner::processRecipe($recipe);
}

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