class SortArrayTest in Modules weight 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/Utility/SortArrayTest.php \Drupal\Tests\modules_weight\Unit\Utility\SortArrayTest
Tests the SortArray class methods.
@group modules_weight @coversDefaultClass \Drupal\modules_weight\Utility\SortArray
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\modules_weight\Unit\Utility\SortArrayTest
Expanded class hierarchy of SortArrayTest
File
- tests/
src/ Unit/ Utility/ SortArrayTest.php, line 14
Namespace
Drupal\Tests\modules_weight\Unit\UtilityView source
class SortArrayTest extends UnitTestCase {
/**
* Tests the array sort with SortArray::sortByWeightAndName().
*
* @param int $expected
* The expected result from calling the function.
* @param array $a
* The first input array to order through SortArray::sortByWeightAndName().
* @param array $b
* The second input array to order through SortArray::sortByWeightAndName().
*
* @covers ::sortByWeightAndName
* @dataProvider providerSortByWeightAndName
*/
public function testSortByWeightAndName($expected, array $a, array $b) {
$result = SortArray::sortByWeightAndName($a, $b);
// Checking that the two values are numerics.
$this
->assertTrue(is_numeric($expected) && is_numeric($result), 'Parameters are numeric.');
// Checking that both are equals.
$this
->assertTrue($expected < 0 && $result < 0 || $expected > 0 && $result > 0 || $expected === 0 && $result === 0, 'Numbers are either both negative, both positive or both zero.');
}
/**
* Data provider for testSortByWeightAndName().
*
* @return array
* An array of arrays, each containing:
* - 'expected' - Expected return from SortArray::sortByWeightAndName().
* - 'a' - The first input array.
* - 'b' - The second input array.
*
* @see testSortByWeightAndName()
*/
public function providerSortByWeightAndName() {
$tests['same weight different name 1'] = [
-1,
[
'name' => 'Admin Toolbar',
'weight' => 1,
],
[
'name' => 'Asana',
'weight' => 1,
],
];
$tests['same weight different name 2'] = [
1,
[
'name' => 'Asana',
'weight' => 1,
],
[
'name' => 'Admin Toolbar',
'weight' => 1,
],
];
$tests['different weight 1'] = [
-1,
[
'name' => 'Asana',
'weight' => -15,
],
[
'name' => 'Admin Toolbar',
'weight' => 8,
],
];
$tests['different weight 2'] = [
1,
[
'name' => 'Asana',
'weight' => 51,
],
[
'name' => 'Admin Toolbar',
'weight' => -10,
],
];
$tests['with no weight 1'] = [
-1,
[
'name' => 'Asana',
],
[
'name' => 'Admin Toolbar',
'weight' => 8,
],
];
$tests['with no weight 2'] = [
1,
[
'name' => 'Asana',
'weight' => 51,
],
[
'name' => 'Admin Toolbar',
],
];
return $tests;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SortArrayTest:: |
public | function | Data provider for testSortByWeightAndName(). | |
SortArrayTest:: |
public | function | Tests the array sort with SortArray::sortByWeightAndName(). | |
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 |