Index: tests/poll_module.test
===================================================================
RCS file: tests/poll_module.test
diff -N tests/poll_module.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/poll_module.test	3 Jan 2008 11:26:04 -0000
@@ -0,0 +1,85 @@
+<?php
+
+class PollTests extends DrupalTestCase {
+
+  function pollCreate($standalone = TRUE) {
+    $this->assertTrue(TRUE, 'Poll create' . $standalone);
+    $web_user = $this->drupalCreateUserRolePerm(array('create poll content'));
+    $this->drupalLoginUser($web_user);
+    $title = $this->randomName();
+    $edit = array (
+      'title' => $title,
+      'choice[0][chtext]' => 'choice 1',
+      'choice[1][chtext]' => 'choice 2',
+    );
+    $this->drupalPostRequest('node/add/poll', $edit, 'More choices');
+    $edit = array(
+      'title' => $title,
+      'choice[0][chtext]' => 'choice 1',
+      'choice[1][chtext]' => 'choice 2',
+      'choice[2][chtext]' => 'choice 3',
+      'choice[3][chtext]' => 'choice 4',
+      'choice[4][chtext]' => 'choice 5',
+      'choice[5][chtext]' => 'choice 6',
+      'choice[6][chtext]' => 'choice 7',
+    );
+    if ($standalone) {
+      $this->drupalPostRequest(NULL, $edit, 'Preview');
+      for ($i = 0; $i <= 6; $i++) {
+        $bar = theme('poll_bar', $edit['choice['. $i .'][chtext]'], NULL, 0, FALSE, FALSE);
+        $this->assertTrue($bar, "bar $i is themed");
+        $this->assertWantedRaw($bar, "bar $i found in preview");
+      }
+    }
+    $this->drupalPostRequest(NULL, $edit, 'Save');
+    $this->nid = preg_replace('/\D/', '', $this->getUrl());
+    $this->assertWantedRaw(t('@type %title has been created.', array('@type' => node_get_types('name', 'poll'), '%title' => $title)), 'Poll has been created.');
+  }
+
+}
+
+class PollCreateTest extends PollTests {
+  
+  /**
+   * Implementation of get_info() for information
+   */
+  function get_info() {
+    return array('name' => t('Poll create'), 'desc' => 'Adds "more choices", previews and creates a poll.', 'group' => 'Poll module tests');
+  }
+
+  function tearDown() {
+    parent::tearDown();
+  }
+
+  function testPollCreate() {
+    $this->pollCreate(TRUE);
+  }
+}
+
+class PollVoteTest extends PollTests {
+  /**
+   * Implementation of get_info() for information
+   */
+  function get_info() {
+    return array('name' => t('Poll vote'), 'desc' => 'Vote on a poll', 'group' => 'Poll module tests');
+  }
+
+  function tearDown() {
+    parent::tearDown();
+  }
+
+  function testPollVote() {
+    $this->pollCreate(FALSE);
+    $this->drupalGet(url('logout', array('absolute' => TRUE)));
+    $web_user = $this->drupalCreateUserRolePerm(array('cancel own vote', 'inspect all votes', 'vote on polls'));
+    $this->drupalLoginUser($web_user);
+    $edit = array (
+      'choice' => '1',
+    );
+    $this->drupalPostRequest('node/'. $this->nid, $edit, 'Vote');
+    $this->assertWantedRaw('Your vote was recorded.', 'Your vote was recorded.');
+    $this->drupalGet(url("node/$this->nid/votes", array("absolute" => TRUE)));
+    $this->assertWantedRaw(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->assertWantedRaw('choice 2', 'vote recorded');
+  }
+}
