You are here

public function DisplayTest::testReorderDisplay in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/tests/src/Functional/DisplayTest.php \Drupal\Tests\views_ui\Functional\DisplayTest::testReorderDisplay()
  2. 9 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 52

Class

DisplayTest
Tests the display UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testReorderDisplay() {
  $view = [
    'block[create]' => TRUE,
  ];
  $view = $this
    ->randomView($view);
  $this
    ->clickLink('Reorder displays');
  $this
    ->assertNotEmpty($this
    ->xpath('//tr[@id="display-row-default"]'), 'Make sure the default display appears on the reorder listing');
  $this
    ->assertNotEmpty($this
    ->xpath('//tr[@id="display-row-page_1"]'), 'Make sure the page display appears on the reorder listing');
  $this
    ->assertNotEmpty($this
    ->xpath('//tr[@id="display-row-block_1"]'), 'Make sure the block display appears on the reorder listing');

  // 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.');
}