X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FModerationStateFieldItemListTest.php;fp=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FModerationStateFieldItemListTest.php;h=6281ab82bfa0f18603bb42a08e8647911a380963;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=5a2f6a0b325559275b9fb3740f098bcf28c63907;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/web/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php index 5a2f6a0b3..6281ab82b 100644 --- a/web/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php +++ b/web/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php @@ -79,4 +79,49 @@ class ModerationStateFieldItemListTest extends KernelTestBase { $this->assertEquals(['draft'], $states); } + /** + * Tests that moderation state changes also change the related entity state. + */ + public function testModerationStateChanges() { + // Change the moderation state and check that the entity's + // 'isDefaultRevision' flag and the publishing status have also been + // updated. + $this->testNode->moderation_state->value = 'published'; + + $this->assertTrue($this->testNode->isPublished()); + $this->assertTrue($this->testNode->isDefaultRevision()); + + $this->testNode->save(); + + // Repeat the checks using an 'unpublished' state. + $this->testNode->moderation_state->value = 'draft'; + $this->assertFalse($this->testNode->isPublished()); + $this->assertFalse($this->testNode->isDefaultRevision()); + } + + /** + * Test updating the state for an entity without a workflow. + */ + public function testEntityWithNoWorkflow() { + $node_type = NodeType::create([ + 'type' => 'example_no_workflow', + ]); + $node_type->save(); + $test_node = Node::create([ + 'type' => 'example_no_workflow', + 'title' => 'Test node with no workflow', + ]); + $test_node->save(); + + /** @var \Drupal\content_moderation\ModerationInformationInterface $content_moderation_info */ + $content_moderation_info = \Drupal::service('content_moderation.moderation_information'); + $workflow = $content_moderation_info->getWorkflowForEntity($test_node); + $this->assertNull($workflow); + + $this->assertTrue($test_node->isPublished()); + $test_node->moderation_state->setValue('draft'); + // The entity is still published because there is not a workflow. + $this->assertTrue($test_node->isPublished()); + } + }