Commit 19e169d1 authored by TravisCarden's avatar TravisCarden

By TravisCarden: Refactored simpletests to use mock module.

parent e12ddf98
......@@ -3,5 +3,5 @@ description = Provides an API for creating fillable, persistent checklists.
core = 7.x
package = Other
files[] = lib/Drupal/checklistapi/ChecklistapiChecklist.php
files[] = checklistapi.test
files[] = tests/checklistapi.test
configure = admin/reports/checklistapi
......@@ -20,6 +20,7 @@ class ChecklistapiUnitTestCase extends DrupalUnitTestCase {
public function setUp() {
drupal_load('module', 'checklistapi');
drupal_load('module', 'checklistapi_test');
parent::setUp();
}
......@@ -27,36 +28,21 @@ class ChecklistapiUnitTestCase extends DrupalUnitTestCase {
* Test checklistapi_sort_array().
*/
public function testChecklistapiSortArray() {
$input = array(
'#title' => '',
'two' => array(),
'one' => array(
'#weight' => -1,
'gamma' => array('#weight' => 1),
'alpha' => array('#weight' => -1),
'beta' => array(),
),
'three' => array('#weight' => 'invalid'),
'four' => array('#weight' => 1),
);
$input = array_pop(checklistapi_test_checklistapi_checklist_info());
$output = checklistapi_sort_array($input);
$expected = array(
'#title' => '',
'one' => array(
'#weight' => -1,
'alpha' => array('#weight' => -1),
'beta' => array('#weight' => 0),
'gamma' => array('#weight' => 1),
),
'two' => array('#weight' => 0),
'three' => array('#weight' => 0),
'four' => array('#weight' => 1),
$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.'
);
$this->assertEqual($output['two']['#weight'], $expected['two']['#weight'], 'Supplied a default for missing element weight.');
$this->assertEqual($output['four']['#weight'], $expected['four']['#weight'], 'Supplied a default for invalid element weight.');
$this->assertEqual($output['one']['#weight'], $expected['one']['#weight'], 'Retained a valid element weight.');
$this->assertEqual(array_keys($output), array_keys($expected), 'Sorted elements by weight.');
$this->assertNotEqual($input['one'], $output['one'], 'Recursed on child elements.');
}
}
......
name = Checklist API test module
description = Provides an implementation of the Checklist API for testing.
package = Testing
version = VERSION
core = 7.x
dependencies[] = checklistapi
hidden = TRUE
<?php
/**
* @file
* Test module for Checklist API.
*/
/**
* Implements hook_checklistapi_checklist_info().
*/
function checklistapi_test_checklistapi_checklist_info() {
$checklists = array();
$checklists['test_checklist'] = array(
'#title' => t('Checklist API test'),
'#description' => t('A test checklist.'),
'#path' => 'admin/config/development/checklistapi-test',
'#help' => t('<p>This is a test checklist.</p>'),
'group_two' => array(
'#title' => t('Group two'),
),
'group_one' => array(
'#title' => t('Group one'),
'#description' => t('<p>Group one description.</p>'),
'#weight' => -1,
'item_three' => array(
'#title' => t('Item three'),
'#weight' => 1,
),
'item_one' => array(
'#title' => t('Item one'),
'#description' => t('Item one description'),
'#weight' => -1,
'link_three' => array(
'#text' => t('Link three'),
'#path' => 'http://example.com/three',
'#weight' => 3,
),
'link_two' => array(
'#text' => t('Link two'),
'#path' => 'http://example.com/two',
'#weight' => 2,
),
'link_one' => array(
'#text' => t('Link one'),
'#path' => 'http://example.com/one',
'#weight' => 1,
),
),
'item_two' => array(
'#title' => t('Item two'),
),
),
'group_four' => array(
'#title' => t('Group four'),
'#weight' => 1,
),
'group_three' => array(
'#title' => t('Group three'),
'#weight' => 'invalid',
),
);
return $checklists;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment