Spike PHPCoverage Details: poll.test

Line #FrequencySource Line
1 <?php
2 // $Id: poll.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
3 
4 class PollTestCase extends DrupalTestCase {
5 
6   function pollCreate($standalone = TRUE) {
7     $this->assertTrue(TRUE, 'Poll create' . $standalone);
8     $web_user = $this->drupalCreateUser(array('create poll content', 'access content'));
9     $this->drupalLogin($web_user);
10     $title = $this->randomName();
11     $edit = array (
12       'title' => $title,
13       'choice[0][chtext]' => 'choice 1',
14       'choice[1][chtext]' => 'choice 2',
15     );
16     $this->drupalPost('node/add/poll', $edit, t('More choices'));
17     $edit = array(
18       'title' => $title,
19       'choice[0][chtext]' => 'choice 1',
20       'choice[1][chtext]' => 'choice 2',
21       'choice[2][chtext]' => 'choice 3',
22       'choice[3][chtext]' => 'choice 4',
23       'choice[4][chtext]' => 'choice 5',
24       'choice[5][chtext]' => 'choice 6',
25       'choice[6][chtext]' => 'choice 7',
26     );
27     if ($standalone) {
28       $this->drupalPost(NULL, $edit, t('Preview'));
29       for ($i = 0; $i <= 6; $i++) {
30         $bar = theme('poll_bar', $edit['choice['. $i .'][chtext]'], NULL, 0, FALSE, FALSE);
31         $this->assertTrue($bar, "bar $i is themed");
32         $this->assertRaw($bar, "bar $i found in preview");
33       }
34     }
35     $this->drupalPost(NULL, $edit, t('Save'));
36     $node = node_load(array('title' => $title));
37     $this->nid = $node->nid;
38     $this->assertRaw(t('@type %title has been created.', array('@type' => node_get_types('name', 'poll'), '%title' => $title)), 'Poll has been created.');
39     $this->assertTrue($this->nid, t('Poll has been found in the database'));
40   }
41 
42 }
43 
44 class PollCreateTestCase extends PollTestCase {
45 
46   /**
47    * Implementation of getInfo() for information
48    */
49   function getInfo() {
501    return array('name' => t('Poll create'), 'description' => 'Adds "more choices", previews and creates a poll.', 'group' => 'Poll module tests');
51   }
52 
53   function setUp() {
54     parent::setUp();
55     $this->drupalModuleEnable('poll');
56   }
57 
58   function testPollCreate() {
59     $this->pollCreate(TRUE);
60   }
61 }
62 
63 class PollVoteTestCase extends PollTestCase {
64   /**
65    * Implementation of getInfo() for information
66    */
67   function getInfo() {
681    return array('name' => t('Poll vote'), 'description' => 'Vote on a poll', 'group' => 'Poll module tests');
69   }
70 
71   function setUp() {
72     parent::setUp();
73     $this->drupalModuleEnable('poll');
74   }
75 
76   function tearDown() {
77     parent::tearDown();
78   }
79 
80   function testPollVote() {
81     $this->pollCreate(FALSE);
82     $this->drupalGet('logout');
83     $web_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
84     $this->drupalLogin($web_user);
85     $edit = array (
86       'choice' => '1',
87     );
88     $this->drupalPost('node/'. $this->nid, $edit, t('Vote'));
89     $this->assertText('Your vote was recorded.', 'Your vote was recorded.');
90     $this->drupalGet("node/$this->nid/votes");
91     $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.');
92     $this->assertText('choice 2', 'vote recorded');
93   }
94 }