Révision a192dc0b
Ajouté par Assos Assos il y a environ 8 ans
drupal7/sites/all/modules/feeds/tests/parser_csv.test | ||
---|---|---|
32 | 32 |
|
33 | 33 |
$this->_testSimple(); |
34 | 34 |
$this->_testBatching(); |
35 |
$this->_testEncodingConversion(); |
|
36 |
$this->_testEncodingConversionFailure(); |
|
35 | 37 |
} |
36 | 38 |
|
37 | 39 |
/** |
... | ... | |
53 | 55 |
} |
54 | 56 |
} |
55 | 57 |
|
58 |
/** |
|
59 |
* Simple test of encoding conversion prior to parsing. |
|
60 |
*/ |
|
61 |
protected function _testEncodingConversion() { |
|
62 |
// Pull in the $control_result array. |
|
63 |
include $this->absolutePath() . '/tests/feeds/encoding.csv.php'; |
|
64 |
|
|
65 |
$encodings = $this->getEncodings(); |
|
66 |
foreach ($encodings as $encoding) { |
|
67 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv"; |
|
68 |
$iterator = new ParserCSVIterator($file); |
|
69 |
$parser = new ParserCSV(); |
|
70 |
$parser->setDelimiter(','); |
|
71 |
$parser->setEncoding($encoding); |
|
72 |
$rows = $parser->parse($iterator); |
|
73 |
$this->assertFalse($parser->lastLinePos(), format_string('CSV reports all lines parsed, with encoding: %encoding', array('%encoding' => $encoding))); |
|
74 |
$this->assertEqual(md5(serialize($rows)), md5(serialize($control_result)), 'Converted and parsed result matches control result.'); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Simple test of failed encoding conversion prior to parsing. |
|
80 |
*/ |
|
81 |
protected function _testEncodingConversionFailure() { |
|
82 |
// Pull in the $control_result array. |
|
83 |
include $this->absolutePath() . '/tests/feeds/encoding.csv.php'; |
|
84 |
|
|
85 |
$encodings = $this->getEncodings(); |
|
86 |
foreach ($encodings as $encoding) { |
|
87 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv"; |
|
88 |
$iterator = new ParserCSVIterator($file); |
|
89 |
$parser = new ParserCSV(); |
|
90 |
$parser->setDelimiter(','); |
|
91 |
// Attempt to read file as UTF-8. |
|
92 |
$parser->setEncoding('UTF-8'); |
|
93 |
try { |
|
94 |
$rows = $parser->parse($iterator); |
|
95 |
$this->fail('Incorrect conversion attempt throws exception.'); |
|
96 |
} |
|
97 |
catch (ParserCSVEncodingException $e) { |
|
98 |
$this->assertNotNull($e->getMessage(), 'Incorrect conversion attempt throws exception.'); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
56 | 103 |
/** |
57 | 104 |
* Test batching. |
58 | 105 |
*/ |
... | ... | |
100 | 147 |
'tab' => "\t", |
101 | 148 |
); |
102 | 149 |
} |
150 |
|
|
151 |
static function getEncodings() { |
|
152 |
return array( |
|
153 |
'SJIS-win', |
|
154 |
'SJIS', |
|
155 |
); |
|
156 |
} |
|
103 | 157 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules