protected function EntityQueryTest::testTableSort

Test tablesort().

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php, line 352
Definition of Drupal\system\Tests\Entity\EntityQueryTest.

Class

EntityQueryTest
Tests the basic Entity API.

Namespace

Drupal\system\Tests\Entity

Code

protected function testTableSort() {

  // While ordering on bundles do not give us a definite order, we can still
  // assert that all entities from one bundle are after the other as the
  // order dictates.
  $_GET['sort'] = 'asc';
  $_GET['order'] = 'Type';
  $header = array(
    'id' => array(
      'data' => 'Id',
      'specifier' => 'ftid',
    ),
    'type' => array(
      'data' => 'Type',
      'specifier' => 'fttype',
    ),
  );
  $this->queryResults = array_values($this->factory
    ->get('test_entity')
    ->tableSort($header)
    ->execute());
  $this
    ->assertBundleOrder('asc');
  $_GET['sort'] = 'desc';
  $header = array(
    'id' => array(
      'data' => 'Id',
      'specifier' => 'ftid',
    ),
    'type' => array(
      'data' => 'Type',
      'specifier' => 'fttype',
    ),
  );
  $this->queryResults = array_values($this->factory
    ->get('test_entity')
    ->tableSort($header)
    ->execute());
  $this
    ->assertBundleOrder('desc');

  // Ordering on ID is definite, however.
  $_GET['order'] = 'Id';
  $this->queryResults = $this->factory
    ->get('test_entity')
    ->tableSort($header)
    ->execute();
  $this
    ->assertResult(range(15, 1));
}