3 namespace Drupal\Tests\aggregator\Functional;
10 class AddFeedTest extends AggregatorTestBase {
12 protected function setUp() {
15 $this->drupalPlaceBlock('page_title_block');
19 * Creates and ensures that a feed is unique, checks source, and deletes feed.
21 public function testAddFeed() {
22 $feed = $this->createFeed();
23 $feed->refreshItems();
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.');
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());
35 // Try to add a duplicate.
37 'title[0][value]' => $feed->label(),
38 'url[0][value]' => $feed->getUrl(),
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()]));
46 $this->deleteFeed($feed);
50 * Ensures that the feed label is escaping when rendering the feed icon.
52 public function testFeedLabelEscaping() {
53 $feed = $this->createFeed(NULL, ['title[0][value]' => 'Test feed title <script>alert(123);</script>']);
54 $this->checkForMetaRefresh();
56 $this->drupalGet('aggregator/sources/' . $feed->id());
57 $this->assertResponse(200);
59 $this->assertEscaped('Test feed title <script>alert(123);</script>');
60 $this->assertNoRaw('Test feed title <script>alert(123);</script>');
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 <script>alert(123);</script> feed</a>') !== FALSE);
67 * Tests feeds with very long URLs.
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();
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();
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.');
86 $this->drupalGet('aggregator/sources/' . $feed->id());
87 $this->assertResponse(200, 'Long URL feed source exists.');
88 $this->assertText($feed->label(), 'Page title');
91 $this->deleteFeed($feed);
92 $this->deleteFeed($feed_2);