| 1.20.x common.test | public CommonBackdropSortUnitTest::testBackdropSort() | 
Tests backdrop_sort().
File
- modules/simpletest/ tests/ common.test, line 3284 
- Tests for common.inc functionality.
Class
- CommonBackdropSortUnitTest
- Test that backdrop_sort() works correctly.
Code
public function testBackdropSort() {
  $expected = array(
    'form',
    'custom_block',
    'content',
    'main-menu',
    'recent',
    'breadcrumb',
  );
  // Sort by a single numeric key.
  backdrop_sort($this->test_array, array('weight' => SORT_NUMERIC));
  $this->assertIdentical(array_keys($this->test_array), $expected);
  // Sort by direction.
  backdrop_sort($this->test_array, array('weight' => SORT_NUMERIC), SORT_DESC);
  $this->assertIdentical(array_keys($this->test_array), array_reverse($expected));
  $expected = array(
    'custom_block',
    'main-menu',
    'recent',
    'breadcrumb',
    'content',
    'form',
  );
  // Sort by a single string key.
  backdrop_sort($this->test_array, array('description' => SORT_STRING));
  $this->assertIdentical(array_keys($this->test_array), $expected);
  // Sort by direction.
  backdrop_sort($this->test_array, array('description' => SORT_STRING), SORT_DESC);
  $this->assertIdentical(array_keys($this->test_array), array_reverse($expected));
  $expected = array(
    'form',
    'custom_block',
    'content',
    'main-menu',
    'recent',
    'breadcrumb',
  );
  // Sort by numeric and string keys.
  backdrop_sort($this->test_array, array('weight' => SORT_NUMERIC, 'info' => SORT_STRING));
  $this->assertIdentical(array_keys($this->test_array), $expected);
  // Sort by direction.
  backdrop_sort($this->test_array, array('weight' => SORT_NUMERIC, 'info' => SORT_STRING), SORT_DESC);
  $this->assertIdentical(array_keys($this->test_array), array_reverse($expected));
}