View source
<?php
namespace Drupal\KernelTests\Core\Pager;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
class PagerManagerTest extends KernelTestBase {
public function testGetUpdatedParameters() {
$element = 2;
$index = 5;
$test_parameters = [
'other' => 'arbitrary',
];
$request = Request::create('http://example.com', 'GET', $test_parameters);
$request_stack = $this->container
->get('request_stack');
$request_stack
->push($request);
$pager_manager = $this->container
->get('pager.manager');
$pager_manager
->createPager(30, 10, $element);
$query = $pager_manager
->getUpdatedParameters($request->query
->all(), $element, $index);
$this
->assertArrayHasKey('other', $query);
$this
->assertEquals(",,{$index}", $query['page']);
}
public function testFindPage() {
$request = Request::create('http://example.com', 'GET', [
'page' => '0,10',
]);
$request_stack = $this->container
->get('request_stack');
$request_stack
->push($request);
$pager_manager = $this->container
->get('pager.manager');
$this
->assertEquals(10, $pager_manager
->findPage(1));
}
public function testGetMaxPagerElementId(array $elements, int $expected_max_element_id) : void {
$pager_manager = $this->container
->get('pager.manager');
foreach ($elements as $element) {
$pager_manager
->createPager(30, 10, $element);
}
$this
->assertEquals($expected_max_element_id, $pager_manager
->getMaxPagerElementId());
}
public function providerTestGetMaxPagerElementId() : array {
return [
'no_pager' => [
[],
-1,
],
'single_pager' => [
[
0,
],
0,
],
'multiple_pagers' => [
[
30,
10,
20,
],
30,
],
];
}
}