class ChecklistapiModuleTest in Checklist API 8
Tests the functions in checklistapi.module.
@group checklistapi
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\checklistapi\Unit\ChecklistapiModuleTest
Expanded class hierarchy of ChecklistapiModuleTest
File
- tests/
src/ Unit/ ChecklistapiModuleTest.php, line 18
Namespace
Drupal\Tests\checklistapi\UnitView source
class ChecklistapiModuleTest extends UnitTestCase {
/**
* Tests checklistapi_sort_array().
*/
public function testChecklistapiSortArray() {
$input = [
'#title' => 'Checklist API test',
'#path' => 'admin/config/development/checklistapi-test',
// @codingStandardsIgnoreLine
'#description' => 'A test checklist.',
'#help' => '<p>This is a test checklist.</p>',
'group_two' => [
'#title' => 'Group two',
],
'group_one' => [
'#title' => 'Group one',
// @codingStandardsIgnoreLine
'#description' => '<p>Group one description.</p>',
'#weight' => -1,
'item_three' => [
'#title' => 'Item three',
'#weight' => 1,
],
'item_one' => [
'#title' => 'Item one',
// @codingStandardsIgnoreLine
'#description' => 'Item one description',
'#weight' => -1,
'link_three' => [
'#text' => 'Link three',
'#url' => Url::fromUri('http://example.com/three'),
'#weight' => 3,
],
'link_two' => [
'#text' => 'Link two',
'#url' => Url::fromUri('http://example.com/two'),
'#weight' => 2,
],
'link_one' => [
'#text' => 'Link one',
'#url' => Url::fromUri('http://example.com/one'),
'#weight' => 1,
],
],
'item_two' => [
'#title' => 'Item two',
],
],
'group_four' => [
'#title' => 'Group four',
'#weight' => 1,
],
'group_three' => [
'#title' => 'Group three',
],
];
$output = checklistapi_sort_array($input);
$this
->assertEquals(0, $output['group_two']['#weight'], 'Failed to supply a default for omitted element weight.');
$this
->assertEquals(0, $output['group_three']['#weight'], 'Failed to supply a default in place of invalid element weight.');
$this
->assertEquals(-1, $output['group_one']['#weight'], 'Failed to retain a valid element weight.');
$this
->assertEquals([
'group_one',
'group_two',
'group_three',
'group_four',
], Element::children($output), 'Failed to sort elements by weight.');
$this
->assertEquals([
'link_one',
'link_two',
'link_three',
], Element::children($output['group_one']['item_one']), 'Failed to recurse through element descendants.');
}
/**
* Tests checklistapi_strtolowercamel().
*/
public function testChecklistapiStrtolowercamel() {
$this
->assertEquals('abcDefGhi', checklistapi_strtolowercamel('Abc def_ghi'), 'Failed to convert string to lowerCamel case.');
}
/**
* Tests that checklistapi_checklist_access() rejects an invalid mode.
*/
public function testChecklistapiChecklistAccessInvalidMode() {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('No such operation "invalid operation');
checklistapi_checklist_access(NULL, 'invalid operation');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChecklistapiModuleTest:: |
public | function | Tests that checklistapi_checklist_access() rejects an invalid mode. | |
ChecklistapiModuleTest:: |
public | function | Tests checklistapi_sort_array(). | |
ChecklistapiModuleTest:: |
public | function | Tests checklistapi_strtolowercamel(). | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |