You are here

public function FeedsTokenTest::testFeedsTokens in Feeds 7.2

Test if tokens defined by Feeds work.

File

tests/feeds_tokens.test, line 41

Class

FeedsTokenTest
Test cases for token replacement.

Code

public function testFeedsTokens() {

  // Import a RSS feed.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
    'title' => 'RSS Feed title',
  );
  $this
    ->drupalPost('node/add/page', $edit, 'Save');

  // Load an imported node.
  $data = array(
    'node' => node_load(2),
  );

  // Setup tokens to test for replacement.
  $texts = array(
    'Source: [node:feed-source]' => 'Source: RSS Feed title',
    'Nid: [node:feed-source:nid]' => 'Nid: 1',
    'Title: [node:feed-source:title]' => 'Title: RSS Feed title',
  );

  // Replace tokens and assert result.
  foreach ($texts as $text => $expected) {
    $replaced = token_replace($text, $data);
    $this
      ->assertEqual($expected, $replaced, format_string('The tokens for "@text" got replaced correctly with "@expected". Actual: "@replaced".', array(
      '@text' => $text,
      '@expected' => $expected,
      '@replaced' => $replaced,
    )));
  }
}