You are here

public function FeedsWebTestBase::importURL in Feeds 8.2

Import a URL through the import form. Assumes http in place.

2 calls to FeedsWebTestBase::importURL()
FeedsRSStoNodesTest::test in lib/Drupal/feeds/Tests/FeedsRSStoNodesTest.php
Test node creation, refreshing/deleting feeds and feed items.
FeedsRSStoNodesTest::testExpiry in lib/Drupal/feeds/Tests/FeedsRSStoNodesTest.php
Tests expiring nodes.

File

lib/Drupal/feeds/Tests/FeedsWebTestBase.php, line 328
Common functionality for all Feeds tests.

Class

FeedsWebTestBase
Test basic Data API functionality.

Namespace

Drupal\feeds\Tests

Code

public function importURL($id, $feed_url = NULL) {
  if (empty($feed_url)) {
    $feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
  }
  $edit = array(
    'feeds[Drupal\\feeds\\Plugin\\feeds\\fetcher\\FeedsHTTPFetcher][source]' => $feed_url,
  );
  $nid = $this
    ->drupalPost('import/' . $id, $edit, 'Import');

  // Check whether feed got recorded in feeds_source table.
  $this
    ->assertEqual(1, db_query("SELECT COUNT(*) FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(
    ':id' => $id,
  ))
    ->fetchField());
  $source = db_query("SELECT * FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(
    ':id' => $id,
  ))
    ->fetchObject();
  $config = unserialize($source->config);
  $this
    ->assertEqual($config['Drupal\\feeds\\Plugin\\feeds\\fetcher\\FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));

  // Check whether feed got properly added to scheduler.
  $this
    ->assertEqual(1, db_query("SELECT COUNT(*) FROM {job_schedule} WHERE type = :id AND id = 0 AND name = 'feeds_source_import' AND last <> 0 AND scheduled = 0", array(
    ':id' => $id,
  ))
    ->fetchField());

  // Check expire scheduler.
  $jobs = db_query("SELECT COUNT(*) FROM {job_schedule} WHERE type = :id AND id = 0 AND name = 'feeds_source_expire'", array(
    ':id' => $id,
  ))
    ->fetchField();
  if (feeds_importer($id)->processor
    ->expiryTime() == FEEDS_EXPIRE_NEVER) {
    $this
      ->assertEqual(0, $jobs);
  }
  else {
    $this
      ->assertEqual(1, $jobs);
  }
}