annotate core/modules/tracker/tests/src/Functional/TrackerTest.php @ 12:7a779792577d

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