2010-07-02 15:24:31 +00:00
<?php
/**
* @file
2011-02-04 18:42:22 +00:00
* Tests for dashboard.module.
2010-07-02 15:24:31 +00:00
*/
2012-02-14 19:38:27 +00:00
/**
* Tests the Dashboard module blocks.
*/
2010-09-14 21:51:01 +00:00
class DashboardBlocksTestCase extends DrupalWebTestCase {
2010-07-02 15:24:31 +00:00
public static function getInfo() {
return array(
2010-09-14 21:51:01 +00:00
'name' => 'Dashboard blocks',
'description' => 'Test blocks as used by the dashboard.',
2010-07-02 15:24:31 +00:00
'group' => 'Dashboard',
);
}
function setUp() {
parent::setUp();
// Create and log in an administrative user having access to the dashboard.
2010-10-31 21:36:24 +00:00
$admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks', 'access administration pages', 'administer modules'));
2010-07-02 15:24:31 +00:00
$this->drupalLogin($admin_user);
// Make sure that the dashboard is using the same theme as the rest of the
// site (and in particular, the same theme used on 403 pages). This forces
// the dashboard blocks to be the same for an administrator as for a
// regular user, and therefore lets us test that the dashboard blocks
// themselves are specifically removed for a user who does not have access
// to the dashboard page.
theme_enable(array('stark'));
variable_set('theme_default', 'stark');
variable_set('admin_theme', 'stark');
}
/**
2012-02-14 19:38:27 +00:00
* Tests adding a block to the dashboard and checking access to it.
2010-07-02 15:24:31 +00:00
*/
function testDashboardAccess() {
// Add a new custom block to a dashboard region.
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
$custom_block['body[value]'] = $this->randomName(32);
$custom_block['regions[stark]'] = 'dashboard_main';
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Ensure admin access.
2010-08-20 01:42:52 +00:00
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertResponse(200, 'Admin has access to the dashboard.');
$this->assertRaw($custom_block['title'], 'Admin has access to a dashboard block.');
2010-07-02 15:24:31 +00:00
// Ensure non-admin access is denied.
$normal_user = $this->drupalCreateUser();
$this->drupalLogin($normal_user);
2010-08-20 01:42:52 +00:00
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertResponse(403, 'Non-admin has no access to the dashboard.');
$this->assertNoText($custom_block['title'], 'Non-admin has no access to a dashboard block.');
2010-07-02 15:24:31 +00:00
}
2010-09-14 21:51:01 +00:00
/**
2012-02-14 19:38:27 +00:00
* Tests that dashboard regions are displayed or hidden properly.
2010-09-14 21:51:01 +00:00
*/
function testDashboardRegions() {
$dashboard_regions = dashboard_region_descriptions();
// Ensure blocks can be placed in dashboard regions.
2010-10-21 11:55:09 +00:00
$this->drupalGet('admin/dashboard/configure');
2010-09-14 21:51:01 +00:00
foreach ($dashboard_regions as $region => $description) {
$elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
2013-08-12 19:46:50 +00:00
$this->assertTrue(!empty($elements), format_string('%region is an available choice on the dashboard block configuration page.', array('%region' => $region)));
2010-09-14 21:51:01 +00:00
}
// Ensure blocks cannot be placed in dashboard regions on the standard
// blocks configuration page.
$this->drupalGet('admin/structure/block');
foreach ($dashboard_regions as $region => $description) {
$elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
2013-08-12 19:46:50 +00:00
$this->assertTrue(empty($elements), format_string('%region is not an available choice on the block configuration page.', array('%region' => $region)));
2010-09-14 21:51:01 +00:00
}
}
2010-10-31 21:36:24 +00:00
/**
2012-02-14 19:38:27 +00:00
* Tests that the dashboard module can be re-enabled, retaining its blocks.
2010-10-31 21:36:24 +00:00
*/
function testDisableEnable() {
// Add a new custom block to a dashboard region.
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
$custom_block['body[value]'] = $this->randomName(32);
$custom_block['regions[stark]'] = 'dashboard_main';
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertRaw($custom_block['title'], 'Block appears on the dashboard.');
2010-10-31 21:36:24 +00:00
$edit = array();
$edit['modules[Core][dashboard][enable]'] = FALSE;
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2013-08-12 19:46:50 +00:00
$this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
$this->assertNoRaw('assigned to the invalid region', 'Dashboard blocks gracefully disabled.');
2010-10-31 21:36:24 +00:00
module_list(TRUE);
2013-08-12 19:46:50 +00:00
$this->assertFalse(module_exists('dashboard'), 'Dashboard disabled.');
2010-10-31 21:36:24 +00:00
$edit['modules[Core][dashboard][enable]'] = 'dashboard';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2013-08-12 19:46:50 +00:00
$this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
2010-10-31 21:36:24 +00:00
module_list(TRUE);
2013-08-12 19:46:50 +00:00
$this->assertTrue(module_exists('dashboard'), 'Dashboard enabled.');
2010-10-31 21:36:24 +00:00
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertRaw($custom_block['title'], 'Block still appears on the dashboard.');
2010-10-31 21:36:24 +00:00
}
2010-11-06 23:24:33 +00:00
/**
2012-02-14 19:38:27 +00:00
* Tests that administrative blocks are available for the dashboard.
2010-11-06 23:24:33 +00:00
*/
function testBlockAvailability() {
// Test "Recent comments", which should be available (defined as
// "administrative") but not enabled.
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertNoText(t('Recent comments'), '"Recent comments" not on dashboard.');
2010-11-06 23:24:33 +00:00
$this->drupalGet('admin/dashboard/drawer');
2013-08-12 19:46:50 +00:00
$this->assertText(t('Recent comments'), 'Drawer of disabled blocks includes a block defined as "administrative".');
$this->assertNoText(t('Syndicate'), 'Drawer of disabled blocks excludes a block not defined as "administrative".');
2010-11-06 23:24:33 +00:00
$this->drupalGet('admin/dashboard/configure');
$elements = $this->xpath('//select[@id=:id]//option[@selected="selected"]', array(':id' => 'edit-blocks-comment-recent-region'));
2013-08-12 19:46:50 +00:00
$this->assertTrue($elements[0]['value'] == 'dashboard_inactive', 'A block defined as "administrative" defaults to dashboard_inactive.');
2010-11-06 23:24:33 +00:00
// Now enable the block on the dashboard.
$values = array();
$values['blocks[comment_recent][region]'] = 'dashboard_main';
$this->drupalPost('admin/dashboard/configure', $values, t('Save blocks'));
$this->drupalGet('admin/dashboard');
2013-08-12 19:46:50 +00:00
$this->assertText(t('Recent comments'), '"Recent comments" was placed on dashboard.');
2010-11-06 23:24:33 +00:00
$this->drupalGet('admin/dashboard/drawer');
2013-08-12 19:46:50 +00:00
$this->assertNoText(t('Recent comments'), 'Drawer of disabled blocks excludes enabled blocks.');
2010-11-06 23:24:33 +00:00
}
2010-07-02 15:24:31 +00:00
}