1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for plugins/FeedsSyndicationParser.inc.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Test single feeds.
|
10 |
|
|
*/
|
11 |
7295e063
|
Assos Assos
|
class FeedsSyndicationParserTestCase extends FeedsMapperTestCase {
|
12 |
41cc1b08
|
Assos Assos
|
|
13 |
85ad3d82
|
Assos Assos
|
public static function getInfo() {
|
14 |
|
|
return array(
|
15 |
|
|
'name' => 'Syndication parsers',
|
16 |
|
|
'description' => 'Regression tests for syndication parsers Common syndication and SimplePie. Tests parsers against a set of feeds in the context of Feeds module. <strong>Requires SimplePie parser to be configured correctly.</strong>',
|
17 |
|
|
'group' => 'Feeds',
|
18 |
|
|
);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Run tests.
|
23 |
|
|
*/
|
24 |
|
|
public function test() {
|
25 |
41cc1b08
|
Assos Assos
|
// Only download simplepie if the plugin doesn't already exist somewhere.
|
26 |
|
|
// People running tests locally might have it.
|
27 |
|
|
if (!feeds_simplepie_exists()) {
|
28 |
|
|
$this->downloadExtractSimplePie('1.3');
|
29 |
|
|
$this->assertTrue(feeds_simplepie_exists());
|
30 |
|
|
// Reset all the caches!
|
31 |
|
|
$this->resetAll();
|
32 |
|
|
}
|
33 |
|
|
|
34 |
85ad3d82
|
Assos Assos
|
$this->createImporterConfiguration('Syndication', 'syndication');
|
35 |
|
|
|
36 |
|
|
foreach (array('FeedsSyndicationParser', 'FeedsSimplePieParser') as $parser) {
|
37 |
|
|
$this->setPlugin('syndication', $parser);
|
38 |
|
|
foreach ($this->feedUrls() as $url => $assertions) {
|
39 |
|
|
$this->createFeedNode('syndication', $url);
|
40 |
|
|
$this->assertText('Created ' . $assertions['item_count'] . ' nodes');
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
41cc1b08
|
Assos Assos
|
|
44 |
|
|
feeds_include_simplepie();
|
45 |
|
|
variable_set('feeds_never_use_curl', TRUE);
|
46 |
|
|
|
47 |
|
|
$link = $GLOBALS['base_url'] . '/testing/feeds/flickr.xml';
|
48 |
|
|
$enclosure = new FeedsSimplePieEnclosure(new SimplePie_Enclosure($link));
|
49 |
|
|
|
50 |
|
|
$enclosure->setAllowedExtensions('xml');
|
51 |
|
|
$this->assertEqual(1, $enclosure->getFile('public://')->fid);
|
52 |
85ad3d82
|
Assos Assos
|
}
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* Return an array of test feeds.
|
56 |
|
|
*/
|
57 |
|
|
protected function feedUrls() {
|
58 |
|
|
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/';
|
59 |
|
|
return array(
|
60 |
|
|
"{$path}developmentseed.rss2" => array(
|
61 |
|
|
'item_count' => 10,
|
62 |
|
|
),
|
63 |
|
|
"{$path}feed_without_guid.rss2" => array(
|
64 |
|
|
'item_count' => 10,
|
65 |
|
|
),
|
66 |
|
|
);
|
67 |
|
|
}
|
68 |
41cc1b08
|
Assos Assos
|
|
69 |
7295e063
|
Assos Assos
|
/**
|
70 |
|
|
* Tests if the "<source>" element of a RSS feed is parsed correctly.
|
71 |
|
|
*
|
72 |
|
|
* This element is optional according to the RSS 2.0 specification.
|
73 |
|
|
*/
|
74 |
|
|
public function testRSSSourceElement() {
|
75 |
|
|
// Do not use curl as that will result into HTTP requests returning a 404.
|
76 |
|
|
variable_set('feeds_never_use_curl', TRUE);
|
77 |
|
|
|
78 |
|
|
// Create content type with two text fields.
|
79 |
|
|
$typename = $this->createContentType(array(), array(
|
80 |
|
|
'source_title' => 'text',
|
81 |
|
|
'source_url' => 'text',
|
82 |
|
|
));
|
83 |
|
|
|
84 |
|
|
// Create importer and map sources from source element to text fields.
|
85 |
|
|
$this->createImporterConfiguration('Syndication', 'syndication');
|
86 |
|
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename));
|
87 |
|
|
$this->addMappings('syndication',
|
88 |
|
|
array(
|
89 |
|
|
0 => array(
|
90 |
|
|
'source' => 'title',
|
91 |
|
|
'target' => 'title',
|
92 |
|
|
'unique' => FALSE,
|
93 |
|
|
),
|
94 |
|
|
1 => array(
|
95 |
|
|
'source' => 'source:title',
|
96 |
|
|
'target' => 'field_source_title',
|
97 |
|
|
),
|
98 |
|
|
2 => array(
|
99 |
|
|
'source' => 'source:url',
|
100 |
|
|
'target' => 'field_source_url',
|
101 |
|
|
),
|
102 |
|
|
)
|
103 |
|
|
);
|
104 |
|
|
|
105 |
|
|
// Import url.
|
106 |
|
|
$url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
|
107 |
|
|
$this->createFeedNode('syndication', $url);
|
108 |
|
|
|
109 |
|
|
// Assert that the contents for the source element were imported for the
|
110 |
|
|
// first imported node.
|
111 |
|
|
$node = node_load(2);
|
112 |
|
|
$fields = array(
|
113 |
|
|
'field_source_title' => array(
|
114 |
|
|
'expected' => 'Technological Solutions for Progressive Organizations',
|
115 |
|
|
'actual' => $node->field_source_title[LANGUAGE_NONE][0]['value'],
|
116 |
|
|
),
|
117 |
|
|
'field_source_url' => array(
|
118 |
|
|
'expected' => 'http://developmentseed.org/node/974',
|
119 |
|
|
'actual' => $node->field_source_url[LANGUAGE_NONE][0]['value'],
|
120 |
|
|
),
|
121 |
|
|
);
|
122 |
|
|
foreach ($fields as $field_name => $value) {
|
123 |
|
|
$this->assertEqual($value['expected'], $value['actual'], format_string('The field %field has the expected value (actual: @actual).', array('%field' => $field_name, '@actual' => $value['actual'])));
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
// Assert that for the second imported node, no values were imported,
|
127 |
|
|
// because the second item does not contain a source element.
|
128 |
|
|
$node = node_load(3);
|
129 |
|
|
foreach ($fields as $field_name => $value) {
|
130 |
|
|
$this->assertTrue(!isset($node->{$field_name}[LANGUAGE_NONE][0]['value']), format_string('The field %field does not contain a value (actual: @actual).', array('%field' => $field_name, '@actual' => $value['actual'])));
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
85ad3d82
|
Assos Assos
|
} |