summaryrefslogtreecommitdiff
path: root/modules/dashboard/dashboard.test
blob: 9c03d75c2d3b1782ef15c050288354e5a37900ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// $Id$

/**
 * @file
 * Tests for the dashboard module.
 */

class DashboardBlocksTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Dashboard blocks',
      'description' => 'Test blocks as used by the dashboard.',
      'group' => 'Dashboard',
    );
  }

  function setUp() {
    parent::setUp();

    // Create and log in an administrative user having access to the dashboard.
    $admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks'));
    $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');
  }

  /**
   * Test adding a block to the dashboard and checking access to it.
   */
  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, t('Admin has access to the dashboard.'));
    $this->assertRaw($custom_block['title'], t('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, t('Non-admin has no access to the dashboard.'));
    $this->assertNoText($custom_block['title'], t('Non-admin has no access to a dashboard block.'));
  }

  /**
   * Test that dashboard regions are displayed or hidden properly.
   */
  function testDashboardRegions() {
    $dashboard_regions = dashboard_region_descriptions();

    // Ensure blocks can be placed in dashboard regions.
    $this->drupalGet('admin/structure/dashboard');
    foreach ($dashboard_regions as $region => $description) {
      $elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
      $this->assertTrue(!empty($elements), t('%region is an available choice on the dashboard block configuration page.', array('%region' => $region)));
    }

    // 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));
      $this->assertTrue(empty($elements), t('%region is not an available choice on the block configuration page.', array('%region' => $region)));
    }
  }
}