class ModerationStateFieldTest

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

Tests the moderation state field.

Attributes

#[Group('content_moderation')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of ModerationStateFieldTest

File

core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldTest.php, line 16

Namespace

Drupal\Tests\content_moderation\Kernel
View source
class ModerationStateFieldTest extends KernelTestBase {
  use ContentModerationTestTrait;
  use ContentTypeCreationTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'workflows',
    'content_moderation',
    'node',
    'user',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->installSchema('node', 'node_access');
    $this->installEntitySchema('workflow');
    $this->installEntitySchema('content_moderation_state');
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
  }
  
  /**
   * Tests that the moderation state field target bundle is always correct.
   */
  public function testFieldDefinitionBundles() : void {
    $workflow = $this->createEditorialWorkflow();
    /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
    $workflow_type = $workflow->getTypePlugin();
    $node_types = [];
    for ($i = 0; $i < 3; ++$i) {
      $node_type = $this->createContentType(create_body: FALSE);
      $workflow_type->addEntityTypeAndBundle('node', $node_type->id());
      $node_types[] = $node_type;
    }
    $workflow->save();
    /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
    $entity_field_manager = \Drupal::service('entity_field.manager');
    $this->assertNotEmpty($node_types);
    foreach ($node_types as $node_type) {
      $field_definitions = $entity_field_manager->getFieldDefinitions('node', $node_type->id());
      $this->assertSame($node_type->id(), $field_definitions['moderation_state']->getTargetBundle());
    }
  }

}

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