function HandlerTest::testHandlerWeights

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testHandlerWeights()
  2. 8.9.x core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testHandlerWeights()
  3. 11.x core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testHandlerWeights()

Tests the order of handlers is the same before and after saving.

File

core/modules/views/tests/src/Functional/Handler/HandlerTest.php, line 206

Class

HandlerTest
Tests abstract handler definitions.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testHandlerWeights() : void {
  $handler_types = [
    'fields',
    'filters',
    'sorts',
  ];
  $view = Views::getView('test_view_handler_weight');
  $view->initDisplay();
  // Store the order of handlers before saving the view.
  $original_order = [];
  foreach ($handler_types as $type) {
    $original_order[$type] = array_keys($view->display_handler
      ->getOption($type));
  }
  // Save the view and see if our filters are in the same order.
  $view->save();
  $view = views::getView('test_view_handler_weight');
  $view->initDisplay();
  foreach ($handler_types as $type) {
    $loaded_order = array_keys($view->display_handler
      ->getOption($type));
    $this->assertSame($original_order[$type], $loaded_order);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.