? 602998-grndlvl-6.patch
? poll_timestamp.patch
? sites/drupal7.jonathan.local
Index: modules/poll/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.328
diff -u -p -r1.328 poll.module
--- modules/poll/poll.module	4 Dec 2009 16:49:47 -0000	1.328
+++ modules/poll/poll.module	8 Dec 2009 20:26:00 -0000
@@ -689,7 +689,8 @@ function poll_vote($form, &$form_state) 
       'nid' => $node->nid,
       'chid' => $choice,
       'uid' => $user->uid,
-      'hostname' => $user->uid ? ip_address() : '',
+      'hostname' => $user->uid ? '' : ip_address(),
+      'timestamp' => REQUEST_TIME,
     ))
     ->execute();
 
Index: modules/poll/poll.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.test,v
retrieving revision 1.27
diff -u -p -r1.27 poll.test
--- modules/poll/poll.test	2 Dec 2009 19:26:22 -0000	1.27
+++ modules/poll/poll.test	8 Dec 2009 20:26:00 -0000
@@ -349,3 +349,111 @@ class PollJSAddChoice extends DrupalWebT
     $this->assertFieldByName('choice[new:0][chtext]', '', t('Field !i found', array('!i' => 2)));
   }
 }
+
+class PollVoteCheckHostname extends PollTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User poll vote capability.',
+      'description' => 'Check that users and anonymous users from specified ip-address can only vote once.',
+      'group' => 'Poll'
+    );
+  }
+
+  function setUp() {
+    parent::setUp('poll');
+
+    // Create and login user.
+    $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'create poll content'));
+    $this->drupalLogin($this->admin_user);
+
+    // Allow anonymous users to vote on polls.
+    user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+      'access content' => TRUE,
+      'vote on polls' => TRUE,
+    ));
+
+    // Create poll. 
+    $title = $this->randomName();
+    $choices = $this->_generateChoices(3);
+    $this->poll_nid = $this->pollCreate($title, $choices, FALSE);
+
+    $this->drupalLogout();
+
+    // Create web users.
+    $this->web_user1 = $this->drupalCreateUser(array('access content', 'vote on polls'));
+    $this->web_user2 = $this->drupalCreateUser(array('access content', 'vote on polls'));
+  }
+
+  /**
+   * Check that anonymous users with same ip cannot vote on poll more than once
+   * unless user is logged in.
+   */
+  function testHostnamePollVote() {
+    // Login User1.
+    $this->drupalLogin($this->web_user1);
+
+    $edit = array(
+      'choice' => '1',
+    );
+
+    // User1 vote on Poll.
+    $this->drupalPost('node/' . $this->poll_nid, $edit, t('Vote'));
+    $this->assertText('Your vote was recorded.', t('%user vote was recorded.', array('%user' => $this->web_user1->name)));
+    $this->assertText('Total votes: 1', t('Vote count updated correctly.'));
+
+    // Check to make sure User1 cannot vote again.
+    $this->drupalGet('node/' . $this->poll_nid);
+    $elements = $this->xpath('//input[@value="Vote"]');
+    $this->assertTrue(empty($elements), t("%user is not able to vote again.", array('%user' => $this->web_user1->name)));
+
+    // Logout User1.
+    $this->drupalLogout();
+
+    // Anonymous user vote on Poll.
+    $this->drupalPost('node/' . $this->poll_nid, $edit, t('Vote'));
+    $this->assertText('Your vote was recorded.', t('Anonymous vote was recorded.'));
+    $this->assertText('Total votes: 2', t('Vote count updated correctly.'));
+
+    // Check to make sure Anonymous user cannot vote again.
+    $this->drupalGet('node/' . $this->poll_nid);
+    $elements = $this->xpath('//input[@value="Vote"]');
+    $this->assertTrue(empty($elements), t("Anonymous is not able to vote again."));
+
+    // Login User2.
+    $this->drupalLogin($this->web_user2);
+
+    // User2 vote on poll.
+    $this->drupalPost('node/' . $this->poll_nid, $edit, t('Vote'));
+    $this->assertText('Your vote was recorded.', t('%user vote was recorded.', array('%user' => $this->web_user2->name)));
+    $this->assertText('Total votes: 3', 'Vote count updated correctly.');
+
+    // Logout User2.
+    $this->drupalLogout();
+
+    // Change host name for anonymous users.
+    db_update('poll_vote')
+      ->fields(array(
+        'hostname' => '123.456.789.20',
+        ))
+        ->condition('hostname', '', '!=')
+        ->execute();
+
+    // Check to make sure Anonymous user can vote again after hostname change.
+    $this->drupalPost('node/' . $this->poll_nid, $edit, t('Vote'));
+    $this->assertText('Your vote was recorded.', t('%user vote was recorded.', array('%user' => $this->web_user2->name)));
+    $this->assertText('Total votes: 4', 'Vote count updated correctly.');
+
+    // Check to make sure Anonymous user cannot vote again.
+    $this->drupalGet('node/' . $this->poll_nid);
+    $elements = $this->xpath('//input[@value="Vote"]');
+    $this->assertTrue(empty($elements), t("Anonymous is not able to vote again."));
+
+    // Login User1.
+    $this->drupalLogin($this->web_user1);
+
+    // Check to make sure User1 still cannot vote even after hostname changed.
+    $this->drupalGet('node/' . $this->poll_nid);
+    $elements = $this->xpath('//input[@value="Vote"]');
+    $this->assertTrue(empty($elements), t("%user is not able to vote again.", array('%user' => $this->web_user1->name)));
+  }
+}
