From 96c7b31a4ce7592da4ba865c3984d652a28005aa Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 22 May 2017 12:36:33 +0100 Subject: [PATCH] Issue #2876210 by Lendude, michielnugter: Convert \Drupal\views\Tests\ViewElementTest and \Drupal\views\Tests\Plugin\StyleGridTest to kernel tests --- .../Functional/Plugin/StyleSummaryTest.php | 3 + .../tests/src/Functional/ViewElementTest.php | 119 ++++++++++++++++++ .../src/Kernel}/Plugin/StyleGridTest.php | 18 +-- .../src/Kernel}/ViewElementTest.php | 60 ++------- 4 files changed, 134 insertions(+), 66 deletions(-) create mode 100644 core/modules/views/tests/src/Functional/ViewElementTest.php rename core/modules/views/{src/Tests => tests/src/Kernel}/Plugin/StyleGridTest.php (90%) rename core/modules/views/{src/Tests => tests/src/Kernel}/ViewElementTest.php (62%) diff --git a/core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php b/core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php index 252a3091cae..a2359b97344 100644 --- a/core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleSummaryTest.php @@ -54,6 +54,9 @@ class StyleSummaryTest extends ViewTestBase { public function testSummaryView() { $this->drupalGet('test-summary'); + // Ensure styles are properly added for summary views. + $this->assertRaw('stable/css/views/views.module.css'); + $summary_list = $this->cssSelect('ul.views-summary li'); $this->assertEqual(4, count($summary_list)); diff --git a/core/modules/views/tests/src/Functional/ViewElementTest.php b/core/modules/views/tests/src/Functional/ViewElementTest.php new file mode 100644 index 00000000000..2dbc54f6b50 --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewElementTest.php @@ -0,0 +1,119 @@ +enableViewsTestModule(); + } + + /** + * Tests the rendered output and form output of a view element. + */ + public function testViewElement() { + $view = Views::getView('test_view_embed'); + $view->setDisplay(); + // Test a form. + $this->drupalGet('views_test_data_element_form'); + + $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); + $this->assertTrue($xpath, 'The view container has been found on the form.'); + + $xpath = $this->xpath('//div[@class="view-content"]'); + $this->assertTrue($xpath, 'The view content has been found on the form.'); + // There should be 5 rows in the results. + $xpath = $this->xpath('//div[@class="view-content"]/div'); + $this->assertEqual(count($xpath), 5); + + // Add an argument and save the view. + $view->displayHandlers->get('default')->overrideOption('arguments', [ + 'age' => [ + 'default_action' => 'ignore', + 'title' => '', + 'default_argument_type' => 'fixed', + 'validate' => [ + 'type' => 'none', + 'fail' => 'not found', + ], + 'break_phrase' => FALSE, + 'not' => FALSE, + 'id' => 'age', + 'table' => 'views_test_data', + 'field' => 'age', + 'plugin_id' => 'numeric', + ], + ]); + $view->save(); + + // Test that the form has the expected result. + $this->drupalGet('views_test_data_element_form'); + $xpath = $this->xpath('//div[@class="view-content"]/div'); + $this->assertEqual(count($xpath), 1); + } + + /** + * Tests the rendered output and form output of a view element, using the + * embed display plugin. + */ + public function testViewElementEmbed() { + $view = Views::getView('test_view_embed'); + $view->setDisplay(); + // Test a form. + $this->drupalGet('views_test_data_element_embed_form'); + + $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); + $this->assertTrue($xpath, 'The view container has been found on the form.'); + + $xpath = $this->xpath('//div[@class="view-content"]'); + $this->assertTrue($xpath, 'The view content has been found on the form.'); + // There should be 5 rows in the results. + $xpath = $this->xpath('//div[@class="view-content"]/div'); + $this->assertEqual(count($xpath), 5); + + // Add an argument and save the view. + $view->displayHandlers->get('default')->overrideOption('arguments', [ + 'age' => [ + 'default_action' => 'ignore', + 'title' => '', + 'default_argument_type' => 'fixed', + 'validate' => [ + 'type' => 'none', + 'fail' => 'not found', + ], + 'break_phrase' => FALSE, + 'not' => FALSE, + 'id' => 'age', + 'table' => 'views_test_data', + 'field' => 'age', + 'plugin_id' => 'numeric', + ], + ]); + $view->save(); + + // Test that the form has the same expected result. + $this->drupalGet('views_test_data_element_embed_form'); + $xpath = $this->xpath('//div[@class="view-content"]/div'); + $this->assertEqual(count($xpath), 1); + } + +} diff --git a/core/modules/views/src/Tests/Plugin/StyleGridTest.php b/core/modules/views/tests/src/Kernel/Plugin/StyleGridTest.php similarity index 90% rename from core/modules/views/src/Tests/Plugin/StyleGridTest.php rename to core/modules/views/tests/src/Kernel/Plugin/StyleGridTest.php index 3b8989cbdb0..1495399eeb3 100644 --- a/core/modules/views/src/Tests/Plugin/StyleGridTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/StyleGridTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); - } - /** * Tests the grid style. */ @@ -45,10 +39,6 @@ class StyleGridTest extends PluginTestBase { $this->assertGrid($view, $alignment, 2); $this->assertGrid($view, $alignment, 1); } - - // Ensure styles are properly added for grid views. - $this->drupalGet('test-grid'); - $this->assertRaw('stable/css/views/views.module.css'); } /** diff --git a/core/modules/views/src/Tests/ViewElementTest.php b/core/modules/views/tests/src/Kernel/ViewElementTest.php similarity index 62% rename from core/modules/views/src/Tests/ViewElementTest.php rename to core/modules/views/tests/src/Kernel/ViewElementTest.php index ff11dc2c765..c6149e90e93 100644 --- a/core/modules/views/src/Tests/ViewElementTest.php +++ b/core/modules/views/tests/src/Kernel/ViewElementTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); - } - /** * Tests the rendered output and form output of a view element. */ @@ -41,22 +35,8 @@ class ViewElementTest extends ViewTestBase { $xpath = $this->xpath('//div[@class="views-element-container"]'); $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found in the rendered output.'); // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Test a form. - $this->drupalGet('views_test_data_element_form'); - - $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); - $this->assertTrue($xpath, 'The view container has been found on the form.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found on the form.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); + $xpath = $this->xpath('//div[@class="views-row"]'); $this->assertEqual(count($xpath), 5); // Add an argument and save the view. @@ -75,7 +55,7 @@ class ViewElementTest extends ViewTestBase { 'table' => 'views_test_data', 'field' => 'age', 'plugin_id' => 'numeric', - ] + ], ]); $view->save(); @@ -84,12 +64,7 @@ class ViewElementTest extends ViewTestBase { $render = $view->buildRenderable(NULL, [25]); $this->setRawContent($renderer->renderRoot($render)); // There should be 1 row in the results, 'John' arg 25. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - - // Test that the form has the same expected result. - $this->drupalGet('views_test_data_element_form'); - $xpath = $this->xpath('//div[@class="view-content"]/div'); + $xpath = $this->xpath('//div[@class="views-row"]'); $this->assertEqual(count($xpath), 1); } @@ -110,22 +85,8 @@ class ViewElementTest extends ViewTestBase { $xpath = $this->xpath('//div[@class="views-element-container"]'); $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found in the rendered output.'); // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Test a form. - $this->drupalGet('views_test_data_element_embed_form'); - - $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); - $this->assertTrue($xpath, 'The view container has been found on the form.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found on the form.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); + $xpath = $this->xpath('//div[@class="views-row"]'); $this->assertEqual(count($xpath), 5); // Add an argument and save the view. @@ -144,7 +105,7 @@ class ViewElementTest extends ViewTestBase { 'table' => 'views_test_data', 'field' => 'age', 'plugin_id' => 'numeric', - ] + ], ]); $view->save(); @@ -153,12 +114,7 @@ class ViewElementTest extends ViewTestBase { $render = $view->buildRenderable('embed_1', [25]); $this->setRawContent($renderer->renderRoot($render)); // There should be 1 row in the results, 'John' arg 25. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - - // Test that the form has the same expected result. - $this->drupalGet('views_test_data_element_embed_form'); - $xpath = $this->xpath('//div[@class="view-content"]/div'); + $xpath = $this->xpath('//div[@class="views-row"]'); $this->assertEqual(count($xpath), 1); // Tests the render array with an exposed filter.