Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\tracker\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\comment\CommentInterface;
|
Chris@0
|
6 use Drupal\comment\Tests\CommentTestTrait;
|
Chris@0
|
7 use Drupal\Core\Cache\Cache;
|
Chris@18
|
8 use Drupal\Core\Database\Database;
|
Chris@0
|
9 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
Chris@0
|
10 use Drupal\Core\Session\AccountInterface;
|
Chris@0
|
11 use Drupal\field\Entity\FieldStorageConfig;
|
Chris@0
|
12 use Drupal\node\Entity\Node;
|
Chris@0
|
13 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
14 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Create and delete nodes and check for their display in the tracker listings.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @group tracker
|
Chris@0
|
20 */
|
Chris@0
|
21 class TrackerTest extends BrowserTestBase {
|
Chris@0
|
22
|
Chris@0
|
23 use CommentTestTrait;
|
Chris@0
|
24 use AssertPageCacheContextsAndTagsTrait;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Modules to enable.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @var array
|
Chris@0
|
30 */
|
Chris@0
|
31 public static $modules = ['block', 'comment', 'tracker', 'history', 'node_test'];
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * The main user for testing.
|
Chris@0
|
35 *
|
Chris@0
|
36 * @var \Drupal\user\UserInterface
|
Chris@0
|
37 */
|
Chris@0
|
38 protected $user;
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * A second user that will 'create' comments and nodes.
|
Chris@0
|
42 *
|
Chris@0
|
43 * @var \Drupal\user\UserInterface
|
Chris@0
|
44 */
|
Chris@0
|
45 protected $otherUser;
|
Chris@0
|
46
|
Chris@0
|
47 protected function setUp() {
|
Chris@0
|
48 parent::setUp();
|
Chris@0
|
49
|
Chris@0
|
50 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
Chris@0
|
51
|
Chris@0
|
52 $permissions = ['access comments', 'create page content', 'post comments', 'skip comment approval'];
|
Chris@0
|
53 $this->user = $this->drupalCreateUser($permissions);
|
Chris@0
|
54 $this->otherUser = $this->drupalCreateUser($permissions);
|
Chris@0
|
55 $this->addDefaultCommentField('node', 'page');
|
Chris@0
|
56 user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
|
Chris@0
|
57 'access content',
|
Chris@0
|
58 'access user profiles',
|
Chris@0
|
59 ]);
|
Chris@0
|
60 $this->drupalPlaceBlock('local_tasks_block', ['id' => 'page_tabs_block']);
|
Chris@0
|
61 $this->drupalPlaceBlock('local_actions_block', ['id' => 'page_actions_block']);
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * Tests for the presence of nodes on the global tracker listing.
|
Chris@0
|
66 */
|
Chris@0
|
67 public function testTrackerAll() {
|
Chris@0
|
68 $this->drupalLogin($this->user);
|
Chris@0
|
69
|
Chris@0
|
70 $unpublished = $this->drupalCreateNode([
|
Chris@0
|
71 'title' => $this->randomMachineName(8),
|
Chris@0
|
72 'status' => 0,
|
Chris@0
|
73 ]);
|
Chris@0
|
74 $published = $this->drupalCreateNode([
|
Chris@0
|
75 'title' => $this->randomMachineName(8),
|
Chris@0
|
76 'status' => 1,
|
Chris@0
|
77 ]);
|
Chris@0
|
78
|
Chris@0
|
79 $this->drupalGet('activity');
|
Chris@0
|
80 $this->assertNoText($unpublished->label(), 'Unpublished node does not show up in the tracker listing.');
|
Chris@0
|
81 $this->assertText($published->label(), 'Published node shows up in the tracker listing.');
|
Chris@0
|
82 $this->assertLink(t('My recent content'), 0, 'User tab shows up on the global tracker page.');
|
Chris@0
|
83
|
Chris@0
|
84 // Assert cache contexts, specifically the pager and node access contexts.
|
Chris@0
|
85 $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'url.query_args.pagers:0', 'user.node_grants:view', 'user']);
|
Chris@0
|
86 // Assert cache tags for the action/tabs blocks, visible node, and node list
|
Chris@0
|
87 // cache tag.
|
Chris@0
|
88 $expected_tags = Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags());
|
Chris@0
|
89 // Because the 'user.permissions' cache context is being optimized away.
|
Chris@0
|
90 $role_tags = [];
|
Chris@0
|
91 foreach ($this->user->getRoles() as $rid) {
|
Chris@0
|
92 $role_tags[] = "config:user.role.$rid";
|
Chris@0
|
93 }
|
Chris@0
|
94 $expected_tags = Cache::mergeTags($expected_tags, $role_tags);
|
Chris@0
|
95 $block_tags = [
|
Chris@0
|
96 'block_view',
|
Chris@17
|
97 'local_task',
|
Chris@0
|
98 'config:block.block.page_actions_block',
|
Chris@0
|
99 'config:block.block.page_tabs_block',
|
Chris@0
|
100 'config:block_list',
|
Chris@0
|
101 ];
|
Chris@0
|
102 $expected_tags = Cache::mergeTags($expected_tags, $block_tags);
|
Chris@0
|
103 $additional_tags = [
|
Chris@0
|
104 'node_list',
|
Chris@0
|
105 'rendered',
|
Chris@0
|
106 ];
|
Chris@0
|
107 $expected_tags = Cache::mergeTags($expected_tags, $additional_tags);
|
Chris@0
|
108 $this->assertCacheTags($expected_tags);
|
Chris@0
|
109
|
Chris@0
|
110 // Delete a node and ensure it no longer appears on the tracker.
|
Chris@0
|
111 $published->delete();
|
Chris@0
|
112 $this->drupalGet('activity');
|
Chris@0
|
113 $this->assertNoText($published->label(), 'Deleted node does not show up in the tracker listing.');
|
Chris@0
|
114
|
Chris@0
|
115 // Test proper display of time on activity page when comments are disabled.
|
Chris@0
|
116 // Disable comments.
|
Chris@0
|
117 FieldStorageConfig::loadByName('node', 'comment')->delete();
|
Chris@0
|
118 $node = $this->drupalCreateNode([
|
Chris@0
|
119 // This title is required to trigger the custom changed time set in the
|
Chris@0
|
120 // node_test module. This is needed in order to ensure a sufficiently
|
Chris@0
|
121 // large 'time ago' interval that isn't numbered in seconds.
|
Chris@0
|
122 'title' => 'testing_node_presave',
|
Chris@0
|
123 'status' => 1,
|
Chris@0
|
124 ]);
|
Chris@0
|
125
|
Chris@0
|
126 $this->drupalGet('activity');
|
Chris@0
|
127 $this->assertText($node->label(), 'Published node shows up in the tracker listing.');
|
Chris@0
|
128 $this->assertText(\Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime()), 'The changed time was displayed on the tracker listing.');
|
Chris@0
|
129 }
|
Chris@0
|
130
|
Chris@0
|
131 /**
|
Chris@0
|
132 * Tests for the presence of nodes on a user's tracker listing.
|
Chris@0
|
133 */
|
Chris@0
|
134 public function testTrackerUser() {
|
Chris@0
|
135 $this->drupalLogin($this->user);
|
Chris@0
|
136
|
Chris@0
|
137 $unpublished = $this->drupalCreateNode([
|
Chris@0
|
138 'title' => $this->randomMachineName(8),
|
Chris@0
|
139 'uid' => $this->user->id(),
|
Chris@0
|
140 'status' => 0,
|
Chris@0
|
141 ]);
|
Chris@0
|
142 $my_published = $this->drupalCreateNode([
|
Chris@0
|
143 'title' => $this->randomMachineName(8),
|
Chris@0
|
144 'uid' => $this->user->id(),
|
Chris@0
|
145 'status' => 1,
|
Chris@0
|
146 ]);
|
Chris@0
|
147 $other_published_no_comment = $this->drupalCreateNode([
|
Chris@0
|
148 'title' => $this->randomMachineName(8),
|
Chris@0
|
149 'uid' => $this->otherUser->id(),
|
Chris@0
|
150 'status' => 1,
|
Chris@0
|
151 ]);
|
Chris@0
|
152 $other_published_my_comment = $this->drupalCreateNode([
|
Chris@0
|
153 'title' => $this->randomMachineName(8),
|
Chris@0
|
154 'uid' => $this->otherUser->id(),
|
Chris@0
|
155 'status' => 1,
|
Chris@0
|
156 ]);
|
Chris@0
|
157 $comment = [
|
Chris@0
|
158 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
159 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
160 ];
|
Chris@0
|
161 $this->drupalPostForm('comment/reply/node/' . $other_published_my_comment->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
162
|
Chris@0
|
163 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
164 $this->assertNoText($unpublished->label(), "Unpublished nodes do not show up in the user's tracker listing.");
|
Chris@0
|
165 $this->assertText($my_published->label(), "Published nodes show up in the user's tracker listing.");
|
Chris@0
|
166 $this->assertNoText($other_published_no_comment->label(), "Another user's nodes do not show up in the user's tracker listing.");
|
Chris@0
|
167 $this->assertText($other_published_my_comment->label(), "Nodes that the user has commented on appear in the user's tracker listing.");
|
Chris@0
|
168
|
Chris@0
|
169 // Assert cache contexts.
|
Chris@0
|
170 $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'url.query_args.pagers:0', 'user', 'user.node_grants:view']);
|
Chris@0
|
171 // Assert cache tags for the visible nodes (including owners) and node list
|
Chris@0
|
172 // cache tag.
|
Chris@0
|
173 $expected_tags = Cache::mergeTags($my_published->getCacheTags(), $my_published->getOwner()->getCacheTags());
|
Chris@0
|
174 $expected_tags = Cache::mergeTags($expected_tags, $other_published_my_comment->getCacheTags());
|
Chris@0
|
175 $expected_tags = Cache::mergeTags($expected_tags, $other_published_my_comment->getOwner()->getCacheTags());
|
Chris@0
|
176 // Because the 'user.permissions' cache context is being optimized away.
|
Chris@0
|
177 $role_tags = [];
|
Chris@0
|
178 foreach ($this->user->getRoles() as $rid) {
|
Chris@0
|
179 $role_tags[] = "config:user.role.$rid";
|
Chris@0
|
180 }
|
Chris@0
|
181 $expected_tags = Cache::mergeTags($expected_tags, $role_tags);
|
Chris@0
|
182 $block_tags = [
|
Chris@0
|
183 'block_view',
|
Chris@17
|
184 'local_task',
|
Chris@0
|
185 'config:block.block.page_actions_block',
|
Chris@0
|
186 'config:block.block.page_tabs_block',
|
Chris@0
|
187 'config:block_list',
|
Chris@0
|
188 ];
|
Chris@0
|
189 $expected_tags = Cache::mergeTags($expected_tags, $block_tags);
|
Chris@0
|
190 $additional_tags = [
|
Chris@0
|
191 'node_list',
|
Chris@0
|
192 'rendered',
|
Chris@0
|
193 ];
|
Chris@0
|
194 $expected_tags = Cache::mergeTags($expected_tags, $additional_tags);
|
Chris@0
|
195
|
Chris@0
|
196 $this->assertCacheTags($expected_tags);
|
Chris@0
|
197 $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'url.query_args.pagers:0', 'user', 'user.node_grants:view']);
|
Chris@0
|
198
|
Chris@0
|
199 $this->assertLink($my_published->label());
|
Chris@0
|
200 $this->assertNoLink($unpublished->label());
|
Chris@0
|
201 // Verify that title and tab title have been set correctly.
|
Chris@0
|
202 $this->assertText('Activity', 'The user activity tab has the name "Activity".');
|
Chris@18
|
203 $this->assertTitle(t('@name | @site', ['@name' => $this->user->getAccountName(), '@site' => $this->config('system.site')->get('name')]), 'The user tracker page has the correct page title.');
|
Chris@0
|
204
|
Chris@0
|
205 // Verify that unpublished comments are removed from the tracker.
|
Chris@0
|
206 $admin_user = $this->drupalCreateUser(['post comments', 'administer comments', 'access user profiles']);
|
Chris@0
|
207 $this->drupalLogin($admin_user);
|
Chris@0
|
208 $this->drupalPostForm('comment/1/edit', ['status' => CommentInterface::NOT_PUBLISHED], t('Save'));
|
Chris@0
|
209 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
210 $this->assertNoText($other_published_my_comment->label(), 'Unpublished comments are not counted on the tracker listing.');
|
Chris@0
|
211
|
Chris@0
|
212 // Test escaping of title on user's tracker tab.
|
Chris@0
|
213 \Drupal::service('module_installer')->install(['user_hooks_test']);
|
Chris@0
|
214 Cache::invalidateTags(['rendered']);
|
Chris@0
|
215 \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
|
Chris@0
|
216 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
217 $this->assertEscaped('<em>' . $this->user->id() . '</em>');
|
Chris@0
|
218
|
Chris@0
|
219 \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
|
Chris@0
|
220 Cache::invalidateTags(['rendered']);
|
Chris@0
|
221 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
222 $this->assertNoEscaped('<em>' . $this->user->id() . '</em>');
|
Chris@0
|
223 $this->assertRaw('<em>' . $this->user->id() . '</em>');
|
Chris@0
|
224 }
|
Chris@0
|
225
|
Chris@0
|
226 /**
|
Chris@0
|
227 * Tests the metadata for the "new"/"updated" indicators.
|
Chris@0
|
228 */
|
Chris@0
|
229 public function testTrackerHistoryMetadata() {
|
Chris@0
|
230 $this->drupalLogin($this->user);
|
Chris@0
|
231
|
Chris@0
|
232 // Create a page node.
|
Chris@0
|
233 $edit = [
|
Chris@0
|
234 'title' => $this->randomMachineName(8),
|
Chris@0
|
235 ];
|
Chris@0
|
236 $node = $this->drupalCreateNode($edit);
|
Chris@0
|
237
|
Chris@0
|
238 // Verify that the history metadata is present.
|
Chris@0
|
239 $this->drupalGet('activity');
|
Chris@0
|
240 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
|
Chris@0
|
241 $this->drupalGet('activity/' . $this->user->id());
|
Chris@0
|
242 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
|
Chris@0
|
243 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
244 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
|
Chris@0
|
245
|
Chris@0
|
246 // Add a comment to the page, make sure it is created after the node by
|
Chris@0
|
247 // sleeping for one second, to ensure the last comment timestamp is
|
Chris@0
|
248 // different from before.
|
Chris@0
|
249 $comment = [
|
Chris@0
|
250 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
251 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
252 ];
|
Chris@0
|
253 sleep(1);
|
Chris@0
|
254 $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
255 // Reload the node so that comment.module's hook_node_load()
|
Chris@0
|
256 // implementation can set $node->last_comment_timestamp for the freshly
|
Chris@0
|
257 // posted comment.
|
Chris@0
|
258 $node = Node::load($node->id());
|
Chris@0
|
259
|
Chris@0
|
260 // Verify that the history metadata is updated.
|
Chris@0
|
261 $this->drupalGet('activity');
|
Chris@0
|
262 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
|
Chris@0
|
263 $this->drupalGet('activity/' . $this->user->id());
|
Chris@0
|
264 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
|
Chris@0
|
265 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
266 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
|
Chris@0
|
267
|
Chris@0
|
268 // Log out, now verify that the metadata is still there, but the library is
|
Chris@0
|
269 // not.
|
Chris@0
|
270 $this->drupalLogout();
|
Chris@0
|
271 $this->drupalGet('activity');
|
Chris@0
|
272 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp, FALSE);
|
Chris@0
|
273 $this->drupalGet('user/' . $this->user->id() . '/activity');
|
Chris@0
|
274 $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp, FALSE);
|
Chris@0
|
275 }
|
Chris@0
|
276
|
Chris@0
|
277 /**
|
Chris@0
|
278 * Tests for ordering on a users tracker listing when comments are posted.
|
Chris@0
|
279 */
|
Chris@0
|
280 public function testTrackerOrderingNewComments() {
|
Chris@0
|
281 $this->drupalLogin($this->user);
|
Chris@0
|
282
|
Chris@0
|
283 $node_one = $this->drupalCreateNode([
|
Chris@0
|
284 'title' => $this->randomMachineName(8),
|
Chris@0
|
285 ]);
|
Chris@0
|
286
|
Chris@0
|
287 $node_two = $this->drupalCreateNode([
|
Chris@0
|
288 'title' => $this->randomMachineName(8),
|
Chris@0
|
289 ]);
|
Chris@0
|
290
|
Chris@0
|
291 // Now get otherUser to track these pieces of content.
|
Chris@0
|
292 $this->drupalLogin($this->otherUser);
|
Chris@0
|
293
|
Chris@0
|
294 // Add a comment to the first page.
|
Chris@0
|
295 $comment = [
|
Chris@0
|
296 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
297 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
298 ];
|
Chris@0
|
299 $this->drupalPostForm('comment/reply/node/' . $node_one->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
300
|
Chris@0
|
301 // If the comment is posted in the same second as the last one then Drupal
|
Chris@0
|
302 // can't tell the difference, so we wait one second here.
|
Chris@0
|
303 sleep(1);
|
Chris@0
|
304
|
Chris@0
|
305 // Add a comment to the second page.
|
Chris@0
|
306 $comment = [
|
Chris@0
|
307 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
308 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
309 ];
|
Chris@0
|
310 $this->drupalPostForm('comment/reply/node/' . $node_two->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
311
|
Chris@0
|
312 // We should at this point have in our tracker for otherUser:
|
Chris@0
|
313 // 1. node_two
|
Chris@0
|
314 // 2. node_one
|
Chris@0
|
315 // Because that's the reverse order of the posted comments.
|
Chris@0
|
316
|
Chris@0
|
317 // Now we're going to post a comment to node_one which should jump it to the
|
Chris@0
|
318 // top of the list.
|
Chris@0
|
319
|
Chris@0
|
320 $this->drupalLogin($this->user);
|
Chris@0
|
321 // If the comment is posted in the same second as the last one then Drupal
|
Chris@0
|
322 // can't tell the difference, so we wait one second here.
|
Chris@0
|
323 sleep(1);
|
Chris@0
|
324
|
Chris@0
|
325 // Add a comment to the second page.
|
Chris@0
|
326 $comment = [
|
Chris@0
|
327 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
328 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
329 ];
|
Chris@0
|
330 $this->drupalPostForm('comment/reply/node/' . $node_one->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
331
|
Chris@0
|
332 // Switch back to the otherUser and assert that the order has swapped.
|
Chris@0
|
333 $this->drupalLogin($this->otherUser);
|
Chris@0
|
334 $this->drupalGet('user/' . $this->otherUser->id() . '/activity');
|
Chris@0
|
335 // This is a cheeky way of asserting that the nodes are in the right order
|
Chris@0
|
336 // on the tracker page.
|
Chris@0
|
337 // It's almost certainly too brittle.
|
Chris@0
|
338 $pattern = '/' . preg_quote($node_one->getTitle()) . '.+' . preg_quote($node_two->getTitle()) . '/s';
|
Chris@0
|
339 $this->verbose($pattern);
|
Chris@0
|
340 $this->assertPattern($pattern, 'Most recently commented on node appears at the top of tracker');
|
Chris@0
|
341 }
|
Chris@0
|
342
|
Chris@0
|
343 /**
|
Chris@0
|
344 * Tests that existing nodes are indexed by cron.
|
Chris@0
|
345 */
|
Chris@0
|
346 public function testTrackerCronIndexing() {
|
Chris@0
|
347 $this->drupalLogin($this->user);
|
Chris@0
|
348
|
Chris@0
|
349 // Create 3 nodes.
|
Chris@0
|
350 $edits = [];
|
Chris@0
|
351 $nodes = [];
|
Chris@0
|
352 for ($i = 1; $i <= 3; $i++) {
|
Chris@0
|
353 $edits[$i] = [
|
Chris@0
|
354 'title' => $this->randomMachineName(),
|
Chris@0
|
355 ];
|
Chris@0
|
356 $nodes[$i] = $this->drupalCreateNode($edits[$i]);
|
Chris@0
|
357 }
|
Chris@0
|
358
|
Chris@0
|
359 // Add a comment to the last node as other user.
|
Chris@0
|
360 $this->drupalLogin($this->otherUser);
|
Chris@0
|
361 $comment = [
|
Chris@0
|
362 'subject[0][value]' => $this->randomMachineName(),
|
Chris@0
|
363 'comment_body[0][value]' => $this->randomMachineName(20),
|
Chris@0
|
364 ];
|
Chris@0
|
365 $this->drupalPostForm('comment/reply/node/' . $nodes[3]->id() . '/comment', $comment, t('Save'));
|
Chris@0
|
366
|
Chris@16
|
367 // Create an unpublished node.
|
Chris@16
|
368 $unpublished = $this->drupalCreateNode([
|
Chris@16
|
369 'title' => $this->randomMachineName(8),
|
Chris@16
|
370 'status' => 0,
|
Chris@16
|
371 ]);
|
Chris@16
|
372
|
Chris@16
|
373 // Start indexing backwards from node 4.
|
Chris@16
|
374 \Drupal::state()->set('tracker.index_nid', 4);
|
Chris@0
|
375
|
Chris@0
|
376 // Clear the current tracker tables and rebuild them.
|
Chris@18
|
377 $connection = Database::getConnection();
|
Chris@18
|
378 $connection->delete('tracker_node')
|
Chris@0
|
379 ->execute();
|
Chris@18
|
380 $connection->delete('tracker_user')
|
Chris@0
|
381 ->execute();
|
Chris@0
|
382 tracker_cron();
|
Chris@0
|
383
|
Chris@0
|
384 $this->drupalLogin($this->user);
|
Chris@0
|
385
|
Chris@0
|
386 // Fetch the user's tracker.
|
Chris@0
|
387 $this->drupalGet('activity/' . $this->user->id());
|
Chris@0
|
388
|
Chris@0
|
389 // Assert that all node titles are displayed.
|
Chris@0
|
390 foreach ($nodes as $i => $node) {
|
Chris@0
|
391 $this->assertText($node->label(), format_string('Node @i is displayed on the tracker listing pages.', ['@i' => $i]));
|
Chris@0
|
392 }
|
Chris@0
|
393
|
Chris@0
|
394 // Fetch the site-wide tracker.
|
Chris@0
|
395 $this->drupalGet('activity');
|
Chris@0
|
396
|
Chris@0
|
397 // Assert that all node titles are displayed.
|
Chris@0
|
398 foreach ($nodes as $i => $node) {
|
Chris@0
|
399 $this->assertText($node->label(), format_string('Node @i is displayed on the tracker listing pages.', ['@i' => $i]));
|
Chris@0
|
400 }
|
Chris@0
|
401 }
|
Chris@0
|
402
|
Chris@0
|
403 /**
|
Chris@0
|
404 * Tests that publish/unpublish works at admin/content/node.
|
Chris@0
|
405 */
|
Chris@0
|
406 public function testTrackerAdminUnpublish() {
|
Chris@0
|
407 \Drupal::service('module_installer')->install(['views']);
|
Chris@0
|
408 \Drupal::service('router.builder')->rebuild();
|
Chris@0
|
409 $admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']);
|
Chris@0
|
410 $this->drupalLogin($admin_user);
|
Chris@0
|
411
|
Chris@0
|
412 $node = $this->drupalCreateNode([
|
Chris@0
|
413 'title' => $this->randomMachineName(),
|
Chris@0
|
414 ]);
|
Chris@0
|
415
|
Chris@0
|
416 // Assert that the node is displayed.
|
Chris@0
|
417 $this->drupalGet('activity');
|
Chris@0
|
418 $this->assertText($node->label(), 'A node is displayed on the tracker listing pages.');
|
Chris@0
|
419
|
Chris@0
|
420 // Unpublish the node and ensure that it's no longer displayed.
|
Chris@0
|
421 $edit = [
|
Chris@0
|
422 'action' => 'node_unpublish_action',
|
Chris@0
|
423 'node_bulk_form[0]' => $node->id(),
|
Chris@0
|
424 ];
|
Chris@0
|
425 $this->drupalPostForm('admin/content', $edit, t('Apply to selected items'));
|
Chris@0
|
426
|
Chris@0
|
427 $this->drupalGet('activity');
|
Chris@0
|
428 $this->assertText(t('No content available.'), 'A node is displayed on the tracker listing pages.');
|
Chris@0
|
429 }
|
Chris@0
|
430
|
Chris@0
|
431 /**
|
Chris@0
|
432 * Passes if the appropriate history metadata exists.
|
Chris@0
|
433 *
|
Chris@0
|
434 * Verify the data-history-node-id, data-history-node-timestamp and
|
Chris@0
|
435 * data-history-node-last-comment-timestamp attributes, which are used by the
|
Chris@0
|
436 * drupal.tracker-history library to add the appropriate "new" and "updated"
|
Chris@0
|
437 * indicators, as well as the "x new" replies link to the tracker.
|
Chris@0
|
438 * We do this in JavaScript to prevent breaking the render cache.
|
Chris@0
|
439 *
|
Chris@0
|
440 * @param int $node_id
|
Chris@0
|
441 * A node ID, that must exist as a data-history-node-id attribute
|
Chris@0
|
442 * @param int $node_timestamp
|
Chris@0
|
443 * A node timestamp, that must exist as a data-history-node-timestamp
|
Chris@0
|
444 * attribute.
|
Chris@0
|
445 * @param int $node_last_comment_timestamp
|
Chris@0
|
446 * A node's last comment timestamp, that must exist as a
|
Chris@0
|
447 * data-history-node-last-comment-timestamp attribute.
|
Chris@0
|
448 * @param bool $library_is_present
|
Chris@0
|
449 * Whether the drupal.tracker-history library should be present or not.
|
Chris@0
|
450 */
|
Chris@0
|
451 public function assertHistoryMetadata($node_id, $node_timestamp, $node_last_comment_timestamp, $library_is_present = TRUE) {
|
Chris@0
|
452 $settings = $this->getDrupalSettings();
|
Chris@0
|
453 $this->assertIdentical($library_is_present, isset($settings['ajaxPageState']) && in_array('tracker/history', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.tracker-history library is present.');
|
Chris@0
|
454 $this->assertIdentical(1, count($this->xpath('//table/tbody/tr/td[@data-history-node-id="' . $node_id . '" and @data-history-node-timestamp="' . $node_timestamp . '"]')), 'Tracker table cell contains the data-history-node-id and data-history-node-timestamp attributes for the node.');
|
Chris@0
|
455 $this->assertIdentical(1, count($this->xpath('//table/tbody/tr/td[@data-history-node-last-comment-timestamp="' . $node_last_comment_timestamp . '"]')), 'Tracker table cell contains the data-history-node-last-comment-timestamp attribute for the node.');
|
Chris@0
|
456 }
|
Chris@0
|
457
|
Chris@0
|
458 }
|