You are here

public function AjaxControllerTest::testAjaxSave in Sortableviews 8

Tests the ajaxSave method.

@covers ::ajaxSave

File

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

Class

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

Namespace

Drupal\Tests\sortableviews\Unit\Controller

Code

public function testAjaxSave() {
  $dom_id = 'domid';
  $request = new Request();
  $request->attributes
    ->set('entity_type', 'some_type');
  $request->attributes
    ->set('weight_field', 'some_field');
  $request->attributes
    ->set('items_per_page', 2);
  $request->attributes
    ->set('sort_order', 'asc');
  $request->attributes
    ->set('page_number', 0);
  $request->attributes
    ->set('dom_id', $dom_id);
  $request->attributes
    ->set('current_order', []);
  $response = $this->ajaxController
    ->ajaxSave($request);
  $this
    ->assertTrue($response instanceof AjaxResponse);
  $commands = $response
    ->getCommands($response);
  $this
    ->assertEquals('insert', $commands[0]['command']);
  $this
    ->assertEquals('prepend', $commands[0]['method']);
  $this
    ->assertEquals('.js-view-dom-id-' . $dom_id, $commands[0]['selector']);
  $this
    ->assertEquals('remove', $commands[1]['command']);
  $this
    ->assertEquals('.js-view-dom-id-' . $dom_id . ' .sortableviews-ajax-trigger', $commands[1]['selector']);
}