diff --git a/core/modules/views/src/Tests/Handler/HandlerTestBase.php b/core/modules/views/src/Tests/Handler/HandlerTestBase.php index 5345f47b05e600c82e4b71d0c563468ab1e76b7a..1603329bdbb1939efd522db65c88c71ef8407820 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTestBase.php +++ b/core/modules/views/src/Tests/Handler/HandlerTestBase.php @@ -1,11 +1,13 @@ ['all'], ]; - protected function setUp() { - parent::setUp(); + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); $this->drupalPlaceBlock('page_title_block'); diff --git a/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php b/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php similarity index 89% rename from core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php rename to core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php index 698a43e79f810a51c59802ef744366d40f36655f..19aa191e1413b11d2aff7c661e95205cab3af7c6 100644 --- a/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php +++ b/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php @@ -1,9 +1,9 @@ container->get('entity.definition_update_manager'); \Drupal::entityManager()->clearCachedDefinitions(); diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php similarity index 96% rename from core/modules/views/src/Tests/Entity/FieldEntityTest.php rename to core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php index 89f71edf0c3c3f8c95ab281b3257313da5685626..a46e54c9e5817b46e4782675021949cd8ff17514 100644 --- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php +++ b/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php @@ -1,11 +1,11 @@ cssSelect('div.views-row'); foreach ($rows as $row) { $actual[] = [ - 'title' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))[0], - 'sticky' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))[0], + 'title' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))->getText(), + 'sticky' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))->getText(), ]; } $this->assertEqual($actual, $expected); diff --git a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/tests/src/Functional/Entity/FilterEntityBundleTest.php similarity index 95% rename from core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php rename to core/modules/views/tests/src/Functional/Entity/FilterEntityBundleTest.php index f099569b80b410f0fe7c0f45c07133eb5ff1d6e6..993293cebf48e85e837be085e72882e7357ee547 100644 --- a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php +++ b/core/modules/views/tests/src/Functional/Entity/FilterEntityBundleTest.php @@ -1,9 +1,9 @@ drupalCreateContentType(['type' => 'test_bundle']); diff --git a/core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php b/core/modules/views/tests/src/Functional/Entity/ViewNonTranslatableEntityTest.php similarity index 87% rename from core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php rename to core/modules/views/tests/src/Functional/Entity/ViewNonTranslatableEntityTest.php index 82c683995cfa922dabfde1713025f6ed6e79cc94..911cd61e66a5c04bfb701824f00372dc1273794b 100644 --- a/core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php +++ b/core/modules/views/tests/src/Functional/Entity/ViewNonTranslatableEntityTest.php @@ -1,17 +1,17 @@ xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', [':href' => $href, ':label' => $label]); $this->assertTrue(count($result)); - // The rendered output looks like "| (count)" so let's figure out the int. - $result_count = trim(str_replace(['|', '(', ')'], '', (string) $result[0])); + // The rendered output looks like "X | (count)" so let's + // figure out the int. + $result_count = explode(' ', trim(str_replace(['|', '(', ')'], '', $result[0]->getText())))[1]; $this->assertEqual($result_count, $count, 'The expected number got rendered.'); } } diff --git a/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php b/core/modules/views/tests/src/Functional/Handler/AreaHTTPStatusCodeTest.php similarity index 86% rename from core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php rename to core/modules/views/tests/src/Functional/Handler/AreaHTTPStatusCodeTest.php index 2656adc4dcdb6898e1ea25797ab504b09016bc41..dc914ce219e6d0f8aeb575b647faf5e366d2771c 100644 --- a/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php +++ b/core/modules/views/tests/src/Functional/Handler/AreaHTTPStatusCodeTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); } @@ -110,41 +111,6 @@ public function testRenderArea() { $this->assertTrue(strpos($output, 'initHandlers(); - - // Set example empty text. - $view->empty['test_example']->options['string'] = '

' . $this->randomMachineName() . '

'; - - $xpath = '//div[contains(@class, :class)]'; - - // Verify that the empty header and footer sections have not been rendered. - $output = $view->preview(); - $html = $this->container->get('renderer')->renderRoot($output); - $this->setRawContent($html); - $this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-header']))); - $this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-footer']))); - - // Set example header text. - $view->header['test_example']->options['string'] = '

' . $this->randomMachineName() . '

'; - $view->header['test_example']->options['empty'] = TRUE; - - // Set example footer text. - $view->footer['test_example']->options['string'] = '

' . $this->randomMachineName() . '

