Issue #2876210 by Lendude, michielnugter: Convert \Drupal\views\Tests\ViewElementTest and \Drupal\views\Tests\Plugin\StyleGridTest to kernel tests

8.4.x
Alex Pott 2017-05-22 12:36:33 +01:00
parent 84233bab05
commit 96c7b31a4c
4 changed files with 134 additions and 66 deletions

View File

@ -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));

View File

@ -0,0 +1,119 @@
<?php
namespace Drupal\Tests\views\Functional;
use Drupal\views\Views;
/**
* Tests the view render element.
*
* @group views
*/
class ViewElementTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_view_embed'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->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);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\views\Tests\Plugin;
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
@ -11,7 +11,7 @@ use Drupal\views\ViewExecutable;
* @group views
* @see \Drupal\views\Plugin\views\style\Grid
*/
class StyleGridTest extends PluginTestBase {
class StyleGridTest extends PluginKernelTestBase {
/**
* Views used by this test.
@ -22,17 +22,11 @@ class StyleGridTest extends PluginTestBase {
/**
* Keeps track of which alignments have been tested.
*
* @var array
*/
protected $alignmentsTested = [];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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');
}
/**

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\views\Tests;
namespace Drupal\Tests\views\Kernel;
use Drupal\views\Views;
@ -9,7 +9,7 @@ use Drupal\views\Views;
*
* @group views
*/
class ViewElementTest extends ViewTestBase {
class ViewElementTest extends ViewsKernelTestBase {
/**
* Views used by this test.
@ -18,12 +18,6 @@ class ViewElementTest extends ViewTestBase {
*/
public static $testViews = ['test_view_embed'];
protected function setUp() {
parent::setUp();
$this->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.