You are here

public function AddFeedTest::testAddFeed in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/aggregator/src/Tests/AddFeedTest.php \Drupal\aggregator\Tests\AddFeedTest::testAddFeed()

Creates and ensures that a feed is unique, checks source, and deletes feed.

File

core/modules/aggregator/src/Tests/AddFeedTest.php, line 26
Contains \Drupal\aggregator\Tests\AddFeedTest.

Class

AddFeedTest
Add feed test.

Namespace

Drupal\aggregator\Tests

Code

public function testAddFeed() {
  $feed = $this
    ->createFeed();
  $feed
    ->refreshItems();

  // Check feed data.
  $this
    ->assertUrl(\Drupal::url('aggregator.feed_add', [], [
    'absolute' => TRUE,
  ]), [], 'Directed to correct url.');
  $this
    ->assertTrue($this
    ->uniqueFeed($feed
    ->label(), $feed
    ->getUrl()), 'The feed is unique.');

  // Check feed source.
  $this
    ->drupalGet('aggregator/sources/' . $feed
    ->id());
  $this
    ->assertResponse(200, 'Feed source exists.');
  $this
    ->assertText($feed
    ->label(), 'Page title');
  $this
    ->assertRaw($feed
    ->getWebsiteUrl());

  // Try to add a duplicate.
  $edit = [
    'title[0][value]' => $feed
      ->label(),
    'url[0][value]' => $feed
      ->getUrl(),
    'refresh' => '900',
  ];
  $this
    ->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
  $this
    ->assertRaw(t('A feed named %feed already exists. Enter a unique title.', array(
    '%feed' => $feed
      ->label(),
  )));
  $this
    ->assertRaw(t('A feed with this URL %url already exists. Enter a unique URL.', array(
    '%url' => $feed
      ->getUrl(),
  )));

  // Delete feed.
  $this
    ->deleteFeed($feed);
}