Pull merge.
[yaffs-website] / web / core / modules / views / tests / src / Functional / ViewElementTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional;
4
5 use Drupal\views\Views;
6
7 /**
8  * Tests the view render element.
9  *
10  * @group views
11  */
12 class ViewElementTest extends ViewTestBase {
13
14   /**
15    * Views used by this test.
16    *
17    * @var array
18    */
19   public static $testViews = ['test_view_embed'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp($import_test_views = TRUE) {
25     parent::setUp($import_test_views);
26
27     $this->enableViewsTestModule();
28   }
29
30   /**
31    * Tests the rendered output and form output of a view element.
32    */
33   public function testViewElement() {
34     $view = Views::getView('test_view_embed');
35     $view->setDisplay();
36     // Test a form.
37     $this->drupalGet('views_test_data_element_form');
38
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.');
41
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);
47
48     // Add an argument and save the view.
49     $view->displayHandlers->get('default')->overrideOption('arguments', [
50       'age' => [
51         'default_action' => 'ignore',
52         'title' => '',
53         'default_argument_type' => 'fixed',
54         'validate' => [
55           'type' => 'none',
56           'fail' => 'not found',
57         ],
58         'break_phrase' => FALSE,
59         'not' => FALSE,
60         'id' => 'age',
61         'table' => 'views_test_data',
62         'field' => 'age',
63         'plugin_id' => 'numeric',
64       ],
65     ]);
66     $view->save();
67
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);
72   }
73
74   /**
75    * Tests the rendered output and form output of a view element, using the
76    * embed display plugin.
77    */
78   public function testViewElementEmbed() {
79     $view = Views::getView('test_view_embed');
80     $view->setDisplay();
81     // Test a form.
82     $this->drupalGet('views_test_data_element_embed_form');
83
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.');
86
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);
92
93     // Add an argument and save the view.
94     $view->displayHandlers->get('default')->overrideOption('arguments', [
95       'age' => [
96         'default_action' => 'ignore',
97         'title' => '',
98         'default_argument_type' => 'fixed',
99         'validate' => [
100           'type' => 'none',
101           'fail' => 'not found',
102         ],
103         'break_phrase' => FALSE,
104         'not' => FALSE,
105         'id' => 'age',
106         'table' => 'views_test_data',
107         'field' => 'age',
108         'plugin_id' => 'numeric',
109       ],
110     ]);
111     $view->save();
112
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);
117   }
118
119 }