Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / FieldUITest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the UI of field handlers.
10  *
11  * @group views_ui
12  * @see \Drupal\views\Plugin\views\field\FieldPluginBase
13  */
14 class FieldUITest 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 the UI of field handlers.
25    */
26   public function testFieldUI() {
27     // Ensure the field is not marked as hidden on the first run.
28     $this->drupalGet('admin/structure/views/view/test_view/edit');
29     $this->assertText('Views test: Name');
30     $this->assertNoText('Views test: Name [' . t('hidden') . ']');
31
32     // Hides the field and check whether the hidden label is appended.
33     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
34     $this->drupalPostForm($edit_handler_url, ['options[exclude]' => TRUE], t('Apply'));
35
36     $this->assertText('Views test: Name [' . t('hidden') . ']');
37
38     // Ensure that the expected tokens appear in the UI.
39     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/age';
40     $this->drupalGet($edit_handler_url);
41     $result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
42     $this->assertEqual($result[0]->getHtml(), '{{ age }} == Age');
43
44     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/id';
45     $this->drupalGet($edit_handler_url);
46     $result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
47     $this->assertEqual(trim($result[0]->getHtml()), '{{ age }} == Age');
48     $this->assertEqual(trim($result[1]->getHtml()), '{{ id }} == ID');
49
50     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
51     $this->drupalGet($edit_handler_url);
52     $result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
53     $this->assertEqual(trim($result[0]->getHtml()), '{{ age }} == Age');
54     $this->assertEqual(trim($result[1]->getHtml()), '{{ id }} == ID');
55     $this->assertEqual(trim($result[2]->getHtml()), '{{ name }} == Name');
56
57     $result = $this->xpath('//details[@id="edit-options-more"]');
58     $this->assertEqual(empty($result), TRUE, "Container 'more' is empty and should not be displayed.");
59
60     // Ensure that dialog titles are not escaped.
61     $edit_groupby_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
62     $this->assertNoLinkByHref($edit_groupby_url, 0, 'No aggregation link found.');
63
64     // Enable aggregation on the view.
65     $edit = [
66       'group_by' => TRUE,
67     ];
68     $this->drupalPostForm('/admin/structure/views/nojs/display/test_view/default/group_by', $edit, t('Apply'));
69
70     $this->assertLinkByHref($edit_groupby_url, 0, 'Aggregation link found.');
71
72     $edit_handler_url = '/admin/structure/views/ajax/handler-group/test_view/default/field/name';
73     $this->drupalGet($edit_handler_url);
74     $data = Json::decode($this->getSession()->getPage()->getContent());
75     $this->assertEqual($data[3]['dialogOptions']['title'], 'Configure aggregation settings for field Views test: Name');
76   }
77
78   /**
79    * Tests the field labels.
80    */
81   public function testFieldLabel() {
82     // Create a view with unformatted style and make sure the fields have no
83     // labels by default.
84     $view = [];
85     $view['label'] = $this->randomMachineName(16);
86     $view['id'] = strtolower($this->randomMachineName(16));
87     $view['description'] = $this->randomMachineName(16);
88     $view['show[wizard_key]'] = 'node';
89     $view['page[create]'] = TRUE;
90     $view['page[style][style_plugin]'] = 'default';
91     $view['page[title]'] = $this->randomMachineName(16);
92     $view['page[path]'] = $view['id'];
93     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
94
95     $view = Views::getView($view['id']);
96     $view->initHandlers();
97     $this->assertEqual($view->field['title']->options['label'], '', 'The field label for normal styles are empty.');
98   }
99
100 }