449fefafd2092ea7eac3bcba6ebbd77ed653af96
[project/feeds.git] / tests / feeds_parser_sitemap.test
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Tests for plugins/FeedsSitemapParser.inc
7 */
8
9 // Require FeedsWebTestCase class definition.
10 require_once(dirname(__FILE__) .'/feeds.test.inc');
11
12 /**
13 * Test Sitemap parser.
14 */
15 class FeedsSitemapParserTestCase extends FeedsWebTestCase {
16
17 /**
18 * Describe this test.
19 */
20 public function getInfo() {
21 return array(
22 'name' => t('Sitemap parser'),
23 'description' => t('Regression tests for Sitemap XML format parser.'),
24 'group' => t('Feeds'),
25 );
26 }
27
28 /**
29 * Set up test.
30 */
31 public function setUp() {
32 parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
33
34 $this->drupalLogin(
35 $this->drupalCreateUser(
36 array(
37 'administer feeds', 'administer nodes',
38 )
39 )
40 );
41 }
42
43 /**
44 * Run tests.
45 */
46 public function test() {
47 $this->createImporterConfiguration('Sitemap', 'sitemap');
48 $this->setPlugin('sitemap', 'FeedsSitemapParser');
49
50 $this->addMappings('sitemap',
51 array(
52 array(
53 'source' => 'changefreq',
54 'target' => 'title',
55 'unique' => FALSE,
56 ),
57 array(
58 'source' => 'priority',
59 'target' => 'body',
60 'unique' => FALSE,
61 ),
62 array(
63 'source' => 'lastmod',
64 'target' => 'created',
65 'unique' => FALSE,
66 ),
67 array(
68 'source' => 'url',
69 'target' => 'url',
70 'unique' => TRUE,
71 ),
72 array(
73 'source' => 'url',
74 'target' => 'guid',
75 'unique' => TRUE,
76 ),
77 )
78 );
79
80
81 $path = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/';
82 $nid = $this->createFeedNode('sitemap', $path .'sitemap-example.xml', 'Testing Sitemap Parser');
83 $this->assertText('Created 5 Article nodes.');
84
85 // Assert DB status.
86 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
87 $this->assertEqual($count, 5, 'Accurate number of items in database.');
88
89 // Check items against known content of feed.
90 $items = db_query('SELECT * FROM {feeds_node_item} WHERE feed_nid = :nid ORDER BY nid', array(':nid' => $nid));
91
92 // Check first item.
93 date_default_timezone_set('GMT');
94 $item = $items->fetch();
95 $node = node_load($item->nid);
96 $this->assertEqual($node->title, 'monthly', 'Feed item 1 changefreq is correct.');
97 $this->assertEqual($node->body, '0.8', 'Feed item 1 priority is correct.');
98 $this->assertEqual($node->created, strtotime('2005-01-01'), 'Feed item 1 lastmod is correct.');
99 $this->assertEqual($node->feeds_node_item->url, 'http://www.example.com/', 'Feed item 1 url is correct.');
100 $this->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 1 guid is correct.');
101
102 // Check second item.
103 $item = $items->fetch();
104 $node = node_load($item->nid);
105 $this->assertEqual($node->title, 'weekly', 'Feed item 2 changefreq is correct.');
106 $this->assertEqual($node->body, '', 'Feed item 2 priority is correct.');
107 // $node->created is... recently
108 $this->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=12&desc=vacation_hawaii', 'Feed item 2 url is correct.');
109 $this->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 2 guid is correct.');
110
111 // Check third item.
112 $item = $items->fetch();
113 $node = node_load($item->nid);
114 $this->assertEqual($node->title, 'weekly', 'Feed item 3 changefreq is correct.');
115 $this->assertEqual($node->body, '', 'Feed item 3 priority is correct.');
116 $this->assertEqual($node->created, strtotime('2004-12-23'), 'Feed item 3 lastmod is correct.');
117 $this->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=73&desc=vacation_new_zealand', 'Feed item 3 url is correct.');
118 $this->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 3 guid is correct.');
119
120 // Check fourth item.
121 $item = $items->fetch();
122 $node = node_load($item->nid);
123 $this->assertEqual($node->title, '', 'Feed item 4 changefreq is correct.');
124 $this->assertEqual($node->body, '0.3', 'Feed item 4 priority is correct.');
125 $this->assertEqual($node->created, strtotime('2004-12-23T18:00:15+00:00'), 'Feed item 4 lastmod is correct.');
126 $this->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=74&desc=vacation_newfoundland', 'Feed item 4 url is correct.');
127 $this->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 1 guid is correct.');
128
129 // Check fifth item.
130 $item = $items->fetch();
131 $node = node_load($item->nid);
132 $this->assertEqual($node->title, '', 'Feed item 5 changefreq is correct.');
133 $this->assertEqual($node->body, '', 'Feed item 5 priority is correct.');
134 $this->assertEqual($node->created, strtotime('2004-11-23'), 'Feed item 5 lastmod is correct.');
135 $this->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=83&desc=vacation_usa', 'Feed item 5 url is correct.');
136 $this->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 5 guid is correct.');
137
138 // Check for more items.
139 $item = $items->fetch();
140 $this->assertFalse($item, 'Correct number of feed items recorded.');
141 }
142 }