View source
<?php
class FeedsTokenTest extends FeedsWebTestCase {
public static function getInfo() {
return array(
'name' => 'Feeds token tests',
'description' => 'Test the Feeds tokens.',
'group' => 'Feeds',
);
}
public function setUp() {
parent::setUp();
$this
->createImporterConfiguration('Syndication', 'syndication');
$this
->addMappings('syndication', array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
));
}
public function testFeedsTokens() {
$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');
$data = array(
'node' => node_load(2),
);
$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',
);
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,
)));
}
}
public function testPerformance() {
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
);
$this
->drupalPost('node/add/page', $edit, 'Save');
variable_set('feeds_track_node_loads', TRUE);
$data = array(
'node' => node_load(2),
);
token_replace('[node:title]', $data);
$loaded_nodes = variable_get('feeds_loaded_nodes');
$this
->assertEqual(array(
2,
), $loaded_nodes, format_string('The feed node (1) did not get loaded during token replacement, only node 2. Actual: @actual', array(
'@actual' => var_export($loaded_nodes, TRUE),
)));
}
}