public function DisplayCRUDTest::testDuplicateDisplay in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views_ui/src/Tests/DisplayCRUDTest.php \Drupal\views_ui\Tests\DisplayCRUDTest::testDuplicateDisplay()
Tests the duplicating of a display.
File
- core/
modules/ views_ui/ src/ Tests/ DisplayCRUDTest.php, line 103 - Contains \Drupal\views_ui\Tests\DisplayCRUDTest.
Class
- DisplayCRUDTest
- Tests creation, retrieval, updating, and deletion of displays in the Web UI.
Namespace
Drupal\views_ui\TestsCode
public function testDuplicateDisplay() {
$view = $this
->randomView();
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
$path = $view['page[path]'];
$this
->drupalGet($path_prefix);
$this
->drupalPostForm(NULL, array(), 'Duplicate Page');
$this
->assertLinkByHref($path_prefix . '/page_2', 0, 'Make sure after duplicating the new display appears in the UI');
$this
->assertUrl($path_prefix . '/page_2', array(), 'The user got redirected to the new display.');
// Set the title and override the css classes.
$random_title = $this
->randomMachineName();
$random_css = $this
->randomMachineName();
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/title", array(
'title' => $random_title,
), t('Apply'));
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/css_class", array(
'override[dropdown]' => 'page_2',
'css_class' => $random_css,
), t('Apply'));
// Duplicate as a different display type.
$this
->drupalPostForm(NULL, array(), 'Duplicate as Block');
$this
->assertLinkByHref($path_prefix . '/block_1', 0, 'Make sure after duplicating the new display appears in the UI');
$this
->assertUrl($path_prefix . '/block_1', array(), 'The user got redirected to the new display.');
$this
->assertText(t('Block settings'));
$this
->assertNoText(t('Page settings'));
$this
->drupalPostForm(NULL, array(), t('Save'));
$view = Views::getView($view['id']);
$view
->initDisplay();
$page_2 = $view->displayHandlers
->get('page_2');
$this
->assertTrue($page_2, 'The new page display got saved.');
$this
->assertEqual($page_2->display['display_title'], 'Page');
$this
->assertEqual($page_2->display['display_options']['path'], $path);
$block_1 = $view->displayHandlers
->get('block_1');
$this
->assertTrue($block_1, 'The new block display got saved.');
$this
->assertEqual($block_1->display['display_plugin'], 'block');
$this
->assertEqual($block_1->display['display_title'], 'Block', 'The new display title got generated as expected.');
$this
->assertFalse(isset($block_1->display['display_options']['path']));
$this
->assertEqual($block_1
->getOption('title'), $random_title, 'The overridden title option from the display got copied into the duplicate');
$this
->assertEqual($block_1
->getOption('css_class'), $random_css, 'The overridden css_class option from the display got copied into the duplicate');
}