public function EntityOperationsTest::testArchive in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\workbench_moderation\Kernel\EntityOperationsTest::testArchive()
Verifies that an unpublished state may be made the default revision.
File
- tests/
src/ Kernel/ EntityOperationsTest.php, line 154
Class
- EntityOperationsTest
- Class EntityOperationsTest.
Namespace
Drupal\Tests\workbench_moderation\KernelCode
public function testArchive() {
$published_id = $this
->randomMachineName();
$published_state = ModerationState::create([
'id' => $published_id,
'label' => $this
->randomString(),
'published' => TRUE,
'default_revision' => TRUE,
]);
$published_state
->save();
$archived_id = $this
->randomMachineName();
$archived_state = ModerationState::create([
'id' => $archived_id,
'label' => $this
->randomString(),
'published' => FALSE,
'default_revision' => TRUE,
]);
$archived_state
->save();
$page = Node::create([
'type' => 'page',
'title' => $this
->randomString(),
]);
$page->moderation_state->target_id = $published_id;
$page
->save();
$id = $page
->id();
// The newly-created page should already be published.
$page = Node::load($id);
$this
->assertTrue($page
->isPublished());
// When the page is moderated to the archived state, then the latest
// revision should be the default revision, and it should be unpublished.
$page->moderation_state->target_id = $archived_id;
$page
->save();
$new_revision_id = $page
->getRevisionId();
$storage = \Drupal::entityTypeManager()
->getStorage('node');
$new_revision = $storage
->loadRevision($new_revision_id);
$this
->assertFalse($new_revision
->isPublished());
$this
->assertTrue($new_revision
->isDefaultRevision());
}