3 namespace Drupal\Tests\views\Functional\Plugin;
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Views;
9 * Tests the attachment display plugin.
12 * @see \Drupal\views\Plugin\views\display\Attachment
14 class DisplayAttachmentTest extends ViewTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_display_attachment', 'test_attached_disabled'];
28 public static $modules = ['node', 'views'];
30 protected function setUp($import_test_views = TRUE) {
31 parent::setUp($import_test_views);
33 $this->enableViewsTestModule();
35 $admin_user = $this->drupalCreateUser(['administer site configuration']);
36 $this->drupalLogin($admin_user);
40 * Tests the attachment plugin.
42 public function testAttachment() {
43 $this->drupalGet('test-display-attachment');
45 $result = $this->xpath('//div[contains(@class, "view-content")]');
46 $this->assertEqual(count($result), 2, 'Both actual view and the attachment is rendered.');
48 $result = $this->xpath('//div[contains(@class, "attachment-after")]');
49 $this->assertEqual(count($result), 0, 'The attachment is not rendered after the actual view.');
51 $result = $this->xpath('//div[contains(@class, "attachment-before")]');
52 $this->assertEqual(count($result), 1, 'The attachment is rendered before the actual view.');
56 * Tests that nothing is output when the attachment displays are disabled.
58 public function testDisabledAttachments() {
59 $this->drupalCreateContentType(['type' => 'page']);
60 $this->drupalCreateNode();
62 // Ensure that the feed_1 display is attached to the page_1 display.
63 $view = Views::getView('test_attached_disabled');
64 $view->setDisplay('page_1');
65 $attached_displays = $view->display_handler->getAttachedDisplays();
66 $this->assertTrue(in_array('attachment_1', $attached_displays), 'The attachment_1 display is attached to the page display.');
67 $this->assertTrue(in_array('attachment_2', $attached_displays), 'The attachment_2 display is attached to the page display.');
69 // Check that the attachments are output on the page display.
70 $this->drupalGet('test-attached-disabled');
72 $result = $this->xpath('//div[contains(@class, "view-content")]');
73 $this->assertEqual(count($result), 3, 'The page view and the attachments are rendered.');
75 $result = $this->xpath('//div[contains(@class, "attachment-before")]');
76 $this->assertEqual(count($result), 1, 'The attachment is rendered before the page view.');
78 $result = $this->xpath('//div[contains(@class, "attachment-after")]');
79 $this->assertEqual(count($result), 1, 'The attachment is rendered after the page view.');
81 // Disable the attachment_1 display.
82 $view->displayHandlers->get('attachment_1')->setOption('enabled', FALSE);
85 // Test that the before attachment is not displayed.
86 $this->drupalGet('/test-attached-disabled');
87 $result = $this->xpath('//div[contains(@class, "view-content")]');
88 $this->assertEqual(count($result), 2, 'The page view and only one attachment are rendered.');
90 $result = $this->xpath('//div[contains(@class, "attachment-before")]');
91 $this->assertEqual(count($result), 0, 'The attachment_1 is not rendered.');
93 // Disable the attachment_2 display.
94 $view->displayHandlers->get('attachment_2')->setOption('enabled', FALSE);
97 // Test that the after attachment is not displayed.
98 $this->drupalGet('/test-attached-disabled');
99 $result = $this->xpath('//div[contains(@class, "view-content")]');
100 $this->assertEqual(count($result), 1, 'The page view is rendered without attachments.');
102 $result = $this->xpath('//div[contains(@class, "attachment-after")]');
103 $this->assertEqual(count($result), 0, 'The attachment_2 is not rendered.');