function SearchPageRepositoryTest::testSortSearchPages

Same name in other branches
  1. 9 core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php \Drupal\Tests\search\Unit\SearchPageRepositoryTest::testSortSearchPages()
  2. 10 core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php \Drupal\Tests\search\Unit\SearchPageRepositoryTest::testSortSearchPages()
  3. 11.x core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php \Drupal\Tests\search\Unit\SearchPageRepositoryTest::testSortSearchPages()

Tests the sortSearchPages() method.

File

core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php, line 252

Class

SearchPageRepositoryTest
@coversDefaultClass \Drupal\search\SearchPageRepository @group search

Namespace

Drupal\Tests\search\Unit

Code

public function testSortSearchPages() {
    $entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
    $entity_type->expects($this->any())
        ->method('getClass')
        ->will($this->returnValue('Drupal\\Tests\\search\\Unit\\TestSearchPage'));
    $this->storage
        ->expects($this->once())
        ->method('getEntityType')
        ->will($this->returnValue($entity_type));
    // Declare entities out of their expected order so we can be sure they were
    // sorted. We cannot mock these because of uasort(), see
    // https://bugs.php.net/bug.php?id=50688.
    $unsorted_entities['test4'] = new TestSearchPage([
        'weight' => 0,
        'status' => FALSE,
        'label' => 'Test4',
    ]);
    $unsorted_entities['test3'] = new TestSearchPage([
        'weight' => 10,
        'status' => TRUE,
        'label' => 'Test3',
    ]);
    $unsorted_entities['test2'] = new TestSearchPage([
        'weight' => 0,
        'status' => TRUE,
        'label' => 'Test2',
    ]);
    $unsorted_entities['test1'] = new TestSearchPage([
        'weight' => 0,
        'status' => TRUE,
        'label' => 'Test1',
    ]);
    $expected = $unsorted_entities;
    ksort($expected);
    $sorted_entities = $this->searchPageRepository
        ->sortSearchPages($unsorted_entities);
    $this->assertSame($expected, $sorted_entities);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.