Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Plugin / DisabledDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Plugin;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6
7 /**
8  * Tests the ability to disable and enable view displays.
9  *
10  * @group views
11  * @see \Drupal\views\Plugin\views\display\Feed
12  */
13 class DisabledDisplayTest extends ViewTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_disabled_display'];
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = ['block', 'node', 'views'];
28
29   protected function setUp($import_test_views = TRUE) {
30     parent::setUp($import_test_views);
31
32     $this->enableViewsTestModule();
33
34     $this->drupalPlaceBlock('page_title_block');
35
36     $admin_user = $this->drupalCreateUser(['administer site configuration']);
37     $this->drupalLogin($admin_user);
38   }
39
40   /**
41    * Tests that views displays can be disabled.
42    *
43    * This method only checks the page displays via a HTTP request, but should
44    * the .enabled property disappear from the schema both the load and save
45    * calls will start failing.
46    */
47   public function testDisabledDisplays() {
48     // The displays defined in this view.
49     $display_ids = ['attachment_1', 'block_1', 'embed_1', 'feed_1', 'page_2'];
50
51     $this->drupalCreateContentType(['type' => 'page']);
52     $this->drupalCreateNode();
53
54     // Load the test view and initialize its displays.
55     $view = $this->container->get('entity.manager')->getStorage('view')->load('test_disabled_display');
56     $view->getExecutable()->setDisplay();
57
58     // Enabled page display should return content.
59     $this->drupalGet('test-disabled-display');
60     $result = $this->xpath('//h1[@class="page-title"]');
61     $this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_1 display is accessible.');
62
63     // Disabled page view should 404.
64     $this->drupalGet('test-disabled-display-2');
65     $this->assertResponse(404);
66
67     // Enable each disabled display and save the view.
68     foreach ($display_ids as $display_id) {
69       $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', TRUE);
70       $view->save();
71       $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
72       $this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled');
73     }
74
75     \Drupal::service('router.builder')->rebuildIfNeeded();
76
77     // Check that the originally disabled page_2 display is now enabled.
78     $this->drupalGet('test-disabled-display-2');
79     $result = $this->xpath('//h1[@class="page-title"]');
80     $this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_2 display is accessible.');
81
82     // Disable each disabled display and save the view.
83     foreach ($display_ids as $display_id) {
84       $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', FALSE);
85       $view->save();
86       $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
87       $this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled');
88     }
89
90     \Drupal::service('router.builder')->rebuild();
91
92     // Check that the page_1 display still works.
93     $this->drupalGet('test-disabled-display');
94     $this->assertResponse(200);
95
96     // Check that the page_2 display is now disabled again.
97     $this->drupalGet('test-disabled-display-2');
98     $this->assertResponse(404);
99   }
100
101 }