.../comment/Controller/CommentController.php | 2 +- .../history/Controller/HistoryController.php | 4 +- .../system/Tests/Theme/ThemeInfoStylesTest.php | 21 +++---- .../lib/Drupal/tracker/Tests/TrackerTest.php | 62 ++++++++++++++++++-- core/modules/tracker/tracker.pages.inc | 4 +- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index 594c195..01b1a0d 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -143,7 +143,7 @@ public function commentPermalink(Request $request, CommentInterface $comment) { * The JSON response. */ public function renderNewCommentsNodeLinks(Request $request) { - if ($request->attributes->get('account')->isAnonymous()) { + if ($request->attributes->get('_account')->isAnonymous()) { throw new AccessDeniedHttpException(); } diff --git a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php index c49de9e..7388e17 100644 --- a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php +++ b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php @@ -37,7 +37,7 @@ public static function create(ContainerInterface $container) { * The JSON response. */ public function getNodeReadTimestamps(Request $request) { - if ($request->attributes->get('account')->isAnonymous()) { + if ($request->attributes->get('_account')->isAnonymous()) { throw new AccessDeniedHttpException(); } @@ -64,7 +64,7 @@ public function getNodeReadTimestamps(Request $request) { * The node whose "last read" timestamp should be updated. */ public function readNode(Request $request, NodeInterface $node) { - if ($request->attributes->get('account')->isAnonymous()) { + if ($request->attributes->get('_account')->isAnonymous()) { throw new AccessDeniedHttpException(); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php index 47acb01..bae08f9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php @@ -47,18 +47,19 @@ function testStylesheets() { $this->drupalGet('theme-test/info/stylesheets'); - $this->assertRaw("$base/base-add.css"); - $this->assertRaw("$base/base-override.css"); - $this->assertNoRaw("base-remove.css"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$base/base-add.css')]")), "$base/base-add.css found"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$base/base-override.css')]")), "$base/base-override.css found"); + $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-remove.css')]")), "base-remove.css not found"); - $this->assertRaw("$sub/sub-add.css"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/sub-add.css')]")), "$sub/sub-add.css found"); - $this->assertRaw("$sub/sub-override.css"); - $this->assertRaw("$sub/base-add.sub-override.css"); - $this->assertRaw("$sub/base-remove.sub-override.css"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/sub-override.css')]")), "$sub/sub-override.css found"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/base-add.sub-override.css')]")), "$sub/base-add.sub-override.css found"); + $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/base-remove.sub-override.css')]")), "$sub/base-remove.sub-override.css found"); - $this->assertNoRaw("sub-remove.css"); - $this->assertNoRaw("base-add.sub-remove.css"); - $this->assertNoRaw("base-override.sub-remove.css"); + $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'sub-remove.css')]")), "sub-remove.css not found"); + $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-add.sub-remove.css')]")), "base-add.sub-remove.css not found"); + $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-override.sub-remove.css')]")), "base-override.sub-remove.css not found"); } + } diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index c772465..95495fd 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -52,6 +52,10 @@ function setUp() { $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); $this->user = $this->drupalCreateUser($permissions); $this->other_user = $this->drupalCreateUser($permissions); + user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access content', + 'access user profiles', + )); // Make node preview optional. variable_set('comment_preview_page', 0); @@ -130,7 +134,7 @@ function testTrackerUser() { } /** - * Tests for the presence of the metadata for the "new"/"updated" indicators. + * Tests the metadata for the "new"/"updated" indicators. */ function testTrackerHistoryMetadata() { $this->drupalLogin($this->user); @@ -141,6 +145,14 @@ function testTrackerHistoryMetadata() { ); $node = $this->drupalCreateNode($edit); + // Verify. + $this->drupalGet('tracker'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime()); + $this->drupalGet('tracker/' . $this->user->id()); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime()); + $this->drupalGet('user/' . $this->user->id() . '/track'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime()); + // Add a comment to the page, make sure it is created after the node. $edit = array( 'subject' => $this->randomName(), @@ -148,15 +160,26 @@ function testTrackerHistoryMetadata() { ); sleep(1); $this->drupalPost('comment/reply/' . $node->id(), $edit, t('Save')); - // Reload the node so that comment.module's hook_node_load() // implementation can set $node->last_comment_timestamp for the freshly // posted comment. $node = node_load($node->id()); + // Verify. + $this->drupalGet('tracker'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->last_comment_timestamp); + $this->drupalGet('tracker/' . $this->user->id()); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->last_comment_timestamp); + $this->drupalGet('user/' . $this->user->id() . '/track'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->last_comment_timestamp); + + // Log out, now verify that the metadata is still there, but the library is + // not. + $this->drupalLogout(); $this->drupalGet('tracker'); - $this->assertIdentical(1, count($this->xpath('//table/tbody/tr/td[@data-history-node-id="' . $node->id() . '" and @data-history-node-timestamp="' . $node->getChangedTime() . '"]')), 'Tracker table cell contains the data-history-node-id and data-history-node-timestamp attributes for the node.'); - $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.'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->last_comment_timestamp, FALSE); + $this->drupalGet('user/' . $this->user->id() . '/track'); + $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->last_comment_timestamp, FALSE); } /** @@ -239,4 +262,35 @@ function testTrackerAdminUnpublish() { $this->drupalGet('tracker'); $this->assertText(t('No content available.'), 'Node is displayed on the tracker listing pages.'); } + + /** + * Passes if the appropriate history metadata exists. + * + * Verify the data-history-node-id, data-history-node-timestamp and + * data-history-node-last-comment-timestamp attributes, which are used by the + * drupal.tracker-history library to add the appropriate "new" and "updated" + * indicators, as well as the "x new" replies link to the tracker. + * We do this in JavaScript to prevent breaking the render cache. + * + * @param int $node_id + * A node ID, that must exist as a data-history-node-id attribute + * @param int $node_timestamp + * A node timestamp, that must exist as a data-history-node-timestamp + * attribute. + * @param int $node_last_comment_timestamp + * A node's last comment timestamp, that must exist as a + * data-history-node-last-comment-timestamp attribute. + * @param bool $library_is_present + * Whether the drupal.tracker-history library should be present or not. + * + * @return + * TRUE if the assertion succeeded, FALSE otherwise. + */ + function assertHistoryMetadata($node_id, $node_timestamp, $node_last_comment_timestamp, $library_is_present = TRUE) { + $settings = $this->drupalGetSettings(); + $this->assertIdentical($library_is_present, isset($settings['ajaxPageState']['js']['core/modules/tracker/js/tracker-history.js']), 'drupal.tracker-history library is present.'); + $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.'); + $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.'); + } + } diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index d8cea8c..5cd521a 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -18,6 +18,8 @@ * @see tracker_menu() */ function tracker_page($account = NULL, $set_title = FALSE) { + global $user; + if ($account) { $query = db_select('tracker_user', 't') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') @@ -143,7 +145,7 @@ function tracker_page($account = NULL, $set_title = FALSE) { ); $page['#sorted'] = TRUE; - if (module_exists('history') && $account) { + if (module_exists('history') && $user->isAuthenticated()) { $page['#attached']['library'][] = array('tracker', 'drupal.tracker-history'); }