Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\views\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\views\Views;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the view render element.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group views
|
Chris@0
|
11 */
|
Chris@0
|
12 class ViewElementTest extends ViewTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Views used by this test.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $testViews = ['test_view_embed'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * {@inheritdoc}
|
Chris@0
|
23 */
|
Chris@0
|
24 protected function setUp($import_test_views = TRUE) {
|
Chris@0
|
25 parent::setUp($import_test_views);
|
Chris@0
|
26
|
Chris@0
|
27 $this->enableViewsTestModule();
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * Tests the rendered output and form output of a view element.
|
Chris@0
|
32 */
|
Chris@0
|
33 public function testViewElement() {
|
Chris@0
|
34 $view = Views::getView('test_view_embed');
|
Chris@0
|
35 $view->setDisplay();
|
Chris@0
|
36 // Test a form.
|
Chris@0
|
37 $this->drupalGet('views_test_data_element_form');
|
Chris@0
|
38
|
Chris@0
|
39 $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
|
Chris@0
|
40 $this->assertTrue($xpath, 'The view container has been found on the form.');
|
Chris@0
|
41
|
Chris@0
|
42 $xpath = $this->xpath('//div[@class="view-content"]');
|
Chris@0
|
43 $this->assertTrue($xpath, 'The view content has been found on the form.');
|
Chris@0
|
44 // There should be 5 rows in the results.
|
Chris@0
|
45 $xpath = $this->xpath('//div[@class="view-content"]/div');
|
Chris@0
|
46 $this->assertEqual(count($xpath), 5);
|
Chris@0
|
47
|
Chris@0
|
48 // Add an argument and save the view.
|
Chris@0
|
49 $view->displayHandlers->get('default')->overrideOption('arguments', [
|
Chris@0
|
50 'age' => [
|
Chris@0
|
51 'default_action' => 'ignore',
|
Chris@0
|
52 'title' => '',
|
Chris@0
|
53 'default_argument_type' => 'fixed',
|
Chris@0
|
54 'validate' => [
|
Chris@0
|
55 'type' => 'none',
|
Chris@0
|
56 'fail' => 'not found',
|
Chris@0
|
57 ],
|
Chris@0
|
58 'break_phrase' => FALSE,
|
Chris@0
|
59 'not' => FALSE,
|
Chris@0
|
60 'id' => 'age',
|
Chris@0
|
61 'table' => 'views_test_data',
|
Chris@0
|
62 'field' => 'age',
|
Chris@0
|
63 'plugin_id' => 'numeric',
|
Chris@0
|
64 ],
|
Chris@0
|
65 ]);
|
Chris@0
|
66 $view->save();
|
Chris@0
|
67
|
Chris@0
|
68 // Test that the form has the expected result.
|
Chris@0
|
69 $this->drupalGet('views_test_data_element_form');
|
Chris@0
|
70 $xpath = $this->xpath('//div[@class="view-content"]/div');
|
Chris@0
|
71 $this->assertEqual(count($xpath), 1);
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * Tests the rendered output and form output of a view element, using the
|
Chris@0
|
76 * embed display plugin.
|
Chris@0
|
77 */
|
Chris@0
|
78 public function testViewElementEmbed() {
|
Chris@0
|
79 $view = Views::getView('test_view_embed');
|
Chris@0
|
80 $view->setDisplay();
|
Chris@0
|
81 // Test a form.
|
Chris@0
|
82 $this->drupalGet('views_test_data_element_embed_form');
|
Chris@0
|
83
|
Chris@0
|
84 $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]');
|
Chris@0
|
85 $this->assertTrue($xpath, 'The view container has been found on the form.');
|
Chris@0
|
86
|
Chris@0
|
87 $xpath = $this->xpath('//div[@class="view-content"]');
|
Chris@0
|
88 $this->assertTrue($xpath, 'The view content has been found on the form.');
|
Chris@0
|
89 // There should be 5 rows in the results.
|
Chris@0
|
90 $xpath = $this->xpath('//div[@class="view-content"]/div');
|
Chris@0
|
91 $this->assertEqual(count($xpath), 5);
|
Chris@0
|
92
|
Chris@0
|
93 // Add an argument and save the view.
|
Chris@0
|
94 $view->displayHandlers->get('default')->overrideOption('arguments', [
|
Chris@0
|
95 'age' => [
|
Chris@0
|
96 'default_action' => 'ignore',
|
Chris@0
|
97 'title' => '',
|
Chris@0
|
98 'default_argument_type' => 'fixed',
|
Chris@0
|
99 'validate' => [
|
Chris@0
|
100 'type' => 'none',
|
Chris@0
|
101 'fail' => 'not found',
|
Chris@0
|
102 ],
|
Chris@0
|
103 'break_phrase' => FALSE,
|
Chris@0
|
104 'not' => FALSE,
|
Chris@0
|
105 'id' => 'age',
|
Chris@0
|
106 'table' => 'views_test_data',
|
Chris@0
|
107 'field' => 'age',
|
Chris@0
|
108 'plugin_id' => 'numeric',
|
Chris@0
|
109 ],
|
Chris@0
|
110 ]);
|
Chris@0
|
111 $view->save();
|
Chris@0
|
112
|
Chris@0
|
113 // Test that the form has the same expected result.
|
Chris@0
|
114 $this->drupalGet('views_test_data_element_embed_form');
|
Chris@0
|
115 $xpath = $this->xpath('//div[@class="view-content"]/div');
|
Chris@0
|
116 $this->assertEqual(count($xpath), 1);
|
Chris@0
|
117 }
|
Chris@0
|
118
|
Chris@0
|
119 }
|