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