/**
  * Sorts a structured array by either a set 'weight' property or by the ID.
  *
  * @param array $a
  *   First item for comparison.
  * @param array $b
  *   Second item for comparison.
  *
  * @return int
  *   The comparison result for uasort().
  */
 public static function sort(array $a, array $b)
 {
     if (isset($a['weight']) || isset($b['weight'])) {
         return SortArray::sortByWeightElement($a, $b);
     } else {
         return SortArray::sortByKeyString($a, $b, 'id');
     }
 }
Ejemplo n.º 2
0
 /**
  * Tests SortArray::sortByWeightElement() input against expected output.
  *
  * @dataProvider providerSortByWeightElement
  * @covers ::sortByWeightElement
  * @covers ::sortByKeyInt
  *
  * @param array $a
  *   The first input array for the SortArray::sortByWeightElement() method.
  * @param array $b
  *   The second input array for the SortArray::sortByWeightElement().
  * @param integer $expected
  *   The expected output from calling the method.
  */
 public function testSortByWeightElement($a, $b, $expected)
 {
     $result = SortArray::sortByWeightElement($a, $b);
     $this->assertBothNegativePositiveOrZero($expected, $result);
 }
 /**
  * Tests SortArray::sortByWeightElement() input against expected output.
  *
  * @dataProvider providerSortByWeightElement
  *
  * @param array $a
  *   The first input array for the SortArray::sortByWeightElement() method.
  * @param array $b
  *   The second input array for the SortArray::sortByWeightElement().
  * @param integer $expected
  *   The expected output from calling the method.
  *
  * @see \Drupal\Component\Utility\SortArray::sortByWeightElement()
  * @see \Drupal\Tests\Component\Utility\SortArrayTest::providersortByWeightElement()
  */
 public function testSortByWeightElement($a, $b, $expected)
 {
     $result = SortArray::sortByWeightElement($a, $b);
     $this->assertEquals($expected, $result);
 }