summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/checklistapi/tests/checklistapi.test
blob: 816216d670386cae84faef9a14f4cb34abf60857 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php

/**
 * @file
 * Tests for Checklist API module.
 */

/**
 * Unit tests for Checklist API.
 */
class ChecklistapiUnitTestCase extends DrupalUnitTestCase {

  /**
   * Overrides DrupalUnitTestCase::getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => 'Unit tests',
      'description' => 'Test Checklist API classes and functions.',
      'group' => 'Checklist API',
    );
  }

  /**
   * Overrides DrupalUnitTestCase::setUp().
   */
  public function setUp() {
    drupal_load('module', 'checklistapi');
    drupal_load('module', 'checklistapi_test');
    parent::setUp();
  }

  /**
   * Test checklistapi_sort_array().
   */
  public function testChecklistapiSortArray() {
    $input = array_pop(checklistapi_test_checklistapi_checklist_info());
    $output = checklistapi_sort_array($input);
    $this->assertEqual($output['group_two']['#weight'], 0, 'Supplied a default for omitted element weight.');
    $this->assertEqual($output['group_three']['#weight'], 0, 'Supplied a default in place of invalid element weight.');
    $this->assertEqual($output['group_one']['#weight'], -1, 'Retained a valid element weight.');
    $this->assertEqual(
      element_children($output),
      array('group_one', 'group_two', 'group_three', 'group_four'),
      'Sorted elements by weight.'
    );
    $this->assertEqual(
      element_children($output['group_one']['item_one']),
      array('link_one', 'link_two', 'link_three'),
      'Recursed through element descendants.'
    );
  }

  /**
   * Test checklistapi_strtolowercamel().
   */
  public function testChecklistapiStrtolowercamel() {
    $this->assertEqual(checklistapi_strtolowercamel('Abc def_ghi'), 'abcDefGhi', 'Converted string to lowerCamel case.');
  }

}

/**
 * Functional tests for Checklist API.
 *
 * @todo Add tests for vertical tabs progress indicators.
 * @todo Add tests for saving and retrieving checklist progress.
 * @todo Add tests for clearing saved progress.
 */
class ChecklistapiWebTestCase extends DrupalWebTestCase {
  protected $privilegedUser;

  /**
   * Overrides DrupalWebTestCase::getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => 'Functional tests',
      'description' => 'Test the functionality of Checklist API.',
      'group' => 'Checklist API',
    );
  }

  /**
   * Overrides DrupalWebTestCase::setUp().
   */
  public function setUp() {
    parent::setUp('checklistapi_example');
    $permissions = array('edit any checklistapi checklist');
    $this->privilegedUser = $this->drupalCreateUser($permissions);
    $this->drupalLogin($this->privilegedUser);
  }

  /**
   * Test checklist access.
   */
  public function testAccessChecklist() {
    $this->drupalGet('admin/config/development/checklistapi-example');
    $this->assertResponse(200, 'Granted access to user with "edit any checklistapi checklist" permission.');

    $permissions = array('edit example_checklist checklistapi checklist');
    $semi_privileged_user = $this->drupalCreateUser($permissions);
    $this->drupalLogin($semi_privileged_user);
    $this->drupalGet('admin/config/development/checklistapi-example');
    $this->assertResponse(200, 'Granted access to user with checklist-specific permission.');

    $this->drupalLogout();
    $this->drupalGet('admin/config/development/checklistapi-example');
    $this->assertResponse(403, 'Denied access to nonprivileged user.');
  }

  /**
   * Test checklist composition.
   */
  public function testChecklistComposition() {
    $menu_item = menu_get_item('admin/config/development/checklistapi-example');
    $this->assertEqual($menu_item['path'], 'admin/config/development/checklistapi-example', 'Created per-checklist menu item.');

    $permissions = array('edit example_checklist checklistapi checklist');
    $this->assertTrue($this->checkPermissions($permissions), 'Created per-checklist permission.');

    $this->drupalGet('admin/config/development/checklistapi-example');
    $this->assertRaw('id="block-system-help"', 'Created per-checklist help block.');
  }

}