diff options
Diffstat (limited to 'modules/poll')
-rw-r--r-- | modules/poll/poll.module | 38 | ||||
-rw-r--r-- | modules/poll/poll.test | 29 |
2 files changed, 50 insertions, 17 deletions
diff --git a/modules/poll/poll.module b/modules/poll/poll.module index cd7d49474..f31ac634d 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -136,29 +136,33 @@ function _poll_menu_access($node, $perm, $inspect_allowvotes) { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). + */ +function poll_block_list() { + if (user_access('access content')) { + $blocks['recent']['info'] = t('Most recent poll'); + return $blocks; + } +} + +/** + * Implementation of hook_block_view(). * * Generates a block containing the latest poll. */ -function poll_block($op = 'list', $delta = '') { +function poll_block_view($delta = '') { if (user_access('access content')) { - if ($op == 'list') { - $blocks['recent']['info'] = t('Most recent poll'); - return $blocks; - } - elseif ($op == 'view') { - // Retrieve the latest poll. - $record = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = :status AND p.active = :active ORDER BY n.created DESC"), array(':status' => 1, ':active' => 1), 0, 1)->fetch(); - if ($record) { - $poll = node_load($record->nid); - if ($poll->nid) { - $poll = poll_view($poll, TRUE, FALSE, TRUE); - } + // Retrieve the latest poll. + $record = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = :status AND p.active = :active ORDER BY n.created DESC"), array(':status' => 1, ':active' => 1), 0, 1)->fetch(); + if ($record) { + $poll = node_load($record->nid); + if ($poll->nid) { + $poll = poll_view($poll, TRUE, FALSE, TRUE); } - $block['subject'] = t('Poll'); - $block['content'] = drupal_render($poll->content); - return $block; } + $block['subject'] = t('Poll'); + $block['content'] = drupal_render($poll->content); + return $block; } } diff --git a/modules/poll/poll.test b/modules/poll/poll.test index 83ac61778..a7030db3f 100644 --- a/modules/poll/poll.test +++ b/modules/poll/poll.test @@ -124,3 +124,32 @@ class PollVoteTestCase extends PollTestCase { } } +class PollBlockTestCase extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Block availability'), + 'description' => t('Check if the most recent poll block is available.'), + 'group' => t('Poll'), + ); + } + + function setUp() { + parent::setUp('poll'); + + // Create and login user + $admin_user = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($admin_user); + } + + function testRecentBlock() { + // Set block title to confirm that the interface is availble. + $this->drupalPost('admin/build/block/configure/poll/recent', array('title' => $this->randomName(8)), t('Save block')); + $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.')); + + // Set the block to a region to confirm block is availble. + $edit = array(); + $edit['poll_recent[region]'] = 'footer'; + $this->drupalPost('admin/build/block', $edit, t('Save blocks')); + $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); + } +} |