diff options
author | David Rothstein <drothstein@gmail.com> | 2014-11-01 19:20:54 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2014-11-01 19:20:54 -0400 |
commit | e052539654ea7f475c9359ebaf9b0be066522d18 (patch) | |
tree | f80d02ce23a592284f533141a01d4a61b8c08fe8 /modules/tracker | |
parent | 71651dbf4f0f9f0e3169e3beb9b89f9037f5c13e (diff) | |
download | brdo-e052539654ea7f475c9359ebaf9b0be066522d18.tar.gz brdo-e052539654ea7f475c9359ebaf9b0be066522d18.tar.bz2 |
Issue #2224917 by m1r1k, Steven Jones, drumm: Fixed Tracker page doesn't order results properly.
Diffstat (limited to 'modules/tracker')
-rw-r--r-- | modules/tracker/tracker.module | 10 | ||||
-rw-r--r-- | modules/tracker/tracker.test | 66 |
2 files changed, 75 insertions, 1 deletions
diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index 8694222d8..ab3e7485c 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -263,7 +263,7 @@ function _tracker_add($nid, $uid, $changed) { )) ->execute(); - // Create or update the user-level data. + // Create or update the user-level data, first for the user posting. db_merge('tracker_user') ->key(array( 'nid' => $nid, @@ -274,6 +274,14 @@ function _tracker_add($nid, $uid, $changed) { 'published' => $node->status, )) ->execute(); + // Update the times for all the other users tracking the post. + db_update('tracker_user') + ->condition('nid', $nid) + ->fields(array( + 'changed' => $changed, + 'published' => $node->status, + )) + ->execute(); } /** diff --git a/modules/tracker/tracker.test b/modules/tracker/tracker.test index 66ebb848e..8a48ea811 100644 --- a/modules/tracker/tracker.test +++ b/modules/tracker/tracker.test @@ -183,6 +183,72 @@ class TrackerTest extends DrupalWebTestCase { } /** + * Tests for ordering on a users tracker listing when comments are posted. + */ + function testTrackerOrderingNewComments() { + $this->drupalLogin($this->user); + + $node_one = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + )); + + $node_two = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + )); + + // Now get other_user to track these pieces of content. + $this->drupalLogin($this->other_user); + + // Add a comment to the first page. + $comment = array( + 'subject' => $this->randomName(), + 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20), + ); + $this->drupalPost('comment/reply/' . $node_one->nid, $comment, t('Save')); + + // If the comment is posted in the same second as the last one then Drupal + // can't tell the difference, so we wait one second here. + sleep(1); + + // Add a comment to the second page. + $comment = array( + 'subject' => $this->randomName(), + 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20), + ); + $this->drupalPost('comment/reply/' . $node_two->nid, $comment, t('Save')); + + // We should at this point have in our tracker for other_user: + // 1. node_two + // 2. node_one + // Because that's the reverse order of the posted comments. + + // Now we're going to post a comment to node_one which should jump it to the + // top of the list. + + $this->drupalLogin($this->user); + // If the comment is posted in the same second as the last one then Drupal + // can't tell the difference, so we wait one second here. + sleep(1); + + // Add a comment to the second page. + $comment = array( + 'subject' => $this->randomName(), + 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20), + ); + $this->drupalPost('comment/reply/' . $node_one->nid, $comment, t('Save')); + + // Switch back to the other_user and assert that the order has swapped. + $this->drupalLogin($this->other_user); + $this->drupalGet('user/' . $this->other_user->uid . '/track'); + // This is a cheeky way of asserting that the nodes are in the right order + // on the tracker page. + // It's almost certainly too brittle. + $pattern = '/' . preg_quote($node_one->title) . '.+' . preg_quote($node_two->title) . '/s'; + $this->verbose($pattern); + $this->assertPattern($pattern, 'Most recently commented on node appears at the top of tracker'); + } + + /** * Tests that existing nodes are indexed by cron. */ function testTrackerCronIndexing() { |