Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / Tests / Core / EventSubscriber / RssResponseRelativeUrlFilterTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\EventSubscriber;
4
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;
11
12 /**
13  * @coversDefaultClass \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter
14  * @group event_subscriber
15  */
16 class RssResponseRelativeUrlFilterTest extends UnitTestCase {
17
18   public function providerTestOnResponse() {
19     $data = [];
20
21     $valid_feed = <<<RSS
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">
24 <channel>
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>
30   <item>
31      <title>Drupal 8 turns one!</title>
32      <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
33      <description>&lt;a href=&quot;localhost/node/1&quot;&gt;Hello&lt;/a&gt;
34     </description>
35   </item>
36   </channel>
37 </rss>
38 RSS;
39
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">
43 <channel>
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>
49   <item>
50      <title>Drupal 8 turns one!</title>
51      <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
52      <description>&lt;a href="localhost/node/1"&gt;Hello&lt;/a&gt;
53     </description>
54   </item>
55   </channel>
56 </rss>
57
58 RSS;
59
60     $data['valid-feed'] = [$valid_feed, $valid_expected_feed];
61
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/">
65 <channel>
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>
71   <item>
72      <title>Drupal 8 turns one!</title>
73      <link>https://www.drupal.org/blog/drupal-8-turns-one</link>
74      <description>
75      <![CDATA[
76      &lt;a href="localhost/node/1"&gt;Hello&lt;/a&gt;
77      <script>
78 <!--//--><![CDATA[// ><!--
79
80 <!--//--><![CDATA[// ><!--
81
82 <!--//--><![CDATA[// ><!--
83 (function(d, s, id) {
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[>
91
92 //--><!]]]]><![CDATA[>
93
94 //--><!]]>
95 </script>
96     ]]>
97     </description>
98   </item>
99   </channel>
100 </rss>
101 RSS;
102
103     $data['invalid-feed'] = [$invalid_feed, $invalid_feed];
104     return $data;
105   }
106
107   /**
108    * @dataProvider providerTestOnResponse
109    *
110    * @param string $content
111    * @param string $expected_content
112    */
113   public function testOnResponse($content, $expected_content) {
114     $event = new FilterResponseEvent(
115       $this->prophesize(HttpKernelInterface::class)->reveal(),
116       Request::create('/'),
117       'foo',
118       new Response($content, 200, [
119         'Content-Type' => 'application/rss+xml'
120       ])
121     );
122
123     $url_filter = new RssResponseRelativeUrlFilter();
124     $url_filter->onResponse($event);
125
126     $this->assertEquals($expected_content, $event->getResponse()->getContent());
127   }
128
129 }