'; - $view->footer['test_example']->options['empty'] = TRUE; - - // Verify that the header and footer sections have been rendered. - $output = $view->preview(); - $html = $this->container->get('renderer')->renderRoot($output); - $this->setRawContent($html); - $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-header']))); - $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-footer']))); - } - /** * Tests the access for an area. */ diff --git a/core/modules/views/src/Tests/Handler/AreaTitleWebTest.php b/core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php similarity index 91% rename from core/modules/views/src/Tests/Handler/AreaTitleWebTest.php rename to core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php index afae1eb8ec05884531d45dd8404511ef72e58e58..9e1fcfad233dc7c1a71e4f32953600f390b536d0 100644 --- a/core/modules/views/src/Tests/Handler/AreaTitleWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php @@ -1,9 +1,9 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/Handler/ArgumentStringTest.php b/core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php similarity index 89% rename from core/modules/views/src/Tests/Handler/ArgumentStringTest.php rename to core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php index 0682892e89570cea042976a7f055a554cf1bbca7..17ece944c5cd9eb8cd3516775d9fbda469bf6169 100644 --- a/core/modules/views/src/Tests/Handler/ArgumentStringTest.php +++ b/core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php @@ -1,7 +1,8 @@ drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']); $this->drupalLogin($admin_user); @@ -48,7 +50,7 @@ public function testDropbutton() { foreach ($nodes as $node) { $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => $node->label()]); $this->assertEqual(count($result), 1, 'Just one node title link was found.'); - $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => t('Custom Text')]); + $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => 'Custom Text']); $this->assertEqual(count($result), 1, 'Just one custom link was found.'); } diff --git a/core/modules/views/src/Tests/Handler/FieldEntityOperationsTest.php b/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php similarity index 92% rename from core/modules/views/src/Tests/Handler/FieldEntityOperationsTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php index 7efd1d7414491ae5859b129b1d42d24fffc26557..653ce11527e370c2255ebef292d89f2bf72511de 100644 --- a/core/modules/views/src/Tests/Handler/FieldEntityOperationsTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php @@ -1,17 +1,18 @@ drupalCreateContentType(['type' => 'article', 'name' => 'Article']); @@ -72,7 +73,7 @@ public function testEntityOperations() { $this->assertTrue(count($operations) > 0, 'There are operations.'); foreach ($operations as $operation) { $expected_destination = Url::fromUri('internal:/test-entity-operations')->toString(); - $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => $operation['title']]); + $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => (string) $operation['title']]); $this->assertEqual(count($result), 1, t('Found entity @operation link with destination parameter.', ['@operation' => $operation['title']])); // Entities which were created in Hungarian should link to the Hungarian // edit form, others to the English one (which has no path prefix here). diff --git a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsTest.php similarity index 92% rename from core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldGroupRowsTest.php index 2521e6329e7ed76fbda2c23b037282403fc3db22..d38ba41792bac35df11e849c10c26bef37008599 100644 --- a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsTest.php @@ -1,10 +1,11 @@ drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); diff --git a/core/modules/views/src/Tests/Handler/FieldGroupRowsWebTest.php b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsWebTest.php similarity index 90% rename from core/modules/views/src/Tests/Handler/FieldGroupRowsWebTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldGroupRowsWebTest.php index 646cb1224266ac3be5f9adc802ef0ad6703a9541..275960cb0d4a9162cd43c890eff0e019cea9a2f1 100644 --- a/core/modules/views/src/Tests/Handler/FieldGroupRowsWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsWebTest.php @@ -1,11 +1,11 @@ nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); @@ -98,7 +98,7 @@ public function testGroupRows() { $rendered_value = []; foreach ($result as $row) { - $rendered_value[] = (string) $row[0]; + $rendered_value[] = $row->getText(); } $this->assertEqual(['a, b, c'], $rendered_value); } @@ -111,7 +111,7 @@ public function testUngroupedRows() { $result = $this->cssSelect('div.views-field-field-views-testing-group- div'); $rendered_value = []; foreach ($result as $row) { - $rendered_value[] = (string) $row[0]; + $rendered_value[] = $row->getText(); } $this->assertEqual(['a', 'b', 'c'], $rendered_value); } diff --git a/core/modules/views/src/Tests/Handler/FieldWebTest.php b/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php similarity index 99% rename from core/modules/views/src/Tests/Handler/FieldWebTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldWebTest.php index 31de7be7e627a8571d1551a58d6d7f083c44ee02..318be3f902cb9a22d1a6280eeee5eea0d4fe23e4 100644 --- a/core/modules/views/src/Tests/Handler/FieldWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php @@ -1,6 +1,6 @@ 'name', ]; - protected function setUp() { - parent::setUp(); + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); $this->enableViewsTestModule(); } @@ -99,7 +100,7 @@ protected function clickSortLoadIdsFromOutput() { $fields = $this->xpath("//td[contains(@class, 'views-field-id')]"); $ids = []; foreach ($fields as $field) { - $ids[] = (int) $field[0]; + $ids[] = (int) $field->getText(); } return $ids; } diff --git a/core/modules/views/src/Tests/Handler/FilterDateTest.php b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php similarity index 89% rename from core/modules/views/src/Tests/Handler/FilterDateTest.php rename to core/modules/views/tests/src/Functional/Handler/FilterDateTest.php index f81e753d6045a001ef15826e99161c51181b744b..ec3b52385fb6389b605b617fac1567586f683a66 100644 --- a/core/modules/views/src/Tests/Handler/FilterDateTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php @@ -1,11 +1,12 @@ assertFieldByName($name, $value); if (strpos($name, '[value][type]')) { $radio = $this->cssSelect('input[name="' . $name . '"][checked="checked"][type="radio"]'); - $this->assertEqual((string) $radio[0]['value'], $value); + $this->assertEqual($radio[0]->getAttribute('value'), $value); } } @@ -221,22 +222,27 @@ protected function _testFilterDateUI() { $this->assertConfigSchemaByName('views.view.test_filter_date_between'); // Test that the exposed filter works as expected. - $this->drupalGet('admin/structure/views/view/test_filter_date_between/edit'); - $this->drupalPostForm(NULL, [], t('Update preview')); + $path = 'test_filter_date_between-path'; + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between/edit', [], 'Add Page'); + $this->drupalPostForm('admin/structure/views/nojs/display/test_filter_date_between/page_1/path', ['path' => $path], 'Apply'); + $this->drupalPostForm(NULL, [], t('Save')); + + $this->drupalGet($path); + $this->drupalPostForm(NULL, [], 'Apply'); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 4); - $this->drupalPostForm(NULL, ['created' => '1'], t('Update preview')); + $this->drupalPostForm(NULL, ['created' => '1'], 'Apply'); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 1); - $this->assertEqual((string) $results[0], $this->nodes[3]->id()); - $this->drupalPostForm(NULL, ['created' => '2'], t('Update preview')); + $this->assertEqual($results[0]->getText(), $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => '2'], 'Apply'); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 1); - $this->assertEqual((string) $results[0], $this->nodes[3]->id()); - $this->drupalPostForm(NULL, ['created' => '3'], t('Update preview')); + $this->assertEqual($results[0]->getText(), $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => '3'], 'Apply'); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 1); - $this->assertEqual((string) $results[0], $this->nodes[1]->id()); + $this->assertEqual($results[0]->getText(), $this->nodes[1]->id()); // Change the filter to a single filter to test the schema when the operator // is not exposed. @@ -250,15 +256,15 @@ protected function _testFilterDateUI() { $this->assertConfigSchemaByName('views.view.test_filter_date_between'); // Test that the filter works as expected. - $this->drupalPostForm(NULL, [], t('Update preview')); + $this->drupalGet($path); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 1); - $this->assertEqual((string) $results[0], $this->nodes[3]->id()); - $this->drupalPostForm(NULL, ['created' => format_date(250000, 'custom', 'Y-m-d H:i:s')], t('Update preview')); + $this->assertEqual($results[0]->getText(), $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => format_date(250000, 'custom', 'Y-m-d H:i:s')], 'Apply'); $results = $this->cssSelect('.view-content .field-content'); $this->assertEqual(count($results), 2); - $this->assertEqual((string) $results[0], $this->nodes[2]->id()); - $this->assertEqual((string) $results[1], $this->nodes[3]->id()); + $this->assertEqual($results[0]->getText(), $this->nodes[2]->id()); + $this->assertEqual($results[1]->getText(), $this->nodes[3]->id()); } /** diff --git a/core/modules/views/src/Tests/Handler/HandlerAllTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php similarity index 95% rename from core/modules/views/src/Tests/Handler/HandlerAllTest.php rename to core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php index 565437657e7210bf119781ac10802416e4da5316..1a37ce830703eb76686e13d9d980bfde8d4c108d 100644 --- a/core/modules/views/src/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php @@ -1,8 +1,9 @@ drupalCreateContentType(['type' => 'page']); $this->addDefaultCommentField('node', 'page'); $this->enableViewsTestModule(); @@ -260,13 +260,12 @@ public function testRelationshipUI() { $this->assertFieldByName($relationship_name); // Check for available options. - $xpath = $this->constructFieldXpath('name', $relationship_name); - $fields = $this->xpath($xpath); + $fields = $this->getSession()->getPage()->findAll('named_exact', ['field', $relationship_name]); $options = []; foreach ($fields as $field) { - $items = $this->getAllOptions($field); + $items = $field->findAll('css', 'option'); foreach ($items as $item) { - $options[] = $item->attributes()->value; + $options[] = $item->getAttribute('value'); } } $expected_options = ['none', 'nid']; diff --git a/core/modules/views/src/Tests/Plugin/AccessTest.php b/core/modules/views/tests/src/Functional/Plugin/AccessTest.php similarity index 91% rename from core/modules/views/src/Tests/Plugin/AccessTest.php rename to core/modules/views/tests/src/Functional/Plugin/AccessTest.php index 7a4eb1a5b37643047d49c2c4d0219b95a506efb5..41aa6ec53a7c5b25dff9c55dd3c696d6a940bb3d 100644 --- a/core/modules/views/src/Tests/Plugin/AccessTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/AccessTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php similarity index 93% rename from core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php rename to core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php index a4e82172e0903ae4f06eccc849473323b2da89d5..b3956de8ea5ea2175df431cc2c83a324f84c9787 100644 --- a/core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php @@ -1,10 +1,11 @@ enableViewsTestModule(); } @@ -161,9 +162,9 @@ public function testArgumentDefaultNode() { $this->drupalPlaceBlock("views_block:test_argument_default_node-block_1", ['id' => $id]); $xpath = '//*[@id="block-' . $id . '"]'; $this->drupalGet('node/' . $node1->id()); - $this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node1->getTitle())); + $this->assertTrue(strpos($this->xpath($xpath)[0]->getText(), $node1->getTitle())); $this->drupalGet('node/' . $node2->id()); - $this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node2->getTitle())); + $this->assertTrue(strpos($this->xpath($xpath)[0]->getText(), $node2->getTitle())); } /** diff --git a/core/modules/views/src/Tests/Plugin/CacheTagTest.php b/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php similarity index 96% rename from core/modules/views/src/Tests/Plugin/CacheTagTest.php rename to core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php index 72d94f3cf34aabed531787fbe1a9c48851ddc7a6..1d78204db9a93022e97ef1555806bc8c6dbaccc7 100644 --- a/core/modules/views/src/Tests/Plugin/CacheTagTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php @@ -1,8 +1,9 @@ drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); diff --git a/core/modules/views/src/Tests/Plugin/CacheWebTest.php b/core/modules/views/tests/src/Functional/Plugin/CacheWebTest.php similarity index 91% rename from core/modules/views/src/Tests/Plugin/CacheWebTest.php rename to core/modules/views/tests/src/Functional/Plugin/CacheWebTest.php index 7786606376aff848c1a1221d750f522d479ebc17..40bf60189cbb16d68231be6be10a40d7faae01fb 100644 --- a/core/modules/views/src/Tests/Plugin/CacheWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/CacheWebTest.php @@ -1,8 +1,9 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php b/core/modules/views/tests/src/Functional/Plugin/ContextualFiltersBlockContextTest.php similarity index 96% rename from core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php rename to core/modules/views/tests/src/Functional/Plugin/ContextualFiltersBlockContextTest.php index 7fb70580a274b3bce9aef52ddbbd235b179df8a3..567e1c930a69331b2ef3f25f86e51a77e2308549 100644 --- a/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ContextualFiltersBlockContextTest.php @@ -1,10 +1,10 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php b/core/modules/views/tests/src/Functional/Plugin/DisabledDisplayTest.php similarity index 86% rename from core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php rename to core/modules/views/tests/src/Functional/Plugin/DisabledDisplayTest.php index cb43946913376bce49e69b1660325919797b7454..708ac5503037f5dc3924e73544bdbd1a1e23e46f 100644 --- a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisabledDisplayTest.php @@ -1,6 +1,8 @@ enableViewsTestModule(); @@ -56,7 +58,7 @@ public function testDisabledDisplays() { // Enabled page display should return content. $this->drupalGet('test-disabled-display'); $result = $this->xpath('//h1[@class="page-title"]'); - $this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_1 display is accessible.'); + $this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_1 display is accessible.'); // Disabled page view should 404. $this->drupalGet('test-disabled-display-2'); @@ -75,7 +77,7 @@ public function testDisabledDisplays() { // Check that the originally disabled page_2 display is now enabled. $this->drupalGet('test-disabled-display-2'); $result = $this->xpath('//h1[@class="page-title"]'); - $this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_2 display is accessible.'); + $this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_2 display is accessible.'); // Disable each disabled display and save the view. foreach ($display_ids as $display_id) { diff --git a/core/modules/views/src/Tests/Plugin/DisplayAttachmentTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayAttachmentTest.php similarity index 93% rename from core/modules/views/src/Tests/Plugin/DisplayAttachmentTest.php rename to core/modules/views/tests/src/Functional/Plugin/DisplayAttachmentTest.php index 16c0680b36d718725cf4220d5c69e1d17f6e19d9..8c326baa05893eb33bd4511fd6f61a77df681d80 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayAttachmentTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayAttachmentTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php similarity index 97% rename from core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php rename to core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php index ac7209c28419b3c9b1e8250e0e1c963c1db31051..a081ad7d97987f8581620e6e9496afc1bd78df9f 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php @@ -1,11 +1,12 @@ drupalLogin($this->drupalCreateUser(['administer views'])); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php similarity index 84% rename from core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php rename to core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php index b5c853faec5a5223ee4de40b00ef3710c5c7a068..3d2aca6639f69330c9c43dd0819e10021f7c04e4 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php @@ -1,8 +1,9 @@ enableViewsTestModule(); $this->drupalPlaceBlock('local_tasks_block'); @@ -55,13 +56,13 @@ public function testArguments() { $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']); $result = $this->xpath('//span[@class="field-content"]'); $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual((string) $result[0], 1, 'The passed ID was returned.'); + $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.'); $this->drupalGet('test_route_with_suffix/1/suffix'); $this->assertResponse(200); $result = $this->xpath('//span[@class="field-content"]'); $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual((string) $result[0], 1, 'The passed ID was returned.'); + $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.'); $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2'); $this->assertResponse(200); @@ -72,13 +73,13 @@ public function testArguments() { $this->assertResponse(200); $result = $this->xpath('//span[@class="field-content"]'); $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual((string) $result[0], 1, 'The passed ID was returned.'); + $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.'); $this->drupalGet('test_route_with_long_argument/1'); $this->assertResponse(200); $result = $this->xpath('//span[@class="field-content"]'); $this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual((string) $result[0], 1, 'The passed ID was returned.'); + $this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.'); } /** @@ -88,11 +89,11 @@ public function testPageDisplayMenu() { // Check local tasks. $this->drupalGet('test_page_display_menu'); $this->assertResponse(200); - $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]', [ + $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [ ':ul_class' => 'tabs primary', ':a_class' => 'is-active', ]); - $this->assertEqual((string) $element[0], t('Test default tab')); + $this->assertEqual($element[0]->getText(), t('Test default tab')); $this->assertTitle(t('Test default page | Drupal')); $this->drupalGet('test_page_display_menu/default'); @@ -100,11 +101,11 @@ public function testPageDisplayMenu() { $this->drupalGet('test_page_display_menu/local'); $this->assertResponse(200); - $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]', [ + $element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [ ':ul_class' => 'tabs primary', ':a_class' => 'is-active', ]); - $this->assertEqual((string) $element[0], t('Test local tab')); + $this->assertEqual($element[0]->getText(), t('Test local tab')); $this->assertTitle(t('Test local page | Drupal')); // Check an ordinary menu link. @@ -114,7 +115,7 @@ public function testPageDisplayMenu() { $this->drupalGet(''); $menu_link = $this->cssSelect('nav.block-menu ul.menu a'); - $this->assertEqual((string) $menu_link[0], 'Test menu link'); + $this->assertEqual($menu_link[0]->getText(), 'Test menu link'); // Update the menu link. $this->drupalPostForm("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit", [ @@ -123,7 +124,7 @@ public function testPageDisplayMenu() { $this->drupalGet(''); $menu_link = $this->cssSelect('nav.block-menu ul.menu a'); - $this->assertEqual((string) $menu_link[0], 'New title'); + $this->assertEqual($menu_link[0]->getText(), 'New title'); } /** diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php similarity index 80% rename from core/modules/views/src/Tests/Plugin/DisplayTest.php rename to core/modules/views/tests/src/Functional/Plugin/DisplayTest.php index 42a389cb911644101ffa87291ebe438d1274aacd..674815298762cbd114ebd9d6476d57ed38ecfee8 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php @@ -1,9 +1,9 @@ enableViewsTestModule(); @@ -94,6 +94,13 @@ public function testDisplayPlugin() { // Check the test option. $this->assertIdentical($view->display_handler->getOption('test_option'), ''); + $style = $view->display_handler->getOption('style'); + $style['type'] = 'test_style'; + $view->display_handler->setOption('style', $style); + $view->initDisplay(); + $view->initStyle(); + $view->style_plugin->setUsesRowPlugin(FALSE); + $output = $view->preview(); $output = $renderer->renderRoot($output); @@ -113,9 +120,9 @@ public function testDisplayPlugin() { $this->drupalGet('admin/structure/views/view/test_view/edit/display_test_1'); $this->assertText('Display test settings'); // Ensure that the order is as expected. - $result = $this->xpath('//ul[@id="views-display-menu-tabs"]/li'); - $this->assertEqual((string) $result[0]->a, 'Display test 2'); - $this->assertEqual((string) $result[1]->a, 'Display test'); + $result = $this->xpath('//ul[@id="views-display-menu-tabs"]/li/a/child::text()'); + $this->assertEqual($result[0]->getText(), 'Display test 2'); + $this->assertEqual($result[1]->getText(), 'Display test'); $this->clickLink('Test option title'); @@ -160,76 +167,6 @@ public function testGetAttachedDisplays() { $this->assertEqual($view->display_handler->getAttachedDisplays(), []); } - /** - * Tests the readmore functionality. - */ - public function testReadMore() { - /** @var \Drupal\Core\Render\RendererInterface $renderer */ - $renderer = $this->container->get('renderer'); - - if (!isset($this->options['validate']['type'])) { - return; - } - $expected_more_text = 'custom more text'; - - $view = Views::getView('test_display_more'); - $this->executeView($view); - - $output = $view->preview(); - $output = $renderer->renderRoot($output); - - $this->setRawContent($output); - $result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']); - $this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.'); - $this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.'); - - // Test the renderMoreLink method directly. This could be directly unit - // tested. - $more_link = $view->display_handler->renderMoreLink(); - $more_link = $renderer->renderRoot($more_link); - $this->setRawContent($more_link); - $result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']); - $this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.'); - $this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.'); - - // Test the useMoreText method directly. This could be directly unit - // tested. - $more_text = $view->display_handler->useMoreText(); - $this->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.'); - - $view = Views::getView('test_display_more'); - $view->setDisplay(); - $view->display_handler->setOption('use_more', 0); - $this->executeView($view); - $output = $view->preview(); - $output = $renderer->renderRoot($output); - $this->setRawContent($output); - $result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']); - $this->assertTrue(empty($result), 'The more link is not shown.'); - - $view = Views::getView('test_display_more'); - $view->setDisplay(); - $view->display_handler->setOption('use_more', 0); - $view->display_handler->setOption('use_more_always', 0); - $view->display_handler->setOption('pager', [ - 'type' => 'some', - 'options' => [ - 'items_per_page' => 1, - 'offset' => 0, - ], - ]); - $this->executeView($view); - $output = $view->preview(); - $output = $renderer->renderRoot($output); - $this->setRawContent($output); - $result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']); - $this->assertTrue(empty($result), 'The more link is not shown when view has more records.'); - - // Test the default value of use_more_always. - $view = View::create()->getExecutable(); - $this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.'); - } - /** * Tests the readmore validation. */ @@ -290,7 +227,8 @@ public function testInvalidDisplayPlugins() { $this->drupalGet(''); $this->assertResponse(200); - $this->assertBlockAppears($block); + $result = $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); + $this->assertEquals(1, count($result)); // Change the block plugin ID to an invalid one. $config = $this->config('views.view.test_display_invalid'); @@ -302,7 +240,8 @@ public function testInvalidDisplayPlugins() { $this->drupalGet(''); $this->assertResponse(200); $this->assertText('The "invalid" plugin does not exist.'); - $this->assertNoBlockAppears($block); + $result = $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); + $this->assertEquals(0, count($result)); } /** diff --git a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php similarity index 91% rename from core/modules/views/src/Tests/Plugin/ExposedFormTest.php rename to core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php index cfb3c0a0713660b5b84f7a644f628fe9dac87876..38b7327b4d84d3bda90a20506932a5caeddfd514 100644 --- a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php @@ -1,11 +1,11 @@ enableViewsTestModule(); @@ -191,26 +191,6 @@ public function testResetButton() { $this->helperButtonHasLabel('edit-reset', $expected_label); } - /** - * Tests the exposed form markup. - */ - public function testExposedFormRender() { - $view = Views::getView('test_exposed_form_buttons'); - $this->executeView($view); - $exposed_form = $view->display_handler->getPlugin('exposed_form'); - $output = $exposed_form->renderExposedForm(); - $this->setRawContent(\Drupal::service('renderer')->renderRoot($output)); - - $this->assertFieldByXpath('//form/@id', $this->getExpectedExposedFormId($view), 'Expected form ID found.'); - - $view->setDisplay('page_1'); - $expected_action = $view->display_handler->getUrlInfo()->toString(); - $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.'); - // Make sure the description is shown. - $result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]); - $this->assertEqual(count($result), 1, 'Filter description was found.'); - } - /** * Tests overriding the default render option with checkboxes. */ @@ -265,7 +245,8 @@ public function testExposedBlock() { // Test there is an exposed form in a block. $xpath = $this->buildXPathQuery('//div[@id=:id]/form/@id', [':id' => Html::getUniqueId('block-' . $block->id())]); - $this->assertFieldByXpath($xpath, $this->getExpectedExposedFormId($view), 'Expected form found in views block.'); + $result = $this->xpath($xpath); + $this->assertEquals(1, count($result)); // Test there is not an exposed form in the view page content area. $xpath = $this->buildXPathQuery('//div[@class="view-content"]/form/@id', [':id' => Html::getUniqueId('block-' . $block->id())]); @@ -381,7 +362,7 @@ protected function assertIds(array $ids) { $elements = $this->cssSelect('div.view-test-exposed-form-sort-items-per-page div.views-row span.field-content'); $actual_ids = []; foreach ($elements as $element) { - $actual_ids[] = (int) $element; + $actual_ids[] = (int) $element->getText(); } return $this->assertIdentical($ids, $actual_ids); diff --git a/core/modules/views/src/Tests/Plugin/FilterTest.php b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php similarity index 96% rename from core/modules/views/src/Tests/Plugin/FilterTest.php rename to core/modules/views/tests/src/Functional/Plugin/FilterTest.php index 081835f404c9abc5b9e8691150b49d279d577473..60424108f5fab0ace2cec009e405ec5881365dc9 100644 --- a/core/modules/views/src/Tests/Plugin/FilterTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/Plugin/MenuLinkTest.php b/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php similarity index 93% rename from core/modules/views/src/Tests/Plugin/MenuLinkTest.php rename to core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php index 06e661f28b2500e3a286a63b991858064aaf421c..8afbb57b8c8cfe46eafd5ae176b5532e5b7dbc9a 100644 --- a/core/modules/views/src/Tests/Plugin/MenuLinkTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php @@ -1,9 +1,9 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php b/core/modules/views/tests/src/Functional/Plugin/MiniPagerTest.php similarity index 95% rename from core/modules/views/src/Tests/Plugin/MiniPagerTest.php rename to core/modules/views/tests/src/Functional/Plugin/MiniPagerTest.php index 7e9f57a3050b7b8121dc9bfc869b38f93266d0a9..492d22f987979695678bd7e5e07db9bb2ab06a1e 100644 --- a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/MiniPagerTest.php @@ -1,7 +1,8 @@ drupalCreateContentType(['type' => 'page']); // Create a bunch of test nodes. diff --git a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php similarity index 97% rename from core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php rename to core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php index d463336c4182300418b903e25f8d505a3ec7e346..08f2504c54ea92ed07ebb3627d90ebc250e202c6 100644 --- a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php @@ -1,10 +1,10 @@ drupalCreateUser(['administer views', 'administer languages']); $this->drupalLogin($web_user); diff --git a/core/modules/views/src/Tests/Plugin/PagerTest.php b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php similarity index 99% rename from core/modules/views/src/Tests/Plugin/PagerTest.php rename to core/modules/views/tests/src/Functional/Plugin/PagerTest.php index 6ba4c069b46052e9d476bacf934067f81289183f..eda88916d6647f5525e6caf59522c5efd0e96e64 100644 --- a/core/modules/views/src/Tests/Plugin/PagerTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php @@ -1,8 +1,9 @@ assertEqual(4, count($summary_list)); foreach ($summary_list as $summary_list_item) { - $this->assertEqual('(5)', trim((string) $summary_list_item)); + $this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1])); } $summary_links = $this->cssSelect('ul.views-summary a'); $this->assertEqual(4, count($summary_links)); foreach ($summary_links as $index => $summary_link) { - $this->assertEqual('type' . $index, trim((string) $summary_link)); + $this->assertEqual('type' . $index, trim($summary_link->getText())); } $this->clickLink('type1'); @@ -100,13 +100,13 @@ public function testSummaryView() { $this->assertEqual(3, count($summary_list)); foreach ($summary_list as $summary_list_item) { - $this->assertEqual('(5)', trim((string) $summary_list_item)); + $this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1])); } $summary_links = $this->cssSelect('.views-summary-unformatted a'); $this->assertEqual(3, count($summary_links)); foreach ($summary_links as $index => $summary_link) { - $this->assertEqual('type' . $index, trim((string) $summary_link)); + $this->assertEqual('type' . $index, trim($summary_link->getText())); } $this->clickLink('type1'); diff --git a/core/modules/views/src/Tests/Plugin/StyleTableTest.php b/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php similarity index 89% rename from core/modules/views/src/Tests/Plugin/StyleTableTest.php rename to core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php index 537839f7bf03d5cca2ab54968d5e2f2634f443b8..3bbe6bf97c3c965c87dc434f9bd87ad39ff8ca9d 100644 --- a/core/modules/views/src/Tests/Plugin/StyleTableTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); } @@ -33,17 +34,17 @@ protected function setUp() { public function testAccessibilitySettings() { $this->drupalGet('test-table'); - $result = $this->xpath('//caption'); + $result = $this->xpath('//caption/child::text()'); $this->assertTrue(count($result), 'The caption appears on the table.'); - $this->assertEqual(trim((string) $result[0]), 'caption-text'); + $this->assertEqual(trim($result[0]->getText()), 'caption-text'); - $result = $this->xpath('//summary'); + $result = $this->xpath('//summary/child::text()'); $this->assertTrue(count($result), 'The summary appears on the table.'); - $this->assertEqual(trim((string) $result[0]), 'summary-text'); + $this->assertEqual(trim($result[0]->getText()), 'summary-text'); - $result = $this->xpath('//caption/details'); + $result = $this->xpath('//caption/details/child::text()'); $this->assertTrue(count($result), 'The table description appears on the table.'); - $this->assertEqual(trim((string) $result[0]), 'description-text'); + $this->assertEqual(trim($result[0]->getText()), 'description-text'); // Remove the caption and ensure the caption is not displayed anymore. $view = View::load('test_table'); @@ -52,8 +53,8 @@ public function testAccessibilitySettings() { $view->save(); $this->drupalGet('test-table'); - $result = $this->xpath('//caption'); - $this->assertFalse(trim((string) $result[0]), 'Ensure that the caption disappears.'); + $result = $this->xpath('//caption/child::text()'); + $this->assertFalse(trim($result[0]->getText()), 'Ensure that the caption disappears.'); // Remove the table summary. $display = &$view->getDisplay('default'); @@ -61,7 +62,7 @@ public function testAccessibilitySettings() { $view->save(); $this->drupalGet('test-table'); - $result = $this->xpath('//summary'); + $result = $this->xpath('//summary/child::text()'); $this->assertFalse(count($result), 'Ensure that the summary disappears.'); // Remove the table description. @@ -70,7 +71,7 @@ public function testAccessibilitySettings() { $view->save(); $this->drupalGet('test-table'); - $result = $this->xpath('//caption/details'); + $result = $this->xpath('//caption/details/child::text()'); $this->assertFalse(count($result), 'Ensure that the description disappears.'); } diff --git a/core/modules/views/src/Tests/Plugin/StyleTest.php b/core/modules/views/tests/src/Functional/Plugin/StyleTest.php similarity index 98% rename from core/modules/views/src/Tests/Plugin/StyleTest.php rename to core/modules/views/tests/src/Functional/Plugin/StyleTest.php index e059275617bd15a8fc933d0a4834bde741dca56a..fbb5bcfff1426895cea94ce0627bf92e2f46b87c 100644 --- a/core/modules/views/src/Tests/Plugin/StyleTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleTest.php @@ -1,9 +1,9 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php b/core/modules/views/tests/src/Functional/Plugin/ViewsBulkTest.php similarity index 90% rename from core/modules/views/src/Tests/Plugin/ViewsBulkTest.php rename to core/modules/views/tests/src/Functional/Plugin/ViewsBulkTest.php index 269f5b05b5cf90156bf07a54e29ad775653c224f..0ca6f8775e690679e09f91971b71d7550c738cfb 100644 --- a/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ViewsBulkTest.php @@ -1,15 +1,15 @@ drupalCreateContentType(['type' => 'page']); $this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']); diff --git a/core/modules/views/src/Tests/Plugin/ViewsFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ViewsFormTest.php similarity index 83% rename from core/modules/views/src/Tests/Plugin/ViewsFormTest.php rename to core/modules/views/tests/src/Functional/Plugin/ViewsFormTest.php index a73018931795de247e9cc1da3fca0d5beb118686..3f6e1eca5fd52b573a05d63c4ed36cabdd6f244d 100644 --- a/core/modules/views/src/Tests/Plugin/ViewsFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ViewsFormTest.php @@ -1,15 +1,15 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/RenderCacheWebTest.php b/core/modules/views/tests/src/Functional/RenderCacheWebTest.php similarity index 83% rename from core/modules/views/src/Tests/RenderCacheWebTest.php rename to core/modules/views/tests/src/Functional/RenderCacheWebTest.php index fcd38b73043113bc7db5620f787872e0e242c99f..f8dfdd810da26b8abd7532f6a0161b07cf75f0e6 100644 --- a/core/modules/views/src/Tests/RenderCacheWebTest.php +++ b/core/modules/views/tests/src/Functional/RenderCacheWebTest.php @@ -1,6 +1,6 @@ assertEqual([], $this->cssSelect('div.region-header div.views-field-title')); $this->drupalGet($this->nodes[0]->toUrl()); - $result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span; + $result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText(); $this->assertEqual('test title 1', $result); $this->drupalGet($this->nodes[1]->toUrl()); - $result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span; + $result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText(); $this->assertEqual('test title 2', $result); $this->drupalGet($this->nodes[0]->toUrl()); - $result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span; + $result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText(); $this->assertEqual('test title 1', $result); } diff --git a/core/modules/views/src/Tests/SearchIntegrationTest.php b/core/modules/views/tests/src/Functional/SearchIntegrationTest.php similarity index 89% rename from core/modules/views/src/Tests/SearchIntegrationTest.php rename to core/modules/views/tests/src/Functional/SearchIntegrationTest.php index 1b6ab8915961cbb056787891d38c8967bcd9a5a2..f4daac774eb2ed63eb3db2d5e1450577001705ba 100644 --- a/core/modules/views/src/Tests/SearchIntegrationTest.php +++ b/core/modules/views/tests/src/Functional/SearchIntegrationTest.php @@ -1,8 +1,9 @@ cronRun(); $this->drupalGet('test-arg/rocks'); $xpath = '//div[@class="views-row"]//a'; - /** @var \SimpleXMLElement[] $results */ + /** @var \Behat\Mink\Element\NodeElement[] $results */ $results = $this->xpath($xpath); - $this->assertEqual((string) $results[0], "Drupal's search rocks really rocks!"); - $this->assertEqual((string) $results[1], "Drupal's search rocks."); + $this->assertEqual($results[0]->getText(), "Drupal's search rocks really rocks!"); + $this->assertEqual($results[1]->getText(), "Drupal's search rocks."); $this->assertEscaped("Drupal's search rocks really rocks!"); // Test sorting with another set of titles. @@ -127,8 +130,8 @@ public function testSearchIntegration() { $xpath = '//div[@class="views-row"]//a'; /** @var \SimpleXMLElement[] $results */ $results = $this->xpath($xpath); - $this->assertEqual((string) $results[0], "Testing one one one"); - $this->assertEqual((string) $results[1], "Testing one two two two"); + $this->assertEqual($results[0]->getText(), "Testing one one one"); + $this->assertEqual($results[1]->getText(), "Testing one two two two"); } /** diff --git a/core/modules/views/src/Tests/SearchMultilingualTest.php b/core/modules/views/tests/src/Functional/SearchMultilingualTest.php similarity index 96% rename from core/modules/views/src/Tests/SearchMultilingualTest.php rename to core/modules/views/tests/src/Functional/SearchMultilingualTest.php index f53421917bc93af069ef8a67483eac8dd4673302..d6a72bf8cdfb1f8e1cc53f996ef53c554f404a72 100644 --- a/core/modules/views/src/Tests/SearchMultilingualTest.php +++ b/core/modules/views/tests/src/Functional/SearchMultilingualTest.php @@ -1,9 +1,10 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/ViewRenderTest.php b/core/modules/views/tests/src/Functional/ViewRenderTest.php similarity index 84% rename from core/modules/views/src/Tests/ViewRenderTest.php rename to core/modules/views/tests/src/Functional/ViewRenderTest.php index 0b3f0ee2577352f1434b29fca3f2b46f3cbacf78..aaf894cd23e0bb65e0924d2951a5c4df697e1662 100644 --- a/core/modules/views/src/Tests/ViewRenderTest.php +++ b/core/modules/views/tests/src/Functional/ViewRenderTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } diff --git a/core/modules/views/tests/src/Functional/ViewTestBase.php b/core/modules/views/tests/src/Functional/ViewTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..0465f966c314a9c48ca698abb0f15739a4dcec70 --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewTestBase.php @@ -0,0 +1,158 @@ +set('views_test_data_schema', $this->schemaDefinition()); + \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); + + \Drupal::service('module_installer')->install(['views_test_data']); + $this->resetAll(); + $this->rebuildContainer(); + $this->container->get('module_handler')->reload(); + + // Load the test dataset. + $data_set = $this->dataSet(); + $query = db_insert('views_test_data') + ->fields(array_keys($data_set[0])); + foreach ($data_set as $record) { + $query->values($record); + } + $query->execute(); + } + + /** + * Orders a nested array containing a result set based on a given column. + * + * @param array $result_set + * An array of rows from a result set, with each row as an associative + * array keyed by column name. + * @param string $column + * The column name by which to sort the result set. + * @param bool $reverse + * (optional) Boolean indicating whether to sort the result set in reverse + * order. Defaults to FALSE. + * + * @return array + * The sorted result set. + */ + protected function orderResultSet($result_set, $column, $reverse = FALSE) { + $order = $reverse ? -1 : 1; + usort($result_set, function ($a, $b) use ($column, $order) { + if ($a[$column] == $b[$column]) { + return 0; + } + return $order * (($a[$column] < $b[$column]) ? -1 : 1); + }); + return $result_set; + } + + /** + * Asserts the existence of a button with a certain ID and label. + * + * @param string $id + * The HTML ID of the button + * @param string $expected_label + * The expected label for the button. + * @param string $message + * (optional) A custom message to display with the assertion. If no custom + * message is provided, the message will indicate the button label. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + */ + protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { + $xpath = $this->assertSession()->buildXPathQuery('//button[@id=:value]|//input[@id=:value]', [':value' => $id]); + $field = $this->getSession()->getPage()->find('xpath', $xpath); + + if (empty($field)) { + throw new ElementNotFoundException($this->getSession()->getDriver(), 'form field', 'id', $field); + } + + $this->assertEquals($expected_label, $field->getValue()); + } + + /** + * Executes a view with debugging. + * + * @param \Drupal\views\ViewExecutable $view + * The view object. + * @param array $args + * (optional) An array of the view arguments to use for the view. + */ + protected function executeView(ViewExecutable $view, $args = []) { + // A view does not really work outside of a request scope, due to many + // dependencies like the current user. + $view->setDisplay(); + $view->preExecute($args); + $view->execute(); + $verbose_message = '
Executed view: ' . ((string) $view->build_info['query']) . '
'; + if ($view->build_info['query'] instanceof SelectInterface) { + $verbose_message .= '
Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '
'; + } + $this->verbose($verbose_message); + } + + /** + * Returns the schema definition. + */ + protected function schemaDefinition() { + return ViewTestData::schemaDefinition(); + } + + /** + * Returns the views data definition. + */ + protected function viewsData() { + return ViewTestData::viewsData(); + } + + /** + * Returns a very simple test dataset. + */ + protected function dataSet() { + return ViewTestData::dataSet(); + } + +} diff --git a/core/modules/views/src/Tests/ViewsEscapingTest.php b/core/modules/views/tests/src/Functional/ViewsEscapingTest.php similarity index 94% rename from core/modules/views/src/Tests/ViewsEscapingTest.php rename to core/modules/views/tests/src/Functional/ViewsEscapingTest.php index 1ec3a9f3d0e7f0233b610159bc2918a48960e081..80a83987222640c56c46263636c5d911b93949d7 100644 --- a/core/modules/views/src/Tests/ViewsEscapingTest.php +++ b/core/modules/views/tests/src/Functional/ViewsEscapingTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/ViewsFormMultipleTest.php b/core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php similarity index 81% rename from core/modules/views/src/Tests/ViewsFormMultipleTest.php rename to core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php index 844a1b10c96b86085d1472c47c3323ed1e39bde4..03d5bcee8ce5a439e28b85e06a7b226e84dbff7d 100644 --- a/core/modules/views/src/Tests/ViewsFormMultipleTest.php +++ b/core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } @@ -51,9 +51,9 @@ public function testViewsFormMultiple() { // Submit the forms, validate argument returned in message set by handler. // @note There is not a way to specify a specific index for a submit button. So // the row index returned is always the last occurrence. - $this->drupalPostForm(NULL, [], t('Test Button'), [], [], 'views-form-test-form-multiple-default-arg2'); + $this->getSession()->getPage()->pressButton('edit-field-form-button-test-4--2'); $this->assertText('The test button at row 4 for test_form_multiple (default) View with args: arg2 was submitted.'); - $this->drupalPostForm(NULL, [], t('Test Button'), [], [], 'views-form-test-form-multiple-default-arg1'); + $this->getSession()->getPage()->pressButton('edit-field-form-button-test-4'); $this->assertText('The test button at row 4 for test_form_multiple (default) View with args: arg1 was submitted.'); } diff --git a/core/modules/views/src/Tests/ViewsTemplateTest.php b/core/modules/views/tests/src/Functional/ViewsTemplateTest.php similarity index 88% rename from core/modules/views/src/Tests/ViewsTemplateTest.php rename to core/modules/views/tests/src/Functional/ViewsTemplateTest.php index 4a0690829609c82b5ec540960a7d31e2923e7428..8f7de4018483a4d9ba2a280c0b5126e40172c324 100644 --- a/core/modules/views/src/Tests/ViewsTemplateTest.php +++ b/core/modules/views/tests/src/Functional/ViewsTemplateTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); diff --git a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php b/core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php similarity index 95% rename from core/modules/views/src/Tests/ViewsThemeIntegrationTest.php rename to core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php index 1fe836a82ec0f902276a114ab1e0d4768d0fdc0f..9bdb405b86fdea5b5ee9afc64810a116bfd05657 100644 --- a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php +++ b/core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/Wizard/BasicTest.php b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php similarity index 94% rename from core/modules/views/src/Tests/Wizard/BasicTest.php rename to core/modules/views/tests/src/Functional/Wizard/BasicTest.php index 7394991d238b78cccc56ffa06cff1d56567fb936..eb2ddbbb677ea9ab14c39cc4e7770b51c11bbcb3 100644 --- a/core/modules/views/src/Tests/Wizard/BasicTest.php +++ b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php @@ -1,6 +1,6 @@ drupalPlaceBlock('page_title_block'); } @@ -80,7 +80,9 @@ public function testViewsWizardAndListing() { $elements = $this->cssSelect('link[href="' . Url::fromRoute('view.' . $view2['id'] . '.feed_1', [], ['absolute' => TRUE])->toString() . '"]'); $this->assertEqual(count($elements), 1, 'Feed found.'); $this->drupalGet($view2['page[feed_properties][path]']); - $this->assertTrue(!empty($this->cssSelect('rss[version="2.0"]'))); + // Because the response is XML we can't use the page which depends on an + // HTML tag being present. + $this->assertEquals('2.0', $this->getSession()->getDriver()->getAttribute('//rss', 'version')); // The feed should have the same title and nodes as the page. $this->assertText($view2['page[title]']); $this->assertRaw($node1->url('canonical', ['absolute' => TRUE])); @@ -134,7 +136,7 @@ public function testViewsWizardAndListing() { // Confirm that the block is available in the block administration UI. $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default')); - $this->clickLinkPartialName('Place block'); + $this->clickLink('Place block'); $this->assertText($view3['label']); // Place the block. @@ -164,7 +166,7 @@ public function testViewsWizardAndListing() { // Check that the REST export path works. $this->drupalGet($view4['rest_export[path]']); $this->assertResponse(200); - $data = Json::decode($this->content); + $data = Json::decode($this->getSession()->getPage()->getContent()); $this->assertEqual(count($data), 1, 'Only the node of type page is exported.'); $node = reset($data); $this->assertEqual($node['nid'][0]['value'], $node1->id(), 'The node of type page is exported.'); diff --git a/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php b/core/modules/views/tests/src/Functional/Wizard/ItemsPerPageTest.php similarity index 95% rename from core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php rename to core/modules/views/tests/src/Functional/Wizard/ItemsPerPageTest.php index 58f22a8424686aecfefda2f404b1d2b3a1ced020..c480ba94c74a2c3ddc2d0f2d73d375793fce4d28 100644 --- a/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php +++ b/core/modules/views/tests/src/Functional/Wizard/ItemsPerPageTest.php @@ -1,6 +1,6 @@ drupalPlaceBlock('page_title_block'); } @@ -72,7 +72,7 @@ public function testItemsPerPage() { // Confirm that the block is listed in the block administration UI. $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default')); - $this->clickLinkPartialName('Place block'); + $this->clickLink('Place block'); $this->assertText($view['label']); // Place the block, visit a page that displays the block, and check that the diff --git a/core/modules/views/src/Tests/Wizard/MenuTest.php b/core/modules/views/tests/src/Functional/Wizard/MenuTest.php similarity index 97% rename from core/modules/views/src/Tests/Wizard/MenuTest.php rename to core/modules/views/tests/src/Functional/Wizard/MenuTest.php index 0805de6168e5f68d5ccecf329af138451298bd96..853c0692d09ffb89343a86661f3433e49b2e8fa4 100644 --- a/core/modules/views/src/Tests/Wizard/MenuTest.php +++ b/core/modules/views/tests/src/Functional/Wizard/MenuTest.php @@ -1,6 +1,6 @@ drupalPlaceBlock('page_title_block'); } diff --git a/core/modules/views/src/Tests/Wizard/TaggedWithTest.php b/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php similarity index 98% rename from core/modules/views/src/Tests/Wizard/TaggedWithTest.php rename to core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php index f723950419890950ec2416ca1b88965596391a84..680d64496edc5b1cb93402ebd0bbbfad70cd441d 100644 --- a/core/modules/views/src/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php @@ -1,6 +1,6 @@ drupalCreateUser(['administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view all revisions']); + $this->drupalLogin($views_admin); + $this->drupalPlaceBlock('local_actions_block'); + } + +} diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0f209cac2ebd934304919c5604bba3f7770f9359 --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php @@ -0,0 +1,94 @@ +installEntitySchema('node'); + } + + /** + * {@inheritdoc} + */ + protected function viewsData() { + $data = parent::viewsData(); + $data['views']['test_example'] = [ + 'title' => 'Test Example area', + 'help' => 'A area handler which just exists for tests.', + 'area' => [ + 'id' => 'test_example' + ] + ]; + + return $data; + } + + /** + * Views used by this test. + * + * @var array + */ + public static $testViews = ['test_example_area']; + + /** + * Tests that the header and footer areas are not rendered if empty. + */ + public function testRenderEmptyHeaderFooter() { + $view = Views::getView('test_example_area'); + $view->initHandlers(); + + // Set example empty text. + $empty_text = $this->randomMachineName(); + $empty_header = $this->randomMachineName(); + $empty_footer = $this->randomMachineName(); + + // Set empty text. + $view->empty['test_example']->options['string'] = '

