Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / src / Tests / DisplayAttachmentTest.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
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   public static $testViews = ['test_attachment_ui'];
21
22   /**
23    * Tests the attachment UI.
24    */
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.');
28
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>');
33
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]));
36     }
37
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'));
46
47     $view = Views::getView('test_attachment_ui');
48     $view->initDisplay();
49     $this->assertEqual(array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), ['page_1'], 'The attached displays got saved as expected');
50
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'));
55
56     $view = Views::getView('test_attachment_ui');
57     $view->initDisplay();
58     $this->assertEqual(array_keys($view->displayHandlers->get('attachment_1')->getOption('displays')), ['default', 'page_1'], 'The attached displays got saved as expected');
59   }
60
61   /**
62    * Tests the attachment working after the attached page was deleted.
63    */
64   public function testRemoveAttachedDisplay() {
65     // Create a view.
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';
69
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.');
74
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'));
78
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');
83
84     // Open the attachment display and save it.
85     $this->drupalGet($path_prefix . '/attachment_1');
86     $this->drupalPostForm(NULL, [], t('Save'));
87
88     // Check that there is no warning for the removed page display.
89     $this->assertNoText("Plugin ID &#039;page_1&#039; was not found.");
90
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.');
93
94   }
95
96 }