public function EntityOperationsTest::testArchive in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testArchive()
Verifies that an unpublished state may be made the default revision.
File
- core/
modules/ content_moderation/ tests/ src/ Kernel/ EntityOperationsTest.php, line 157
Class
- EntityOperationsTest
- @coversDefaultClass \Drupal\content_moderation\EntityOperations
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testArchive() {
$page = Node::create([
'type' => 'page',
'title' => $this
->randomString(),
]);
$page->moderation_state->value = 'published';
$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->value = 'archived';
$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());
}