' . $empty_text . '

'; + // Set example header text. + $view->header['test_example']->options['string'] = '

' . $empty_header . '

'; + // Set example footer text. + $view->footer['test_example']->options['string'] = '

' . $empty_footer . '

'; + + // Verify that the empty header and footer sections have not been rendered. + $view->setDisplay('default'); + $this->executeView($view); + $output = $view->render(); + $output = \Drupal::service('renderer')->renderRoot($output); + $this->setRawContent($output); + $this->assertText($empty_text); + $this->assertNoText($empty_header); + $this->assertNoText($empty_footer); + + // Enable displaying the header and footer when the View is empty. + $view->header['test_example']->options['empty'] = TRUE; + $view->footer['test_example']->options['empty'] = TRUE; + + // Verify that the header and footer sections have been rendered. + $this->executeView($view); + $output = $view->render(); + $output = \Drupal::service('renderer')->renderRoot($output); + $this->setRawContent($output); + $this->assertText($empty_header); + $this->assertText($empty_footer); + } + +} diff --git a/core/modules/views/src/Tests/Plugin/DisplayExtenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php similarity index 88% rename from core/modules/views/src/Tests/Plugin/DisplayExtenderTest.php rename to core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php index 896b1348dd21d86e936be7fde0ae976ffc627b98..6f7154d10c1050825cf6b8f2292d0cd420684721 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayExtenderTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); - } - /** * Test display extenders. */ diff --git a/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php b/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php index 8aaaa2dd5d764639b3caeedf33251268754ba0e2..3232ecb815d3140176ffd0fe696d85f5d4e3b2ce 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Session\AnonymousUserSession; +use Drupal\views\Entity\View; use Drupal\views\Views; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Symfony\Component\HttpFoundation\Request; @@ -22,7 +23,7 @@ class DisplayPageTest extends ViewsKernelTestBase { * * @var array */ - public static $testViews = ['test_page_display', 'test_page_display_route', 'test_page_display_menu']; + public static $testViews = ['test_page_display', 'test_page_display_route', 'test_page_display_menu', 'test_display_more']; /** * Modules to enable. @@ -149,4 +150,71 @@ public function testDependencies() { $this->assertIdentical($expected, $view->getDependencies()); } + /** + * Tests the readmore functionality. + */ + public function testReadMore() { + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = $this->container->get('renderer'); + + $expected_more_text = 'custom more text'; + + $view = Views::getView('test_display_more'); + $this->executeView($view); + + $output = $view->preview(); + $output = $renderer->renderRoot($output); + + $this->setRawContent($output); + $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']); + $this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.'); + $this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.'); + + // Test the renderMoreLink method directly. This could be directly unit + // tested. + $more_link = $view->display_handler->renderMoreLink(); + $more_link = $renderer->renderRoot($more_link); + $this->setRawContent($more_link); + $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']); + $this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.'); + $this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.'); + + // Test the useMoreText method directly. This could be directly unit + // tested. + $more_text = $view->display_handler->useMoreText(); + $this->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.'); + + $view = Views::getView('test_display_more'); + $view->setDisplay(); + $view->display_handler->setOption('use_more', 0); + $this->executeView($view); + $output = $view->preview(); + $output = $renderer->renderRoot($output); + $this->setRawContent($output); + $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']); + $this->assertTrue(empty($result), 'The more link is not shown.'); + + $view = Views::getView('test_display_more'); + $view->setDisplay(); + $view->display_handler->setOption('use_more', 0); + $view->display_handler->setOption('use_more_always', 0); + $view->display_handler->setOption('pager', [ + 'type' => 'some', + 'options' => [ + 'items_per_page' => 1, + 'offset' => 0, + ], + ]); + $this->executeView($view); + $output = $view->preview(); + $output = $renderer->renderRoot($output); + $this->setRawContent($output); + $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']); + $this->assertTrue(empty($result), 'The more link is not shown when view has more records.'); + + // Test the default value of use_more_always. + $view = View::create()->getExecutable(); + $this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.'); + } + } diff --git a/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6767fffe3caa6d56a3f5e2cd0fe8759138893280 --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php @@ -0,0 +1,55 @@ +installEntitySchema('node'); + } + + /** + * Tests the exposed form markup. + */ + public function testExposedFormRender() { + $view = Views::getView('test_exposed_form_buttons'); + $this->executeView($view); + $exposed_form = $view->display_handler->getPlugin('exposed_form'); + $output = $exposed_form->renderExposedForm(); + $this->setRawContent(\Drupal::service('renderer')->renderRoot($output)); + + $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.'); + + $view->setDisplay('page_1'); + $expected_action = $view->display_handler->getUrlInfo()->toString(); + $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.'); + // Make sure the description is shown. + $result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]); + $this->assertEqual(count($result), 1, 'Filter description was found.'); + } + +}