Mercurial > hg > isophonics-drupal-site
comparison core/modules/views_ui/src/Tests/RowUITest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\views_ui\Tests; | |
4 | |
5 use Drupal\Core\Entity\Entity\EntityViewMode; | |
6 use Drupal\views\Views; | |
7 | |
8 /** | |
9 * Tests the UI of row plugins. | |
10 * | |
11 * @group views_ui | |
12 * @see \Drupal\views_test_data\Plugin\views\row\RowTest. | |
13 */ | |
14 class RowUITest extends UITestBase { | |
15 | |
16 /** | |
17 * Views used by this test. | |
18 * | |
19 * @var array | |
20 */ | |
21 public static $testViews = ['test_view']; | |
22 | |
23 /** | |
24 * Tests changing the row plugin and changing some options of a row. | |
25 */ | |
26 public function testRowUI() { | |
27 $view_name = 'test_view'; | |
28 $view_edit_url = "admin/structure/views/view/$view_name/edit"; | |
29 | |
30 $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row"; | |
31 $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options"; | |
32 | |
33 $this->drupalGet($row_plugin_url); | |
34 $this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.'); | |
35 | |
36 $edit = [ | |
37 'row[type]' => 'test_row' | |
38 ]; | |
39 $this->drupalPostForm(NULL, $edit, t('Apply')); | |
40 $this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.'); | |
41 $random_name = $this->randomMachineName(); | |
42 $edit = [ | |
43 'row_options[test_option]' => $random_name | |
44 ]; | |
45 $this->drupalPostForm(NULL, $edit, t('Apply')); | |
46 $this->drupalGet($row_options_url); | |
47 $this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.'); | |
48 | |
49 $this->drupalPostForm($view_edit_url, [], t('Save')); | |
50 $this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI'); | |
51 | |
52 $view = Views::getView($view_name); | |
53 $view->initDisplay(); | |
54 $row = $view->display_handler->getOption('row'); | |
55 $this->assertEqual($row['type'], 'test_row', 'Make sure that the test_row got saved as used row plugin.'); | |
56 $this->assertEqual($row['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.'); | |
57 | |
58 // Change the row plugin to fields using ajax. | |
59 // Note: this is the best approximation we can achieve, because we cannot | |
60 // simulate the 'openDialog' command in | |
61 // WebTestBase::drupalProcessAjaxResponse(), hence we have to make do. | |
62 $row_plugin_url_ajax = str_replace('/nojs/', '/ajax/', $row_plugin_url); | |
63 $ajax_settings = [ | |
64 'accepts' => 'application/vnd.drupal-ajax', | |
65 'submit' => [ | |
66 '_triggering_element_name' => 'op', | |
67 '_triggering_element_value' => 'Apply', | |
68 ], | |
69 'url' => $row_plugin_url_ajax, | |
70 ]; | |
71 $this->drupalPostAjaxForm($row_plugin_url, ['row[type]' => 'fields'], NULL, $row_plugin_url_ajax, [], [], NULL, $ajax_settings); | |
72 $this->drupalGet($row_plugin_url); | |
73 $this->assertResponse(200); | |
74 $this->assertFieldByName('row[type]', 'fields', 'Make sure that the fields got saved as used row plugin.'); | |
75 | |
76 // Ensure that entity row plugins appear. | |
77 $view_name = 'content'; | |
78 $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row"; | |
79 $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options"; | |
80 | |
81 $this->drupalGet($row_plugin_url); | |
82 $this->assertFieldByName('row[type]', 'entity:node'); | |
83 $this->drupalPostForm(NULL, ['row[type]' => 'entity:node'], t('Apply')); | |
84 $this->assertUrl($row_options_url); | |
85 $this->assertFieldByName('row_options[view_mode]', 'teaser'); | |
86 | |
87 // Change the teaser label to have markup so we can test escaping. | |
88 $teaser = EntityViewMode::load('node.teaser'); | |
89 $teaser->set('label', 'Teaser <em>markup</em>'); | |
90 $teaser->save(); | |
91 $this->drupalGet('admin/structure/views/view/frontpage/edit/default'); | |
92 $this->assertEscaped('Teaser <em>markup</em>'); | |
93 } | |
94 | |
95 } |