diff --git a/advpoll.info b/advpoll.info index 5f87339..dbdcb98 100644 --- a/advpoll.info +++ b/advpoll.info @@ -10,6 +10,7 @@ configure = admin/config/search/advpoll files[] = tests/AdvPollTestBase.test files[] = tests/AdvPollSingleChoice.test +files[] = tests/AdvPollBlockInfo.test core = 7.x package = "Voting" diff --git a/advpoll.module b/advpoll.module index c120b51..defeaeb 100644 --- a/advpoll.module +++ b/advpoll.module @@ -950,6 +950,10 @@ function advpoll_get_recent() { * Block object */ function advpoll_get_poll_info_blocks($blocks) { + // Don't run this query if the required fields do not exist. + if(!advpoll_fields_exist()) { + return $blocks; + } $result = db_query("SELECT n.title, n.nid FROM {node} n LEFT JOIN {field_data_advpoll_dates} d ON d.revision_id = n.vid @@ -979,6 +983,20 @@ function advpoll_get_poll_info_blocks($blocks) { } /** + * Check if advanced poll fields exist. + * @return bool + * TRUE if the necessary fields exist. + */ +function advpoll_fields_exist() { + $dates = field_info_instance('node','advpoll_dates','advpoll'); + $closed = field_info_instance('node','advpoll_closed','advpoll'); + $options = field_info_instance('node','advpoll_options','advpoll'); + + return (($dates) && ($closed) && ($options)); + +} + +/** * Fetch nodes associated with delta for polls that are marked to show as blocks. * * @param $block diff --git a/tests/AdvPollBlockInfo.test b/tests/AdvPollBlockInfo.test new file mode 100644 index 0000000..7919178 --- /dev/null +++ b/tests/AdvPollBlockInfo.test @@ -0,0 +1,45 @@ + 'Advanced Poll Block Info', + 'description' => 'Test advanced Poll Block info.', + 'group' => 'Advanced Poll', + ); + } + + public function testBlockInfoFieldsExist() { + + // Create a poll + $node = $this->createPoll(); + + $this->drupalLogin($this->admin); + + // check that structure blocks pages load OK. + $this->drupalGet('admin/structure/block'); + + $this->assertText('This page provides a drag-and-drop interface for assigning a block to a region'); + + // Now delete the advpoll specific fields, then reload the block info page. + + $instance = field_info_instance('node', 'advpoll_dates', 'advpoll'); + field_delete_instance($instance); + + + // It should still load OK. + $this->drupalGet('admin/structure/block'); + + $this->assertText('This page provides a drag-and-drop interface for assigning a block to a region'); + + + } + +} diff --git a/tests/AdvPollTestBase.test b/tests/AdvPollTestBase.test index 7310ef0..ef28cf0 100644 --- a/tests/AdvPollTestBase.test +++ b/tests/AdvPollTestBase.test @@ -9,22 +9,22 @@ abstract class AdvPollTestBase extends DrupalWebTestCase { /** * @var */ - var $admin; + protected $admin; /** * @var */ -var $poll_admin; +protected $poll_admin; /** * @var */ - var $voter_a; + protected $voter_a; /** * @var */ - var $voter_b; + protected $voter_b; /** * Setup the testing environment. @@ -48,6 +48,7 @@ var $poll_admin; $this->admin = $this->drupalCreateUser(array( 'administer polls', 'inspect all votes', + 'administer blocks', )); $this->poll_admin = $this->drupalCreateUser(array( @@ -85,7 +86,7 @@ var $poll_admin; * - 'open': The poll is open and accepting votes. * - 'closed': The poll is closed and not accepting votes. * - * @returns + * @return object * The poll node. */ protected function createPoll($total_choices = 5,