function ContentModerationStateTest::testRevisionDefaultState

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()
  2. 10 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testRevisionDefaultState()
  3. 11.x 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());
}

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