public function AjaxControllerTest::testDescOrderInPager in Sortableviews 8
Tests adjusted order for entities when in DESC pager.
Uses an imaginary view with 3 pages, 3 items per page and 7 rows.
@covers ::retrieveOrderFromRequest
File
- tests/
src/ Unit/ Controller/ AjaxControllerTest.php, line 174
Class
- AjaxControllerTest
- @coversDefaultClass \Drupal\sortableviews\Controller\AjaxController @group sortableviews
Namespace
Drupal\Tests\sortableviews\Unit\ControllerCode
public function testDescOrderInPager() {
$request = new Request();
$request->attributes
->set('items_per_page', 3);
$request->attributes
->set('sort_order', 'desc');
$request->attributes
->set('total_rows', 7);
// Test page one.
$page = [
6,
7,
5,
];
$request->attributes
->set('page_number', 0);
$request->attributes
->set('current_order', $page);
$result = $this->method
->invokeArgs($this->ajaxController, [
$request,
]);
$this
->assertEquals([
4 => 6,
5 => 7,
6 => 5,
], $result);
// Test page two.
$page = [
4,
2,
3,
];
$request->attributes
->set('page_number', 1);
$request->attributes
->set('current_order', $page);
$result = $this->method
->invokeArgs($this->ajaxController, [
$request,
]);
$this
->assertEquals([
1 => 4,
2 => 2,
3 => 3,
], $result);
// Test page three.
$page = [
1,
];
$request->attributes
->set('page_number', 2);
$request->attributes
->set('current_order', $page);
$result = $this->method
->invokeArgs($this->ajaxController, [
$request,
]);
$this
->assertEquals($page, $result);
}