diff options
Diffstat (limited to 'modules/tracker/tracker.test')
-rw-r--r-- | modules/tracker/tracker.test | 147 |
1 files changed, 122 insertions, 25 deletions
diff --git a/modules/tracker/tracker.test b/modules/tracker/tracker.test index 9943c17aa..7aa215bd1 100644 --- a/modules/tracker/tracker.test +++ b/modules/tracker/tracker.test @@ -20,6 +20,9 @@ class TrackerTest extends DrupalWebTestCase { $permissions = array('access comments', 'create page content', 'post comments', 'post comments without approval'); $this->user = $this->drupalCreateUser($permissions); $this->other_user = $this->drupalCreateUser($permissions); + + // Make node preview optional. + variable_set('comment_preview_page', 0); } /** @@ -28,20 +31,18 @@ class TrackerTest extends DrupalWebTestCase { function testTrackerAll() { $this->drupalLogin($this->user); - $page1 = array( - 'title' => $this->randomName(8), - 'status' => 1, - ); - $page2 = array( + $unpublished = $this->drupalCreateNode(array( 'title' => $this->randomName(8), 'status' => 0, - ); - $this->drupalCreateNode($page1); - $this->drupalCreateNode($page2); + )); + $published = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'status' => 1, + )); $this->drupalGet('tracker'); - $this->assertText($page1['title'], t('Nodes show up in the tracker listing.')); - $this->assertNoText($page2['title'], t('Unpublished nodes do not show up in the tracker listing.')); + $this->assertNoText($unpublished->title, t('Unpublished node do not show up in the tracker listing.')); + $this->assertText($published->title, t('Published node show up in the tracker listing.')); $this->assertLink(t('My recent posts'), 0, t('User tab shows up on the global tracker page.')); } @@ -51,22 +52,37 @@ class TrackerTest extends DrupalWebTestCase { function testTrackerUser() { $this->drupalLogin($this->user); - $page1 = array( + $unpublished = $this->drupalCreateNode(array( 'title' => $this->randomName(8), 'uid' => $this->user->uid, - 'status' => 1, - ); - $page2 = array( + 'status' => 0, + )); + $my_published = $this->drupalCreateNode(array( 'title' => $this->randomName(8), 'uid' => $this->user->uid, - 'status' => 0, + 'status' => 1, + )); + $other_published_no_comment = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'uid' => $this->other_user->uid, + 'status' => 1, + )); + $other_published_my_comment = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'uid' => $this->other_user->uid, + 'status' => 1, + )); + $comment = array( + 'subject' => $this->randomName(), + 'comment' => $this->randomName(20), ); - $this->drupalCreateNode($page1); - $this->drupalCreateNode($page2); + $this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save')); $this->drupalGet('user/' . $this->user->uid . '/track'); - $this->assertText($page1['title'], t("Nodes show up in the author's tracker listing.")); - $this->assertNoText($page2['title'], t("Unpublished nodes do not show up in the author's tracker listing.")); + $this->assertNoText($unpublished->title, t("Unpublished nodes do not show up in the users's tracker listing.")); + $this->assertText($my_published->title, t("Published nodes show up in the user's tracker listing.")); + $this->assertNoText($other_published_no_comment->title, t("Other user's nodes do not show up in the user's tracker listing.")); + $this->assertText($other_published_my_comment->title, t("Nodes that the user has commented on appear in the user's tracker listing.")); } /** @@ -100,16 +116,12 @@ class TrackerTest extends DrupalWebTestCase { * Test comment counters on the tracker listing. */ function testTrackerNewComments() { - // Make node preview optional - variable_set('comment_preview_page', 0); - $this->drupalLogin($this->user); - $edit = array( + $node = $this->drupalCreateNode(array( 'comment' => 2, 'title' => $this->randomName(), - ); - $node = $this->drupalCreateNode($edit); + )); // Add a comment to the page. $comment = array( @@ -137,4 +149,89 @@ class TrackerTest extends DrupalWebTestCase { $this->drupalGet('tracker'); $this->assertText('1 new', t('New comments are counted on the tracker listing pages.')); } + + /** + * Test that existing nodes are indexed by cron. + */ + function testTrackerCronIndexing() { + $this->drupalLogin($this->user); + + // Create 3 nodes. + $edits = array(); + $nodes = array(); + for ($i = 1; $i <= 3; $i++) { + $edits[$i] = array( + 'comment' => 2, + 'title' => $this->randomName(), + ); + $nodes[$i] = $this->drupalCreateNode($edits[$i]); + } + + // Add a comment to the last node as other user. + $this->drupalLogin($this->other_user); + $comment = array( + 'subject' => $this->randomName(), + 'comment' => $this->randomName(20), + ); + $this->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save')); + + // Start indexing backwards from node 3. + variable_set('tracker_index_nid', 3); + + // Clear the current tracker tables and rebuild them. + db_delete('tracker_node') + ->execute(); + db_delete('tracker_user') + ->execute(); + tracker_cron(); + + $this->drupalLogin($this->user); + + // Fetch the user's tracker. + $this->drupalGet('tracker/' . $this->user->uid); + + // Assert that all node titles are displayed. + foreach ($nodes as $i => $node) { + $this->assertText($node->title, t('Node @i is displayed on the tracker listing pages.', array('@i' => $i))); + } + $this->assertText('1 new', t('New comment is counted on the tracker listing pages.')); + $this->assertText('updated', t('Node is listed as updated')); + + + // Fetch the site-wide tracker. + $this->drupalGet('tracker'); + + // Assert that all node titles are displayed. + foreach ($nodes as $i => $node) { + $this->assertText($node->title, t('Node @i is displayed on the tracker listing pages.', array('@i' => $i))); + } + $this->assertText('1 new', t('New comment is counted on the tracker listing pages.')); + } + + /** + * Test that publish/unpublish works at admin/content/node + */ + function testTrackerAdminUnpublish() { + $admin_user = $this->drupalCreateUser(array('administer nodes')); + $this->drupalLogin($admin_user); + + $node = $this->drupalCreateNode(array( + 'comment' => 2, + 'title' => $this->randomName(), + )); + + // Assert that the node is displayed. + $this->drupalGet('tracker'); + $this->assertText($node->title, t('Node is displayed on the tracker listing pages.')); + + // Unpublish the node and ensure that it's no longer displayed. + $edit = array( + 'operation' => 'unpublish', + 'nodes[' . $node->nid . ']' => $node->nid, + ); + $this->drupalPost('admin/content', $edit, t('Update')); + + $this->drupalGet('tracker'); + $this->assertText(t('No posts available.'), t('Node is displayed on the tracker listing pages.')); + } } |