3 namespace Drupal\Tests\node\Functional\Views;
5 use Drupal\node\NodeInterface;
8 * Tests the node.status_extra field handler.
11 * @see \Drupal\node\Plugin\views\filter\Status
13 class StatusExtraTest extends NodeTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_status_extra'];
23 * Tests the status extra filter.
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']);
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]);
35 // Create one unpublished node by a certain author user.
36 $node_unpublished2 = $this->drupalCreateNode(['uid' => $node_author->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
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]);
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());
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());
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());
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());