3 namespace Drupal\views_ui\Tests;
5 use Drupal\Core\Entity\Entity\EntityViewMode;
6 use Drupal\views\Views;
9 * Tests the UI of row plugins.
12 * @see \Drupal\views_test_data\Plugin\views\row\RowTest.
14 class RowUITest extends UITestBase {
17 * Views used by this test.
21 public static $testViews = ['test_view'];
24 * Tests changing the row plugin and changing some options of a row.
26 public function testRowUI() {
27 $view_name = 'test_view';
28 $view_edit_url = "admin/structure/views/view/$view_name/edit";
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";
33 $this->drupalGet($row_plugin_url);
34 $this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.');
37 'row[type]' => 'test_row'
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();
43 'row_options[test_option]' => $random_name
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.');
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');
52 $view = Views::getView($view_name);
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.');
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);
64 'accepts' => 'application/vnd.drupal-ajax',
66 '_triggering_element_name' => 'op',
67 '_triggering_element_value' => 'Apply',
69 'url' => $row_plugin_url_ajax,
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.');
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";
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');
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>');
91 $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
92 $this->assertEscaped('Teaser <em>markup</em>');