checklistapi.test

Tests for Checklist API module.

Classes

Namesort descending Description
ChecklistapiUnitTestCase Unit tests for Checklist API.
ChecklistapiWebTestCase Functional tests for Checklist API.

File

modules/contrib/checklistapi/tests/checklistapi.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Checklist API module.
  5. */
  6. /**
  7. * Unit tests for Checklist API.
  8. */
  9. class ChecklistapiUnitTestCase extends DrupalUnitTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Unit tests',
  13. 'description' => 'Test Checklist API classes and functions.',
  14. 'group' => 'Checklist API',
  15. );
  16. }
  17. public function setUp() {
  18. drupal_load('module', 'checklistapi');
  19. drupal_load('module', 'checklistapi_test');
  20. parent::setUp();
  21. }
  22. /**
  23. * Test checklistapi_sort_array().
  24. */
  25. public function testChecklistapiSortArray() {
  26. $input = array_pop(checklistapi_test_checklistapi_checklist_info());
  27. $output = checklistapi_sort_array($input);
  28. $this->assertEqual($output['group_two']['#weight'], 0, 'Supplied a default for omitted element weight.');
  29. $this->assertEqual($output['group_three']['#weight'], 0, 'Supplied a default in place of invalid element weight.');
  30. $this->assertEqual($output['group_one']['#weight'], -1, 'Retained a valid element weight.');
  31. $this->assertEqual(
  32. element_children($output),
  33. array('group_one', 'group_two', 'group_three', 'group_four'),
  34. 'Sorted elements by weight.'
  35. );
  36. $this->assertEqual(
  37. element_children($output['group_one']['item_one']),
  38. array('link_one', 'link_two', 'link_three'),
  39. 'Recursed through element descendants.'
  40. );
  41. }
  42. /**
  43. * Test checklistapi_strtolowercamel().
  44. */
  45. public function testChecklistapiStrtolowercamel() {
  46. $this->assertEqual(checklistapi_strtolowercamel('Abc def_ghi'), 'abcDefGhi', 'Converted string to lowerCamel case.');
  47. }
  48. }
  49. /**
  50. * Functional tests for Checklist API.
  51. *
  52. * @todo Add tests for vertical tabs progress indicators.
  53. * @todo Add tests for saving and retrieving checklist progress.
  54. * @todo Add tests for clearing saved progress.
  55. */
  56. class ChecklistapiWebTestCase extends DrupalWebTestCase {
  57. protected $privilegedUser;
  58. public static function getInfo() {
  59. return array(
  60. 'name' => 'Functional tests',
  61. 'description' => 'Test the functionality of Checklist API.',
  62. 'group' => 'Checklist API',
  63. );
  64. }
  65. public function setUp() {
  66. parent::setUp('checklistapi_example');
  67. $permissions = array('edit any checklistapi checklist');
  68. $this->privilegedUser = $this->drupalCreateUser($permissions);
  69. $this->drupalLogin($this->privilegedUser);
  70. }
  71. /**
  72. * Test checklist access.
  73. */
  74. public function testAccessChecklist() {
  75. $this->drupalGet('admin/config/development/checklistapi-example');
  76. $this->assertResponse(200, 'Granted access to user with "edit any checklistapi checklist" permission.');
  77. $permissions = array('edit example_checklist checklistapi checklist');
  78. $semi_privileged_user = $this->drupalCreateUser($permissions);
  79. $this->drupalLogin($semi_privileged_user);
  80. $this->drupalGet('admin/config/development/checklistapi-example');
  81. $this->assertResponse(200, 'Granted access to user with checklist-specific permission.');
  82. $this->drupalLogout();
  83. $this->drupalGet('admin/config/development/checklistapi-example');
  84. $this->assertResponse(403, 'Denied access to nonprivileged user.');
  85. }
  86. /**
  87. * Test checklist composition.
  88. */
  89. public function testChecklistComposition() {
  90. $menu_item = menu_get_item('admin/config/development/checklistapi-example');
  91. $this->assertEqual($menu_item['path'], 'admin/config/development/checklistapi-example', 'Created per-checklist menu item.');
  92. $permissions = array('edit example_checklist checklistapi checklist');
  93. $this->assertTrue($this->checkPermissions($permissions), 'Created per-checklist permission.');
  94. $this->drupalGet('admin/config/development/checklistapi-example');
  95. $this->assertRaw('id="block-system-help"', 'Created per-checklist help block.');
  96. }
  97. }