Index: modules/poll/poll.test =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.test,v retrieving revision 1.5 diff -u -p -r1.5 poll.test --- modules/poll/poll.test 5 Aug 2008 18:07:14 -0000 1.5 +++ modules/poll/poll.test 9 Sep 2008 18:20:14 -0000 @@ -129,5 +129,85 @@ class PollVoteTestCase extends PollTestC $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'); } + + /** + * Test anonymous user poll vote + * @see http://drupal.org/node/295994 + */ + function testAnonymousPollVote() { + // create a poll + $title = $this->randomName(); + $choices = $this->_generateChoices(7); + $poll_nid = $this->pollCreate($title, $choices, FALSE); + + $this->drupalLogout(); + // anonymous: check that we are not allowed to vote, but can view the node + $this->drupalGet('node/'.$poll_nid); + $this->assertResponse(200, t('Poll is accessible')); + $this->assertNoRaw(t('Vote'), t('We should NOT see the vote-button (by label)')); + $this->assertNoRaw('edit-vote', t('We should NOT see the vote-button (by id)')); + + // login in as admin user w/ permissions control + $poll_admin = $this->drupalCreateUser(array('create poll content', 'access content', 'administer permissions')); + $this->drupalLogin($poll_admin); + // and allow anonymous to post + $this->drupalGet('admin/user/permissions'); + $this->assertResponse(200, t('We should be able to view this')); + $post_values = array('1[cancel own vote]'=>'checked', '1[vote on polls]'=>'checked'); + $this->drupalPost('admin/user/permissions', $post_values, t('Save permissions')); + $this->drupalLogout(); + + // from now on as anonymous + $this->drupalGet('node/'.$poll_nid); + $this->assertResponse(200, t('We should be able to access a poll')); + $this->drupalGet('node/'.$poll_nid); + // @note: i assert both for label and id, which could be superfluous but i could not get assertFieldByName/assertFieldById to work ... + // there should be a Vote button + $this->assertRaw(t('Vote'), t('We should see the vote-button (by label)')); + // search the raw html for the id ... + $this->assertRaw('edit-vote', t('We should see the vote-button (by id)')); + // post a choice + $edit = array('choice'=>1); + $this->drupalPost('node/'. $poll_nid, $edit, t('Vote')); + $this->assertText(t('Your vote was recorded.'), t('Feedback text present')); + $this->assertRaw(t('Cancel your vote'), t('We should be able to see "cancel the vote"-button (by label)')); + $this->assertRaw('edit-poll-cancel-form', t('We should be able to see the "cancel the vote"-button (by id)')); + + // we check now that the vote button isnt there anymore und then cancel our vote and then the vote button is there again ... + $this->drupalGet('node/'.$poll_nid); + $this->assertNoRaw(t('Vote'), t('We should NOT see the vote-button (by label) anymore')); + // search the raw html for the id ... + $this->assertNoRaw('edit-vote', t('We should NOT see the vote-button (by id) anymore')); + $this->assertRaw('edit-poll-cancel-form', t('We should be able to see the "cancel the vote"-button (by id)')); + + // cancel the vote - and we should see the vote button + $this->drupalPost('node/'. $poll_nid, array(), t('Cancel your vote')); + $this->assertRaw(t('Vote'), t('We should see the vote-button (by label)')); + // search the raw html for the id ... + $this->assertRaw('edit-vote', t('We should see the vote-button (by id)')); + + // remove the 'cancel vote'-permissions and check again + $this->drupalLogin($poll_admin); + $this->drupalGet('admin/user/permissions'); + $this->assertResponse(200, t('We should be able to view this')); + $post_values = array('1[cancel own vote]'=>false, '1[vote on polls]'=>'checked'); + $this->drupalPost('admin/user/permissions', $post_values, t('Save permissions')); + $this->drupalLogout(); + + // now as anonymous + // post a choice + $edit = array('choice'=>1); + $this->drupalPost('node/'. $poll_nid, $edit, t('Vote')); + $this->assertText(t('Your vote was recorded.'), t('Feedback text present')); + // but no more cancelling available + $this->assertNoRaw(t('Cancel your vote'), t('We should be able to see "cancel the vote"-button (by label)')); + $this->assertNoRaw('edit-poll-cancel-form', t('We should be able to see the "cancel the vote"-button (by id)')); + + // @todo: maybe check the no. of votes, but the rendered html does not lend itself to "parsing" really - unpleasant xpathing :) + // HTML per choice: