AddFeedTest.php in Drupal 9
File
core/modules/aggregator/tests/src/Functional/AddFeedTest.php
View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Core\Url;
class AddFeedTest extends AggregatorTestBase {
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
public function testAddFeed() {
$feed = $this
->createFeed();
$feed
->refreshItems();
$this
->assertSession()
->addressEquals(Url::fromRoute('aggregator.feed_add'));
$this
->assertTrue($this
->uniqueFeed($feed
->label(), $feed
->getUrl()), 'The feed is unique.');
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($feed
->label());
$this
->assertSession()
->pageTextContains($feed
->getWebsiteUrl());
$edit = [
'title[0][value]' => $feed
->label(),
'url[0][value]' => $feed
->getUrl(),
'refresh' => '900',
];
$this
->drupalGet('aggregator/sources/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('A feed named ' . $feed
->label() . ' already exists. Enter a unique title.');
$this
->assertSession()
->pageTextContains('A feed with this URL ' . $feed
->getUrl() . ' already exists. Enter a unique URL.');
$this
->deleteFeed($feed);
}
public function testFeedLabelEscaping() {
$feed = $this
->createFeed(NULL, [
'title[0][value]' => 'Test feed title <script>alert(123);</script>',
]);
$this
->checkForMetaRefresh();
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->assertEscaped('Test feed title <script>alert(123);</script>');
$this
->assertSession()
->responseNotContains('Test feed title <script>alert(123);</script>');
$this
->assertStringContainsString('class="feed-icon"> Subscribe to Test feed title <script>alert(123);</script> feed</a>', str_replace([
"\n",
"\r",
], '', $this
->getSession()
->getPage()
->getContent()));
}
public function testAddLongFeed() {
$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";
$feed = $this
->createFeed($long_url);
$feed
->refreshItems();
$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";
$feed_2 = $this
->createFeed($long_url_2);
$feed
->refreshItems();
$this
->assertTrue($this
->uniqueFeed($feed
->label(), $feed
->getUrl()), 'The first long URL feed is unique.');
$this
->assertTrue($this
->uniqueFeed($feed_2
->label(), $feed_2
->getUrl()), 'The second long URL feed is unique.');
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($feed
->label());
$this
->deleteFeed($feed);
$this
->deleteFeed($feed_2);
}
}