Newer
Older
maximpodorov
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Test cases for token replacement.
*/
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();
// Create an importer configuration.
$this->createImporterConfiguration('Syndication', 'syndication');
$this->addMappings('syndication',
array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
)
);
}
/**
* Test if tokens defined by Feeds work.
*/
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,
)));
}
}
/**
* Tests if a feed node does not get loaded if *not* replacing tokens like
* [node:feeds-source:x].
*/
public function testPerformance() {
// Import a RSS feed.
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
);
$this->drupalPost('node/add/page', $edit, 'Save');
// Keep track of loaded nodes from now on.
variable_set('feeds_track_node_loads', TRUE);
// Load an imported node.
$data = array(
'node' => node_load(2),
);
// Replace a single token.
token_replace('[node:title]', $data);
// Ensure only node 2 was loaded.
$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),
)));
}
}