Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / aggregator / tests / src / Functional / AddFeedTest.php
1 <?php
2
3 namespace Drupal\Tests\aggregator\Functional;
4
5 /**
6  * Add feed test.
7  *
8  * @group aggregator
9  */
10 class AddFeedTest extends AggregatorTestBase {
11
12   protected function setUp() {
13     parent::setUp();
14
15     $this->drupalPlaceBlock('page_title_block');
16   }
17
18   /**
19    * Creates and ensures that a feed is unique, checks source, and deletes feed.
20    */
21   public function testAddFeed() {
22     $feed = $this->createFeed();
23     $feed->refreshItems();
24
25     // Check feed data.
26     $this->assertUrl(\Drupal::url('aggregator.feed_add', [], ['absolute' => TRUE]), [], 'Directed to correct URL.');
27     $this->assertTrue($this->uniqueFeed($feed->label(), $feed->getUrl()), 'The feed is unique.');
28
29     // Check feed source.
30     $this->drupalGet('aggregator/sources/' . $feed->id());
31     $this->assertResponse(200, 'Feed source exists.');
32     $this->assertText($feed->label(), 'Page title');
33     $this->assertRaw($feed->getWebsiteUrl());
34
35     // Try to add a duplicate.
36     $edit = [
37       'title[0][value]' => $feed->label(),
38       'url[0][value]' => $feed->getUrl(),
39       'refresh' => '900',
40     ];
41     $this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
42     $this->assertRaw(t('A feed named %feed already exists. Enter a unique title.', ['%feed' => $feed->label()]));
43     $this->assertRaw(t('A feed with this URL %url already exists. Enter a unique URL.', ['%url' => $feed->getUrl()]));
44
45     // Delete feed.
46     $this->deleteFeed($feed);
47   }
48
49   /**
50    * Ensures that the feed label is escaping when rendering the feed icon.
51    */
52   public function testFeedLabelEscaping() {
53     $feed = $this->createFeed(NULL, ['title[0][value]' => 'Test feed title <script>alert(123);</script>']);
54     $this->checkForMetaRefresh();
55
56     $this->drupalGet('aggregator/sources/' . $feed->id());
57     $this->assertResponse(200);
58
59     $this->assertEscaped('Test feed title <script>alert(123);</script>');
60     $this->assertNoRaw('Test feed title <script>alert(123);</script>');
61
62     // Ensure the feed icon title is escaped.
63     $this->assertTrue(strpos(str_replace(["\n", "\r"], '', $this->getRawContent()), 'class="feed-icon">  Subscribe to Test feed title &lt;script&gt;alert(123);&lt;/script&gt; feed</a>') !== FALSE);
64   }
65
66   /**
67    * Tests feeds with very long URLs.
68    */
69   public function testAddLongFeed() {
70     // Create a feed with a URL of > 255 characters.
71     $long_url = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889&ix=heb";
72     $feed = $this->createFeed($long_url);
73     $feed->refreshItems();
74
75     // Create a second feed of > 255 characters, where the only difference is
76     // after the 255th character.
77     $long_url_2 = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889";
78     $feed_2 = $this->createFeed($long_url_2);
79     $feed->refreshItems();
80
81     // Check feed data.
82     $this->assertTrue($this->uniqueFeed($feed->label(), $feed->getUrl()), 'The first long URL feed is unique.');
83     $this->assertTrue($this->uniqueFeed($feed_2->label(), $feed_2->getUrl()), 'The second long URL feed is unique.');
84
85     // Check feed source.
86     $this->drupalGet('aggregator/sources/' . $feed->id());
87     $this->assertResponse(200, 'Long URL feed source exists.');
88     $this->assertText($feed->label(), 'Page title');
89
90     // Delete feeds.
91     $this->deleteFeed($feed);
92     $this->deleteFeed($feed_2);
93   }
94
95 }