3 namespace Drupal\views_ui\Tests;
5 use Drupal\views\Views;
8 * Tests the UI for the attachment display plugin.
11 * @see \Drupal\views\Plugin\views\display\Attachment
13 class DisplayAttachmentTest extends UITestBase {
16 * Views used by this test.
20 public static $testViews = ['test_attachment_ui'];
23 * Tests the attachment UI.
25 public function testAttachmentUI() {
26 $this->drupalGet('admin/structure/views/view/test_attachment_ui/edit/attachment_1');
27 $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
29 $attachment_display_url = 'admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays';
30 $this->drupalGet($attachment_display_url);
31 // Display labels should be escaped.
32 $this->assertEscaped('<em>Page</em>');
34 foreach (['default', 'page-1'] as $display_id) {
35 $this->assertNoFieldChecked("edit-displays-$display_id", format_string('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id]));
38 // Save the attachments and test the value on the view.
39 $this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
40 // Options summary should be escaped.
41 $this->assertEscaped('<em>Page</em>');
42 $this->assertNoRaw('<em>Page</em>');
43 $result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
44 $this->assertEqual($result[0]->attributes()->title, t('Page'));
45 $this->drupalPostForm(NULL, [], t('Save'));
47 $view = Views::getView('test_attachment_ui');
49 $this->assertEqual(array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), ['page_1'], 'The attached displays got saved as expected');
51 $this->drupalPostForm($attachment_display_url, ['displays[default]' => 1, 'displays[page_1]' => 1], t('Apply'));
52 $result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
53 $this->assertEqual($result[0]->attributes()->title, t('Multiple displays'));
54 $this->drupalPostForm(NULL, [], t('Save'));
56 $view = Views::getView('test_attachment_ui');
58 $this->assertEqual(array_keys($view->displayHandlers->get('attachment_1')->getOption('displays')), ['default', 'page_1'], 'The attached displays got saved as expected');
62 * Tests the attachment working after the attached page was deleted.
64 public function testRemoveAttachedDisplay() {
66 $view = $this->randomView();
67 $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
68 $attachment_display_url = 'admin/structure/views/nojs/display/' . $view['id'] . '/attachment_1/displays';
70 // Open the Page display and create the attachment display.
71 $this->drupalGet($path_prefix . '/page_1');
72 $this->drupalPostForm(NULL, [], 'Add Attachment');
73 $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
75 // Attach the Attachment to the Page display.
76 $this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
77 $this->drupalPostForm(NULL, [], t('Save'));
79 // Open the Page display and mark it as deleted.
80 $this->drupalGet($path_prefix . '/page_1');
81 $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display.');
82 $this->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
84 // Open the attachment display and save it.
85 $this->drupalGet($path_prefix . '/attachment_1');
86 $this->drupalPostForm(NULL, [], t('Save'));
88 // Check that there is no warning for the removed page display.
89 $this->assertNoText("Plugin ID 'page_1' was not found.");
91 // Check that the attachment is no longer linked to the removed display.
92 $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');