8b256f4373eb391dbab9f29e3308e0d8f4d98cdf
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / RowUITest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
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     $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.');
62
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";
67
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');
73
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>');
77     $teaser->save();
78     $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
79     $this->assertEscaped('Teaser <em>markup</em>');
80   }
81
82 }