function ContentModerationStateTest::testContentModerationStateRevisionDataRemoval

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testContentModerationStateRevisionDataRemoval()
  2. 10 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testContentModerationStateRevisionDataRemoval()
  3. 11.x core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testContentModerationStateRevisionDataRemoval()

Tests removal of content moderation state entity revisions.

@dataProvider basicModerationTestCases

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testContentModerationStateRevisionDataRemoval($entity_type_id) {
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->createEntity($entity_type_id);
    $revision_1 = clone $entity;
    $this->assertNotNull(ContentModerationState::loadFromModeratedEntity($revision_1));
    // Create a second revision.
    $entity = $this->reloadEntity($entity);
    $entity->setNewRevision(TRUE);
    $entity->save();
    $revision_2 = clone $entity;
    // Create a third revision.
    $entity = $this->reloadEntity($entity);
    $entity->setNewRevision(TRUE);
    $entity->save();
    $revision_3 = clone $entity;
    // Delete the second revision and check that its content moderation state is
    // removed as well, while the content moderation states for revisions 1 and
    // 3 are kept in place.
    $entity_storage = $this->entityTypeManager
        ->getStorage($entity_type_id);
    $entity_storage->deleteRevision($revision_2->getRevisionId());
    $this->assertNotNull(ContentModerationState::loadFromModeratedEntity($revision_1));
    $this->assertNull(ContentModerationState::loadFromModeratedEntity($revision_2));
    $this->assertNotNull(ContentModerationState::loadFromModeratedEntity($revision_3));
}

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