Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@0
|
4
|
Chris@18
|
5 use Drupal\Core\Database\Database;
|
Chris@0
|
6 use Drupal\user\RoleInterface;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests node administration page functionality.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group node
|
Chris@0
|
12 */
|
Chris@0
|
13 class NodeAdminTest extends NodeTestBase {
|
Chris@0
|
14 /**
|
Chris@0
|
15 * A user with permission to bypass access content.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var \Drupal\user\UserInterface
|
Chris@0
|
18 */
|
Chris@0
|
19 protected $adminUser;
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * A user with the 'access content overview' permission.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @var \Drupal\user\UserInterface
|
Chris@0
|
25 */
|
Chris@0
|
26 protected $baseUser1;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * A normal user with permission to view own unpublished content.
|
Chris@0
|
30 *
|
Chris@0
|
31 * @var \Drupal\user\UserInterface
|
Chris@0
|
32 */
|
Chris@0
|
33 protected $baseUser2;
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * A normal user with permission to bypass node access content.
|
Chris@0
|
37 *
|
Chris@0
|
38 * @var \Drupal\user\UserInterface
|
Chris@0
|
39 */
|
Chris@0
|
40 protected $baseUser3;
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * Modules to enable.
|
Chris@0
|
44 *
|
Chris@0
|
45 * @var array
|
Chris@0
|
46 */
|
Chris@0
|
47 public static $modules = ['views'];
|
Chris@0
|
48
|
Chris@0
|
49 protected function setUp() {
|
Chris@0
|
50 parent::setUp();
|
Chris@0
|
51
|
Chris@0
|
52 // Remove the "view own unpublished content" permission which is set
|
Chris@0
|
53 // by default for authenticated users so we can test this permission
|
Chris@0
|
54 // correctly.
|
Chris@0
|
55 user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, ['view own unpublished content']);
|
Chris@0
|
56
|
Chris@0
|
57 $this->adminUser = $this->drupalCreateUser(['access administration pages', 'access content overview', 'administer nodes', 'bypass node access']);
|
Chris@0
|
58 $this->baseUser1 = $this->drupalCreateUser(['access content overview']);
|
Chris@0
|
59 $this->baseUser2 = $this->drupalCreateUser(['access content overview', 'view own unpublished content']);
|
Chris@0
|
60 $this->baseUser3 = $this->drupalCreateUser(['access content overview', 'bypass node access']);
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 /**
|
Chris@0
|
64 * Tests that the table sorting works on the content admin pages.
|
Chris@0
|
65 */
|
Chris@0
|
66 public function testContentAdminSort() {
|
Chris@0
|
67 $this->drupalLogin($this->adminUser);
|
Chris@0
|
68
|
Chris@0
|
69 $changed = REQUEST_TIME;
|
Chris@18
|
70 $connection = Database::getConnection();
|
Chris@0
|
71 foreach (['dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB'] as $prefix) {
|
Chris@0
|
72 $changed += 1000;
|
Chris@0
|
73 $node = $this->drupalCreateNode(['title' => $prefix . $this->randomMachineName(6)]);
|
Chris@18
|
74 $connection->update('node_field_data')
|
Chris@0
|
75 ->fields(['changed' => $changed])
|
Chris@0
|
76 ->condition('nid', $node->id())
|
Chris@0
|
77 ->execute();
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 // Test that the default sort by node.changed DESC actually fires properly.
|
Chris@18
|
81 $nodes_query = $connection->select('node_field_data', 'n')
|
Chris@0
|
82 ->fields('n', ['title'])
|
Chris@0
|
83 ->orderBy('changed', 'DESC')
|
Chris@0
|
84 ->execute()
|
Chris@0
|
85 ->fetchCol();
|
Chris@0
|
86
|
Chris@0
|
87 $this->drupalGet('admin/content');
|
Chris@0
|
88 foreach ($nodes_query as $delta => $string) {
|
Chris@0
|
89 $elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]);
|
Chris@0
|
90 $this->assertTrue(!empty($elements), 'The node was found in the correct order.');
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 // Compare the rendered HTML node list to a query for the nodes ordered by
|
Chris@0
|
94 // title to account for possible database-dependent sort order.
|
Chris@18
|
95 $nodes_query = $connection->select('node_field_data', 'n')
|
Chris@0
|
96 ->fields('n', ['title'])
|
Chris@0
|
97 ->orderBy('title')
|
Chris@0
|
98 ->execute()
|
Chris@0
|
99 ->fetchCol();
|
Chris@0
|
100
|
Chris@0
|
101 $this->drupalGet('admin/content', ['query' => ['sort' => 'asc', 'order' => 'title']]);
|
Chris@0
|
102 foreach ($nodes_query as $delta => $string) {
|
Chris@0
|
103 $elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]);
|
Chris@0
|
104 $this->assertTrue(!empty($elements), 'The node was found in the correct order.');
|
Chris@0
|
105 }
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Tests content overview with different user permissions.
|
Chris@0
|
110 *
|
Chris@0
|
111 * Taxonomy filters are tested separately.
|
Chris@0
|
112 *
|
Chris@0
|
113 * @see TaxonomyNodeFilterTestCase
|
Chris@0
|
114 */
|
Chris@0
|
115 public function testContentAdminPages() {
|
Chris@0
|
116 $this->drupalLogin($this->adminUser);
|
Chris@0
|
117
|
Chris@0
|
118 // Use an explicit changed time to ensure the expected order in the content
|
Chris@0
|
119 // admin listing. We want these to appear in the table in the same order as
|
Chris@0
|
120 // they appear in the following code, and the 'content' View has a table
|
Chris@0
|
121 // style configuration with a default sort on the 'changed' field DESC.
|
Chris@0
|
122 $time = time();
|
Chris@0
|
123 $nodes['published_page'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--]);
|
Chris@0
|
124 $nodes['published_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--]);
|
Chris@0
|
125 $nodes['unpublished_page_1'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--, 'uid' => $this->baseUser1->id(), 'status' => 0]);
|
Chris@0
|
126 $nodes['unpublished_page_2'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time, 'uid' => $this->baseUser2->id(), 'status' => 0]);
|
Chris@0
|
127
|
Chris@0
|
128 // Verify view, edit, and delete links for any content.
|
Chris@0
|
129 $this->drupalGet('admin/content');
|
Chris@0
|
130 $this->assertResponse(200);
|
Chris@0
|
131
|
Chris@0
|
132 $node_type_labels = $this->xpath('//td[contains(@class, "views-field-type")]');
|
Chris@0
|
133 $delta = 0;
|
Chris@0
|
134 foreach ($nodes as $node) {
|
Chris@0
|
135 $this->assertLinkByHref('node/' . $node->id());
|
Chris@0
|
136 $this->assertLinkByHref('node/' . $node->id() . '/edit');
|
Chris@0
|
137 $this->assertLinkByHref('node/' . $node->id() . '/delete');
|
Chris@0
|
138 // Verify that we can see the content type label.
|
Chris@0
|
139 $this->assertEqual(trim($node_type_labels[$delta]->getText()), $node->type->entity->label());
|
Chris@0
|
140 $delta++;
|
Chris@0
|
141 }
|
Chris@0
|
142
|
Chris@0
|
143 // Verify filtering by publishing status.
|
Chris@0
|
144 $this->drupalGet('admin/content', ['query' => ['status' => TRUE]]);
|
Chris@0
|
145
|
Chris@0
|
146 $this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit');
|
Chris@0
|
147 $this->assertLinkByHref('node/' . $nodes['published_article']->id() . '/edit');
|
Chris@0
|
148 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit');
|
Chris@0
|
149
|
Chris@0
|
150 // Verify filtering by status and content type.
|
Chris@0
|
151 $this->drupalGet('admin/content', ['query' => ['status' => TRUE, 'type' => 'page']]);
|
Chris@0
|
152
|
Chris@0
|
153 $this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit');
|
Chris@0
|
154 $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/edit');
|
Chris@0
|
155
|
Chris@0
|
156 // Verify no operation links are displayed for regular users.
|
Chris@0
|
157 $this->drupalLogout();
|
Chris@0
|
158 $this->drupalLogin($this->baseUser1);
|
Chris@0
|
159 $this->drupalGet('admin/content');
|
Chris@0
|
160 $this->assertResponse(200);
|
Chris@0
|
161 $this->assertLinkByHref('node/' . $nodes['published_page']->id());
|
Chris@0
|
162 $this->assertLinkByHref('node/' . $nodes['published_article']->id());
|
Chris@0
|
163 $this->assertNoLinkByHref('node/' . $nodes['published_page']->id() . '/edit');
|
Chris@0
|
164 $this->assertNoLinkByHref('node/' . $nodes['published_page']->id() . '/delete');
|
Chris@0
|
165 $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/edit');
|
Chris@0
|
166 $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/delete');
|
Chris@0
|
167
|
Chris@0
|
168 // Verify no unpublished content is displayed without permission.
|
Chris@0
|
169 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id());
|
Chris@0
|
170 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit');
|
Chris@0
|
171 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/delete');
|
Chris@0
|
172
|
Chris@0
|
173 // Verify no tableselect.
|
Chris@0
|
174 $this->assertNoFieldByName('nodes[' . $nodes['published_page']->id() . ']', '', 'No tableselect found.');
|
Chris@0
|
175
|
Chris@0
|
176 // Verify unpublished content is displayed with permission.
|
Chris@0
|
177 $this->drupalLogout();
|
Chris@0
|
178 $this->drupalLogin($this->baseUser2);
|
Chris@0
|
179 $this->drupalGet('admin/content');
|
Chris@0
|
180 $this->assertResponse(200);
|
Chris@0
|
181 $this->assertLinkByHref('node/' . $nodes['unpublished_page_2']->id());
|
Chris@0
|
182 // Verify no operation links are displayed.
|
Chris@0
|
183 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->id() . '/edit');
|
Chris@0
|
184 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->id() . '/delete');
|
Chris@0
|
185
|
Chris@0
|
186 // Verify user cannot see unpublished content of other users.
|
Chris@0
|
187 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id());
|
Chris@0
|
188 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit');
|
Chris@0
|
189 $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/delete');
|
Chris@0
|
190
|
Chris@0
|
191 // Verify no tableselect.
|
Chris@0
|
192 $this->assertNoFieldByName('nodes[' . $nodes['unpublished_page_2']->id() . ']', '', 'No tableselect found.');
|
Chris@0
|
193
|
Chris@0
|
194 // Verify node access can be bypassed.
|
Chris@0
|
195 $this->drupalLogout();
|
Chris@0
|
196 $this->drupalLogin($this->baseUser3);
|
Chris@0
|
197 $this->drupalGet('admin/content');
|
Chris@0
|
198 $this->assertResponse(200);
|
Chris@0
|
199 foreach ($nodes as $node) {
|
Chris@0
|
200 $this->assertLinkByHref('node/' . $node->id());
|
Chris@0
|
201 $this->assertLinkByHref('node/' . $node->id() . '/edit');
|
Chris@0
|
202 $this->assertLinkByHref('node/' . $node->id() . '/delete');
|
Chris@0
|
203 }
|
Chris@0
|
204 }
|
Chris@0
|
205
|
Chris@0
|
206 }
|