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. 10 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 51

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(t('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->assertEqual(array_keys(Views::getView($view['id'])->storage
        ->get('display')), $expected_display_order, '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->drupalPostForm(NULL, $edit, t('Apply'));
    $this->drupalPostForm(NULL, [], t('Save'));
    $view = Views::getView($view['id']);
    $displays = $view->storage
        ->get('display');
    $this->assertEqual($displays['default']['position'], 0, 'Make sure the master display comes first.');
    $this->assertEqual($displays['block_1']['position'], 1, 'Make sure the block display comes before the page display.');
    $this->assertEqual($displays['page_1']['position'], 2, 'Make sure the page display comes after the block display.');
    // Ensure the view displays are in the expected order in configuration.
    $this->assertEqual(array_keys($view->storage
        ->get('display')), $expected_display_order, 'The correct display names are present.');
}

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