X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FDefaultRevisionStateTest.php;h=84bade45781765d1291d147bbf24376453179217;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=274e8b525dc18f3bcae9060c162075d0acbcf631;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php b/web/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php index 274e8b525..84bade457 100644 --- a/web/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php +++ b/web/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php @@ -83,6 +83,7 @@ class DefaultRevisionStateTest extends KernelTestBase { $this->assertEquals('draft', $english_node->moderation_state->value); $this->assertFalse($english_node->isPublished()); $this->assertTrue($english_node->isDefaultRevision()); + $this->assertModerationState($english_node->getRevisionId(), $english_node->language()->getId(), 'draft'); // Revision 2 (fr) $french_node = $english_node->addTranslation('fr', ['title' => 'French title']); @@ -90,6 +91,7 @@ class DefaultRevisionStateTest extends KernelTestBase { $french_node->save(); $this->assertTrue($french_node->isPublished()); $this->assertTrue($french_node->isDefaultRevision()); + $this->assertModerationState($french_node->getRevisionId(), $french_node->language()->getId(), 'published'); // Revision 3 (fr) $node = Node::load($english_node->id())->getTranslation('fr'); @@ -97,6 +99,7 @@ class DefaultRevisionStateTest extends KernelTestBase { $node->save(); $this->assertFalse($node->isPublished()); $this->assertFalse($node->isDefaultRevision()); + $this->assertModerationState($node->getRevisionId(), $node->language()->getId(), 'draft'); // Revision 4 (en) $latest_revision = $this->entityTypeManager->getStorage('node')->loadRevision(3); @@ -104,6 +107,36 @@ class DefaultRevisionStateTest extends KernelTestBase { $latest_revision->save(); $this->assertFalse($latest_revision->isPublished()); $this->assertFalse($latest_revision->isDefaultRevision()); + $this->assertModerationState($latest_revision->getRevisionId(), $latest_revision->language()->getId(), 'draft'); + } + + /** + * Verifies the expected moderation state revision exists. + * + * @param int $revision_id + * The revision ID of the host entity. + * @param string $langcode + * The language code of the host entity to check. + * @param string $expected_state + * The state the content moderation state revision should be in. + * @param string $expected_workflow + * The workflow the content moderation state revision should be using. + */ + protected function assertModerationState($revision_id, $langcode, $expected_state, $expected_workflow = 'editorial') { + $moderation_state_storage = $this->entityTypeManager->getStorage('content_moderation_state'); + + $query = $moderation_state_storage->getQuery(); + $results = $query->allRevisions() + ->condition('content_entity_revision_id', $revision_id) + ->condition('langcode', $langcode) + ->execute(); + $this->assertCount(1, $results); + + $moderation_state = $moderation_state_storage + ->loadRevision(key($results)) + ->getTranslation($langcode); + $this->assertEquals($expected_state, $moderation_state->get('moderation_state')->value); + $this->assertEquals($expected_workflow, $moderation_state->get('workflow')->target_id); } }