diff --git a/core/modules/views/src/Tests/Handler/HandlerTestBase.php b/core/modules/views/src/Tests/Handler/HandlerTestBase.php index 5345f47..1603329 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 698a43e..19aa191 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 89f71ed..a46e54c 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 f099569..993293c 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 82c6839..911cd61 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 2656adc..dc914ce 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(); } @@ -111,41 +112,6 @@ public function testRenderArea() { } /** - * 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. - $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. */ public function testAreaAccess() { 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 afae1eb..9e1fcfa 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 0682892..17ece94 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 7efd1d7..653ce11 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 2521e63..d38ba41 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 646cb12..275960c 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 31de7be..318be3f 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 f81e753..ec3b523 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 5654376..1a37ce8 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 7a4eb1a..41aa6ec 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 a4e8217..b3956de 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 72d94f3..1d78204 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 7786606..40bf601 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 7fb7058..567e1c9 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 cb43946..708ac55 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 16c0680..8c326ba 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 ac7209c..a081ad7 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 b5c853f..3d2aca6 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('' . $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 896b134..6f7154d 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 8aaaa2d..3232ecb 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 0000000..6767fff --- /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.'); + } + +}