PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/core/modules/views_ui/src/Tests/DisplayCRUDTest.php

http://github.com/drupal/drupal
PHP | 138 lines | 77 code | 27 blank | 34 comment | 0 complexity | 810be6fec77b2743343fe225274bbba3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. namespace Drupal\views_ui\Tests;
  3. use Drupal\views\Views;
  4. /**
  5. * Tests creation, retrieval, updating, and deletion of displays in the Web UI.
  6. *
  7. * @group views_ui
  8. */
  9. class DisplayCRUDTest extends UITestBase {
  10. /**
  11. * Views used by this test.
  12. *
  13. * @var array
  14. */
  15. public static $testViews = array('test_display');
  16. /**
  17. * Modules to enable
  18. *
  19. * @var array
  20. */
  21. public static $modules = array('contextual');
  22. /**
  23. * Tests adding a display.
  24. */
  25. public function testAddDisplay() {
  26. // Show the master display.
  27. $this->config('views.settings')->set('ui.show.master_display', TRUE)->save();
  28. $settings['page[create]'] = FALSE;
  29. $view = $this->randomView($settings);
  30. $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
  31. $this->drupalGet($path_prefix);
  32. // Add a new display.
  33. $this->drupalPostForm(NULL, array(), 'Add Page');
  34. $this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after adding a display the new display appears in the UI');
  35. $this->assertNoLink('Master*', 'Make sure the master display is not marked as changed.');
  36. $this->assertLink('Page*', 0, 'Make sure the added display is marked as changed.');
  37. $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/path", array('path' => 'test/path'), t('Apply'));
  38. $this->drupalPostForm(NULL, array(), t('Save'));
  39. }
  40. /**
  41. * Tests removing a display.
  42. */
  43. public function testRemoveDisplay() {
  44. $view = $this->randomView();
  45. $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
  46. $this->drupalGet($path_prefix . '/default');
  47. $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.');
  48. $this->drupalGet($path_prefix . '/page_1');
  49. $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.');
  50. // Delete the page, so we can test the undo process.
  51. $this->drupalPostForm($path_prefix . '/page_1', array(), 'Delete Page');
  52. $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.');
  53. $element = $this->xpath('//a[contains(@href, :href) and contains(@class, :class)]', array(':href' => $path_prefix . '/page_1', ':class' => 'views-display-deleted-link'));
  54. $this->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');
  55. $element = $this->xpath('//a[contains(@href, :href) and contains(@class, :class)]', array(':href' => $path_prefix . '/page_1', ':class' => 'views-display-deleted-link'));
  56. $this->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');
  57. // Undo the deleting of the display.
  58. $this->drupalPostForm($path_prefix . '/page_1', array(), 'Undo delete of Page');
  59. $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.');
  60. $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.');
  61. // Now delete again and save the view.
  62. $this->drupalPostForm($path_prefix . '/page_1', array(), 'Delete Page');
  63. $this->drupalPostForm(NULL, array(), t('Save'));
  64. $this->assertNoLinkByHref($path_prefix . '/page_1', 'Make sure there is no display tab for the deleted display.');
  65. }
  66. /**
  67. * Tests that the correct display is loaded by default.
  68. */
  69. public function testDefaultDisplay() {
  70. $this->drupalGet('admin/structure/views/view/test_display');
  71. $elements = $this->xpath('//*[@id="views-page-1-display-title"]');
  72. $this->assertEqual(count($elements), 1, 'The page display is loaded as the default display.');
  73. }
  74. /**
  75. * Tests the duplicating of a display.
  76. */
  77. public function testDuplicateDisplay() {
  78. $view = $this->randomView();
  79. $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
  80. $path = $view['page[path]'];
  81. $this->drupalGet($path_prefix);
  82. $this->drupalPostForm(NULL, array(), 'Duplicate Page');
  83. $this->assertLinkByHref($path_prefix . '/page_2', 0, 'Make sure after duplicating the new display appears in the UI');
  84. $this->assertUrl($path_prefix . '/page_2', array(), 'The user got redirected to the new display.');
  85. // Set the title and override the css classes.
  86. $random_title = $this->randomMachineName();
  87. $random_css = $this->randomMachineName();
  88. $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/title", array('title' => $random_title), t('Apply'));
  89. $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/css_class", array('override[dropdown]' => 'page_2', 'css_class' => $random_css), t('Apply'));
  90. // Duplicate as a different display type.
  91. $this->drupalPostForm(NULL, array(), 'Duplicate as Block');
  92. $this->assertLinkByHref($path_prefix . '/block_1', 0, 'Make sure after duplicating the new display appears in the UI');
  93. $this->assertUrl($path_prefix . '/block_1', array(), 'The user got redirected to the new display.');
  94. $this->assertText(t('Block settings'));
  95. $this->assertNoText(t('Page settings'));
  96. $this->drupalPostForm(NULL, array(), t('Save'));
  97. $view = Views::getView($view['id']);
  98. $view->initDisplay();
  99. $page_2 = $view->displayHandlers->get('page_2');
  100. $this->assertTrue($page_2, 'The new page display got saved.');
  101. $this->assertEqual($page_2->display['display_title'], 'Page');
  102. $this->assertEqual($page_2->display['display_options']['path'], $path);
  103. $block_1 = $view->displayHandlers->get('block_1');
  104. $this->assertTrue($block_1, 'The new block display got saved.');
  105. $this->assertEqual($block_1->display['display_plugin'], 'block');
  106. $this->assertEqual($block_1->display['display_title'], 'Block', 'The new display title got generated as expected.');
  107. $this->assertFalse(isset($block_1->display['display_options']['path']));
  108. $this->assertEqual($block_1->getOption('title'), $random_title, 'The overridden title option from the display got copied into the duplicate');
  109. $this->assertEqual($block_1->getOption('css_class'), $random_css, 'The overridden css_class option from the display got copied into the duplicate');
  110. }
  111. }