X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FFunctional%2FLatestRevisionViewsFilterTest.php;fp=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FFunctional%2FLatestRevisionViewsFilterTest.php;h=cf14b23297efd36795892bbb20ccf507aa0b099f;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php b/web/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php new file mode 100644 index 000000000..cf14b2329 --- /dev/null +++ b/web/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php @@ -0,0 +1,130 @@ +createNodeType('Test', 'test'); + + $permissions = [ + 'access content', + 'view all revisions', + ]; + $editor1 = $this->drupalCreateUser($permissions); + + $this->drupalLogin($editor1); + + // Make a pre-moderation node. + /** @var Node $node_0 */ + $node_0 = Node::create([ + 'type' => 'test', + 'title' => 'Node 0 - Rev 1', + 'uid' => $editor1->id(), + ]); + $node_0->save(); + + // Now enable moderation for subsequent nodes. + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'test'); + $workflow->save(); + + // Make a node that is only ever in Draft. + /** @var Node $node_1 */ + $node_1 = Node::create([ + 'type' => 'test', + 'title' => 'Node 1 - Rev 1', + 'uid' => $editor1->id(), + ]); + $node_1->moderation_state->value = 'draft'; + $node_1->save(); + + // Make a node that is in Draft, then Published. + /** @var Node $node_2 */ + $node_2 = Node::create([ + 'type' => 'test', + 'title' => 'Node 2 - Rev 1', + 'uid' => $editor1->id(), + ]); + $node_2->moderation_state->value = 'draft'; + $node_2->save(); + + $node_2->setTitle('Node 2 - Rev 2'); + $node_2->moderation_state->value = 'published'; + $node_2->save(); + + // Make a node that is in Draft, then Published, then Draft. + /** @var Node $node_3 */ + $node_3 = Node::create([ + 'type' => 'test', + 'title' => 'Node 3 - Rev 1', + 'uid' => $editor1->id(), + ]); + $node_3->moderation_state->value = 'draft'; + $node_3->save(); + + $node_3->setTitle('Node 3 - Rev 2'); + $node_3->moderation_state->value = 'published'; + $node_3->save(); + + $node_3->setTitle('Node 3 - Rev 3'); + $node_3->moderation_state->value = 'draft'; + $node_3->save(); + + // Now show the View, and confirm that only the correct titles are showing. + $this->drupalGet('/latest'); + $page = $this->getSession()->getPage(); + $this->assertEquals(200, $this->getSession()->getStatusCode()); + $this->assertTrue($page->hasContent('Node 1 - Rev 1')); + $this->assertTrue($page->hasContent('Node 2 - Rev 2')); + $this->assertTrue($page->hasContent('Node 3 - Rev 3')); + $this->assertFalse($page->hasContent('Node 2 - Rev 1')); + $this->assertFalse($page->hasContent('Node 3 - Rev 1')); + $this->assertFalse($page->hasContent('Node 3 - Rev 2')); + $this->assertFalse($page->hasContent('Node 0 - Rev 1')); + } + + /** + * Creates a new node type. + * + * @param string $label + * The human-readable label of the type to create. + * @param string $machine_name + * The machine name of the type to create. + * + * @return NodeType + * The node type just created. + */ + protected function createNodeType($label, $machine_name) { + /** @var NodeType $node_type */ + $node_type = NodeType::create([ + 'type' => $machine_name, + 'label' => $label, + ]); + $node_type->save(); + + return $node_type; + } + +}