FeedParserTest.php in Drupal 8
File
core/modules/aggregator/tests/src/Functional/FeedParserTest.php
View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\aggregator\FeedStorageInterface;
use Drupal\Core\Url;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
class FeedParserTest extends AggregatorTestBase {
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->config('aggregator.settings')
->set('items.expire', FeedStorageInterface::CLEAR_NEVER)
->save();
}
public function testRSS091Sample() {
$feed = $this
->createFeed($this
->getRSS091Sample());
$feed
->refreshItems();
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('First example feed item title');
$this
->assertLinkByHref('http://example.com/example-turns-one');
$this
->assertText('First example feed item description.');
$this
->assertRaw('<img src="http://example.com/images/druplicon.png"');
$this
->assertRaw("Second example feed item title.");
$this
->assertText('Long link feed item title');
$this
->assertText('Long link feed item description');
$this
->assertLinkByHref('http://example.com/tomorrow/and/tomorrow/and/tomorrow/creeps/in/this/petty/pace/from/day/to/day/to/the/last/syllable/of/recorded/time/and/all/our/yesterdays/have/lighted/fools/the/way/to/dusty/death/out/out/brief/candle/life/is/but/a/walking/shadow/a/poor/player/that/struts/and/frets/his/hour/upon/the/stage/and/is/heard/no/more/it/is/a/tale/told/by/an/idiot/full/of/sound/and/fury/signifying/nothing');
$this
->assertText('Long author feed item title');
$this
->assertText('Long author feed item description');
$this
->assertLinkByHref('http://example.com/long/author');
}
public function testAtomSample() {
$feed = $this
->createFeed($this
->getAtomSample());
$feed
->refreshItems();
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('Atom-Powered Robots Run Amok');
$this
->assertLinkByHref('http://example.org/2003/12/13/atom03');
$this
->assertText('Some text.');
$item_ids = \Drupal::entityQuery('aggregator_item')
->condition('link', 'http://example.org/2003/12/13/atom03')
->execute();
$item = Item::load(array_values($item_ids)[0]);
$this
->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $item
->getGuid(), 'Atom entry id element is parsed correctly.');
$this
->assertText('We tried to stop them, but we failed.');
$this
->assertLinkByHref('http://example.org/2003/12/14/atom03');
$this
->assertText('Some other text.');
$item_ids = \Drupal::entityQuery('aggregator_item')
->condition('link', 'http://example.org/2003/12/14/atom03')
->execute();
$item = Item::load(array_values($item_ids)[0]);
$this
->assertEqual('urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a', $item
->getGuid(), 'Atom entry id element is parsed correctly.');
}
public function testHtmlEntitiesSample() {
$feed = $this
->createFeed($this
->getHtmlEntitiesSample());
$feed
->refreshItems();
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertRaw("Quote" Amp&");
}
public function testRedirectFeed() {
$redirect_url = Url::fromRoute('aggregator_test.redirect')
->setAbsolute()
->toString();
$feed = Feed::create([
'url' => $redirect_url,
'title' => $this
->randomMachineName(),
]);
$feed
->save();
$feed
->refreshItems();
$this
->assertEqual($feed
->getUrl(), Url::fromRoute('aggregator_test.feed', [], [
'absolute' => TRUE,
])
->toString());
}
public function testInvalidFeed() {
$invalid_url = 'http:/www.drupal.org';
$feed = Feed::create([
'url' => $invalid_url,
'title' => $this
->randomMachineName(),
]);
$feed
->save();
$this
->drupalGet('admin/config/services/aggregator');
$this
->clickLink(t('Update items'));
$this
->assertRaw(t('The feed from %title seems to be broken because of error', [
'%title' => $feed
->label(),
]));
}
}