TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CsvUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
18 
23 {
27  public function csvToArrayDataProvider()
28  {
29  return [
30  'Valid data' => [
31  'input' => 'Column A, Column B, Column C' . LF . 'Value, Value2, Value 3',
32  'fieldDelimiter' => ',',
33  'fieldEnclosure' => '"',
34  'maximumColumns' => 0,
35  'expectedResult' => [
36  ['Column A', ' Column B', ' Column C'],
37  ['Value', ' Value2', ' Value 3']
38  ]
39  ],
40 
41  'Valid data with enclosed "' => [
42  'input' => '"Column A", "Column B", "Column C"' . LF . '"Value", "Value2", "Value 3"',
43  'fieldDelimiter' => ',',
44  'fieldEnclosure' => '"',
45  'maximumColumns' => 0,
46  'expectedResult' => [
47  ['Column A', 'Column B', 'Column C'],
48  ['Value', 'Value2', 'Value 3']
49  ]
50  ],
51 
52  'Valid data with semicolons and enclosed "' => [
53  'input' => '"Column A"; "Column B"; "Column C"' . LF . '"Value"; "Value2"; "Value 3"',
54  'fieldDelimiter' => ';',
55  'fieldEnclosure' => '"',
56  'maximumColumns' => 0,
57  'expectedResult' => [
58  ['Column A', 'Column B', 'Column C'],
59  ['Value', 'Value2', 'Value 3']
60  ]
61  ],
62 
63  'Valid data with semicolons and enclosed " and two columns' => [
64  'input' => '"Column A"; "Column B"; "Column C"; "Column D"' . LF . '"Value"; "Value2"; "Value 3"',
65  'fieldDelimiter' => ';',
66  'fieldEnclosure' => '"',
67  'maximumColumns' => 2,
68  'expectedResult' => [
69  ['Column A', 'Column B'],
70  ['Value', 'Value2']
71  ]
72  ],
73 
74  'Data with comma but configured with semicolons and enclosed "' => [
75  'input' => '"Column A", "Column B", "Column C"' . LF . '"Value", "Value2", "Value 3"',
76  'fieldDelimiter' => ';',
77  'fieldEnclosure' => '"',
78  'maximumColumns' => 0,
79  'expectedResult' => [
80  ['Column A, "Column B", "Column C"'],
81  ['Value, "Value2", "Value 3"']
82  ]
83  ]
84  ];
85  }
86 
91  public function csvToArraySplitsAsExpected($input, $fieldDelimiter, $fieldEnclosure, $maximumColumns, $expectedResult)
92  {
93  $this->assertEquals($expectedResult, CsvUtility::csvToArray($input, $fieldDelimiter, $fieldEnclosure, $maximumColumns));
94  }
95 }
csvToArraySplitsAsExpected($input, $fieldDelimiter, $fieldEnclosure, $maximumColumns, $expectedResult)