randomView(); $this->assertNoText('Block'); $this->assertNoText('Block 2'); $this->drupalPostForm(NULL, [], t('Add @display', ['@display' => 'Block'])); $this->assertText('Block'); $this->assertNoText('Block 2'); // Views has special form handling in views_ui_form_button_was_clicked() // to be able to change the submit button text via JS, this simulates what // the JS is doing. $this->drupalPostForm(NULL, [], NULL, [], [], NULL, '&op=Block'); $this->assertText('Block'); $this->assertText('Block 2'); } /** * Tests reordering of displays. */ public function testReorderDisplay() { $view = [ 'block[create]' => TRUE ]; $view = $this->randomView($view); $this->clickLink(t('Reorder displays')); $this->assertTrue($this->xpath('//tr[@id="display-row-default"]'), 'Make sure the default display appears on the reorder listing'); $this->assertTrue($this->xpath('//tr[@id="display-row-page_1"]'), 'Make sure the page display appears on the reorder listing'); $this->assertTrue($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.'); } /** * Tests disabling of a display. */ public function testDisableDisplay() { $view = $this->randomView(); $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit'; $this->drupalGet($path_prefix); $this->assertFalse($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class does not appear after initial adding of a view.'); $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', '', 'Make sure the disable button is visible.'); $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', '', 'Make sure the enable button is not visible.'); $this->drupalPostForm(NULL, [], 'Disable Page'); $this->assertTrue($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class appears once the display is marked as such.'); $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', '', 'Make sure the disable button is not visible.'); $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', '', 'Make sure the enable button is visible.'); $this->drupalPostForm(NULL, [], 'Enable Page'); $this->assertFalse($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class does not appears once the display is enabled again.'); } /** * Tests views_ui_views_plugins_display_alter is altering plugin definitions. */ public function testDisplayPluginsAlter() { $definitions = Views::pluginManager('display')->getDefinitions(); $expected = [ 'route_name' => 'entity.view.edit_form', 'route_parameters_names' => ['view' => 'id'], ]; // Test the expected views_ui array exists on each definition. foreach ($definitions as $definition) { $this->assertIdentical($definition['contextual links']['entity.view.edit_form'], $expected, 'Expected views_ui array found in plugin definition.'); } } /** * Tests display areas. */ public function testDisplayAreas() { // Show the advanced column. $this->config('views.settings')->set('ui.show.advanced_column', TRUE)->save(); // Add a new data display to the view. $view = Views::getView('test_display'); $view->storage->addDisplay('display_no_area_test'); $view->save(); $this->drupalGet('admin/structure/views/view/test_display/edit/display_no_area_test_1'); $areas = [ 'header', 'footer', 'empty', ]; // Assert that the expected text is found in each area category. foreach ($areas as $type) { $element = $this->xpath('//div[contains(@class, :class)]/div', [':class' => $type]); $this->assertEqual((string) $element[0], SafeMarkup::format('The selected display type does not use @type plugins', ['@type' => $type])); } } /** * Tests the link-display setting. */ public function testLinkDisplay() { // Test setting the link display in the UI form. $path = 'admin/structure/views/view/test_display/edit/block_1'; $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display'; // Test the link text displays 'None' and not 'Block 1' $this->drupalGet($path); $result = $this->xpath("//a[contains(@href, :path)]", [':path' => $link_display_path]); $this->assertEqual($result[0], t('None'), 'Make sure that the link option summary shows "None" by default.'); $this->drupalGet($link_display_path); $this->assertFieldChecked('edit-link-display-0'); // Test the default radio option on the link display form. $this->drupalPostForm($link_display_path, ['link_display' => 'page_1'], t('Apply')); // The form redirects to the master display. $this->drupalGet($path); $result = $this->xpath("//a[contains(@href, :path)]", [':path' => $link_display_path]); $this->assertEqual($result[0], 'Page', 'Make sure that the link option summary shows the right linked display.'); $this->drupalPostForm($link_display_path, ['link_display' => 'custom_url', 'link_url' => 'a-custom-url'], t('Apply')); // The form redirects to the master display. $this->drupalGet($path); $this->assertLink(t('Custom URL'), 0, 'The link option has custom URL as summary.'); // Test the default link_url value for new display $this->drupalPostForm(NULL, [], t('Add Block')); $this->assertUrl('admin/structure/views/view/test_display/edit/block_2'); $this->clickLink(t('Custom URL')); $this->assertFieldByName('link_url', 'a-custom-url'); } /** * Tests contextual links on Views page displays. */ public function testPageContextualLinks() { $this->drupalLogin($this->drupalCreateUser(['administer views', 'access contextual links'])); $view = View::load('test_display'); $view->enable()->save(); $this->container->get('router.builder')->rebuildIfNeeded(); // When no "main content" block is placed, we find a contextual link // placeholder for editing just the view. $this->drupalGet('test-display'); $id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en'; // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() $this->assertRaw('