function ContentModerationStateTest::doTestBasicModeration
Same name in other branches
- 10 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::doTestBasicModeration()
Tests basic monolingual content moderation through the API.
1 call to ContentModerationStateTest::doTestBasicModeration()
- ContentModerationStateTest::testBasicModeration in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests basic monolingual content moderation through the API.
File
-
core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php, line 124
Class
- ContentModerationStateTest
- Tests links between a content entity and a content_moderation_state entity.
Namespace
Drupal\Tests\content_moderation\KernelCode
protected function doTestBasicModeration($entity_type_id) : void {
$entity = $this->createEntity($entity_type_id, 'draft');
$entity = $this->reloadEntity($entity);
$this->assertEquals('draft', $entity->moderation_state->value);
$entity->moderation_state->value = 'published';
$entity->save();
$entity = $this->reloadEntity($entity);
$this->assertEquals('published', $entity->moderation_state->value);
// Change the state without saving the node.
$content_moderation_state = ContentModerationState::load(1);
$content_moderation_state->set('moderation_state', 'draft');
$content_moderation_state->setNewRevision(TRUE);
$content_moderation_state->save();
$entity = $this->reloadEntity($entity, 3);
$this->assertEquals('draft', $entity->moderation_state->value);
if ($entity instanceof EntityPublishedInterface) {
$this->assertFalse($entity->isPublished());
}
// Check the default revision.
$this->assertDefaultRevision($entity, 2);
$entity->moderation_state->value = 'published';
$entity->save();
$entity = $this->reloadEntity($entity, 4);
$this->assertEquals('published', $entity->moderation_state->value);
// Check the default revision.
$this->assertDefaultRevision($entity, 4);
// Update the node to archived which will then be the default revision.
$entity->moderation_state->value = 'archived';
$entity->save();
// Revert to the previous (published) revision.
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $entity_storage */
$entity_storage = $this->entityTypeManager
->getStorage($entity_type_id);
$previous_revision = $entity_storage->loadRevision(4);
$previous_revision->isDefaultRevision(TRUE);
$previous_revision->setNewRevision(TRUE);
$previous_revision->save();
// Check the default revision.
$this->assertDefaultRevision($entity, 6);
// Set an invalid moderation state.
$this->expectException(EntityStorageException::class);
$entity->moderation_state->value = 'foobar';
$entity->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.