block_example.test

  1. examples
    1. 7 block_example/block_example.test
    2. 8 block_example/block_example.test

Test case for testing the block example module.

Classes

NameDescription
BlockExampleTestCase@file Test case for testing the block example module.

File

block_example/block_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test case for testing the block example module.
  5. */
  6. class BlockExampleTestCase extends DrupalWebTestCase {
  7. protected $web_user;
  8. public static function getInfo() {
  9. return array(
  10. 'name' => 'Block example functionality',
  11. 'description' => 'Test the configuration options and block created by Block Example module.',
  12. 'group' => 'Examples',
  13. );
  14. }
  15. /**
  16. * Enable modules and create user with specific permissions.
  17. */
  18. function setUp() {
  19. parent::setUp('block_example', 'search');
  20. // Create user. Search content permission granted for the search block to
  21. // be shown.
  22. $this->web_user = $this->drupalCreateUser(array('administer blocks', 'search content', 'access contextual links'));
  23. }
  24. /**
  25. * Login user, create an example node, and test block functionality through
  26. * the admin and user interfaces.
  27. */
  28. function testBlockExampleBasic() {
  29. // Login the admin user.
  30. $this->drupalLogin($this->web_user);
  31. // Find the blocks in the settings page.
  32. $this->drupalGet('admin/structure/block');
  33. $this->assertRaw(t('Example: configurable text string'), t('Block configurable-string found.'));
  34. $this->assertRaw(t('Example: empty block'), t('Block empty-block found.'));
  35. // Verify the default settings for block are processed.
  36. $this->assertFieldByName('blocks[block_example_example_empty][region]', 'sidebar_first', t('Empty block is enabled in first sidebar successfully verified.') );
  37. $this->assertFieldByName('blocks[block_example_example_configurable_text][region]', -1, t('Configurable text block is disabled in first sidebar successfully verified.') );
  38. // Verify that blocks are not shown
  39. $this->drupalGet('/');
  40. $this->assertNoRaw( t('Title of first block (example_configurable_text)'), t('Block configurable test not found.'));
  41. $this->assertNoRaw( t('Title of second block (example_empty)'), t('Block empty not found.'));
  42. // Enable the Configurable text block and verify
  43. $this->drupalPost('admin/structure/block', array('blocks[block_example_example_configurable_text][region]' => 'sidebar_first'), t('Save blocks'));
  44. $this->assertFieldByName('blocks[block_example_example_configurable_text][region]', 'sidebar_first', t('Configurable text block is enabled in first sidebar successfully verified.') );
  45. // Verify that blocks are there. Empty block will not be shown, because it is empty
  46. $this->drupalGet('/');
  47. $this->assertRaw( t('Title of first block (example_configurable_text)'), t('Block configurable text found.'));
  48. // Change content of configurable text block
  49. $string = $this->randomName();
  50. $this->drupalPost('admin/structure/block/manage/block_example/example_configurable_text/configure', array('block_example_string' => $string), t('Save block'));
  51. // Verify that new content is shown
  52. $this->drupalGet('/');
  53. $this->assertRaw( $string, t('Content of configurable text block successfully verified.'));
  54. // Make sure our example uppercased block is shown as altered by the
  55. // hook_block_view_alter().
  56. $this->assertRaw(t('UPPERCASE THIS PLEASE'));
  57. // Create a new block and make sure it gets uppercased.
  58. $post = array(
  59. 'title' => t('configurable block to be uppercased'),
  60. 'info' => t('configurable block to be uppercased'),
  61. 'body[value]' => t('body of new block'),
  62. 'regions[bartik]' => 'sidebar_first',
  63. );
  64. $this->drupalPost('admin/structure/block/add', $post, t('Save block'));
  65. $this->drupalGet('/');
  66. $this->assertRaw(('CONFIGURABLE BLOCK TO BE UPPERCASED'));
  67. // Verify that search block is at the bottom of the region.
  68. // Enable the search block on top of sidebar_first.
  69. $block_options = array(
  70. 'blocks[search_form][region]' => 'sidebar_first',
  71. 'blocks[search_form][weight]' => -9,
  72. );
  73. $this->drupalPost('admin/structure/block', $block_options, t('Save blocks'));
  74. // The first 'configure block' link should be from our configurable block,
  75. // the second from the Navigation menu, and the fifth (#4) from
  76. // search block if it was successfully pushed to the bottom.
  77. $this->drupalGet('/');
  78. $this->clickLink('Configure block', 4);
  79. $this->assertText(t("'@search' block", array('@search' => t('Search form'))), t('hook_block_info_alter successfully verified.') );
  80. }
  81. }
Login or register to post comments