Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\views_ui\Tests;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Serialization\Json;
|
Chris@0
|
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests the UI preview functionality.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group views_ui
|
Chris@0
|
12 */
|
Chris@0
|
13 class PreviewTest extends UITestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Views used by this test.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var array
|
Chris@0
|
19 */
|
Chris@0
|
20 public static $testViews = ['test_preview', 'test_preview_error', 'test_pager_full', 'test_mini_pager', 'test_click_sort'];
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Tests contextual links in the preview form.
|
Chris@0
|
24 */
|
Chris@0
|
25 public function testPreviewContextual() {
|
Chris@0
|
26 \Drupal::service('module_installer')->install(['contextual']);
|
Chris@0
|
27 $this->resetAll();
|
Chris@0
|
28
|
Chris@0
|
29 $this->drupalGet('admin/structure/views/view/test_preview/edit');
|
Chris@0
|
30 $this->assertResponse(200);
|
Chris@0
|
31 $this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
Chris@0
|
32
|
Chris@0
|
33 $elements = $this->xpath('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li[contains(@class, :li-class)]', [':ul-class' => 'contextual-links', ':li-class' => 'filter-add']);
|
Chris@0
|
34 $this->assertEqual(count($elements), 1, 'The contextual link to add a new field is shown.');
|
Chris@0
|
35
|
Chris@0
|
36 $this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
Chris@0
|
37
|
Chris@0
|
38 // Test that area text and exposed filters are present and rendered.
|
Chris@0
|
39 $this->assertFieldByName('id', NULL, 'ID exposed filter field found.');
|
Chris@0
|
40 $this->assertText('Test header text', 'Rendered header text found');
|
Chris@0
|
41 $this->assertText('Test footer text', 'Rendered footer text found.');
|
Chris@0
|
42 $this->assertText('Test empty text', 'Rendered empty text found.');
|
Chris@0
|
43 }
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Tests arguments in the preview form.
|
Chris@0
|
47 */
|
Chris@0
|
48 public function testPreviewUI() {
|
Chris@0
|
49 $this->drupalGet('admin/structure/views/view/test_preview/edit');
|
Chris@0
|
50 $this->assertResponse(200);
|
Chris@0
|
51
|
Chris@0
|
52 $this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
Chris@0
|
53
|
Chris@0
|
54 $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
Chris@0
|
55 $this->assertEqual(count($elements), 5);
|
Chris@0
|
56
|
Chris@0
|
57 // Filter just the first result.
|
Chris@0
|
58 $this->drupalPostForm(NULL, $edit = ['view_args' => '1'], t('Update preview'));
|
Chris@0
|
59
|
Chris@0
|
60 $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
Chris@0
|
61 $this->assertEqual(count($elements), 1);
|
Chris@0
|
62
|
Chris@0
|
63 // Filter for no results.
|
Chris@0
|
64 $this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
Chris@0
|
65
|
Chris@0
|
66 $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
Chris@0
|
67 $this->assertEqual(count($elements), 0);
|
Chris@0
|
68
|
Chris@0
|
69 // Test that area text and exposed filters are present and rendered.
|
Chris@0
|
70 $this->assertFieldByName('id', NULL, 'ID exposed filter field found.');
|
Chris@0
|
71 $this->assertText('Test header text', 'Rendered header text found');
|
Chris@0
|
72 $this->assertText('Test footer text', 'Rendered footer text found.');
|
Chris@0
|
73 $this->assertText('Test empty text', 'Rendered empty text found.');
|
Chris@0
|
74
|
Chris@0
|
75 // Test feed preview.
|
Chris@0
|
76 $view = [];
|
Chris@0
|
77 $view['label'] = $this->randomMachineName(16);
|
Chris@0
|
78 $view['id'] = strtolower($this->randomMachineName(16));
|
Chris@0
|
79 $view['page[create]'] = 1;
|
Chris@0
|
80 $view['page[title]'] = $this->randomMachineName(16);
|
Chris@0
|
81 $view['page[path]'] = $this->randomMachineName(16);
|
Chris@0
|
82 $view['page[feed]'] = 1;
|
Chris@0
|
83 $view['page[feed_properties][path]'] = $this->randomMachineName(16);
|
Chris@0
|
84 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
Chris@0
|
85 $this->clickLink(t('Feed'));
|
Chris@0
|
86 $this->drupalPostForm(NULL, [], t('Update preview'));
|
Chris@0
|
87 $result = $this->xpath('//div[@id="views-live-preview"]/pre');
|
Chris@0
|
88 $this->assertTrue(strpos($result[0], '<title>' . $view['page[title]'] . '</title>'), 'The Feed RSS preview was rendered.');
|
Chris@0
|
89
|
Chris@0
|
90 // Test the non-default UI display options.
|
Chris@0
|
91 // Statistics only, no query.
|
Chris@0
|
92 $settings = \Drupal::configFactory()->getEditable('views.settings');
|
Chris@0
|
93 $settings->set('ui.show.performance_statistics', TRUE)->save();
|
Chris@0
|
94 $this->drupalGet('admin/structure/views/view/test_preview/edit');
|
Chris@0
|
95 $this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
Chris@0
|
96 $this->assertText(t('Query build time'));
|
Chris@0
|
97 $this->assertText(t('Query execute time'));
|
Chris@0
|
98 $this->assertText(t('View render time'));
|
Chris@0
|
99 $this->assertNoRaw('<strong>Query</strong>');
|
Chris@0
|
100
|
Chris@0
|
101 // Statistics and query.
|
Chris@0
|
102 $settings->set('ui.show.sql_query.enabled', TRUE)->save();
|
Chris@0
|
103 $this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
Chris@0
|
104 $this->assertText(t('Query build time'));
|
Chris@0
|
105 $this->assertText(t('Query execute time'));
|
Chris@0
|
106 $this->assertText(t('View render time'));
|
Chris@0
|
107 $this->assertRaw('<strong>Query</strong>');
|
Chris@0
|
108 $this->assertText("SELECT views_test_data.name AS views_test_data_name\nFROM \n{views_test_data} views_test_data\nWHERE (views_test_data.id = '100' )");
|
Chris@0
|
109
|
Chris@0
|
110 // Test that the statistics and query are rendered above the preview.
|
Chris@0
|
111 $this->assertTrue(strpos($this->getRawContent(), 'views-query-info') < strpos($this->getRawContent(), 'view-test-preview'), 'Statistics shown above the preview.');
|
Chris@0
|
112
|
Chris@0
|
113 // Test that statistics and query rendered below the preview.
|
Chris@0
|
114 $settings->set('ui.show.sql_query.where', 'below')->save();
|
Chris@0
|
115 $this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
Chris@0
|
116 $this->assertTrue(strpos($this->getRawContent(), 'view-test-preview') < strpos($this->getRawContent(), 'views-query-info'), 'Statistics shown below the preview.');
|
Chris@0
|
117
|
Chris@0
|
118 // Test that the preview title isn't double escaped.
|
Chris@0
|
119 $this->drupalPostForm("admin/structure/views/nojs/display/test_preview/default/title", $edit = ['title' => 'Double & escaped'], t('Apply'));
|
Chris@0
|
120 $this->drupalPostForm(NULL, [], t('Update preview'));
|
Chris@0
|
121 $elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', [':text' => t('Double & escaped')]);
|
Chris@0
|
122 $this->assertEqual(1, count($elements));
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 /**
|
Chris@0
|
126 * Tests the taxonomy term preview AJAX.
|
Chris@0
|
127 *
|
Chris@0
|
128 * This tests a specific regression in the taxonomy term view preview.
|
Chris@0
|
129 *
|
Chris@0
|
130 * @see https://www.drupal.org/node/2452659
|
Chris@0
|
131 */
|
Chris@0
|
132 public function testTaxonomyAJAX() {
|
Chris@0
|
133 \Drupal::service('module_installer')->install(['taxonomy']);
|
Chris@0
|
134 $this->getPreviewAJAX('taxonomy_term', 'page_1', 0);
|
Chris@0
|
135 }
|
Chris@0
|
136
|
Chris@0
|
137 /**
|
Chris@0
|
138 * Tests pagers in the preview form.
|
Chris@0
|
139 */
|
Chris@0
|
140 public function testPreviewWithPagersUI() {
|
Chris@0
|
141
|
Chris@0
|
142 // Create 11 nodes and make sure that everyone is returned.
|
Chris@0
|
143 $this->drupalCreateContentType(['type' => 'page']);
|
Chris@0
|
144 for ($i = 0; $i < 11; $i++) {
|
Chris@0
|
145 $this->drupalCreateNode();
|
Chris@0
|
146 }
|
Chris@0
|
147
|
Chris@0
|
148 // Test Full Pager.
|
Chris@0
|
149 $this->getPreviewAJAX('test_pager_full', 'default', 5);
|
Chris@0
|
150
|
Chris@0
|
151 // Test that the pager is present and rendered.
|
Chris@0
|
152 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
Chris@0
|
153 $this->assertTrue(!empty($elements), 'Full pager found.');
|
Chris@0
|
154
|
Chris@0
|
155 // Verify elements and links to pages.
|
Chris@0
|
156 // We expect to find 5 elements: current page == 1, links to pages 2 and
|
Chris@0
|
157 // and 3, links to 'next >' and 'last >>' pages.
|
Chris@0
|
158 $this->assertClass($elements[0], 'is-active', 'Element for current page has .is-active class.');
|
Chris@0
|
159 $this->assertTrue($elements[0]->a, 'Element for current page has link.');
|
Chris@0
|
160
|
Chris@0
|
161 $this->assertClass($elements[1], 'pager__item', 'Element for page 2 has .pager__item class.');
|
Chris@0
|
162 $this->assertTrue($elements[1]->a, 'Link to page 2 found.');
|
Chris@0
|
163
|
Chris@0
|
164 $this->assertClass($elements[2], 'pager__item', 'Element for page 3 has .pager__item class.');
|
Chris@0
|
165 $this->assertTrue($elements[2]->a, 'Link to page 3 found.');
|
Chris@0
|
166
|
Chris@0
|
167 $this->assertClass($elements[3], 'pager__item--next', 'Element for next page has .pager__item--next class.');
|
Chris@0
|
168 $this->assertTrue($elements[3]->a, 'Link to next page found.');
|
Chris@0
|
169
|
Chris@0
|
170 $this->assertClass($elements[4], 'pager__item--last', 'Element for last page has .pager__item--last class.');
|
Chris@0
|
171 $this->assertTrue($elements[4]->a, 'Link to last page found.');
|
Chris@0
|
172
|
Chris@0
|
173 // Navigate to next page.
|
Chris@0
|
174 $elements = $this->xpath('//li[contains(@class, :class)]/a', [':class' => 'pager__item--next']);
|
Chris@0
|
175 $this->clickPreviewLinkAJAX($elements[0]['href'], 5);
|
Chris@0
|
176
|
Chris@0
|
177 // Test that the pager is present and rendered.
|
Chris@0
|
178 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
Chris@0
|
179 $this->assertTrue(!empty($elements), 'Full pager found.');
|
Chris@0
|
180
|
Chris@0
|
181 // Verify elements and links to pages.
|
Chris@0
|
182 // We expect to find 7 elements: links to '<< first' and '< previous'
|
Chris@0
|
183 // pages, link to page 1, current page == 2, link to page 3 and links
|
Chris@0
|
184 // to 'next >' and 'last >>' pages.
|
Chris@0
|
185 $this->assertClass($elements[0], 'pager__item--first', 'Element for first page has .pager__item--first class.');
|
Chris@0
|
186 $this->assertTrue($elements[0]->a, 'Link to first page found.');
|
Chris@0
|
187
|
Chris@0
|
188 $this->assertClass($elements[1], 'pager__item--previous', 'Element for previous page has .pager__item--previous class.');
|
Chris@0
|
189 $this->assertTrue($elements[1]->a, 'Link to previous page found.');
|
Chris@0
|
190
|
Chris@0
|
191 $this->assertClass($elements[2], 'pager__item', 'Element for page 1 has .pager__item class.');
|
Chris@0
|
192 $this->assertTrue($elements[2]->a, 'Link to page 1 found.');
|
Chris@0
|
193
|
Chris@0
|
194 $this->assertClass($elements[3], 'is-active', 'Element for current page has .is-active class.');
|
Chris@0
|
195 $this->assertTrue($elements[3]->a, 'Element for current page has link.');
|
Chris@0
|
196
|
Chris@0
|
197 $this->assertClass($elements[4], 'pager__item', 'Element for page 3 has .pager__item class.');
|
Chris@0
|
198 $this->assertTrue($elements[4]->a, 'Link to page 3 found.');
|
Chris@0
|
199
|
Chris@0
|
200 $this->assertClass($elements[5], 'pager__item--next', 'Element for next page has .pager__item--next class.');
|
Chris@0
|
201 $this->assertTrue($elements[5]->a, 'Link to next page found.');
|
Chris@0
|
202
|
Chris@0
|
203 $this->assertClass($elements[6], 'pager__item--last', 'Element for last page has .pager__item--last class.');
|
Chris@0
|
204 $this->assertTrue($elements[6]->a, 'Link to last page found.');
|
Chris@0
|
205
|
Chris@0
|
206 // Test Mini Pager.
|
Chris@0
|
207 $this->getPreviewAJAX('test_mini_pager', 'default', 3);
|
Chris@0
|
208
|
Chris@0
|
209 // Test that the pager is present and rendered.
|
Chris@0
|
210 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
Chris@0
|
211 $this->assertTrue(!empty($elements), 'Mini pager found.');
|
Chris@0
|
212
|
Chris@0
|
213 // Verify elements and links to pages.
|
Chris@0
|
214 // We expect to find current pages element with no link, next page element
|
Chris@0
|
215 // with a link, and not to find previous page element.
|
Chris@0
|
216 $this->assertClass($elements[0], 'is-active', 'Element for current page has .is-active class.');
|
Chris@0
|
217
|
Chris@0
|
218 $this->assertClass($elements[1], 'pager__item--next', 'Element for next page has .pager__item--next class.');
|
Chris@0
|
219 $this->assertTrue($elements[1]->a, 'Link to next page found.');
|
Chris@0
|
220
|
Chris@0
|
221 // Navigate to next page.
|
Chris@0
|
222 $elements = $this->xpath('//li[contains(@class, :class)]/a', [':class' => 'pager__item--next']);
|
Chris@0
|
223 $this->clickPreviewLinkAJAX($elements[0]['href'], 3);
|
Chris@0
|
224
|
Chris@0
|
225 // Test that the pager is present and rendered.
|
Chris@0
|
226 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
Chris@0
|
227 $this->assertTrue(!empty($elements), 'Mini pager found.');
|
Chris@0
|
228
|
Chris@0
|
229 // Verify elements and links to pages.
|
Chris@0
|
230 // We expect to find 3 elements: previous page with a link, current
|
Chris@0
|
231 // page with no link, and next page with a link.
|
Chris@0
|
232 $this->assertClass($elements[0], 'pager__item--previous', 'Element for previous page has .pager__item--previous class.');
|
Chris@0
|
233 $this->assertTrue($elements[0]->a, 'Link to previous page found.');
|
Chris@0
|
234
|
Chris@0
|
235 $this->assertClass($elements[1], 'is-active', 'Element for current page has .is-active class.');
|
Chris@0
|
236 $this->assertFalse(isset($elements[1]->a), 'Element for current page has no link.');
|
Chris@0
|
237
|
Chris@0
|
238 $this->assertClass($elements[2], 'pager__item--next', 'Element for next page has .pager__item--next class.');
|
Chris@0
|
239 $this->assertTrue($elements[2]->a, 'Link to next page found.');
|
Chris@0
|
240 }
|
Chris@0
|
241
|
Chris@0
|
242 /**
|
Chris@0
|
243 * Tests the additional information query info area.
|
Chris@0
|
244 */
|
Chris@0
|
245 public function testPreviewAdditionalInfo() {
|
Chris@0
|
246 \Drupal::service('module_installer')->install(['views_ui_test']);
|
Chris@0
|
247 $this->resetAll();
|
Chris@0
|
248
|
Chris@0
|
249 $this->drupalGet('admin/structure/views/view/test_preview/edit');
|
Chris@0
|
250 $this->assertResponse(200);
|
Chris@0
|
251
|
Chris@0
|
252 $this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
Chris@0
|
253
|
Chris@0
|
254 // Check for implementation of hook_views_preview_info_alter().
|
Chris@0
|
255 // @see views_ui_test.module
|
Chris@0
|
256 $elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', [':text' => t('Test row count')]);
|
Chris@0
|
257 $this->assertEqual(count($elements), 1, 'Views Query Preview Info area altered.');
|
Chris@0
|
258 // Check that additional assets are attached.
|
Chris@0
|
259 $this->assertTrue(strpos($this->getDrupalSettings()['ajaxPageState']['libraries'], 'views_ui_test/views_ui_test.test') !== FALSE, 'Attached library found.');
|
Chris@0
|
260 $this->assertRaw('css/views_ui_test.test.css', 'Attached CSS asset found.');
|
Chris@0
|
261 }
|
Chris@0
|
262
|
Chris@0
|
263 /**
|
Chris@0
|
264 * Tests view validation error messages in the preview.
|
Chris@0
|
265 */
|
Chris@0
|
266 public function testPreviewError() {
|
Chris@0
|
267 $this->drupalGet('admin/structure/views/view/test_preview_error/edit');
|
Chris@0
|
268 $this->assertResponse(200);
|
Chris@0
|
269
|
Chris@0
|
270 $this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
Chris@0
|
271
|
Chris@0
|
272 $this->assertText('Unable to preview due to validation errors.', 'Preview error text found.');
|
Chris@0
|
273 }
|
Chris@0
|
274
|
Chris@0
|
275 /**
|
Chris@0
|
276 * Tests the link to sort in the preview form.
|
Chris@0
|
277 */
|
Chris@0
|
278 public function testPreviewSortLink() {
|
Chris@0
|
279
|
Chris@0
|
280 // Get the preview.
|
Chris@0
|
281 $this->getPreviewAJAX('test_click_sort', 'page_1', 0);
|
Chris@0
|
282
|
Chris@0
|
283 // Test that the header label is present.
|
Chris@0
|
284 $elements = $this->xpath('//th[contains(@class, :class)]/a', [':class' => 'views-field views-field-name']);
|
Chris@0
|
285 $this->assertTrue(!empty($elements), 'The header label is present.');
|
Chris@0
|
286
|
Chris@0
|
287 // Verify link.
|
Chris@0
|
288 $this->assertLinkByHref('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=desc', 0, 'The output URL is as expected.');
|
Chris@0
|
289
|
Chris@0
|
290 // Click link to sort.
|
Chris@0
|
291 $this->clickPreviewLinkAJAX($elements[0]['href'], 0);
|
Chris@0
|
292
|
Chris@0
|
293 // Test that the header label is present.
|
Chris@0
|
294 $elements = $this->xpath('//th[contains(@class, :class)]/a', [':class' => 'views-field views-field-name is-active']);
|
Chris@0
|
295 $this->assertTrue(!empty($elements), 'The header label is present.');
|
Chris@0
|
296
|
Chris@0
|
297 // Verify link.
|
Chris@0
|
298 $this->assertLinkByHref('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=asc', 0, 'The output URL is as expected.');
|
Chris@0
|
299 }
|
Chris@0
|
300
|
Chris@0
|
301 /**
|
Chris@0
|
302 * Get the preview form and force an AJAX preview update.
|
Chris@0
|
303 *
|
Chris@0
|
304 * @param string $view_name
|
Chris@0
|
305 * The view to test.
|
Chris@0
|
306 * @param string $panel_id
|
Chris@0
|
307 * The view panel to test.
|
Chris@0
|
308 * @param int $row_count
|
Chris@0
|
309 * The expected number of rows in the preview.
|
Chris@0
|
310 */
|
Chris@0
|
311 protected function getPreviewAJAX($view_name, $panel_id, $row_count) {
|
Chris@0
|
312 $this->drupalGet('admin/structure/views/view/' . $view_name . '/preview/' . $panel_id);
|
Chris@0
|
313 $result = $this->drupalPostAjaxForm(NULL, [], ['op' => t('Update preview')]);
|
Chris@0
|
314 $this->assertPreviewAJAX($result, $row_count);
|
Chris@0
|
315 }
|
Chris@0
|
316
|
Chris@0
|
317 /**
|
Chris@0
|
318 * Mimic clicking on a preview link.
|
Chris@0
|
319 *
|
Chris@0
|
320 * @param string $url
|
Chris@0
|
321 * The url to navigate to.
|
Chris@0
|
322 * @param int $row_count
|
Chris@0
|
323 * The expected number of rows in the preview.
|
Chris@0
|
324 */
|
Chris@0
|
325 protected function clickPreviewLinkAJAX($url, $row_count) {
|
Chris@0
|
326 $content = $this->content;
|
Chris@0
|
327 $drupal_settings = $this->drupalSettings;
|
Chris@0
|
328 $ajax_settings = [
|
Chris@0
|
329 'wrapper' => 'views-preview-wrapper',
|
Chris@0
|
330 'method' => 'replaceWith',
|
Chris@0
|
331 ];
|
Chris@0
|
332 $url = $this->getAbsoluteUrl($url);
|
Chris@0
|
333 $post = ['js' => 'true'] + $this->getAjaxPageStatePostData();
|
Chris@0
|
334 $result = Json::decode($this->drupalPost($url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]));
|
Chris@0
|
335 if (!empty($result)) {
|
Chris@0
|
336 $this->drupalProcessAjaxResponse($content, $result, $ajax_settings, $drupal_settings);
|
Chris@0
|
337 }
|
Chris@0
|
338 $this->assertPreviewAJAX($result, $row_count);
|
Chris@0
|
339 }
|
Chris@0
|
340
|
Chris@0
|
341 /**
|
Chris@0
|
342 * Assert that the AJAX response contains expected data.
|
Chris@0
|
343 *
|
Chris@0
|
344 * @param array $result
|
Chris@0
|
345 * An array of AJAX commands.
|
Chris@0
|
346 * @param int $row_count
|
Chris@0
|
347 * The expected number of rows in the preview.
|
Chris@0
|
348 */
|
Chris@0
|
349 protected function assertPreviewAJAX($result, $row_count) {
|
Chris@0
|
350 // Has AJAX callback replied with an insert command? If so, we can
|
Chris@0
|
351 // assume that the page content was updated with AJAX returned data.
|
Chris@0
|
352 $result_commands = [];
|
Chris@0
|
353 foreach ($result as $command) {
|
Chris@0
|
354 $result_commands[$command['command']] = $command;
|
Chris@0
|
355 }
|
Chris@0
|
356 $this->assertTrue(isset($result_commands['insert']), 'AJAX insert command received.');
|
Chris@0
|
357
|
Chris@0
|
358 // Test if preview contains the expected number of rows.
|
Chris@0
|
359 $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
Chris@0
|
360 $this->assertEqual(count($elements), $row_count, 'Expected items found on page.');
|
Chris@0
|
361 }
|
Chris@0
|
362
|
Chris@0
|
363 /**
|
Chris@0
|
364 * Asserts that an element has a given class.
|
Chris@0
|
365 *
|
Chris@0
|
366 * @param \SimpleXMLElement $element
|
Chris@0
|
367 * The element to test.
|
Chris@0
|
368 * @param string $class
|
Chris@0
|
369 * The class to assert.
|
Chris@0
|
370 * @param string $message
|
Chris@0
|
371 * (optional) A verbose message to output.
|
Chris@0
|
372 */
|
Chris@0
|
373 protected function assertClass(\SimpleXMLElement $element, $class, $message = NULL) {
|
Chris@0
|
374 if (!isset($message)) {
|
Chris@0
|
375 $message = "Class .$class found.";
|
Chris@0
|
376 }
|
Chris@0
|
377 $this->assertTrue(strpos($element['class'], $class) !== FALSE, $message);
|
Chris@0
|
378 }
|
Chris@0
|
379
|
Chris@0
|
380 }
|