'Block example functionality', 'description' => 'Test the configuration options and block created by Block Example module.', 'group' => 'Examples', ); } /** * Enable modules and create user with specific permissions. */ function setUp() { parent::setUp('block_example', 'search'); // Create user. Search content permission granted for the search block to // be shown. $this->web_user = $this->drupalCreateUser(array('administer blocks', 'search content', 'access contextual links')); } /** * Login user, create an example node, and test block functionality through * the admin and user interfaces. */ function testBlockExampleBasic() { // Login the admin user. $this->drupalLogin($this->web_user); // Find the blocks in the settings page. $this->drupalGet('admin/structure/block'); $this->assertRaw(t('Example: configurable text string'), t('Block configurable-string found.')); $this->assertRaw(t('Example: empty block'), t('Block empty-block found.')); // Verify the default settings for block are processed. $this->assertFieldByName('blocks[block_example_example_empty][region]', 'sidebar_first', t('Empty block is enabled in first sidebar successfully verified.') ); $this->assertFieldByName('blocks[block_example_example_configurable_text][region]', -1, t('Configurable text block is disabled in first sidebar successfully verified.') ); // Verify that blocks are not shown $this->drupalGet('/'); $this->assertNoRaw( t('Title of first block (example_configurable_text)'), t('Block configurable test not found.')); $this->assertNoRaw( t('Title of second block (example_empty)'), t('Block empty not found.')); // Enable the Configurable text block and verify $this->drupalPost('admin/structure/block', array('blocks[block_example_example_configurable_text][region]' => 'sidebar_first'), t('Save blocks')); $this->assertFieldByName('blocks[block_example_example_configurable_text][region]', 'sidebar_first', t('Configurable text block is enabled in first sidebar successfully verified.') ); // Verify that blocks are there. Empty block will not be shown, because it is empty $this->drupalGet('/'); $this->assertRaw( t('Title of first block (example_configurable_text)'), t('Block configurable text found.')); // Change content of configurable text block $string = $this->randomName(); $this->drupalPost('admin/structure/block/manage/block_example/example_configurable_text/configure', array('block_example_string' => $string), t('Save block')); // Verify that new content is shown $this->drupalGet('/'); $this->assertRaw( $string, t('Content of configurable text block successfully verified.')); // Verify the view_alter hook implementation. Change content of our block // to be 'magic string' $string = 'there is a magic string in content'; $this->drupalPost('admin/structure/block/manage/block_example/example_configurable_text/configure', array('block_example_string' => $string), t('Save block')); // Verify that new content is shown and the title is uppercase $this->drupalGet('/'); $this->assertRaw( $string, t('Content of configurable text block successfully verified.')); $this->assertText(t('Title of first block (example_configurable_text)'), t('hook_block_view_alter implementation successfully verified.')); // Verify that search block is at the bottom of the region. // Enable the search block on top of sidebar_first. $block_options = array( 'blocks[search_form][region]' => 'sidebar_first', 'blocks[search_form][weight]' => -9, ); $this->drupalPost('admin/structure/block', $block_options, t('Save blocks')); // The first 'configure block' link should be from our configurable block, // the second from the Navigation menu, and the third (#2) from search block // if it was successfully pushed to the bottom. $this->drupalGet('/'); $this->clickLink('Configure block', 2); $this->assertText(t("'@search' block", array('@search' => t('Search form'))), t('hook_block_info_alter successfully verified.') ); } }