function ContentModerationStateTest::doTestRevisionDefaultState

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

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

Parameters

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

1 call to ContentModerationStateTest::doTestRevisionDefaultState()
ContentModerationStateTest::testRevisionDefaultState in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Tests the revision default state of the moderation state entity revisions.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function doTestRevisionDefaultState($entity_type_id) : void {
  // 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.