You are here

public function SortWidgetKernelTest::testResetSortOptions 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::testResetSortOptions()

Tests adding a reset sort option.

File

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

Class

SortWidgetKernelTest
Tests the advanced options of a sort widget.

Namespace

Drupal\Tests\better_exposed_filters\Kernel\Plugin\sort

Code

public function testResetSortOptions() {
  $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,
        'reset' => TRUE,
        'reset_label' => 'Reset sort',
      ],
    ],
  ]);

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

  // Assert our "sort_bef_combine" contains a reset option at the top.
  $options = $output['sort_bef_combine']['#options'];
  $assert = [
    ' ' => 'Reset sort',
    'created_ASC' => 'Created Asc',
    'created_DESC' => 'Created Desc',
  ];

  // Assert our combined sort options are added.
  $this
    ->assertEqual($options, $assert, 'Reset sort option was added.');
  $view
    ->destroy();
}