Unverified Commit 5f2605fe authored by alexpott's avatar alexpott

Issue #2876211 by Lendude, dawehner, michielnugter: Convert...

Issue #2876211 by Lendude, dawehner, michielnugter: Convert \Drupal\views\Tests\Plugin\StyleOpmlTest and \Drupal\views\Tests\Plugin\DisplayFeedTest to PHPUnit tests
parent 137cfee8
<?php <?php
namespace Drupal\views\Tests\Plugin; namespace Drupal\Tests\views\Functional\Plugin;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -10,7 +11,7 @@ ...@@ -10,7 +11,7 @@
* @group views * @group views
* @see \Drupal\views\Plugin\views\display\Feed * @see \Drupal\views\Plugin\views\display\Feed
*/ */
class DisplayFeedTest extends PluginTestBase { class DisplayFeedTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
...@@ -58,9 +59,8 @@ public function testFeedOutput() { ...@@ -58,9 +59,8 @@ public function testFeedOutput() {
$this->config('system.site')->set('name', $site_name)->save(); $this->config('system.site')->set('name', $site_name)->save();
$this->drupalGet('test-feed-display.xml'); $this->drupalGet('test-feed-display.xml');
$result = $this->xpath('//title'); $this->assertEquals($site_name, $this->getSession()->getDriver()->getText('//title'));
$this->assertEqual($result[0], $site_name, 'The site title is used for the feed title.'); $this->assertEquals($node_title, $this->getSession()->getDriver()->getText('//item/title'));
$this->assertEqual($result[1], $node_title, 'Node title with HTML entities displays correctly.');
// Verify HTML is properly escaped in the description field. // Verify HTML is properly escaped in the description field.
$this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;'); $this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;');
...@@ -70,8 +70,7 @@ public function testFeedOutput() { ...@@ -70,8 +70,7 @@ public function testFeedOutput() {
$view->save(); $view->save();
$this->drupalGet('test-feed-display.xml'); $this->drupalGet('test-feed-display.xml');
$result = $this->xpath('//title'); $this->assertEquals('test_display_feed', $this->getSession()->getDriver()->getText('//title'));
$this->assertEqual($result[0], 'test_display_feed', 'The display title is used for the feed title.');
// Add a block display and attach the feed. // Add a block display and attach the feed.
$view->getExecutable()->newDisplay('block', NULL, 'test'); $view->getExecutable()->newDisplay('block', NULL, 'test');
...@@ -82,14 +81,14 @@ public function testFeedOutput() { ...@@ -82,14 +81,14 @@ public function testFeedOutput() {
$this->drupalPlaceBlock('views_block:test_display_feed-test'); $this->drupalPlaceBlock('views_block:test_display_feed-test');
$this->drupalGet('<front>'); $this->drupalGet('<front>');
$feed_icon = $this->cssSelect('div.view-id-test_display_feed a.feed-icon'); $feed_icon = $this->cssSelect('div.view-id-test_display_feed a.feed-icon');
$this->assertTrue(strpos($feed_icon[0]['href'], 'test-feed-display.xml'), 'The feed icon was found.'); $this->assertTrue(strpos($feed_icon[0]->getAttribute('href'), 'test-feed-display.xml'), 'The feed icon was found.');
// Test feed display attached to page display with arguments. // Test feed display attached to page display with arguments.
$this->drupalGet('test-feed-icon/' . $node->id()); $this->drupalGet('test-feed-icon/' . $node->id());
$page_url = $this->getUrl(); $page_url = $this->getUrl();
$icon_href = $this->cssSelect('a.feed-icon[href *= "test-feed-icon"]')[0]['href']; $icon_href = $this->cssSelect('a.feed-icon[href *= "test-feed-icon"]')[0]->getAttribute('href');
$this->assertEqual($icon_href, $page_url . '/feed', 'The feed icon was found.'); $this->assertEqual($icon_href, $page_url . '/feed', 'The feed icon was found.');
$link_href = $this->cssSelect('link[type = "application/rss+xml"][href *= "test-feed-icon"]')[0]['href']; $link_href = $this->cssSelect('link[type = "application/rss+xml"][href *= "test-feed-icon"]')[0]->getAttribute('href');
$this->assertEqual($link_href, $page_url . '/feed', 'The RSS link was found.'); $this->assertEqual($link_href, $page_url . '/feed', 'The RSS link was found.');
$feed_link = simplexml_load_string($this->drupalGet($icon_href))->channel->link; $feed_link = simplexml_load_string($this->drupalGet($icon_href))->channel->link;
$this->assertEqual($feed_link, $page_url, 'The channel link was found.'); $this->assertEqual($feed_link, $page_url, 'The channel link was found.');
...@@ -114,8 +113,7 @@ public function testFeedFieldOutput() { ...@@ -114,8 +113,7 @@ public function testFeedFieldOutput() {
]); ]);
$this->drupalGet('test-feed-display-fields.xml'); $this->drupalGet('test-feed-display-fields.xml');
$result = $this->xpath('//title/a'); $this->assertEquals($node_title, $this->getSession()->getDriver()->getText('//title/a'));
$this->assertEqual($result[0], $node_title, 'Node title with HTML entities displays correctly.');
// Verify HTML is properly escaped in the description field. // Verify HTML is properly escaped in the description field.
$this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;'); $this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;');
} }
...@@ -136,8 +134,8 @@ public function testDisabledFeed() { ...@@ -136,8 +134,8 @@ public function testDisabledFeed() {
// Check that the rss header is output on the page display. // Check that the rss header is output on the page display.
$this->drupalGet('/test-attached-disabled'); $this->drupalGet('/test-attached-disabled');
$feed_header = $this->xpath('//link[@rel="alternate"]'); $feed_header = $this->xpath('//link[@rel="alternate"]');
$this->assertEqual($feed_header[0]['type'], 'application/rss+xml', 'The feed link has the type application/rss+xml.'); $this->assertEqual($feed_header[0]->getAttribute('type'), 'application/rss+xml', 'The feed link has the type application/rss+xml.');
$this->assertTrue(strpos($feed_header[0]['href'], 'test-attached-disabled.xml'), 'Page display contains the correct feed URL.'); $this->assertTrue(strpos($feed_header[0]->getAttribute('href'), 'test-attached-disabled.xml'), 'Page display contains the correct feed URL.');
// Disable the feed display. // Disable the feed display.
$view->displayHandlers->get('feed_1')->setOption('enabled', FALSE); $view->displayHandlers->get('feed_1')->setOption('enabled', FALSE);
......
<?php <?php
namespace Drupal\views\Tests\Plugin; namespace Drupal\Tests\views\Functional\Plugin;
use Drupal\Tests\views\Functional\ViewTestBase;
/** /**
* Tests the OPML feed style plugin. * Tests the OPML feed style plugin.
...@@ -8,7 +10,7 @@ ...@@ -8,7 +10,7 @@
* @group views * @group views
* @see \Drupal\views\Plugin\views\style\Opml * @see \Drupal\views\Plugin\views\style\Opml
*/ */
class StyleOpmlTest extends PluginTestBase { class StyleOpmlTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
...@@ -52,10 +54,10 @@ public function testOpmlOutput() { ...@@ -52,10 +54,10 @@ public function testOpmlOutput() {
$feed->save(); $feed->save();
$this->drupalGet('test-feed-opml-style'); $this->drupalGet('test-feed-opml-style');
$outline = $this->xpath('//outline[1]'); $outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
$this->assertEqual($outline[0]['type'], 'rss', 'The correct type attribute is used for rss OPML.'); $this->assertEquals('rss', $outline->getAttribute('type'));
$this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for rss OPML.'); $this->assertEquals($feed->label(), $outline->getAttribute('text'));
$this->assertEqual($outline[0]['xmlurl'], $feed->getUrl(), 'The correct xmlUrl attribute is used for rss OPML.'); $this->assertEquals($feed->getUrl(), $outline->getAttribute('xmlUrl'));
$view = $this->container->get('entity.manager') $view = $this->container->get('entity.manager')
->getStorage('view') ->getStorage('view')
...@@ -66,12 +68,12 @@ public function testOpmlOutput() { ...@@ -66,12 +68,12 @@ public function testOpmlOutput() {
$view->save(); $view->save();
$this->drupalGet('test-feed-opml-style'); $this->drupalGet('test-feed-opml-style');
$outline = $this->xpath('//outline[1]'); $outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
$this->assertEqual($outline[0]['type'], 'link', 'The correct type attribute is used for link OPML.'); $this->assertEquals('link', $outline->getAttribute('type'));
$this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for link OPML.'); $this->assertEquals($feed->label(), $outline->getAttribute('text'));
$this->assertEqual($outline[0]['url'], $feed->getUrl(), 'The correct URL attribute is used for link OPML.'); $this->assertEquals($feed->getUrl(), $outline->getAttribute('url'));
// xmlUrl should not be present when type is link. // xmlUrl should not be present when type is link.
$this->assertNull($outline[0]['xmlUrl'], 'The xmlUrl attribute is not used for link OPML.'); $this->assertNull($outline->getAttribute('xmlUrl'));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment