Révision ba09eb79
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/views_data_export/tests/csv_export.test | ||
---|---|---|
208 | 208 |
|
209 | 209 |
} |
210 | 210 |
|
211 |
/** |
|
212 |
* Test to ensure that all new line characters are replaced in CSV files when requested. |
|
213 |
*/ |
|
214 |
protected function testReplaceNewLines() { |
|
215 |
$view = $this->getBasicExportView(); |
|
216 |
|
|
217 |
$display = $view->display['default']->handler; |
|
218 |
|
|
219 |
$display->override_option('fields', array( |
|
220 |
'id' => array( |
|
221 |
'id' => 'id', |
|
222 |
'table' => 'views_test', |
|
223 |
'field' => 'id', |
|
224 |
'relationship' => 'none', |
|
225 |
'label' => 'ID', |
|
226 |
), |
|
227 |
'name' => array( |
|
228 |
'id' => 'name', |
|
229 |
'table' => 'views_test', |
|
230 |
'field' => 'name', |
|
231 |
'relationship' => 'none', |
|
232 |
), |
|
233 |
'age' => array( |
|
234 |
'id' => 'age', |
|
235 |
'table' => 'views_test', |
|
236 |
'field' => 'age', |
|
237 |
'relationship' => 'none', |
|
238 |
), |
|
239 |
'job' => array( |
|
240 |
'id' => 'job', |
|
241 |
'table' => 'views_test', |
|
242 |
'field' => 'job', |
|
243 |
'relationship' => 'none', |
|
244 |
), |
|
245 |
)); |
|
246 |
|
|
247 |
$style_options = array( |
|
248 |
'replace_newlines' => TRUE, |
|
249 |
'newline_replacement' => ';', |
|
250 |
'newline_token' => 0, |
|
251 |
); |
|
252 |
|
|
253 |
$expected = <<<EOT |
|
254 |
"ID","Name","Age","Job" |
|
255 |
"1","John","25","Singer\r;Songwriter\r;Pianist" |
|
256 |
"2","George","27","Singer;Guitar player;Sitar player" |
|
257 |
"3","Ringo","28","Drummer" |
|
258 |
"4","Paul","26","Songwriter\rBass guitarist" |
|
259 |
"5","Meredith","30","Speaker" |
|
260 |
EOT; |
|
261 |
|
|
262 |
$message = 'Linefeed characters are replaced.'; |
|
263 |
|
|
264 |
$this->executeAndCompareGivenView($view, $expected, $message, $style_options); |
|
265 |
|
|
266 |
// And now replace all kind of newlines. |
|
267 |
$style_options = array( |
|
268 |
'replace_newlines' => TRUE, |
|
269 |
'newline_replacement' => ';', |
|
270 |
'newline_token' => 1, |
|
271 |
); |
|
272 |
|
|
273 |
$expected = '"ID","Name","Age","Job" |
|
274 |
"1","John","25","Singer;Songwriter;Pianist" |
|
275 |
"2","George","27","Singer;Guitar player;Sitar player" |
|
276 |
"3","Ringo","28","Drummer" |
|
277 |
"4","Paul","26","Songwriter;Bass guitarist" |
|
278 |
"5","Meredith","30","Speaker"'; |
|
279 |
|
|
280 |
$message = 'All newline characters are replaced.'; |
|
281 |
|
|
282 |
$this->executeAndCompareGivenView($view, $expected, $message, $style_options); |
|
283 |
} |
|
284 |
|
|
211 | 285 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules