3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\workflows\Entity\Workflow;
11 * Tests the "Latest Revision" views filter.
13 * @group content_moderation
15 class LatestRevisionViewsFilterTest extends BrowserTestBase {
20 public static $modules = [
21 'content_moderation_test_views',
26 * Tests view shows the correct node IDs.
28 public function testViewShowsCorrectNids() {
29 $this->createNodeType('Test', 'test');
35 $editor1 = $this->drupalCreateUser($permissions);
37 $this->drupalLogin($editor1);
39 // Make a pre-moderation node.
40 /** @var Node $node_0 */
41 $node_0 = Node::create([
43 'title' => 'Node 0 - Rev 1',
44 'uid' => $editor1->id(),
48 // Now enable moderation for subsequent nodes.
49 $workflow = Workflow::load('editorial');
50 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'test');
53 // Make a node that is only ever in Draft.
54 /** @var Node $node_1 */
55 $node_1 = Node::create([
57 'title' => 'Node 1 - Rev 1',
58 'uid' => $editor1->id(),
60 $node_1->moderation_state->value = 'draft';
63 // Make a node that is in Draft, then Published.
64 /** @var Node $node_2 */
65 $node_2 = Node::create([
67 'title' => 'Node 2 - Rev 1',
68 'uid' => $editor1->id(),
70 $node_2->moderation_state->value = 'draft';
73 $node_2->setTitle('Node 2 - Rev 2');
74 $node_2->moderation_state->value = 'published';
77 // Make a node that is in Draft, then Published, then Draft.
78 /** @var Node $node_3 */
79 $node_3 = Node::create([
81 'title' => 'Node 3 - Rev 1',
82 'uid' => $editor1->id(),
84 $node_3->moderation_state->value = 'draft';
87 $node_3->setTitle('Node 3 - Rev 2');
88 $node_3->moderation_state->value = 'published';
91 $node_3->setTitle('Node 3 - Rev 3');
92 $node_3->moderation_state->value = 'draft';
95 // Now show the View, and confirm that only the correct titles are showing.
96 $this->drupalGet('/latest');
97 $page = $this->getSession()->getPage();
98 $this->assertEquals(200, $this->getSession()->getStatusCode());
99 $this->assertTrue($page->hasContent('Node 1 - Rev 1'));
100 $this->assertTrue($page->hasContent('Node 2 - Rev 2'));
101 $this->assertTrue($page->hasContent('Node 3 - Rev 3'));
102 $this->assertFalse($page->hasContent('Node 2 - Rev 1'));
103 $this->assertFalse($page->hasContent('Node 3 - Rev 1'));
104 $this->assertFalse($page->hasContent('Node 3 - Rev 2'));
105 $this->assertFalse($page->hasContent('Node 0 - Rev 1'));
109 * Creates a new node type.
111 * @param string $label
112 * The human-readable label of the type to create.
113 * @param string $machine_name
114 * The machine name of the type to create.
117 * The node type just created.
119 protected function createNodeType($label, $machine_name) {
120 /** @var NodeType $node_type */
121 $node_type = NodeType::create([
122 'type' => $machine_name,