class AddModerationConfigActionTest

Same name and namespace in other branches
  1. 11.x core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php \Drupal\Tests\content_moderation\Kernel\ConfigAction\AddModerationConfigActionTest

@covers \Drupal\content_moderation\Plugin\ConfigAction\AddModeration
@covers \Drupal\content_moderation\Plugin\ConfigAction\AddModerationDeriver
@group content_moderation @group Recipe

Hierarchy

Expanded class hierarchy of AddModerationConfigActionTest

File

core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php, line 23

Namespace

Drupal\Tests\content_moderation\Kernel\ConfigAction
View source
class AddModerationConfigActionTest extends KernelTestBase {
  use ContentTypeCreationTrait;
  use RecipeTestTrait {
    createRecipe as traitCreateRecipe;
  }
  use TaxonomyTestTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'field',
    'node',
    'system',
    'taxonomy',
    'text',
    'user',
  ];
  public function testAddEntityTypeAndBundle() : void {
    $this->installConfig('node');
    $this->createContentType([
      'type' => 'a',
    ]);
    $this->createContentType([
      'type' => 'b',
    ]);
    $this->createContentType([
      'type' => 'c',
    ]);
    $this->createVocabulary([
      'vid' => 'tags',
    ]);
    $recipe = $this->createRecipe('workflows.workflow.editorial');
    RecipeRunner::processRecipe($recipe);
    /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $plugin */
    $plugin = Workflow::load('editorial')?->getTypePlugin();
    $this->assertSame([
      'a',
      'b',
    ], $plugin->getBundlesForEntityType('node'));
    $this->assertSame([
      'tags',
    ], $plugin->getBundlesForEntityType('taxonomy_term'));
  }
  public function testWorkflowMustBeContentModeration() : void {
    $this->enableModules([
      'workflows',
      'workflow_type_test',
    ]);
    $workflow = Workflow::create([
      'id' => 'test',
      'label' => 'Test workflow',
      'type' => 'workflow_type_test',
    ]);
    $workflow->save();
    $recipe = $this->createRecipe($workflow->getConfigDependencyName());
    $this->expectException(ConfigActionException::class);
    $this->expectExceptionMessage("The add_moderation:addNodeTypes config action only works with Content Moderation workflows.");
    RecipeRunner::processRecipe($recipe);
  }
  public function testActionOnlyTargetsWorkflows() : void {
    $recipe = $this->createRecipe('user.role.anonymous');
    $this->expectException(PluginNotFoundException::class);
    $this->expectExceptionMessage('The "user_role" entity does not support the "addNodeTypes" config action.');
    RecipeRunner::processRecipe($recipe);
  }
  public function testDeriverAdminLabel() : void {
    $this->enableModules([
      'workflows',
      'content_moderation',
    ]);
    /** @var array<string, array{admin_label: \Stringable}> $definitions */
    $definitions = $this->container
      ->get('plugin.manager.config_action')
      ->getDefinitions();
    $this->assertSame('Add moderation to all content types', (string) $definitions['add_moderation:addNodeTypes']['admin_label']);
    $this->assertSame('Add moderation to all vocabularies', (string) $definitions['add_moderation:addTaxonomyVocabularies']['admin_label']);
  }
  private function createRecipe(string $config_name) : Recipe {
    $recipe = <<<YAML
name: 'Add entity types and bundles to workflow'
recipes:
  - core/recipes/editorial_workflow
config:
  actions:
    {<span class="php-variable">$config_name</span>}:
      addNodeTypes:
        - a
        - b
      addTaxonomyVocabularies: '*'
YAML;
    return $this->traitCreateRecipe($recipe);
  }

}

Members

Title Sort descending Modifiers Object type Summary Member alias
AddModerationConfigActionTest::$modules protected static property Modules to install.
AddModerationConfigActionTest::createRecipe private function
AddModerationConfigActionTest::testActionOnlyTargetsWorkflows public function
AddModerationConfigActionTest::testAddEntityTypeAndBundle public function
AddModerationConfigActionTest::testDeriverAdminLabel public function
AddModerationConfigActionTest::testWorkflowMustBeContentModeration public function
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
RecipeTestTrait::applyRecipe protected function Applies a recipe to the site.
RecipeTestTrait::createRecipe protected function Creates a recipe in a temporary directory. Aliased as: traitCreateRecipe
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.

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