Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / DisplayAttachmentTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\views\Views;
6
7 /**
8  * Tests the UI for the attachment display plugin.
9  *
10  * @group views_ui
11  * @see \Drupal\views\Plugin\views\display\Attachment
12  */
13 class DisplayAttachmentTest extends UITestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    * .
20    */
21   public static $testViews = ['test_attachment_ui'];
22
23   /**
24    * Tests the attachment UI.
25    */
26   public function testAttachmentUI() {
27     $this->drupalGet('admin/structure/views/view/test_attachment_ui/edit/attachment_1');
28     $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
29
30     $attachment_display_url = 'admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays';
31     $this->drupalGet($attachment_display_url);
32     // Display labels should be escaped.
33     $this->assertEscaped('<em>Page</em>');
34
35     foreach (['default', 'page-1'] as $display_id) {
36       $this->assertNoFieldChecked("edit-displays-$display_id", format_string('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id]));
37     }
38
39     // Save the attachments and test the value on the view.
40     $this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
41     // Options summary should be escaped.
42     $this->assertEscaped('<em>Page</em>');
43     $this->assertNoRaw('<em>Page</em>');
44     $result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
45     $this->assertEqual($result[0]->getAttribute('title'), t('Page'));
46     $this->drupalPostForm(NULL, [], t('Save'));
47
48     $view = Views::getView('test_attachment_ui');
49     $view->initDisplay();
50     $this->assertEqual(array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), ['page_1'], 'The attached displays got saved as expected');
51
52     $this->drupalPostForm($attachment_display_url, ['displays[default]' => 1, 'displays[page_1]' => 1], t('Apply'));
53     $result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
54     $this->assertEqual($result[0]->getAttribute('title'), t('Multiple displays'));
55     $this->drupalPostForm(NULL, [], t('Save'));
56
57     $view = Views::getView('test_attachment_ui');
58     $view->initDisplay();
59     $this->assertEqual(array_keys($view->displayHandlers->get('attachment_1')->getOption('displays')), ['default', 'page_1'], 'The attached displays got saved as expected');
60   }
61
62   /**
63    * Tests the attachment working after the attached page was deleted.
64    */
65   public function testRemoveAttachedDisplay() {
66     // Create a view.
67     $view = $this->randomView();
68     $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
69     $attachment_display_url = 'admin/structure/views/nojs/display/' . $view['id'] . '/attachment_1/displays';
70
71     // Open the Page display and create the attachment display.
72     $this->drupalGet($path_prefix . '/page_1');
73     $this->drupalPostForm(NULL, [], 'Add Attachment');
74     $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
75
76     // Attach the Attachment to the Page display.
77     $this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
78     $this->drupalPostForm(NULL, [], t('Save'));
79
80     // Open the Page display and mark it as deleted.
81     $this->drupalGet($path_prefix . '/page_1');
82     $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.');
83     $this->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
84
85     // Open the attachment display and save it.
86     $this->drupalGet($path_prefix . '/attachment_1');
87     $this->drupalPostForm(NULL, [], t('Save'));
88
89     // Check that there is no warning for the removed page display.
90     $this->assertNoText("Plugin ID &#039;page_1&#039; was not found.");
91
92     // Check that the attachment is no longer linked to the removed display.
93     $this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
94
95   }
96
97 }