function ContentModerationStateTest::testExistingContentModerationStateDataRemoval

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

Tests removal of content moderation state entities for preexisting content.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testExistingContentModerationStateDataRemoval() {
    $storage = $this->entityTypeManager
        ->getStorage('entity_test_mulrevpub');
    $entity = $this->createEntity('entity_test_mulrevpub', 'published', FALSE);
    $original_revision_id = $entity->getRevisionId();
    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow, $entity->getEntityTypeId(), $entity->bundle());
    $entity = $this->reloadEntity($entity);
    $entity->moderation_state = 'draft';
    $entity->save();
    $storage->deleteRevision($entity->getRevisionId());
    $entity = $this->reloadEntity($entity);
    $this->assertEquals('published', $entity->moderation_state->value);
    $this->assertEquals($original_revision_id, $storage->getLatestRevisionId($entity->id()));
}

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