You are here

public function SortWidgetKernelTest::testCombineRewriteSortOptions in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Plugin/sort/SortWidgetKernelTest.php \Drupal\Tests\better_exposed_filters\Kernel\Plugin\sort\SortWidgetKernelTest::testCombineRewriteSortOptions()

Tests combining and rewriting sort options (sort order and sort by).

File

tests/src/Kernel/Plugin/sort/SortWidgetKernelTest.php, line 62

Class

SortWidgetKernelTest
Tests the advanced options of a sort widget.

Namespace

Drupal\Tests\better_exposed_filters\Kernel\Plugin\sort

Code

public function testCombineRewriteSortOptions() {
  $view = Views::getView('bef_test');
  $display =& $view->storage
    ->getDisplay('default');

  // Ensure our sort "created" is exposed.
  $display['display_options']['sorts']['created']['exposed'] = TRUE;
  $display['display_options']['sorts']['created']['expose']['label'] = 'Created';

  // Enable combined sort and rewrite options.
  $this
    ->setBetterExposedOptions($view, [
    'sort' => [
      'advanced' => [
        'combine' => TRUE,
        'combine_rewrite' => "Created Desc|down\r\nCreated Asc|up",
      ],
    ],
  ]);

  // Get the exposed form render array.
  $output = $this
    ->getExposedFormRenderArray($view);

  // Assert our "sort_bef_combine" contains both sort by and sort order
  // options, and has its options rewritten.
  $options = $output['sort_bef_combine']['#options'];
  $assert = [
    'created_DESC' => 'down',
    'created_ASC' => 'up',
  ];

  // Assert our combined sort options are added.
  $this
    ->assertEqual($options, $assert, 'Sort options are combined and rewritten.');
  $view
    ->destroy();
}