[BUGFIX] Fix translation key typo
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / CsvUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\CsvUtility;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test cases of CsvUtility
22 */
23 class CsvUtilityTest extends UnitTestCase
24 {
25 /**
26 * @return array
27 */
28 public function csvToArrayDataProvider()
29 {
30 return [
31 'Valid data' => [
32 'input' => 'Column A, Column B, Column C' . LF . 'Value, Value2, Value 3',
33 'fieldDelimiter' => ',',
34 'fieldEnclosure' => '"',
35 'maximumColumns' => 0,
36 'expectedResult' => [
37 ['Column A', ' Column B', ' Column C'],
38 ['Value', ' Value2', ' Value 3']
39 ]
40 ],
41
42 'Valid data with enclosed "' => [
43 'input' => '"Column A", "Column B", "Column C"' . LF . '"Value", "Value2", "Value 3"',
44 'fieldDelimiter' => ',',
45 'fieldEnclosure' => '"',
46 'maximumColumns' => 0,
47 'expectedResult' => [
48 ['Column A', 'Column B', 'Column C'],
49 ['Value', 'Value2', 'Value 3']
50 ]
51 ],
52
53 'Valid data with semicolons and enclosed "' => [
54 'input' => '"Column A"; "Column B"; "Column C"' . LF . '"Value"; "Value2"; "Value 3"',
55 'fieldDelimiter' => ';',
56 'fieldEnclosure' => '"',
57 'maximumColumns' => 0,
58 'expectedResult' => [
59 ['Column A', 'Column B', 'Column C'],
60 ['Value', 'Value2', 'Value 3']
61 ]
62 ],
63
64 'Valid data with semicolons and enclosed " and two columns' => [
65 'input' => '"Column A"; "Column B"; "Column C"; "Column D"' . LF . '"Value"; "Value2"; "Value 3"',
66 'fieldDelimiter' => ';',
67 'fieldEnclosure' => '"',
68 'maximumColumns' => 2,
69 'expectedResult' => [
70 ['Column A', 'Column B'],
71 ['Value', 'Value2']
72 ]
73 ],
74
75 'Data with comma but configured with semicolons and enclosed "' => [
76 'input' => '"Column A", "Column B", "Column C"' . LF . '"Value", "Value2", "Value 3"',
77 'fieldDelimiter' => ';',
78 'fieldEnclosure' => '"',
79 'maximumColumns' => 0,
80 'expectedResult' => [
81 ['Column A, "Column B", "Column C"'],
82 ['Value, "Value2", "Value 3"']
83 ]
84 ]
85 ];
86 }
87
88 /**
89 * @dataProvider csvToArrayDataProvider
90 * @test
91 */
92 public function csvToArraySplitsAsExpected($input, $fieldDelimiter, $fieldEnclosure, $maximumColumns, $expectedResult)
93 {
94 $this->assertEquals($expectedResult, CsvUtility::csvToArray($input, $fieldDelimiter, $fieldEnclosure, $maximumColumns));
95 }
96 }