summaryrefslogtreecommitdiff
path: root/modules/poll
diff options
context:
space:
mode:
Diffstat (limited to 'modules/poll')
-rw-r--r--modules/poll/poll.module7
-rw-r--r--modules/poll/poll.test72
2 files changed, 77 insertions, 2 deletions
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 614bb9240..6cea88648 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -14,7 +14,7 @@ function poll_help($path, $arg) {
case 'admin/help#poll':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The Poll module can be used to create simple surveys or questionnaires that display cumulative results. A poll is a good way to receive feedback from site users and community members. For more information, see the online handbook entry for the <a href="@poll">Poll module</a>.', array('@poll' => 'http://drupal.org/handbook/modules/poll/')) . '</p>';
+ $output .= '<p>' . t('The Poll module can be used to create simple surveys or questionnaires that display cumulative results. A poll is a good way to receive feedback from site users and community members. For more information, see the online handbook entry for the <a href="@poll">Poll module</a>.', array('@poll' => 'http://drupal.org/documentation/modules/poll/')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Creating a poll') . '</dt>';
@@ -76,7 +76,7 @@ function poll_permission() {
'title' => t('Cancel and change own votes'),
),
'inspect all votes' => array(
- 'title' => t('View voting results'),
+ 'title' => t('View details for all votes'),
),
);
@@ -476,6 +476,9 @@ function poll_validate($node, $form) {
function poll_field_attach_prepare_translation_alter(&$entity, $context) {
if ($context['entity_type'] == 'node' && $entity->type == 'poll') {
$entity->choice = $context['source_entity']->choice;
+ foreach ($entity->choice as $i => $options) {
+ $entity->choice[$i]['chvotes'] = 0;
+ }
}
}
diff --git a/modules/poll/poll.test b/modules/poll/poll.test
index f5c93b288..9982222c8 100644
--- a/modules/poll/poll.test
+++ b/modules/poll/poll.test
@@ -798,3 +798,75 @@ class PollDeleteChoiceTestCase extends PollTestCase {
$this->assertText('Third choice', t('Third choice remains.'));
}
}
+
+/**
+ * Tests poll translation logic.
+ */
+class PollTranslateTestCase extends PollTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Poll translation',
+ 'description' => 'Test the poll translation logic.',
+ 'group' => 'Poll',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('poll', 'translation');
+ }
+
+ /**
+ * Tests poll creation and translation.
+ *
+ * Checks that the choice names get copied from the original poll and that
+ * the vote count values are set to 0.
+ */
+ function testPollTranslate() {
+ $admin_user = $this->drupalCreateUser(array('administer content types', 'administer languages', 'edit any poll content', 'create poll content', 'administer nodes', 'translate content'));
+
+ // Set up a poll with two choices.
+ $title = $this->randomName();
+ $choices = array($this->randomName(), $this->randomName());
+ $poll_nid = $this->pollCreate($title, $choices, FALSE);
+ $this->assertTrue($poll_nid, t('Poll for translation logic test created.'));
+
+ $this->drupalLogout();
+ $this->drupalLogin($admin_user);
+
+ // Enable a second language.
+ $this->drupalGet('admin/config/regional/language');
+ $edit = array();
+ $edit['langcode'] = 'nl';
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+ $this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => 'Dutch')), t('Language Dutch has been created.'));
+
+ // Set "Poll" content type to use multilingual support with translation.
+ $this->drupalGet('admin/structure/types/manage/poll');
+ $edit = array();
+ $edit['language_content_type'] = 2;
+ $this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type'));
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Poll')), t('Poll content type has been updated.'));
+
+ // Edit poll.
+ $this->drupalGet("node/$poll_nid/edit");
+ $edit = array();
+ // Set the poll's first choice count to 200.
+ $edit['choice[chid:1][chvotes]'] = 200;
+ // Set the language to Dutch.
+ $edit['language'] = 'nl';
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ // Translate the Dutch poll.
+ $this->drupalGet('node/add/poll', array('query' => array('translation' => $poll_nid, 'target' => 'en')));
+
+ $dutch_poll = node_load($poll_nid);
+
+ // Check that the vote count values didn't get copied from the Dutch poll
+ // and are set to 0.
+ $this->assertFieldByName('choice[chid:1][chvotes]', '0', ('Found choice with vote count 0'));
+ $this->assertFieldByName('choice[chid:2][chvotes]', '0', ('Found choice with vote count 0'));
+ // Check that the choice names got copied from the Dutch poll.
+ $this->assertFieldByName('choice[chid:1][chtext]', $dutch_poll->choice[1]['chtext'], t('Found choice with text @text', array('@text' => $dutch_poll->choice[1]['chtext'])));
+ $this->assertFieldByName('choice[chid:2][chtext]', $dutch_poll->choice[2]['chtext'], t('Found choice with text @text', array('@text' => $dutch_poll->choice[2]['chtext'])));
+ }
+}