3 namespace Drupal\Tests\Core\EventSubscriber;
5 use Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter;
6 use Drupal\Tests\UnitTestCase;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpFoundation\Response;
9 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
10 use Symfony\Component\HttpKernel\HttpKernelInterface;
13 * @coversDefaultClass \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter
14 * @group event_subscriber
16 class RssResponseRelativeUrlFilterTest extends UnitTestCase {
18 public function providerTestOnResponse() {
22 <?xml version="1.0" encoding="utf-8"?>
23 <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0" xml:base="https://www.drupal.org">
25 <title>Drupal.org</title>
26 <link>https://www.drupal.org</link>
27 <description>Come for the software, stay for the community
28 D rupal is an open source content management platform powering millions of websites and applications. It’s built, used, and supported by an active and diverse community of people around the world.</description>
29 <language>en</language>
31 <title>Drupal 8 turns one!</title>
32 <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
33 <description><a href="localhost/node/1">Hello</a>
40 $valid_expected_feed = <<<RSS
41 <?xml version="1.0" encoding="utf-8"?>
42 <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0" xml:base="https://www.drupal.org">
44 <title>Drupal.org</title>
45 <link>https://www.drupal.org</link>
46 <description>Come for the software, stay for the community
47 D rupal is an open source content management platform powering millions of websites and applications. It’s built, used, and supported by an active and diverse community of people around the world.</description>
48 <language>en</language>
50 <title>Drupal 8 turns one!</title>
51 <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
52 <description><a href="localhost/node/1">Hello</a>
60 $data['valid-feed'] = [$valid_feed, $valid_expected_feed];
62 $invalid_feed = <<<RSS
63 <?xml version="1.0" encoding="utf-8"?>
64 <rss version="2.0" xml:base="https://www.drupal.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
66 <title>Drupal.org</title>
67 <link>https://www.drupal.org</link>
68 <description>Come for the software, stay for the community
69 D rupal is an open source content management platform powering millions of websites and applications. It’s built, used, and supported by an active and diverse community of people around the world.</description>
70 <language>en</language>
72 <title>Drupal 8 turns one!</title>
73 <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
76 <a href="localhost/node/1">Hello</a>
78 <!--//--><![CDATA[// ><!--
80 <!--//--><![CDATA[// ><!--
82 <!--//--><![CDATA[// ><!--
84 var js, fjs = d.getElementsByTagName(s)[0];
85 if (d.getElementById(id)) return;
86 js = d.createElement(s); js.id = id;
87 js.src = "//connect.facebook.net/de_DE/sdk.js#xfbml=1&version=v2.3";
88 fjs.parentNode.insertBefore(js, fjs);
89 }(document, 'script', 'facebook-jssdk'));
90 //--><!]]]]]]><![CDATA[><![CDATA[>
92 //--><!]]]]><![CDATA[>
103 $data['invalid-feed'] = [$invalid_feed, $invalid_feed];
108 * @dataProvider providerTestOnResponse
110 * @param string $content
111 * @param string $expected_content
113 public function testOnResponse($content, $expected_content) {
114 $event = new FilterResponseEvent(
115 $this->prophesize(HttpKernelInterface::class)->reveal(),
116 Request::create('/'),
118 new Response($content, 200, [
119 'Content-Type' => 'application/rss+xml'
123 $url_filter = new RssResponseRelativeUrlFilter();
124 $url_filter->onResponse($event);
126 $this->assertEquals($expected_content, $event->getResponse()->getContent());