| 1 |
<?php
|
| 2 |
// $Id: tracker.test,v 1.11 2009/08/31 06:52:50 dries Exp $
|
| 3 |
|
| 4 |
class TrackerTest extends DrupalWebTestCase {
|
| 5 |
protected $user;
|
| 6 |
protected $other_user;
|
| 7 |
protected $new_node;
|
| 8 |
|
| 9 |
public static function getInfo() {
|
| 10 |
return array(
|
| 11 |
'name' => 'Tracker',
|
| 12 |
'description' => 'Create nodes and check for their display in the tracker listings.',
|
| 13 |
'group' => 'Tracker'
|
| 14 |
);
|
| 15 |
}
|
| 16 |
|
| 17 |
function setUp() {
|
| 18 |
parent::setUp('comment', 'tracker');
|
| 19 |
|
| 20 |
$permissions = array('access comments', 'create page content', 'post comments', 'post comments without approval');
|
| 21 |
$this->user = $this->drupalCreateUser($permissions);
|
| 22 |
$this->other_user = $this->drupalCreateUser($permissions);
|
| 23 |
|
| 24 |
// Make node preview optional.
|
| 25 |
variable_set('comment_preview_page', 0);
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Test the presence of nodes on the global tracker listing.
|
| 30 |
*/
|
| 31 |
function testTrackerAll() {
|
| 32 |
$this->drupalLogin($this->user);
|
| 33 |
|
| 34 |
$unpublished = $this->drupalCreateNode(array(
|
| 35 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 36 |
'status' => 0,
|
| 37 |
));
|
| 38 |
$published = $this->drupalCreateNode(array(
|
| 39 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 40 |
'status' => 1,
|
| 41 |
));
|
| 42 |
|
| 43 |
$this->drupalGet('tracker');
|
| 44 |
$this->assertNoText($unpublished->title[FIELD_LANGUAGE_NONE][0]['value'], t('Unpublished node do not show up in the tracker listing.'));
|
| 45 |
$this->assertText($published->title[FIELD_LANGUAGE_NONE][0]['value'], t('Published node show up in the tracker listing.'));
|
| 46 |
$this->assertLink(t('My recent posts'), 0, t('User tab shows up on the global tracker page.'));
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Test the presence of nodes on a user's tracker listing.
|
| 51 |
*/
|
| 52 |
function testTrackerUser() {
|
| 53 |
$this->drupalLogin($this->user);
|
| 54 |
|
| 55 |
$unpublished = $this->drupalCreateNode(array(
|
| 56 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 57 |
'uid' => $this->user->uid,
|
| 58 |
'status' => 0,
|
| 59 |
));
|
| 60 |
$my_published = $this->drupalCreateNode(array(
|
| 61 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 62 |
'uid' => $this->user->uid,
|
| 63 |
'status' => 1,
|
| 64 |
));
|
| 65 |
$other_published_no_comment = $this->drupalCreateNode(array(
|
| 66 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 67 |
'uid' => $this->other_user->uid,
|
| 68 |
'status' => 1,
|
| 69 |
));
|
| 70 |
$other_published_my_comment = $this->drupalCreateNode(array(
|
| 71 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 72 |
'uid' => $this->other_user->uid,
|
| 73 |
'status' => 1,
|
| 74 |
));
|
| 75 |
$comment = array(
|
| 76 |
'subject' => $this->randomName(),
|
| 77 |
'comment' => $this->randomName(20),
|
| 78 |
);
|
| 79 |
$this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save'));
|
| 80 |
|
| 81 |
$this->drupalGet('user/' . $this->user->uid . '/track');
|
| 82 |
$this->assertNoText($unpublished->title[FIELD_LANGUAGE_NONE][0]['value'], t("Unpublished nodes do not show up in the users's tracker listing."));
|
| 83 |
$this->assertText($my_published->title[FIELD_LANGUAGE_NONE][0]['value'], t("Published nodes show up in the user's tracker listing."));
|
| 84 |
$this->assertNoText($other_published_no_comment->title[FIELD_LANGUAGE_NONE][0]['value'], t("Other user's nodes do not show up in the user's tracker listing."));
|
| 85 |
$this->assertText($other_published_my_comment->title[FIELD_LANGUAGE_NONE][0]['value'], t("Nodes that the user has commented on appear in the user's tracker listing."));
|
| 86 |
}
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Test the presence of the "new" flag for nodes.
|
| 90 |
*/
|
| 91 |
function testTrackerNewNodes() {
|
| 92 |
$this->drupalLogin($this->user);
|
| 93 |
|
| 94 |
$edit = array(
|
| 95 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 96 |
);
|
| 97 |
|
| 98 |
$node = $this->drupalCreateNode($edit);
|
| 99 |
$title = $edit['title'][FIELD_LANGUAGE_NONE][0]['value'];
|
| 100 |
$this->drupalGet('tracker');
|
| 101 |
$this->assertPattern('/' . $title . '.*new/', t('New nodes are flagged as such in the tracker listing.'));
|
| 102 |
|
| 103 |
$this->drupalGet('node/' . $node->nid);
|
| 104 |
$this->drupalGet('tracker');
|
| 105 |
$this->assertNoPattern('/' . $title . '.*new/', t('Visited nodes are not flagged as new.'));
|
| 106 |
|
| 107 |
$this->drupalLogin($this->other_user);
|
| 108 |
$this->drupalGet('tracker');
|
| 109 |
$this->assertPattern('/' . $title . '.*new/', t('For another user, new nodes are flagged as such in the tracker listing.'));
|
| 110 |
|
| 111 |
$this->drupalGet('node/' . $node->nid);
|
| 112 |
$this->drupalGet('tracker');
|
| 113 |
$this->assertNoPattern('/' . $title . '.*new/', t('For another user, visited nodes are not flagged as new.'));
|
| 114 |
}
|
| 115 |
|
| 116 |
/**
|
| 117 |
* Test comment counters on the tracker listing.
|
| 118 |
*/
|
| 119 |
function testTrackerNewComments() {
|
| 120 |
$this->drupalLogin($this->user);
|
| 121 |
|
| 122 |
$node = $this->drupalCreateNode(array(
|
| 123 |
'comment' => 2,
|
| 124 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
| 125 |
));
|
| 126 |
|
| 127 |
// Add a comment to the page.
|
| 128 |
$comment = array(
|
| 129 |
'subject' => $this->randomName(),
|
| 130 |
'comment' => $this->randomName(20),
|
| 131 |
);
|
| 132 |
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); // The new comment is automatically viewed by the current user.
|
| 133 |
|
| 134 |
$this->drupalLogin($this->other_user);
|
| 135 |
$this->drupalGet('tracker');
|
| 136 |
$this->assertText('1 new', t('New comments are counted on the tracker listing pages.'));
|
| 137 |
$this->drupalGet('node/' . $node->nid);
|
| 138 |
|
| 139 |
// Add another comment as other_user.
|
| 140 |
$comment = array(
|
| 141 |
'subject' => $this->randomName(),
|
| 142 |
'comment' => $this->randomName(20),
|
| 143 |
);
|
| 144 |
// If the comment is posted in the same second as the last one then Drupal
|
| 145 |
// can't tell a difference, so wait one second here.
|
| 146 |
sleep(1);
|
| 147 |
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
|
| 148 |
|
| 149 |
$this->drupalLogin($this->user);
|
| 150 |
$this->drupalGet('tracker');
|
| 151 |
$this->assertText('1 new', t('New comments are counted on the tracker listing pages.'));
|
| 152 |
}
|
| 153 |
|
| 154 |
/**
|
| 155 |
* Test that existing nodes are indexed by cron.
|
| 156 |
*/
|
| 157 |
function testTrackerCronIndexing() {
|
| 158 |
$this->drupalLogin($this->user);
|
| 159 |
|
| 160 |
// Create 3 nodes.
|
| 161 |
$edits = array();
|
| 162 |
$nodes = array();
|
| 163 |
for ($i = 1; $i <= 3; $i++) {
|
| 164 |
$edits[$i] = array(
|
| 165 |
'comment' => 2,
|
| 166 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName()))),
|
| 167 |
);
|
| 168 |
$nodes[$i] = $this->drupalCreateNode($edits[$i]);
|
| 169 |
}
|
| 170 |
|
| 171 |
// Add a comment to the last node as other user.
|
| 172 |
$this->drupalLogin($this->other_user);
|
| 173 |
$comment = array(
|
| 174 |
'subject' => $this->randomName(),
|
| 175 |
'comment' => $this->randomName(20),
|
| 176 |
);
|
| 177 |
$this->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save'));
|
| 178 |
|
| 179 |
// Start indexing backwards from node 3.
|
| 180 |
variable_set('tracker_index_nid', 3);
|
| 181 |
|
| 182 |
// Clear the current tracker tables and rebuild them.
|
| 183 |
db_delete('tracker_node')
|
| 184 |
->execute();
|
| 185 |
db_delete('tracker_user')
|
| 186 |
->execute();
|
| 187 |
tracker_cron();
|
| 188 |
|
| 189 |
$this->drupalLogin($this->user);
|
| 190 |
|
| 191 |
// Fetch the user's tracker.
|
| 192 |
$this->drupalGet('tracker/' . $this->user->uid);
|
| 193 |
|
| 194 |
// Assert that all node titles are displayed.
|
| 195 |
foreach ($nodes as $i => $node) {
|
| 196 |
$this->assertText($node->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node @i is displayed on the tracker listing pages.', array('@i' => $i)));
|
| 197 |
}
|
| 198 |
$this->assertText('1 new', t('New comment is counted on the tracker listing pages.'));
|
| 199 |
$this->assertText('updated', t('Node is listed as updated'));
|
| 200 |
|
| 201 |
|
| 202 |
// Fetch the site-wide tracker.
|
| 203 |
$this->drupalGet('tracker');
|
| 204 |
|
| 205 |
// Assert that all node titles are displayed.
|
| 206 |
foreach ($nodes as $i => $node) {
|
| 207 |
$this->assertText($node->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node @i is displayed on the tracker listing pages.', array('@i' => $i)));
|
| 208 |
}
|
| 209 |
$this->assertText('1 new', t('New comment is counted on the tracker listing pages.'));
|
| 210 |
}
|
| 211 |
|
| 212 |
/**
|
| 213 |
* Test that publish/unpublish works at admin/content/node
|
| 214 |
*/
|
| 215 |
function testTrackerAdminUnpublish() {
|
| 216 |
$admin_user = $this->drupalCreateUser(array('administer nodes'));
|
| 217 |
$this->drupalLogin($admin_user);
|
| 218 |
|
| 219 |
$node = $this->drupalCreateNode(array(
|
| 220 |
'comment' => 2,
|
| 221 |
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName()))),
|
| 222 |
));
|
| 223 |
|
| 224 |
// Assert that the node is displayed.
|
| 225 |
$this->drupalGet('tracker');
|
| 226 |
$this->assertText($node->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node is displayed on the tracker listing pages.'));
|
| 227 |
|
| 228 |
// Unpublish the node and ensure that it's no longer displayed.
|
| 229 |
$edit = array(
|
| 230 |
'operation' => 'unpublish',
|
| 231 |
'nodes[' . $node->nid . ']' => $node->nid,
|
| 232 |
);
|
| 233 |
$this->drupalPost('admin/content', $edit, t('Update'));
|
| 234 |
|
| 235 |
$this->drupalGet('tracker');
|
| 236 |
$this->assertText(t('No posts available.'), t('Node is displayed on the tracker listing pages.'));
|
| 237 |
}
|
| 238 |
}
|