Révision ed9a13f1
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/feeds/tests/parser_csv.test | ||
---|---|---|
12 | 12 |
* Not inheriting from Feeds base class as ParserCSV should be moved out of |
13 | 13 |
* Feeds at some time. |
14 | 14 |
*/ |
15 |
class ParserCSVTest extends DrupalWebTestCase {
|
|
15 |
class ParserCSVTest extends DrupalWebTestCase { |
|
16 | 16 |
protected $profile = 'testing'; |
17 | 17 |
|
18 |
/** |
|
19 |
* {@inheritdoc} |
|
20 |
*/ |
|
18 | 21 |
public static function getInfo() { |
19 | 22 |
return array( |
20 | 23 |
'name' => 'CSV Parser unit tests', |
... | ... | |
44 | 47 |
include $this->absolutePath() . '/tests/feeds/nodes.csv.php'; |
45 | 48 |
|
46 | 49 |
$delimiters = $this->getDelimiters(); |
47 |
foreach($delimiters as $delimiterType => $delimiter) { |
|
48 |
$file = $this->absolutePath() . '/tests/feeds/nodes_' . $delimiterType . '.csv';
|
|
50 |
foreach ($delimiters as $delimiterType => $delimiter) {
|
|
51 |
$file = $this->absolutePath() . '/tests/feeds/nodes_' . $delimiterType . '.csv'; |
|
49 | 52 |
$iterator = new ParserCSVIterator($file); |
50 | 53 |
$parser = new ParserCSV(); |
51 | 54 |
$parser->setDelimiter($delimiter); |
... | ... | |
64 | 67 |
|
65 | 68 |
$encodings = $this->getEncodings(); |
66 | 69 |
foreach ($encodings as $encoding) { |
67 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv";
|
|
70 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv"; |
|
68 | 71 |
$iterator = new ParserCSVIterator($file); |
69 | 72 |
$parser = new ParserCSV(); |
70 | 73 |
$parser->setDelimiter(','); |
... | ... | |
84 | 87 |
|
85 | 88 |
$encodings = $this->getEncodings(); |
86 | 89 |
foreach ($encodings as $encoding) { |
87 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv";
|
|
90 |
$file = $this->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv"; |
|
88 | 91 |
$iterator = new ParserCSVIterator($file); |
89 | 92 |
$parser = new ParserCSV(); |
90 | 93 |
$parser->setDelimiter(','); |
... | ... | |
104 | 107 |
* Test batching. |
105 | 108 |
*/ |
106 | 109 |
protected function _testBatching() { |
107 |
// Pull in the $control_result array |
|
110 |
// Pull in the $control_result array.
|
|
108 | 111 |
include $this->absolutePath() . '/tests/feeds/nodes.csv.php'; |
109 | 112 |
|
110 | 113 |
$delimiters = $this->getDelimiters(); |
111 |
foreach($delimiters as $delimiterType => $delimiter) { |
|
112 |
$file = $this->absolutePath() . '/tests/feeds/nodes_' . $delimiterType . '.csv';
|
|
114 |
foreach ($delimiters as $delimiterType => $delimiter) {
|
|
115 |
$file = $this->absolutePath() . '/tests/feeds/nodes_' . $delimiterType . '.csv'; |
|
113 | 116 |
// Set up parser with 2 lines to parse per call. |
114 | 117 |
$iterator = new ParserCSVIterator($file); |
115 | 118 |
$parser = new ParserCSV(); |
... | ... | |
124 | 127 |
$rows = array_merge($rows, $parser->parse($iterator)); |
125 | 128 |
$pos = $parser->lastLinePos(); |
126 | 129 |
$this->assertTrue($parser->lastLinePos() || count($rows) == 10, t('Parser reports line limit correctly')); |
127 |
} |
|
128 |
while ($pos = $parser->lastLinePos()); |
|
130 |
} while ($pos = $parser->lastLinePos()); |
|
129 | 131 |
|
130 | 132 |
$this->assertEqual(md5(serialize($rows)), md5(serialize($control_result)), t('Batch parsed result matches control result for delimiter: ') . $delimiterType); |
131 | 133 |
} |
... | ... | |
138 | 140 |
return DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds'); |
139 | 141 |
} |
140 | 142 |
|
141 |
static function getDelimiters() { |
|
143 |
/** |
|
144 |
* {@inheritdoc} |
|
145 |
*/ |
|
146 |
public static function getDelimiters() { |
|
142 | 147 |
return array( |
143 | 148 |
'comma' => ',', |
144 | 149 |
'pipe' => '|', |
... | ... | |
148 | 153 |
); |
149 | 154 |
} |
150 | 155 |
|
151 |
static function getEncodings() { |
|
156 |
/** |
|
157 |
* {@inheritdoc} |
|
158 |
*/ |
|
159 |
public static function getEncodings() { |
|
152 | 160 |
return array( |
153 | 161 |
'SJIS-win', |
154 | 162 |
'SJIS', |
155 | 163 |
); |
156 | 164 |
} |
165 |
|
|
157 | 166 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules