3 namespace Drupal\Tests\views\Functional;
5 use Drupal\views\Views;
8 * Tests the view render element.
12 class ViewElementTest extends ViewTestBase {
15 * Views used by this test.
19 public static $testViews = ['test_view_embed'];
24 protected function setUp($import_test_views = TRUE) {
25 parent::setUp($import_test_views);
27 $this->enableViewsTestModule();
31 * Tests the rendered output and form output of a view element.
33 public function testViewElement() {
34 $view = Views::getView('test_view_embed');
37 $this->drupalGet('views_test_data_element_form');
39 $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
40 $this->assertTrue($xpath, 'The view container has been found on the form.');
42 $xpath = $this->xpath('//div[@class="view-content"]');
43 $this->assertTrue($xpath, 'The view content has been found on the form.');
44 // There should be 5 rows in the results.
45 $xpath = $this->xpath('//div[@class="view-content"]/div');
46 $this->assertEqual(count($xpath), 5);
48 // Add an argument and save the view.
49 $view->displayHandlers->get('default')->overrideOption('arguments', [
51 'default_action' => 'ignore',
53 'default_argument_type' => 'fixed',
56 'fail' => 'not found',
58 'break_phrase' => FALSE,
61 'table' => 'views_test_data',
63 'plugin_id' => 'numeric',
68 // Test that the form has the expected result.
69 $this->drupalGet('views_test_data_element_form');
70 $xpath = $this->xpath('//div[@class="view-content"]/div');
71 $this->assertEqual(count($xpath), 1);
75 * Tests the rendered output and form output of a view element, using the
76 * embed display plugin.
78 public function testViewElementEmbed() {
79 $view = Views::getView('test_view_embed');
82 $this->drupalGet('views_test_data_element_embed_form');
84 $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
85 $this->assertTrue($xpath, 'The view container has been found on the form.');
87 $xpath = $this->xpath('//div[@class="view-content"]');
88 $this->assertTrue($xpath, 'The view content has been found on the form.');
89 // There should be 5 rows in the results.
90 $xpath = $this->xpath('//div[@class="view-content"]/div');
91 $this->assertEqual(count($xpath), 5);
93 // Add an argument and save the view.
94 $view->displayHandlers->get('default')->overrideOption('arguments', [
96 'default_action' => 'ignore',
98 'default_argument_type' => 'fixed',
101 'fail' => 'not found',
103 'break_phrase' => FALSE,
106 'table' => 'views_test_data',
108 'plugin_id' => 'numeric',
113 // Test that the form has the same expected result.
114 $this->drupalGet('views_test_data_element_embed_form');
115 $xpath = $this->xpath('//div[@class="view-content"]/div');
116 $this->assertEqual(count($xpath), 1);