You are here

public function SortArrayTest::testSortByWeightAndName in Modules weight 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Utility/SortArrayTest.php \Drupal\Tests\modules_weight\Unit\Utility\SortArrayTest::testSortByWeightAndName()

Tests the array sort with SortArray::sortByWeightAndName().

@covers ::sortByWeightAndName @dataProvider providerSortByWeightAndName

Parameters

int $expected: The expected result from calling the function.

array $a: The first input array to order through SortArray::sortByWeightAndName().

array $b: The second input array to order through SortArray::sortByWeightAndName().

File

tests/src/Unit/Utility/SortArrayTest.php, line 29

Class

SortArrayTest
Tests the SortArray class methods.

Namespace

Drupal\Tests\modules_weight\Unit\Utility

Code

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.');
}