Test case for testing the block example module.
Classes
| Name | Description |
|---|---|
| BlockExampleTestCase | @file Test case for testing the block example module. |
File
block_example/block_example.testView source
- <?php
- /**
- * @file
- * Test case for testing the block example module.
- */
- class BlockExampleTestCase extends DrupalWebTestCase {
- protected $web_user;
-
- public static function getInfo() {
- return array(
- 'name' => '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.'));
-
- // Make sure our example uppercased block is shown as altered by the
- // hook_block_view_alter().
- $this->assertRaw(t('UPPERCASE THIS PLEASE'));
-
- // Create a new block and make sure it gets uppercased.
- $post = array(
- 'title' => t('configurable block to be uppercased'),
- 'info' => t('configurable block to be uppercased'),
- 'body[value]' => t('body of new block'),
- 'regions[bartik]' => 'sidebar_first',
- );
- $this->drupalPost('admin/structure/block/add', $post, t('Save block'));
- $this->drupalGet('/');
- $this->assertRaw(('CONFIGURABLE BLOCK TO BE UPPERCASED'));
-
- // 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 fifth (#4) from
- // search block if it was successfully pushed to the bottom.
- $this->drupalGet('/');
- $this->clickLink('Configure block', 4);
- $this->assertText(t("'@search' block", array('@search' => t('Search form'))), t('hook_block_info_alter successfully verified.') );
- }
- }
-