class ViewElementTest
Same name in this branch
- 9 core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest
- 11.x core/modules/views/tests/src/Functional/ViewElementTest.php \Drupal\Tests\views\Functional\ViewElementTest
- 10 core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest
- 10 core/modules/views/tests/src/Functional/ViewElementTest.php \Drupal\Tests\views\Functional\ViewElementTest
Tests the view render element.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\Functional\ViewElementTest implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ViewElementTest
File
-
core/
modules/ views/ tests/ src/ Functional/ ViewElementTest.php, line 12
Namespace
Drupal\Tests\views\FunctionalView source
class ViewElementTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_view_embed',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$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');
// Verify that the view container has been found on the form.
$this->assertSession()
->elementExists('xpath', '//div[@class="views-element-container js-form-wrapper form-wrapper"]');
// Verify that the view content has been found on the form.
$this->assertSession()
->elementExists('xpath', '//div[@class="view-content"]');
// There should be 5 rows in the results.
$this->assertSession()
->elementsCount('xpath', '//div[@class="view-content"]/div', 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');
$this->assertSession()
->elementsCount('xpath', '//div[@class="view-content"]/div', 1);
}
/**
* Tests the rendered output and form output of 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');
// Verify that the view container has been found on the form.
$this->assertSession()
->elementExists('xpath', '//div[@class="views-element-container js-form-wrapper form-wrapper"]');
// Verify that the view content has been found on the form.
$this->assertSession()
->elementExists('xpath', '//div[@class="view-content"]');
// There should be 5 rows in the results.
$this->assertSession()
->elementsCount('xpath', '//div[@class="view-content"]/div', 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');
$this->assertSession()
->elementsCount('xpath', '//div[@class="view-content"]/div', 1);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.