function SearchPageRepositoryTest::testSortSearchPages
Same name in other branches
- 9 core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php \Drupal\Tests\search\Unit\SearchPageRepositoryTest::testSortSearchPages()
- 8.9.x core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php \Drupal\Tests\search\Unit\SearchPageRepositoryTest::testSortSearchPages()
- 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\UnitCode
public function testSortSearchPages() : void {
$entity_type = $this->createMock(EntityTypeInterface::class);
$entity_type->method('getClass')
->willReturn(TestSearchPage::class);
$this->storage
->expects($this->once())
->method('getEntityType')
->willReturn($entity_type);
// Declare entities out of their expected order, so we can be sure they were
// sorted.
$entity_test4 = $this->createMock(TestSearchPage::class);
$entity_test4->method('label')
->willReturn('Test4');
$entity_test4->method('status')
->willReturn(FALSE);
$entity_test4->method('getWeight')
->willReturn(0);
$entity_test3 = $this->createMock(TestSearchPage::class);
$entity_test3->method('label')
->willReturn('Test3');
$entity_test3->method('status')
->willReturn(FALSE);
$entity_test3->method('getWeight')
->willReturn(10);
$entity_test2 = $this->createMock(TestSearchPage::class);
$entity_test2->method('label')
->willReturn('Test2');
$entity_test2->method('status')
->willReturn(TRUE);
$entity_test2->method('getWeight')
->willReturn(0);
$entity_test1 = $this->createMock(TestSearchPage::class);
$entity_test1->method('label')
->willReturn('Test1');
$entity_test1->method('status')
->willReturn(TRUE);
$entity_test1->method('getWeight')
->willReturn(0);
$unsorted_entities = [
$entity_test4,
$entity_test3,
$entity_test2,
$entity_test1,
];
$expected = [
$entity_test1,
$entity_test2,
$entity_test3,
$entity_test4,
];
$sorted_entities = $this->searchPageRepository
->sortSearchPages($unsorted_entities);
$this->assertSame($expected, array_values($sorted_entities));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.