You are here

public function FeedsWebTestCase::createFeedNode in Feeds 7

Same name and namespace in other branches
  1. 6 tests/feeds.test \FeedsWebTestCase::createFeedNode()
  2. 7.2 tests/feeds.test \FeedsWebTestCase::createFeedNode()

Create a test feed node. Test user has to have sufficient permissions:

  • create [type] content
  • use feeds

Assumes that page content type has been configured with createImporterConfiguration() as a feed content type.

Return value

The node id of the node created.

12 calls to FeedsWebTestCase::createFeedNode()
FeedsExamplesFastFeedTestCase::test in feeds_fast_news/feeds_fast_news.test
Run tests.
FeedsExamplesFeedTestCase::test in feeds_news/feeds_news.test
Run tests.
FeedsMapperFileFieldTestCase::test in tests/feeds_mapper_filefield.test
Basic test loading a single entry CSV file.
FeedsMapperLinkTestCase::test in tests/feeds_mapper_link.test
Basic test loading a single entry CSV file.
FeedsMapperLocaleTestCase::testInheritLanguage in tests/feeds_mapper_locale.test
Test inheriting language from the feed node.

... See full list

File

tests/feeds.test.inc, line 155
Common functionality for all Feeds tests.

Class

FeedsWebTestCase
Test basic Data API functionality.

Code

public function createFeedNode($id = 'syndication', $feed_url = NULL, $title = '', $content_type = NULL) {
  if (empty($feed_url)) {
    $feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
  }

  // If content type not given, retrieve it.
  if (!$content_type) {
    $result = db_select('feeds_importer', 'f')
      ->condition('f.id', $id, '=')
      ->fields('f', array(
      'config',
    ))
      ->execute();
    $config = unserialize($result
      ->fetchField());
    $content_type = $config['content_type'];
    $this
      ->assertFalse(empty($content_type), 'Valid content type found: ' . $content_type);
  }

  // Create a feed node.
  $edit = array(
    'title' => $title,
    'feeds[FeedsHTTPFetcher][source]' => $feed_url,
  );
  $this
    ->drupalPost('node/add/' . str_replace('_', '-', $content_type), $edit, 'Save');
  $this
    ->assertText('has been created.');

  // Get the node id from URL.
  $nid = $this
    ->getNid($this
    ->getUrl());

  // Check whether feed got recorded in feeds_source table.
  $query = db_select('feeds_source', 's')
    ->condition('s.id', $id, '=')
    ->condition('s.feed_nid', $nid, '=');
  $query
    ->addExpression("COUNT(*)");
  $result = $query
    ->execute()
    ->fetchField();
  $this
    ->assertEqual(1, $result);
  $source = db_select('feeds_source', 's')
    ->condition('s.id', $id, '=')
    ->condition('s.feed_nid', $nid, '=')
    ->fields('s', array(
    'config',
  ))
    ->execute()
    ->fetch();
  $config = unserialize($source->config);
  $this
    ->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
  return $nid;
}