9dba45010f09ba620310921bb8b65908f87ed0d4
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / DisplayFeedTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 /**
6  * Tests the UI for feed display plugin.
7  *
8  * @group views_ui
9  * @see \Drupal\views\Plugin\views\display\Feed
10  */
11 class DisplayFeedTest extends UITestBase {
12
13   /**
14    * Views used by this test.
15    *
16    * @var array
17    */
18   public static $testViews = ['test_display_feed', 'test_style_opml'];
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = ['views_ui', 'aggregator'];
26
27   /**
28    * Tests feed display admin UI.
29    */
30   public function testFeedUI() {
31     // Test both RSS and OPML feeds.
32     foreach (self::$testViews as $view_name) {
33       $this->checkFeedViewUi($view_name);
34     }
35   }
36
37   /**
38    * Checks views UI for a specific feed view.
39    *
40    * @param string $view_name
41    *   The view name to check against.
42    */
43   protected function checkFeedViewUi($view_name) {
44     $this->drupalGet('admin/structure/views');
45     // Verify that the page lists the $view_name view.
46     // Regression test: ViewListBuilder::getDisplayPaths() did not properly
47     // check whether a DisplayPluginCollection was returned in iterating over
48     // all displays.
49     $this->assertText($view_name);
50
51     // Check the attach TO interface.
52     $this->drupalGet('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays');
53     // Display labels should be escaped.
54     $this->assertEscaped('<em>Page</em>');
55
56     // Load all the options of the checkbox.
57     $result = $this->xpath('//div[@id="edit-displays"]/div');
58     $options = [];
59     foreach ($result as $item) {
60       $input_node = $item->find('css', 'input');
61       if ($input_node->hasAttribute('value')) {
62         $options[] = $input_node->getAttribute('value');
63       }
64     }
65
66     $this->assertEqual($options, ['default', 'page'], 'Make sure all displays appears as expected.');
67
68     // Post and save this and check the output.
69     $this->drupalPostForm('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays', ['displays[page]' => 'page'], t('Apply'));
70     // Options summary should be escaped.
71     $this->assertEscaped('<em>Page</em>');
72     $this->assertNoRaw('<em>Page</em>');
73
74     $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
75     $this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', '<em>Page</em>');
76
77     // Add the default display, so there should now be multiple displays.
78     $this->drupalPostForm('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays', ['displays[default]' => 'default'], t('Apply'));
79     $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
80     $this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', 'Multiple displays');
81   }
82
83 }