You are here

public function ContentModerationStateTest::testRevisionDefaultState in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testRevisionDefaultState()

Test the revision default state of the moderation state entity revisions.

@dataProvider basicModerationTestCases

Parameters

string $entity_type_id: The ID of entity type to be tested.

File

core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php, line 657

Class

ContentModerationStateTest
Tests links between a content entity and a content_moderation_state entity.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testRevisionDefaultState($entity_type_id) {

  // Check that the revision default state of the moderated entity and the
  // content moderation state entity always match.
  $entity = $this
    ->createEntity($entity_type_id, 'published');
  $cms_entity = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertEquals($entity
    ->isDefaultRevision(), $cms_entity
    ->isDefaultRevision());
  $entity
    ->get('moderation_state')->value = 'published';
  $entity
    ->save();
  $cms_entity = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertEquals($entity
    ->isDefaultRevision(), $cms_entity
    ->isDefaultRevision());
  $entity
    ->get('moderation_state')->value = 'draft';
  $entity
    ->save();
  $cms_entity = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertEquals($entity
    ->isDefaultRevision(), $cms_entity
    ->isDefaultRevision());
  $entity
    ->get('moderation_state')->value = 'published';
  $entity
    ->save();
  $cms_entity = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertEquals($entity
    ->isDefaultRevision(), $cms_entity
    ->isDefaultRevision());
}