You are here

public function SelectTableSortDefaultTest::testTableSortQueryFirst in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectTableSortDefaultTest::testTableSortQueryFirst()
  2. 10 core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectTableSortDefaultTest::testTableSortQueryFirst()

Confirms precedence of tablesorts headers.

If a tablesort's orderByHeader is called before another orderBy, then its header happens first.

File

core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php, line 53

Class

SelectTableSortDefaultTest
Tests the tablesort query extender.

Namespace

Drupal\Tests\system\Functional\Database

Code

public function testTableSortQueryFirst() {
  $sorts = [
    [
      'field' => t('Task ID'),
      'sort' => 'desc',
      'first' => 'perform at superbowl',
      'last' => 'eat',
    ],
    [
      'field' => t('Task ID'),
      'sort' => 'asc',
      'first' => 'eat',
      'last' => 'perform at superbowl',
    ],
    [
      'field' => t('Task'),
      'sort' => 'asc',
      'first' => 'code',
      'last' => 'sleep',
    ],
    [
      'field' => t('Task'),
      'sort' => 'desc',
      'first' => 'sleep',
      'last' => 'code',
    ],
  ];
  foreach ($sorts as $sort) {
    $this
      ->drupalGet('database_test/tablesort_first/', [
      'query' => [
        'order' => $sort['field'],
        'sort' => $sort['sort'],
      ],
    ]);
    $data = json_decode($this
      ->getSession()
      ->getPage()
      ->getContent());
    $first = array_shift($data->tasks);
    $last = array_pop($data->tasks);
    $this
      ->assertEqual($first->task, $sort['first'], new FormattableMarkup('Items appear in the correct order sorting by @field @sort.', [
      '@field' => $sort['field'],
      '@sort' => $sort['sort'],
    ]));
    $this
      ->assertEqual($last->task, $sort['last'], new FormattableMarkup('Items appear in the correct order sorting by @field @sort.', [
      '@field' => $sort['field'],
      '@sort' => $sort['sort'],
    ]));
  }
}