function EntityOperationsTest::testArchive
Same name in other branches
- 9 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testArchive()
- 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testArchive()
- 10 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 159
Class
- EntityOperationsTest
- @coversDefaultClass \Drupal\content_moderation\EntityOperations
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testArchive() : void {
$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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.