diff --git a/core/modules/views/src/Tests/Handler/HandlerTestBase.php b/core/modules/views/src/Tests/Handler/HandlerTestBase.php index 5345f47..c2afcbc 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTestBase.php +++ b/core/modules/views/src/Tests/Handler/HandlerTestBase.php @@ -1,11 +1,13 @@ 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')); + } + } diff --git a/core/modules/views/src/Tests/Wizard/WizardTestBase.php b/core/modules/views/src/Tests/Wizard/WizardTestBase.php index 835b9f4..f5f7cc0 100644 --- a/core/modules/views/src/Tests/Wizard/WizardTestBase.php +++ b/core/modules/views/src/Tests/Wizard/WizardTestBase.php @@ -1,11 +1,15 @@ ['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 95% rename from core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php rename to core/modules/views/tests/src/Functional/Handler/AreaHTTPStatusCodeTest.php index 2656adc..0e1cca9 100644 --- a/core/modules/views/src/Tests/Handler/AreaHTTPStatusCodeTest.php +++ b/core/modules/views/tests/src/Functional/Handler/AreaHTTPStatusCodeTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } @@ -111,41 +111,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 90% rename from core/modules/views/src/Tests/Handler/AreaTitleWebTest.php rename to core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php index afae1eb..db53771 100644 --- a/core/modules/views/src/Tests/Handler/AreaTitleWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/AreaTitleWebTest.php @@ -1,9 +1,8 @@ enableViewsTestModule(); } diff --git a/core/modules/views/src/Tests/Handler/ArgumentStringTest.php b/core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php similarity index 96% rename from core/modules/views/src/Tests/Handler/ArgumentStringTest.php rename to core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php index 0682892..659e527 100644 --- a/core/modules/views/src/Tests/Handler/ArgumentStringTest.php +++ b/core/modules/views/tests/src/Functional/Handler/ArgumentStringTest.php @@ -1,6 +1,6 @@ drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']); $this->drupalLogin($admin_user); @@ -48,7 +48,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 94% rename from core/modules/views/src/Tests/Handler/FieldEntityOperationsTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php index 7efd1d7..a0b8827 100644 --- a/core/modules/views/src/Tests/Handler/FieldEntityOperationsTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php @@ -1,6 +1,6 @@ drupalCreateContentType(['type' => 'article', 'name' => 'Article']); @@ -72,7 +72,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 95% rename from core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php rename to core/modules/views/tests/src/Functional/Handler/FieldGroupRowsTest.php index 2521e63..fb9e405 100644 --- a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsTest.php @@ -1,6 +1,6 @@ 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..08f701d 100644 --- a/core/modules/views/src/Tests/Handler/FieldGroupRowsWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldGroupRowsWebTest.php @@ -1,18 +1,17 @@ nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); @@ -98,7 +97,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 +110,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..ceb73c4 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 +99,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 90% rename from core/modules/views/src/Tests/Handler/FilterDateTest.php rename to core/modules/views/tests/src/Functional/Handler/FilterDateTest.php index f81e753..5ad85cc 100644 --- a/core/modules/views/src/Tests/Handler/FilterDateTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php @@ -1,6 +1,6 @@ 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 +221,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, [], t('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'], t('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'], t('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'], t('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 +255,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')], t('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 98% rename from core/modules/views/src/Tests/Handler/HandlerAllTest.php rename to core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php index 5654376..77f5754 100644 --- a/core/modules/views/src/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php @@ -1,6 +1,6 @@ drupalCreateContentType(['type' => 'page']); $this->addDefaultCommentField('node', 'page'); $this->enableViewsTestModule(); @@ -260,13 +259,13 @@ public function testRelationshipUI() { $this->assertFieldByName($relationship_name); // Check for available options. - $xpath = $this->constructFieldXpath('name', $relationship_name); + $xpath = $this->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $relationship_name]); $fields = $this->xpath($xpath); $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/tests/src/Functional/Handler/HandlerTestBase.php b/core/modules/views/tests/src/Functional/Handler/HandlerTestBase.php new file mode 100644 index 0000000..e4a7736 --- /dev/null +++ b/core/modules/views/tests/src/Functional/Handler/HandlerTestBase.php @@ -0,0 +1,12 @@ +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 1b6ab89..f4daac7 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 f534219..d6a72bf 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/tests/src/Functional/ViewRenderTest.php b/core/modules/views/tests/src/Functional/ViewRenderTest.php new file mode 100644 index 0000000..aaf894c --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewRenderTest.php @@ -0,0 +1,42 @@ +enableViewsTestModule(); + } + + + /** + * Tests render functionality. + */ + public function testRender() { + \Drupal::state()->set('views_render.test', 0); + + // Make sure that the rendering just calls the preprocess function once. + $view = Views::getView('test_view_render'); + $output = $view->preview(); + $this->container->get('renderer')->renderRoot($output); + + $this->assertEqual(\Drupal::state()->get('views_render.test'), 1); + } + +} 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 0000000..15437fc --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewTestBase.php @@ -0,0 +1,151 @@ +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 $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. + * + * @return bool + * TRUE if the assertion was successful, or FALSE on failure. + */ + protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { + return $this->assertFieldById($id, $expected_label, t($message, ['%label' => $expected_label])); + } + + /** + * 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/tests/src/Functional/ViewsEscapingTest.php b/core/modules/views/tests/src/Functional/ViewsEscapingTest.php new file mode 100644 index 0000000..80a8398 --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewsEscapingTest.php @@ -0,0 +1,84 @@ +enableViewsTestModule(); + } + + /** + * Tests for incorrectly escaped markup in the views-view-fields.html.twig. + */ + public function testViewsViewFieldsEscaping() { + // Test with system theme using theme function. + $this->drupalGet('test_page_display_200'); + + // Assert that there are no escaped '<'s characters. + $this->assertNoEscaped('<'); + + // Install theme to test with template system. + \Drupal::service('theme_handler')->install(['views_test_theme']); + + // Make base theme default then test for hook invocations. + $this->config('system.theme') + ->set('default', 'views_test_theme') + ->save(); + $this->assertEqual($this->config('system.theme')->get('default'), 'views_test_theme'); + + $this->drupalGet('test_page_display_200'); + + // Assert that we are using the correct template. + $this->assertText('force', 'The force is strong with this one'); + + // Assert that there are no escaped '<'s characters. + $this->assertNoEscaped('<'); + } + + /** + * Tests for incorrectly escaped markup in a header label on a display table. + */ + public function testViewsFieldHeaderEscaping() { + // Test with a field header label having an html element wrapper. + $this->drupalGet('test_field_header'); + + // Assert that there are no escaped '<'s characters. + $this->assertNoEscaped('<'); + + // Test with a field header label having a XSS test as a wrapper. + $this->drupalGet('test_field_header_xss'); + + // Assert that XSS test is escaped. + $this->assertNoRaw('', 'Harmful tags are escaped in header label.'); + } + +} diff --git a/core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php b/core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php new file mode 100644 index 0000000..03d5bce --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewsFormMultipleTest.php @@ -0,0 +1,60 @@ +enableViewsTestModule(); + } + + /** + * {@inheritdoc} + */ + protected function viewsData() { + $data = parent::viewsData(); + $data['views_test_data']['field_form_button_test']['field'] = [ + 'title' => t('Button test'), + 'help' => t('Adds a test form button.'), + 'id' => 'field_form_button_test', + ]; + return $data; + } + + + /** + * Tests the a page with multiple View forms in it. + */ + public function testViewsFormMultiple() { + // Get the test page. + $this->drupalGet('views_test_form_multiple'); + + $this->assertText('Test base form ID with Views forms and arguments.'); + + // 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->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->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/tests/src/Functional/ViewsTemplateTest.php b/core/modules/views/tests/src/Functional/ViewsTemplateTest.php new file mode 100644 index 0000000..2282cee --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewsTemplateTest.php @@ -0,0 +1,46 @@ +enableViewsTestModule(); + ViewTestData::createTestViews(get_class($this), ['views_test_config']); + } + + /** + * Tests render functionality. + */ + public function testTemplate() { + + // Make sure that the rendering just calls the preprocess function once. + $view = Views::getView('test_view_display_template'); + $output = $view->preview(); + + // Check if we got the rendered output of our template file. + $this->assertTrue(strpos(\Drupal::service('renderer')->renderRoot($output), 'This module defines its own display template.') !== FALSE, 'Display plugin DisplayTemplateTest defines its own template.'); + + } + +} diff --git a/core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php b/core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php new file mode 100644 index 0000000..9bdb405 --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php @@ -0,0 +1,81 @@ +enableViewsTestModule(); + } + + /** + * Tests for exceptions and successful execution of hook_views_pre_render() + * and hook_views_post_render() in theme and subtheme. + */ + public function testThemedViewPage() { + + \Drupal::service('theme_handler')->install(['test_basetheme', 'test_subtheme']); + + // Make base theme default then test for hook invocations. + $this->config('system.theme') + ->set('default', 'test_basetheme') + ->save(); + $this->assertEqual($this->config('system.theme')->get('default'), 'test_basetheme'); + + // Make sure a views rendered page is touched. + $this->drupalGet('test_page_display_200'); + + $this->assertRaw("test_basetheme_views_pre_render", "Views title changed by test_basetheme.test_basetheme_views_pre_render"); + $this->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render"); + + // Make sub theme default to test for hook invocation + // from both sub and base theme. + $this->config('system.theme') + ->set('default', 'test_subtheme') + ->save(); + $this->assertEqual($this->config('system.theme')->get('default'), 'test_subtheme'); + + // Make sure a views rendered page is touched. + $this->drupalGet('test_page_display_200'); + + $this->assertRaw("test_subtheme_views_pre_render", "Views title changed by test_subtheme.test_subtheme_views_pre_render"); + $this->assertRaw("test_subtheme_views_post_render", "Views title changed by test_subtheme.test_subtheme_views_post_render"); + + $this->assertRaw("test_basetheme_views_pre_render", "Views title changed by test_basetheme.test_basetheme_views_pre_render"); + $this->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render"); + + $this->assertRaw('' . count($this->dataSet()) . ' items found.', 'Views group title added by test_subtheme.test_subtheme_views_post_render'); + } + +} diff --git a/core/modules/views/src/Tests/Wizard/BasicTest.php b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php similarity index 96% rename from core/modules/views/src/Tests/Wizard/BasicTest.php rename to core/modules/views/tests/src/Functional/Wizard/BasicTest.php index 7394991..27dc2c7 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,7 @@ 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"]'))); + $this->assertEmpty($this->cssSelect('rss[version="2.0"]')); // 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 +134,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 +164,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 58f22a8..c480ba9 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 0805de6..853c069 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 f723950..680d644 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 0000000..349be13 --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php @@ -0,0 +1,65 @@ +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. + $view->setDisplay('default'); + $this->executeView($view); + $output = $view->render(); + $output = \Drupal::service('renderer')->renderRoot($output); + $this->setRawContent($output); + $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. + $this->executeView($view); + $output = $view->render(); + $output = \Drupal::service('renderer')->renderRoot($output); + $this->setRawContent($output); + $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-header']))); + $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-footer']))); + } + +}