block_example.test 4.5 KB

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