3 namespace Drupal\Tests\views\Functional\Plugin;
5 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7 use Drupal\views\Views;
10 * Tests the views page display plugin as webtest.
14 class DisplayPageWebTest extends ViewTestBase {
16 use AssertPageCacheContextsAndTagsTrait;
19 * Views used by this test.
23 public static $testViews = ['test_page_display', 'test_page_display_arguments', 'test_page_display_menu', 'test_page_display_path'];
30 public static $modules = ['menu_ui', 'block', 'views_ui'];
35 protected function setUp($import_test_views = TRUE) {
36 parent::setUp($import_test_views);
38 $this->enableViewsTestModule();
39 $this->drupalPlaceBlock('local_tasks_block');
45 public function testArguments() {
46 $this->drupalGet('test_route_without_arguments');
47 $this->assertResponse(200);
48 $result = $this->xpath('//span[@class="field-content"]');
49 $this->assertEqual(count($result), 5, 'All entries was returned');
51 $this->drupalGet('test_route_without_arguments/1');
52 $this->assertResponse(404);
54 $this->drupalGet('test_route_with_argument/1');
55 $this->assertResponse(200);
56 $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']);
57 $result = $this->xpath('//span[@class="field-content"]');
58 $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
59 $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
61 $this->drupalGet('test_route_with_suffix/1/suffix');
62 $this->assertResponse(200);
63 $result = $this->xpath('//span[@class="field-content"]');
64 $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
65 $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
67 $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
68 $this->assertResponse(200);
69 $result = $this->xpath('//span[@class="field-content"]');
70 $this->assertEqual(count($result), 0, 'No result was returned.');
72 $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1');
73 $this->assertResponse(200);
74 $result = $this->xpath('//span[@class="field-content"]');
75 $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
76 $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
78 $this->drupalGet('test_route_with_long_argument/1');
79 $this->assertResponse(200);
80 $result = $this->xpath('//span[@class="field-content"]');
81 $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
82 $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
86 * Tests menu settings of page displays.
88 public function testPageDisplayMenu() {
90 $this->drupalGet('test_page_display_menu');
91 $this->assertResponse(200);
92 $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [
93 ':ul_class' => 'tabs primary',
94 ':a_class' => 'is-active',
96 $this->assertEqual($element[0]->getText(), t('Test default tab'));
97 $this->assertTitle(t('Test default page | Drupal'));
99 $this->drupalGet('test_page_display_menu/default');
100 $this->assertResponse(404);
102 $this->drupalGet('test_page_display_menu/local');
103 $this->assertResponse(200);
104 $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [
105 ':ul_class' => 'tabs primary',
106 ':a_class' => 'is-active',
108 $this->assertEqual($element[0]->getText(), t('Test local tab'));
109 $this->assertTitle(t('Test local page | Drupal'));
111 // Check an ordinary menu link.
112 $admin_user = $this->drupalCreateUser(['administer menu']);
113 $this->drupalLogin($admin_user);
114 $this->drupalPlaceBlock('system_menu_block:tools');
115 $this->drupalGet('<front>');
117 $menu_link = $this->cssSelect('nav.block-menu ul.menu a');
118 $this->assertEqual($menu_link[0]->getText(), 'Test menu link');
120 // Update the menu link.
121 $this->drupalPostForm("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit", [
122 'title' => 'New title',
125 $this->drupalGet('<front>');
126 $menu_link = $this->cssSelect('nav.block-menu ul.menu a');
127 $this->assertEqual($menu_link[0]->getText(), 'New title');
131 * Tests the title is not displayed in the output.
133 public function testTitleOutput() {
134 $this->drupalGet('test_page_display_200');
136 $view = Views::getView('test_page_display');
137 $xpath = $this->cssSelect('div.view:contains("' . $view->getTitle() . '")');
138 $this->assertFalse($xpath, 'The view title was not displayed in the view markup.');
142 * Tests the views page path functionality.
144 public function testPagePaths() {
145 $this->drupalLogin($this->rootUser);
146 $this->assertPagePath('0');
147 $this->assertPagePath('9999');
151 * Tests that we can successfully change a view page display path.
153 * @param string $path
154 * Path that will be set as the view page display path.
159 public function assertPagePath($path) {
160 $view = Views::getView('test_page_display_path');
161 $view->initDisplay('page_1');
162 $view->displayHandlers->get('page_1')->overrideOption('path', $path);
164 $this->container->get('router.builder')->rebuild();
165 // Check if we successfully changed the path.
166 $this->drupalGet($path);
167 $success = $this->assertResponse(200);
168 // Check if we don't get any error on the view edit page.
169 $this->drupalGet('admin/structure/views/view/test_page_display_path');
170 return $success && $this->assertResponse(200);