You are here

public function StringSorterTest::testAsc in Views XML Backend 8

File

tests/src/Unit/Sorter/StringSorterTest.php, line 15

Class

StringSorterTest
@coversDefaultClass \Drupal\Tests\views_xml_backend\Unit\Sorter\StringSorterTest @group views_xml_backend

Namespace

Drupal\Tests\views_xml_backend\Unit\Sorter

Code

public function testAsc() {
  $sorter = $this
    ->getSorter('field', 'ASC');
  $result = [
    new ResultRow([
      'field' => [
        '5',
      ],
      'index' => 0,
    ]),
    new ResultRow([
      'field' => [
        '4',
      ],
      'index' => 1,
    ]),
    new ResultRow([
      'field' => [
        '1',
      ],
      'index' => 2,
    ]),
    new ResultRow([
      'field' => [
        '1',
      ],
      'index' => 3,
    ]),
    new ResultRow([
      'field' => [
        '3',
      ],
      'index' => 4,
    ]),
    new ResultRow([
      'field' => [
        '2',
      ],
      'index' => 5,
    ]),
  ];
  $sorter($result);
  $values = [
    2 => '1',
    3 => '1',
    5 => '2',
    4 => '3',
    1 => '4',
    0 => '5',
  ];
  foreach ($values as $index => $value) {
    $row = array_shift($result);
    $this
      ->assertSame([
      $value,
    ], $row->field);
    $this
      ->assertSame($index, $row->index);
  }
}