8e2950995ed57be9667764d4aed5db5dd8cb1377
[project/feeds.git] / tests / feeds_mapper_date.test
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Test case for CCK date field mapper mappers/date.inc.
7 */
8
9 require_once(drupal_get_path('module', 'feeds') . '/tests/feeds_mapper_test.inc');
10
11 /**
12 * Class for testing Feeds <em>content</em> mapper.
13 *
14 * @todo: Add test method iCal
15 * @todo: Add test method for end date
16 */
17 class FeedsMapperDateTestCase extends FeedsMapperTestCase {
18
19 public static function getInfo() {
20 return array(
21 'name' => t('Mapper: Date'),
22 'description' => t('Test Feeds Mapper support for CCK Date fields. <strong>Requires CCK and Date module</strong>.'),
23 'group' => t('Feeds'),
24 );
25 }
26
27 /**
28 * Set up the test.
29 */
30 public function setUp() {
31 // Call parent setup with the required module.
32 parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler', 'content', 'date_api', 'date');
33
34 // Create user and login.
35 $this->drupalLogin($this->drupalCreateUser(
36 array(
37 'administer content types',
38 'administer feeds',
39 'administer nodes',
40 'administer site configuration',
41 )
42 ));
43 }
44
45 /**
46 * Basic test loading a single entry CSV file.
47 */
48 public function test() {
49 // Create content type.
50 $typename = $this->createContentType(NULL, array(
51 'date' => 'date',
52 'datestamp' => 'datestamp',
53 'datetime' => 'datetime',
54 ));
55
56 // Create and configure importer.
57 $this->createImporterConfiguration('Date RSS', 'daterss');
58 $this->setSettings('daterss', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER,));
59 $this->setPlugin('daterss', 'FeedsFileFetcher');
60 $this->setPlugin('daterss', 'FeedsSyndicationParser');
61 $this->setSettings('daterss', 'FeedsNodeProcessor', array('content_type' => $typename));
62 $this->addMappings('daterss', array(
63 array(
64 'source' => 'title',
65 'target' => 'title',
66 ),
67 array(
68 'source' => 'description',
69 'target' => 'body',
70 ),
71 array(
72 'source' => 'timestamp',
73 'target' => 'field_date:start',
74 ),
75 array(
76 'source' => 'timestamp',
77 'target' => 'field_datestamp:start',
78 ),
79 ));
80
81 // Import CSV file.
82 $this->importFile('daterss', $this->absolutePath() .'/tests/feeds/googlenewstz.rss2');
83 $this->assertText('Created 6 '. $typename .' nodes.');
84
85 // Check the imported nodes.
86 $values = array(
87 '01/06/2010 - 19:26',
88 '01/06/2010 - 10:21',
89 '01/06/2010 - 13:42',
90 '01/06/2010 - 06:05',
91 '01/06/2010 - 11:26',
92 '01/07/2010 - 00:26',
93 );
94 for ($i = 1; $i <= 6; $i++) {
95 $this->drupalGet("node/$i/edit");
96 $this->assertCCKFieldValue('date', $values[$i-1]);
97 $this->assertCCKFieldValue('datestamp', $values[$i-1]);
98 }
99 }
100
101 protected function getFormFieldsNames($field_name, $index) {
102 if (in_array($field_name, array('date', 'datetime', 'datestamp'))) {
103 return array("field_{$field_name}[{$index}][value][date]");
104 }
105 else {
106 return parent::getFormFieldsNames($field_name, $index);
107 }
108 }
109 }