Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / StatusExtraTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional\Views;
4
5 use Drupal\node\NodeInterface;
6
7 /**
8  * Tests the node.status_extra field handler.
9  *
10  * @group node
11  * @see \Drupal\node\Plugin\views\filter\Status
12  */
13 class StatusExtraTest extends NodeTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_status_extra'];
21
22   /**
23    * Tests the status extra filter.
24    */
25   public function testStatusExtra() {
26     $node_author = $this->drupalCreateUser(['view own unpublished content']);
27     $node_author_not_unpublished = $this->drupalCreateUser();
28     $normal_user = $this->drupalCreateUser();
29     $admin_user = $this->drupalCreateUser(['bypass node access']);
30
31     // Create one published and one unpublished node by the admin.
32     $node_published = $this->drupalCreateNode(['uid' => $admin_user->id()]);
33     $node_unpublished = $this->drupalCreateNode(['uid' => $admin_user->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
34
35     // Create one unpublished node by a certain author user.
36     $node_unpublished2 = $this->drupalCreateNode(['uid' => $node_author->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
37
38     // Create one unpublished node by a user who does not have the `view own
39     // unpublished content` permission.
40     $node_unpublished3 = $this->drupalCreateNode(['uid' => $node_author_not_unpublished->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
41
42     // The administrator should simply see all nodes.
43     $this->drupalLogin($admin_user);
44     $this->drupalGet('test_status_extra');
45     $this->assertText($node_published->label());
46     $this->assertText($node_unpublished->label());
47     $this->assertText($node_unpublished2->label());
48     $this->assertText($node_unpublished3->label());
49
50     // The node author should see the published node and his own node.
51     $this->drupalLogin($node_author);
52     $this->drupalGet('test_status_extra');
53     $this->assertText($node_published->label());
54     $this->assertNoText($node_unpublished->label());
55     $this->assertText($node_unpublished2->label());
56     $this->assertNoText($node_unpublished3->label());
57
58     // The normal user should just see the published node.
59     $this->drupalLogin($normal_user);
60     $this->drupalGet('test_status_extra');
61     $this->assertText($node_published->label());
62     $this->assertNoText($node_unpublished->label());
63     $this->assertNoText($node_unpublished2->label());
64     $this->assertNoText($node_unpublished3->label());
65
66     // The author without the permission to see his own unpublished node should
67     // just see the published node.
68     $this->drupalLogin($node_author_not_unpublished);
69     $this->drupalGet('test_status_extra');
70     $this->assertText($node_published->label());
71     $this->assertNoText($node_unpublished->label());
72     $this->assertNoText($node_unpublished2->label());
73     $this->assertNoText($node_unpublished3->label());
74   }
75
76 }