function DashboardBlocksTestCase::testDashboardAccess

7.x dashboard.test DashboardBlocksTestCase::testDashboardAccess()

Tests adding a block to the dashboard and checking access to it.

File

drupal-7.x/modules/dashboard/dashboard.test, line 41
Tests for dashboard.module.

Class

DashboardBlocksTestCase
Tests the Dashboard module blocks.

Code

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.
  $this->drupalGet('admin/dashboard');
  $this->assertResponse(200, 'Admin has access to the dashboard.');
  $this->assertRaw($custom_block['title'], 'Admin has access to a dashboard block.');

  // Ensure non-admin access is denied.
  $normal_user = $this->drupalCreateUser();
  $this->drupalLogin($normal_user);
  $this->drupalGet('admin/dashboard');
  $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.');
}