You are here

function EntityFieldQueryViewsSortTest::runTestView in EntityFieldQuery Views Backend 8

Parameters

$field:

$expected_result:

1 call to EntityFieldQueryViewsSortTest::runTestView()
EntityFieldQueryViewsSortTest::testSort in src/Tests/EntityFieldQueryViewsSortTest.php
Tests view sort.

File

src/Tests/EntityFieldQueryViewsSortTest.php, line 21
Tests for EntityFieldQuery Views query features.

Class

EntityFieldQueryViewsSortTest
Class EntityFieldQueryViewsSortTest

Namespace

Drupal\efq_views\Tests

Code

function runTestView($field, $expected_result) {
  $view = new view();
  $view->base_table = 'efq_efq_views_test';
  $handler = $view
    ->new_display('default');
  $handler->display->display_options['row_options']['default_field_elements'] = FALSE;
  $handler->display->display_options['fields']['entity_id']['id'] = 'entity_id';
  $handler->display->display_options['fields']['entity_id']['field'] = 'entity_id';
  $handler->display->display_options['fields']['entity_id']['table'] = 'efq_efq_views_test';
  $handler->display->display_options['sorts'][$field]['id'] = $field;
  $handler->display->display_options['sorts'][$field]['field'] = $field;
  $handler->display->display_options['sorts'][$field]['table'] = 'efq_efq_views_test';
  $asc_sorted_view = clone $view;
  $view
    ->execute();
  $this
    ->assertIdentical(array_keys($this
    ->getIds($view->result)), $this
    ->map($expected_result));
  $view = clone $asc_sorted_view;
  $handler = $view->display['default']->handler;
  $handler->display->display_options['sorts'][$field]['order'] = 'DESC';
  $view
    ->execute();
  $this
    ->assertIdentical(array_keys($this
    ->getIds($view->result)), $this
    ->map(array_reverse($expected_result)));
}