function FeedParserTest::testAtomSample

Same name in other branches
  1. 8.9.x core/modules/aggregator/tests/src/Functional/FeedParserTest.php \Drupal\Tests\aggregator\Functional\FeedParserTest::testAtomSample()

Tests a feed that uses the Atom format.

File

core/modules/aggregator/tests/src/Functional/FeedParserTest.php, line 60

Class

FeedParserTest
Tests the built-in feed parser with valid feed samples.

Namespace

Drupal\Tests\aggregator\Functional

Code

public function testAtomSample() {
    $feed = $this->createFeed($this->getAtomSample());
    $feed->refreshItems();
    $this->drupalGet('aggregator/sources/' . $feed->id());
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains('Atom-Powered Robots Run Amok');
    $this->assertSession()
        ->linkByHrefExists('http://example.org/2003/12/13/atom03');
    $this->assertSession()
        ->pageTextContains('Some text.');
    $item_ids = \Drupal::entityQuery('aggregator_item')->accessCheck(FALSE)
        ->condition('link', 'http://example.org/2003/12/13/atom03')
        ->execute();
    $item = Item::load(array_values($item_ids)[0]);
    $this->assertEquals('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.');
    // Check for second feed entry.
    $this->assertSession()
        ->pageTextContains('We tried to stop them, but we failed.');
    $this->assertSession()
        ->linkByHrefExists('http://example.org/2003/12/14/atom03');
    $this->assertSession()
        ->pageTextContains('Some other text.');
    $item_ids = \Drupal::entityQuery('aggregator_item')->accessCheck(FALSE)
        ->condition('link', 'http://example.org/2003/12/14/atom03')
        ->execute();
    $item = Item::load(array_values($item_ids)[0]);
    $this->assertEquals('urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.