You are here

public function FeedsWebTestCase::createFeedNode in Feeds 7.2

Same name and namespace in other branches
  1. 6 tests/feeds.test \FeedsWebTestCase::createFeedNode()
  2. 7 tests/feeds.test.inc \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.

24 calls to FeedsWebTestCase::createFeedNode()
FeedsAccountSwitcherTest::testAuthorizedImport in tests/FeedsAccountSwitcherTest.test
Tests if an extra account switch happens on authorized imports.
FeedsAccountSwitcherTest::testFailingImport in tests/FeedsAccountSwitcherTest.test
Tests if the user is switched back properly when an import fails.
FeedsAccountSwitcherTest::testRunImportAsFeedNodeAuthorInUI in tests/FeedsAccountSwitcherTest.test
Tests if the import is ran as the feed node author when using the UI.
FeedsAccountSwitcherTest::testRunImportAsFeedNodeAuthorOnCron in tests/FeedsAccountSwitcherTest.test
Tests if the import is ran as the feed node author when using cron.
FeedsEntityCase::testGetFeedsItemProperty in tests/feeds_entity.test
Tests getting feeds item properties on an entity.

... See full list

File

tests/feeds.test, line 259
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()
    ->fetchObject();
  $config = unserialize($source->config);
  $this
    ->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
  return $nid;
}