View source
<?php
namespace Drupal\Tests\views\Functional;
use Drupal\views\Views;
class ViewElementTest extends ViewTestBase {
public static $testViews = [
'test_view_embed',
];
protected $defaultTheme = 'classy';
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->enableViewsTestModule();
}
public function testViewElement() {
$view = Views::getView('test_view_embed');
$view
->setDisplay();
$this
->drupalGet('views_test_data_element_form');
$xpath = $this
->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
$this
->assertNotEmpty($xpath, 'The view container has been found on the form.');
$xpath = $this
->xpath('//div[@class="view-content"]');
$this
->assertNotEmpty($xpath, 'The view content has been found on the form.');
$xpath = $this
->xpath('//div[@class="view-content"]/div');
$this
->assertCount(5, $xpath);
$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();
$this
->drupalGet('views_test_data_element_form');
$xpath = $this
->xpath('//div[@class="view-content"]/div');
$this
->assertCount(1, $xpath);
}
public function testViewElementEmbed() {
$view = Views::getView('test_view_embed');
$view
->setDisplay();
$this
->drupalGet('views_test_data_element_embed_form');
$xpath = $this
->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
$this
->assertNotEmpty($xpath, 'The view container has been found on the form.');
$xpath = $this
->xpath('//div[@class="view-content"]');
$this
->assertNotEmpty($xpath, 'The view content has been found on the form.');
$xpath = $this
->xpath('//div[@class="view-content"]/div');
$this
->assertCount(5, $xpath);
$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();
$this
->drupalGet('views_test_data_element_embed_form');
$xpath = $this
->xpath('//div[@class="view-content"]/div');
$this
->assertCount(1, $xpath);
}
}