3 namespace Drupal\Tests\views_ui\Functional;
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 $this->drupalPostForm($row_plugin_url, ['row[type]' => 'fields'], 'Apply');
59 $this->drupalGet($row_plugin_url);
60 $this->assertResponse(200);
61 $this->assertFieldByName('row[type]', 'fields', 'Make sure that the fields got saved as used row plugin.');
63 // Ensure that entity row plugins appear.
64 $view_name = 'content';
65 $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row";
66 $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options";
68 $this->drupalGet($row_plugin_url);
69 $this->assertFieldByName('row[type]', 'entity:node');
70 $this->drupalPostForm(NULL, ['row[type]' => 'entity:node'], t('Apply'));
71 $this->assertUrl($row_options_url);
72 $this->assertFieldByName('row_options[view_mode]', 'teaser');
74 // Change the teaser label to have markup so we can test escaping.
75 $teaser = EntityViewMode::load('node.teaser');
76 $teaser->set('label', 'Teaser <em>markup</em>');
78 $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
79 $this->assertEscaped('Teaser <em>markup</em>');