function WorkspacesContentModerationStateTest::testContentModerationMultipleEntityTypesWithWorkspaces

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

Publish a workspace with multiple entities from different entity types.

File

core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php, line 211

Class

WorkspacesContentModerationStateTest
Tests that Workspaces and Content Moderation work together properly.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testContentModerationMultipleEntityTypesWithWorkspaces() : void {
  $editorial = $this->createEditorialWorkflow();
  $this->createContentType([
    'type' => 'page',
  ]);
  $this->addEntityTypeAndBundleToWorkflow($editorial, 'node', 'page');
  $this->addEntityTypeAndBundleToWorkflow($editorial, 'entity_test_mulrevpub', 'entity_test_mulrevpub');
  // Create an entity with a previous revision that is tracked in unpublished
  // state.
  $entity_with_revision = EntityTestMulRevPub::create([
    'title' => 'Test entity mulrevpub',
    'type' => 'entity_test_mulrevpub',
    'moderation_state' => 'draft',
  ]);
  $entity_with_revision->save();
  $entity_with_revision->save();
  $entity_with_revision = $this->reloadEntity($entity_with_revision);
  // Confirm unpublished earlier revision.
  $this->assertEquals('draft', $entity_with_revision->moderation_state->value);
  $earlier_revision_id = $entity_with_revision->getRevisionId();
  // Publish.
  $entity_with_revision->moderation_state->value = 'published';
  $entity_with_revision->save();
  $entity_with_revision = $this->reloadEntity($entity_with_revision);
  // Confirm publish revision.
  $this->assertEquals('published', $entity_with_revision->moderation_state->value);
  $published_revision_id = $entity_with_revision->getRevisionId();
  $this->assertNotEquals($earlier_revision_id, $published_revision_id);
  // Create an entity that has a default revision id the same as the previous
  // entity's old revision.
  $entity_without_revision = Node::create([
    'title' => 'Test node page',
    'type' => 'page',
    'moderation_state' => 'published',
  ]);
  $entity_without_revision->save();
  $entity_without_revision = $this->reloadEntity($entity_without_revision);
  $this->assertEquals('published', $entity_without_revision->moderation_state->value);
  // Current published revisions of second entity has the same revision as
  // earlier unpublished revision of first entity.
  $this->assertEquals($entity_without_revision->getRevisionId(), $earlier_revision_id);
  $this->workspaces['stage']
    ->publish();
}

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