3 namespace Drupal\views_ui\Tests;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\views\Views;
9 * Tests the UI of field handlers.
12 * @see \Drupal\views\Plugin\views\field\FieldPluginBase
14 class FieldUITest extends UITestBase {
17 * Views used by this test.
21 public static $testViews = ['test_view'];
24 * Tests the UI of field handlers.
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') . ']');
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'));
36 $this->assertText('Views test: Name [' . t('hidden') . ']');
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((string) $result[0], '{{ age }} == Age');
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((string) $result[0], '{{ age }} == Age');
48 $this->assertEqual((string) $result[1], '{{ id }} == ID');
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((string) $result[0], '{{ age }} == Age');
54 $this->assertEqual((string) $result[1], '{{ id }} == ID');
55 $this->assertEqual((string) $result[2], '{{ name }} == Name');
57 $result = $this->xpath('//details[@id="edit-options-more"]');
58 $this->assertEqual(empty($result), TRUE, "Container 'more' is empty and should not be displayed.");
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.');
64 // Enable aggregation on the view.
68 $this->drupalPostForm('/admin/structure/views/nojs/display/test_view/default/group_by', $edit, t('Apply'));
70 $this->assertLinkByHref($edit_groupby_url, 0, 'Aggregation link found.');
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->getRawContent());
75 $this->assertEqual($data[3]['dialogOptions']['title'], 'Configure aggregation settings for field Views test: Name');
79 * Tests the field labels.
81 public function testFieldLabel() {
82 // Create a view with unformatted style and make sure the fields have no
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'));
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.');