DisplayTest.php 8.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?php

/**
 * @file
 * Definition of Drupal\views\Tests\UI\DisplayTest.
 */

namespace Drupal\views\Tests\UI;

/**
 * Tests the handling of displays in the UI, adding removing etc.
 */
class DisplayTest extends UITestBase {

  public static function getInfo() {
    return array(
      'name' => 'Display tests',
      'description' => 'Tests the handling of displays in the UI, adding removing etc.',
      'group' => 'Views UI',
    );
  }

  /**
   * A helper method which creates a random view.
   */
  public function randomView(array $view = array()) {
    // Create a new view in the UI.
    $default = array();
    $default['human_name'] = $this->randomName(16);
    $default['name'] = strtolower($this->randomName(16));
    $default['description'] = $this->randomName(16);
    $default['page[create]'] = TRUE;
    $default['page[path]'] = $default['name'];

    $view += $default;

    $this->drupalPost('admin/structure/views/add', $view, t('Continue & edit'));

    return $default;
  }

  /**
   * Tests removing a display.
   */
  public function testRemoveDisplay() {
    $view = $this->randomView();
    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';

    $this->drupalGet($path_prefix . '/default');
    $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'delete Page', 'Make sure there is no delete button on the default display.');

52
    $this->drupalGet($path_prefix . '/page_1');
53 54 55
    $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'delete Page', 'Make sure there is a delete button on the page display.');

    // Delete the page, so we can test the undo process.
56
    $this->drupalPost($path_prefix . '/page_1', array(), 'delete Page');
57
    $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'undo delete of Page', 'Make sure there a undo button on the page display after deleting.');
58
    $this->assertTrue($this->xpath('//a[contains(@class, :class)]', array(':class' => 'views-display-deleted-link')), 'Make sure the display link is marked as to be deleted.');
59 60

    // Undo the deleting of the display.
61
    $this->drupalPost($path_prefix . '/page_1', array(), 'undo delete of Page');
62 63 64 65
    $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'undo delete of Page', 'Make sure there is no undo button on the page display after reverting.');
    $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'delete Page', 'Make sure there is a delete button on the page display after the reverting.');

    // Now delete again and save the view.
66
    $this->drupalPost($path_prefix . '/page_1', array(), 'delete Page');
67 68
    $this->drupalPost(NULL, array(), t('Save'));

69
    $this->assertNoLinkByHref($path_prefix . '/page_1', 'Make sure there is no display tab for the deleted display.');
70 71 72 73 74 75
  }

  /**
   * Tests adding a display.
   */
  public function testAddDisplay() {
76 77 78
    // Show the master display.
    config('views.settings')->set('ui.show.master_display', TRUE)->save();

79 80 81 82 83
    $settings['page[create]'] = FALSE;
    $view = $this->randomView($settings);

    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';
    $this->drupalGet($path_prefix);
84
    $this->drupalPost(NULL, array(), t('Save'));
85 86 87 88

    // Add a new display.
    $this->drupalPost(NULL, array(), 'Add Page');
    $this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after adding a display the new display appears in the UI');
89 90 91

    $this->assertNoLink('Master*', 0, 'Make sure the master display is not marked as changed.');
    $this->assertLink('Page*', 0, 'Make sure the added display is marked as changed.');
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  }

  /**
   * Tests reordering of displays.
   */
  public function testReorderDisplay() {
    $view = array(
      'block[create]' => TRUE
    );
    $view = $this->randomView($view);
    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';

    $edit = array();
    $this->drupalPost($path_prefix, $edit, t('Save'));
    $this->clickLink(t('reorder displays'));
    $this->assertTrue($this->xpath('//tr[@id="display-row-default"]'), 'Make sure the default display appears on the reorder listing');
108 109
    $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');
110 111 112

    // Put the block display in front of the page display.
    $edit = array(
113 114
      'page_1[weight]' => 2,
      'block_1[weight]' => 1
115 116 117 118 119
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    $this->drupalPost(NULL, array(), t('Save'));

    $view = views_get_view($view['name']);
120 121 122 123
    $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.');
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
  }

  /**
   * Tests that the correct display is loaded by default.
   */
  public function testDefaultDisplay() {
    $this->drupalGet('admin/structure/views/view/test_display');
    $elements = $this->xpath('//*[@id="views-page-display-title"]');
    $this->assertEqual(count($elements), 1, 'The page display is loaded as the default display.');
  }

  /**
   * Tests the cloning of a display.
   */
  public function testCloneDisplay() {
    $view = $this->randomView();
    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';

    $this->drupalGet($path_prefix);
    $this->drupalPost(NULL, array(), 'clone Page');
    $this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after cloning the new display appears in the UI');
  }

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
  /**
   * Tests disabling of a display.
   */
  public function testDisableDisplay() {
    $view = $this->randomView();
    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';

    $this->drupalGet($path_prefix);
    $this->assertFalse($this->xpath('//div[contains(@class, :class)]', array(':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->drupalPost(NULL, array(), 'disable Page');
    $this->assertTrue($this->xpath('//div[contains(@class, :class)]', array(':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->drupalPost(NULL, array(), 'enable Page');
    $this->assertFalse($this->xpath('//div[contains(@class, :class)]', array(':class' => 'views-display-disabled')), 'Make sure the disabled display css class does not appears once the display is enabled again.');
  }

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  /**
   * Tests views_ui_views_plugins_display_alter is altering plugin definitions.
   */
  public function testDisplayPluginsAlter() {
    $definitions = drupal_container()->get('plugin.manager.views.display')->getDefinitions();

    $expected = array(
      'parent path' => 'admin/structure/views/view',
      'argument properties' => array('name'),
    );

    // Test the expected views_ui array exists on each definition.
    foreach ($definitions as $definition) {
      $this->assertIdentical($definition['contextual links']['views_ui'], $expected, 'Expected views_ui array found in plugin definition.');
    }
  }

185
}