You are here

public function AjaxControllerTest::testAscOrderInPager in Sortableviews 8

Tests adjusted order for entities when in ASC pager.

Uses an imaginary view with 3 pages, 3 items per page and 8 rows.

@covers ::retrieveOrderFromRequest

File

tests/src/Unit/Controller/AjaxControllerTest.php, line 132

Class

AjaxControllerTest
@coversDefaultClass \Drupal\sortableviews\Controller\AjaxController @group sortableviews

Namespace

Drupal\Tests\sortableviews\Unit\Controller

Code

public function testAscOrderInPager() {
  $request = new Request();
  $request->attributes
    ->set('items_per_page', 3);
  $request->attributes
    ->set('sort_order', 'asc');

  // Test page one.
  $page = [
    1,
    2,
    3,
  ];
  $request->attributes
    ->set('page_number', 0);
  $request->attributes
    ->set('current_order', $page);
  $result = $this->method
    ->invokeArgs($this->ajaxController, [
    $request,
  ]);
  $this
    ->assertEquals($page, $result);

  // Test page two.
  $page = [
    5,
    6,
    4,
  ];
  $request->attributes
    ->set('page_number', 1);
  $request->attributes
    ->set('current_order', $page);
  $result = $this->method
    ->invokeArgs($this->ajaxController, [
    $request,
  ]);
  $this
    ->assertEquals([
    3 => 5,
    4 => 6,
    5 => 4,
  ], $result);

  // Test page three.
  $page = [
    8,
    7,
  ];
  $request->attributes
    ->set('page_number', 2);
  $request->attributes
    ->set('current_order', $page);
  $result = $this->method
    ->invokeArgs($this->ajaxController, [
    $request,
  ]);
  $this
    ->assertEquals([
    6 => 8,
    7 => 7,
  ], $result);
}