dashboard.test 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file
  4. * Tests for dashboard.module.
  5. */
  6. /**
  7. * Tests the Dashboard module blocks.
  8. */
  9. class DashboardBlocksTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Dashboard blocks',
  13. 'description' => 'Test blocks as used by the dashboard.',
  14. 'group' => 'Dashboard',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp();
  19. // Create and log in an administrative user having access to the dashboard.
  20. $admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks', 'access administration pages', 'administer modules'));
  21. $this->drupalLogin($admin_user);
  22. // Make sure that the dashboard is using the same theme as the rest of the
  23. // site (and in particular, the same theme used on 403 pages). This forces
  24. // the dashboard blocks to be the same for an administrator as for a
  25. // regular user, and therefore lets us test that the dashboard blocks
  26. // themselves are specifically removed for a user who does not have access
  27. // to the dashboard page.
  28. theme_enable(array('stark'));
  29. variable_set('theme_default', 'stark');
  30. variable_set('admin_theme', 'stark');
  31. }
  32. /**
  33. * Tests adding a block to the dashboard and checking access to it.
  34. */
  35. function testDashboardAccess() {
  36. // Add a new custom block to a dashboard region.
  37. $custom_block = array();
  38. $custom_block['info'] = $this->randomName(8);
  39. $custom_block['title'] = $this->randomName(8);
  40. $custom_block['body[value]'] = $this->randomName(32);
  41. $custom_block['regions[stark]'] = 'dashboard_main';
  42. $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
  43. // Ensure admin access.
  44. $this->drupalGet('admin/dashboard');
  45. $this->assertResponse(200, t('Admin has access to the dashboard.'));
  46. $this->assertRaw($custom_block['title'], t('Admin has access to a dashboard block.'));
  47. // Ensure non-admin access is denied.
  48. $normal_user = $this->drupalCreateUser();
  49. $this->drupalLogin($normal_user);
  50. $this->drupalGet('admin/dashboard');
  51. $this->assertResponse(403, t('Non-admin has no access to the dashboard.'));
  52. $this->assertNoText($custom_block['title'], t('Non-admin has no access to a dashboard block.'));
  53. }
  54. /**
  55. * Tests that dashboard regions are displayed or hidden properly.
  56. */
  57. function testDashboardRegions() {
  58. $dashboard_regions = dashboard_region_descriptions();
  59. // Ensure blocks can be placed in dashboard regions.
  60. $this->drupalGet('admin/dashboard/configure');
  61. foreach ($dashboard_regions as $region => $description) {
  62. $elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
  63. $this->assertTrue(!empty($elements), t('%region is an available choice on the dashboard block configuration page.', array('%region' => $region)));
  64. }
  65. // Ensure blocks cannot be placed in dashboard regions on the standard
  66. // blocks configuration page.
  67. $this->drupalGet('admin/structure/block');
  68. foreach ($dashboard_regions as $region => $description) {
  69. $elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
  70. $this->assertTrue(empty($elements), t('%region is not an available choice on the block configuration page.', array('%region' => $region)));
  71. }
  72. }
  73. /**
  74. * Tests that the dashboard module can be re-enabled, retaining its blocks.
  75. */
  76. function testDisableEnable() {
  77. // Add a new custom block to a dashboard region.
  78. $custom_block = array();
  79. $custom_block['info'] = $this->randomName(8);
  80. $custom_block['title'] = $this->randomName(8);
  81. $custom_block['body[value]'] = $this->randomName(32);
  82. $custom_block['regions[stark]'] = 'dashboard_main';
  83. $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
  84. $this->drupalGet('admin/dashboard');
  85. $this->assertRaw($custom_block['title'], t('Block appears on the dashboard.'));
  86. $edit = array();
  87. $edit['modules[Core][dashboard][enable]'] = FALSE;
  88. $this->drupalPost('admin/modules', $edit, t('Save configuration'));
  89. $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
  90. $this->assertNoRaw('assigned to the invalid region', t('Dashboard blocks gracefully disabled.'));
  91. module_list(TRUE);
  92. $this->assertFalse(module_exists('dashboard'), t('Dashboard disabled.'));
  93. $edit['modules[Core][dashboard][enable]'] = 'dashboard';
  94. $this->drupalPost('admin/modules', $edit, t('Save configuration'));
  95. $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
  96. module_list(TRUE);
  97. $this->assertTrue(module_exists('dashboard'), t('Dashboard enabled.'));
  98. $this->drupalGet('admin/dashboard');
  99. $this->assertRaw($custom_block['title'], t('Block still appears on the dashboard.'));
  100. }
  101. /**
  102. * Tests that administrative blocks are available for the dashboard.
  103. */
  104. function testBlockAvailability() {
  105. // Test "Recent comments", which should be available (defined as
  106. // "administrative") but not enabled.
  107. $this->drupalGet('admin/dashboard');
  108. $this->assertNoText(t('Recent comments'), t('"Recent comments" not on dashboard.'));
  109. $this->drupalGet('admin/dashboard/drawer');
  110. $this->assertText(t('Recent comments'), t('Drawer of disabled blocks includes a block defined as "administrative".'));
  111. $this->assertNoText(t('Syndicate'), t('Drawer of disabled blocks excludes a block not defined as "administrative".'));
  112. $this->drupalGet('admin/dashboard/configure');
  113. $elements = $this->xpath('//select[@id=:id]//option[@selected="selected"]', array(':id' => 'edit-blocks-comment-recent-region'));
  114. $this->assertTrue($elements[0]['value'] == 'dashboard_inactive', t('A block defined as "administrative" defaults to dashboard_inactive.'));
  115. // Now enable the block on the dashboard.
  116. $values = array();
  117. $values['blocks[comment_recent][region]'] = 'dashboard_main';
  118. $this->drupalPost('admin/dashboard/configure', $values, t('Save blocks'));
  119. $this->drupalGet('admin/dashboard');
  120. $this->assertText(t('Recent comments'), t('"Recent comments" was placed on dashboard.'));
  121. $this->drupalGet('admin/dashboard/drawer');
  122. $this->assertNoText(t('Recent comments'), t('Drawer of disabled blocks excludes enabled blocks.'));
  123. }
  124. }