Projet

Général

Profil

Paste
Télécharger (6,23 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / dashboard / dashboard.test @ bfb52287

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