1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsCSVParserTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests the CSV parser using the UI.
|
10
|
*/
|
11
|
class FeedsCSVParserTestCase extends FeedsWebTestCase {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'CSV parser functional tests',
|
15
|
'description' => 'Tests the CSV parser using the UI.',
|
16
|
'group' => 'Feeds',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Tests parsing a CSV when the mbstring extension is not available.
|
22
|
*/
|
23
|
public function testMbstringExtensionDisabled() {
|
24
|
// Set "feeds_use_mbstring" to FALSE to emulate that the mbstring extension
|
25
|
// is not loaded.
|
26
|
variable_set('feeds_use_mbstring', FALSE);
|
27
|
|
28
|
// Remove items after parsing because in < PHP 5.4 processing items with
|
29
|
// encoding issues leads to test failures because check_plain() can only
|
30
|
// handle UTF-8 encoded strings.
|
31
|
// @see feeds_tests_feeds_after_parse()
|
32
|
variable_set('feeds_tests_feeds_after_parse_empty_items', TRUE);
|
33
|
|
34
|
// Create node type.
|
35
|
$node_type = $this->drupalCreateContentType();
|
36
|
|
37
|
// Create and configure importer.
|
38
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
39
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
40
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
41
|
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $node_type->type));
|
42
|
$this->addMappings('csv', array(
|
43
|
0 => array(
|
44
|
'source' => 'id',
|
45
|
'target' => 'guid',
|
46
|
),
|
47
|
1 => array(
|
48
|
'source' => 'text',
|
49
|
'target' => 'title',
|
50
|
),
|
51
|
));
|
52
|
|
53
|
// Ensure that on the CSV parser settings page a message is shown about that
|
54
|
// the mbstring extension is not available.
|
55
|
$this->drupalGet('admin/structure/feeds/csv/settings/FeedsCSVParser');
|
56
|
$this->assertNoField('encoding');
|
57
|
$this->assertText('PHP mbstring extension must be available for character encoding conversion.');
|
58
|
|
59
|
// Try to import a CSV file that is not UTF-8 encoded. No encoding warning
|
60
|
// should be shown, but import should fail.
|
61
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/encoding_SJIS.csv');
|
62
|
$this->assertNoText('Source file is not in UTF-8 encoding.');
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Tests an encoding failure during parsing a CSV.
|
67
|
*/
|
68
|
public function testEncodingFailure() {
|
69
|
// Create node type.
|
70
|
$node_type = $this->drupalCreateContentType();
|
71
|
|
72
|
// Create and configure importer.
|
73
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
74
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
75
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
76
|
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $node_type->type));
|
77
|
$this->addMappings('csv', array(
|
78
|
0 => array(
|
79
|
'source' => 'id',
|
80
|
'target' => 'guid',
|
81
|
),
|
82
|
1 => array(
|
83
|
'source' => 'text',
|
84
|
'target' => 'title',
|
85
|
),
|
86
|
));
|
87
|
|
88
|
// Ensure that on the CSV parser settings page a setting for encoding is
|
89
|
// shown.
|
90
|
$this->drupalGet('admin/structure/feeds/csv/settings/FeedsCSVParser');
|
91
|
$this->assertField('encoding');
|
92
|
$this->assertNoText('PHP mbstring extension must be available for character encoding conversion.');
|
93
|
|
94
|
// Try to import a CSV file that is not UTF-8 encoded. Import should be
|
95
|
// halted and an encoding warning should be shown.
|
96
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/encoding_SJIS.csv');
|
97
|
$this->assertNoText('Failed importing 4 nodes.');
|
98
|
$this->assertText('Source file is not in UTF-8 encoding.');
|
99
|
}
|
100
|
}
|