1 | <?php |
---|
2 | module_load_include('test', 'feeds', 'tests/feeds_mapper'); |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Test case for simple CCK field mapper mappers/content.inc. |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * Class for testing Feeds <em>content</em> mapper. |
---|
11 | */ |
---|
12 | class FeedsMapperContentTestCase extends FeedsMapperTestCase { |
---|
13 | public static function getInfo() { |
---|
14 | return array( |
---|
15 | 'name' => 'Mapper: Content', |
---|
16 | 'description' => 'Test Feeds Mapper support for CCK fields.', |
---|
17 | 'group' => 'Feeds', |
---|
18 | 'dependencies' => array('content'), |
---|
19 | ); |
---|
20 | } |
---|
21 | |
---|
22 | function setUp() { |
---|
23 | // Call parent setup with required modules. |
---|
24 | parent::setUp(array('content', 'number', 'text')); |
---|
25 | } |
---|
26 | |
---|
27 | /** |
---|
28 | * Basic test loading a doulbe entry CSV file. |
---|
29 | */ |
---|
30 | function test() { |
---|
31 | |
---|
32 | // Create content type. |
---|
33 | $typename = $this->createContentType(array(), array( |
---|
34 | 'alpha' => 'text', |
---|
35 | 'beta' => 'number_integer', |
---|
36 | 'gamma' => 'number_decimal', |
---|
37 | 'delta' => 'number_float', |
---|
38 | )); |
---|
39 | |
---|
40 | // Create and configure importer. |
---|
41 | $this->createImporterConfiguration('Content CSV', 'csv'); |
---|
42 | $this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER)); |
---|
43 | $this->setPlugin('csv', 'FeedsFileFetcher'); |
---|
44 | $this->setPlugin('csv', 'FeedsCSVParser'); |
---|
45 | $this->setSettings('csv', 'FeedsNodeProcessor', array('content_type' => $typename)); |
---|
46 | $this->addMappings('csv', array( |
---|
47 | array( |
---|
48 | 'source' => 'title', |
---|
49 | 'target' => 'title', |
---|
50 | ), |
---|
51 | array( |
---|
52 | 'source' => 'created', |
---|
53 | 'target' => 'created', |
---|
54 | ), |
---|
55 | array( |
---|
56 | 'source' => 'body', |
---|
57 | 'target' => 'body', |
---|
58 | ), |
---|
59 | array( |
---|
60 | 'source' => 'alpha', |
---|
61 | 'target' => 'field_alpha', |
---|
62 | ), |
---|
63 | array( |
---|
64 | 'source' => 'beta', |
---|
65 | 'target' => 'field_beta', |
---|
66 | ), |
---|
67 | array( |
---|
68 | 'source' => 'gamma', |
---|
69 | 'target' => 'field_gamma', |
---|
70 | ), |
---|
71 | array( |
---|
72 | 'source' => 'delta', |
---|
73 | 'target' => 'field_delta', |
---|
74 | ), |
---|
75 | )); |
---|
76 | |
---|
77 | // Import CSV file. |
---|
78 | $this->importFile('csv', $this->absolutePath() .'/tests/feeds/content.csv'); |
---|
79 | $this->assertText('Created 2 '. $typename .' nodes.'); |
---|
80 | |
---|
81 | // Check the two imported files. |
---|
82 | $this->drupalGet('node/1/edit'); |
---|
83 | $this->assertCCKFieldValue('alpha', 'Lorem'); |
---|
84 | $this->assertCCKFieldValue('beta', '42'); |
---|
85 | $this->assertCCKFieldValue('gamma', '4.20'); |
---|
86 | $this->assertCCKFieldValue('delta', '3.14159'); |
---|
87 | |
---|
88 | $this->drupalGet('node/2/edit'); |
---|
89 | $this->assertCCKFieldValue('alpha', 'Ut wisi'); |
---|
90 | $this->assertCCKFieldValue('beta', '32'); |
---|
91 | $this->assertCCKFieldValue('gamma', '1.20'); |
---|
92 | $this->assertCCKFieldValue('delta', '5.62951'); |
---|
93 | } |
---|
94 | } |
---|