function DisplayTest::testReorderDisplay

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

Tests reordering of displays.

File

core/modules/views_ui/tests/src/Functional/DisplayTest.php, line 54

Class

DisplayTest
Tests the display UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testReorderDisplay() : void {
  $view = [
    'block[create]' => TRUE,
  ];
  $view = $this->randomView($view);
  $this->clickLink('Reorder displays');
  $this->assertSession()
    ->elementExists('xpath', '//tr[@id="display-row-default"]');
  $this->assertSession()
    ->elementExists('xpath', '//tr[@id="display-row-page_1"]');
  $this->assertSession()
    ->elementExists('xpath', '//tr[@id="display-row-block_1"]');
  // Ensure the view displays are in the expected order in configuration.
  $expected_display_order = [
    'default',
    'block_1',
    'page_1',
  ];
  $this->assertEquals($expected_display_order, array_keys(Views::getView($view['id'])->storage
    ->get('display')), 'The correct display names are present.');
  // Put the block display in front of the page display.
  $edit = [
    'displays[page_1][weight]' => 2,
    'displays[block_1][weight]' => 1,
  ];
  $this->submitForm($edit, 'Apply');
  $this->submitForm([], 'Save');
  $view = Views::getView($view['id']);
  $displays = $view->storage
    ->get('display');
  $this->assertEquals(0, $displays['default']['position'], 'Make sure the default display comes first.');
  $this->assertEquals(1, $displays['block_1']['position'], 'Make sure the block display comes before the page display.');
  $this->assertEquals(2, $displays['page_1']['position'], 'Make sure the page display comes after the block display.');
  // Ensure the view displays are in the expected order in configuration.
  $this->assertEquals($expected_display_order, array_keys($view->storage
    ->get('display')), 'The correct display names are present.');
}

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