summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-06-01 11:18:37 +0000
committerDries Buytaert <dries@buytaert.net>2009-06-01 11:18:37 +0000
commit706ce87579e8c29953583a5bfd417aa7e1fbe4b5 (patch)
tree9d97f9bdd13d16c1c1c72a36eec2483d01244a3f /modules
parent2c1bb05313377c9df76bd068f52c9ec632ce13bb (diff)
downloadbrdo-706ce87579e8c29953583a5bfd417aa7e1fbe4b5.tar.gz
brdo-706ce87579e8c29953583a5bfd417aa7e1fbe4b5.tar.bz2
- Patch #474308 by stella: new tests for poll module. New tests:
* that the Recent Poll block outputs the block layout rather than page layout. * that users can vote on polls via the block * that the 'older polls' link in the recent poll block works. * that node is output correctly, including 'Cancel your vote' button appearing * that only users with appropriate permission can cancel their votes * that the 'poll' page contains the correct data. * that polls can be edited * the opening / closing of polls - ensuring block doesn't appear when poll is closed, and neither do the 'Vote' / 'Cancel your vote' buttons, and that the poll status is updated correctly on 'poll' page.
Diffstat (limited to 'modules')
-rw-r--r--modules/poll/poll.test154
1 files changed, 147 insertions, 7 deletions
diff --git a/modules/poll/poll.test b/modules/poll/poll.test
index a9bdea6cc..0c4d84883 100644
--- a/modules/poll/poll.test
+++ b/modules/poll/poll.test
@@ -46,8 +46,8 @@ class PollTestCase extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($title);
- $this->assertRaw(t('@type %title has been created.', array('@type' => node_get_types('name', 'poll'), '%title' => $title)), 'Poll has been created.');
- $this->assertTrue($node->nid, t('Poll has been found in the database'));
+ $this->assertText(t('@type @title has been created.', array('@type' => node_get_types('name', 'poll'), '@title' => $title)), 'Poll has been created.');
+ $this->assertTrue($node->nid, t('Poll has been found in the database.'));
return isset($node->nid) ? $node->nid : FALSE;
}
@@ -76,6 +76,12 @@ class PollTestCase extends DrupalWebTestCase {
}
return $choices;
}
+
+ function pollUpdate($nid, $title, $edit) {
+ // Edit the poll node.
+ $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
+ $this->assertText(t('@type @title has been updated.', array('@type' => node_get_types('name', 'poll'), '@title' => $title)), 'Poll has been updated.');
+ }
}
class PollCreateTestCase extends PollTestCase {
@@ -91,6 +97,66 @@ class PollCreateTestCase extends PollTestCase {
$title = $this->randomName();
$choices = $this->_generateChoices(7);
$this->pollCreate($title, $choices, TRUE);
+
+ // Verify poll appears on 'poll' page.
+ $this->drupalGet('poll');
+ $this->assertText($title, 'Poll appears in poll list.');
+ $this->assertText('open', 'Poll is active.');
+
+ // Click on the poll title to go to node page.
+ $this->clickLink($title);
+ $this->assertText('Total votes: 0', 'Link to poll correct.');
+ }
+
+ function testPollClose() {
+ $content_user = $this->drupalCreateUser(array('create poll content', 'edit any poll content', 'access content'));
+ $vote_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
+
+ // Create poll.
+ $title = $this->randomName();
+ $choices = $this->_generateChoices(7);
+ $poll_nid = $this->pollCreate($title, $choices, FALSE);
+
+ $this->drupalLogout();
+ $this->drupalLogin($content_user);
+
+ // Edit the poll node and close the poll.
+ $close_edit = array('active' => 0);
+ $this->pollUpdate($poll_nid, $title, $close_edit);
+
+ // Verify 'Vote' button no longer appears.
+ $this->drupalGet('node/' . $poll_nid);
+ $elements = $this->xpath('//input[@id="edit-vote"]');
+ $this->assertTrue(empty($elements), t("Vote button doesn't appear."));
+
+ // Verify status on 'poll' page is 'closed'.
+ $this->drupalGet('poll');
+ $this->assertText($title, 'Poll appears in poll list.');
+ $this->assertText('closed', 'Poll is closed.');
+
+ // Edit the poll node and re-activate.
+ $open_edit = array('active' => 1);
+ $this->pollUpdate($poll_nid, $title, $open_edit);
+
+ // Vote on the poll.
+ $this->drupalLogout();
+ $this->drupalLogin($vote_user);
+ $vote_edit = array('choice' => '1');
+ $this->drupalPost('node/' . $poll_nid, $vote_edit, t('Vote'));
+ $this->assertText('Your vote was recorded.', 'Your vote was recorded.');
+ $elements = $this->xpath('//input[@value="Cancel your vote"]');
+ $this->assertTrue(isset($elements[0]), t("'Cancel your vote' button appears."));
+
+ // Edit the poll node and close the poll.
+ $this->drupalLogout();
+ $this->drupalLogin($content_user);
+ $close_edit = array('active' => 0);
+ $this->pollUpdate($poll_nid, $title, $close_edit);
+
+ // Verify 'Cancel your vote' button no longer appears.
+ $this->drupalGet('node/' . $poll_nid);
+ $elements = $this->xpath('//input[@value="Cancel your vote"]');
+ $this->assertTrue(empty($elements), t("'Cancel your vote' button no longer appears."));
}
}
@@ -113,8 +179,10 @@ class PollVoteTestCase extends PollTestCase {
$poll_nid = $this->pollCreate($title, $choices, FALSE);
$this->drupalLogout();
- $web_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
- $this->drupalLogin($web_user);
+ $vote_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
+ $restricted_vote_user = $this->drupalCreateUser(array('vote on polls', 'access content'));
+
+ $this->drupalLogin($vote_user);
// Record a vote for the first choice.
$edit = array(
@@ -122,14 +190,49 @@ class PollVoteTestCase extends PollTestCase {
);
$this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
$this->assertText('Your vote was recorded.', 'Your vote was recorded.');
+ $this->assertText('Total votes: 1', 'Vote count updated correctly.');
+ $elements = $this->xpath('//input[@value="Cancel your vote"]');
+ $this->assertTrue(isset($elements[0]), t("'Cancel your vote' button appears."));
$this->drupalGet("node/$poll_nid/votes");
$this->assertText(t('This table lists all the recorded votes for this poll. If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.'), 'Vote table text.');
$this->assertText($choices[0], 'Vote recorded');
+
+ // Ensure poll listing page has correct number of votes.
+ $this->drupalGet('poll');
+ $this->assertText($title, 'Poll appears in poll list.');
+ $this->assertText('1 vote', 'Poll has 1 vote.');
+
+ // Cancel a vote.
+ $this->drupalPost('node/' . $poll_nid, array(), t('Cancel your vote'));
+ $this->assertText('Your vote was cancelled.', 'Your vote was cancelled.');
+ $this->assertNoText('Cancel your vote', "Cancel vote button doesn't appear.");
+
+ $this->drupalGet("node/$poll_nid/votes");
+ $this->assertNoText($choices[0], 'Vote cancelled');
+
+ // Ensure poll listing page has correct number of votes.
+ $this->drupalGet('poll');
+ $this->assertText($title, 'Poll appears in poll list.');
+ $this->assertText('0 votes', 'Poll has 0 votes.');
+
+ // Log in as a user who can only vote on polls.
+ $this->drupalLogout();
+ $this->drupalLogin($restricted_vote_user);
+
+ // Vote on a poll.
+ $edit = array(
+ 'choice' => '1',
+ );
+ $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
+ $this->assertText('Your vote was recorded.', 'Your vote was recorded.');
+ $this->assertText('Total votes: 1', 'Vote count updated correctly.');
+ $elements = $this->xpath('//input[@value="Cancel your vote"]');
+ $this->assertTrue(empty($elements), t("'Cancel your vote' button does not appear."));
}
}
-class PollBlockTestCase extends DrupalWebTestCase {
+class PollBlockTestCase extends PollTestCase {
public static function getInfo() {
return array(
'name' => t('Block availability'),
@@ -147,15 +250,52 @@ class PollBlockTestCase extends DrupalWebTestCase {
}
function testRecentBlock() {
- // Set block title to confirm that the interface is availble.
+ // Set block title to confirm that the interface is available.
$this->drupalPost('admin/build/block/configure/poll/recent', array('title' => $this->randomName(8)), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
- // Set the block to a region to confirm block is availble.
+ // Set the block to a region to confirm block is available.
$edit = array();
$edit['poll_recent[region]'] = 'footer';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+
+ // Create a poll which should appear in recent polls block.
+ $title = $this->randomName();
+ $choices = $this->_generateChoices(7);
+ $poll_nid = $this->pollCreate($title, $choices, TRUE);
+
+ // Verify poll appears in a block.
+ // View user page so we're not matching the poll node on front page.
+ $this->drupalGet('user');
+ // If a 'block' view not generated, this title would not appear even though
+ // the choices might.
+ $this->assertText($title, 'Poll appears in block.');
+
+ // Logout and login back in as a user who can vote.
+ $this->drupalLogout();
+ $vote_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
+ $this->drupalLogin($vote_user);
+
+ // Verify we can vote via the block.
+ $edit = array(
+ 'choice' => '1',
+ );
+ $this->drupalPost('user/' . $vote_user->uid, $edit, t('Vote'));
+ $this->assertText('Your vote was recorded.', 'Your vote was recorded.');
+ $this->assertText('Total votes: 1', 'Vote count updated correctly.');
+ $this->assertText('Older polls', 'Link to older polls appears.');
+ $this->clickLink('Older polls');
+ $this->assertText('1 vote - open', 'Link to poll listing correct.');
+
+ // Close the poll and verify block doesn't appear.
+ $content_user = $this->drupalCreateUser(array('create poll content', 'edit any poll content', 'access content'));
+ $this->drupalLogout();
+ $this->drupalLogin($content_user);
+ $close_edit = array('active' => 0);
+ $this->pollUpdate($poll_nid, $title, $close_edit);
+ $this->drupalGet('user/' . $content_user->uid);
+ $this->assertNoText($title, 'Poll no longer appears in block.');
}
}