|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Utils\ColumnSanitizerTest |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 7 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Team CSI <[email protected]> |
|
15
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Utils; |
|
22
|
|
|
|
|
23
|
|
|
use PHPUnit\Framework\TestCase; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Test class for the column sanitizer utility. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Team CSI <[email protected]> |
|
29
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class ColumnSanitizerTest extends TestCase |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The utility we want to test. |
|
39
|
|
|
* |
|
40
|
|
|
* @var \TechDivision\Import\Utils\SanitizerInterface |
|
|
|
|
|
|
41
|
|
|
*/ |
|
42
|
|
|
protected $columnSanitizer; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Sets up the fixture, for example, open a network connection. |
|
46
|
|
|
* This method is called before a test is executed. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
* @see \PHPUnit\Framework\TestCase::setUp() |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function setUp() |
|
52
|
|
|
{ |
|
53
|
|
|
// initialize the utility we want to test |
|
54
|
|
|
$this->columnSanitizer = new ColumnSanitizer(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testExecuteGivenEmptyRowReturnsEmptyRow() |
|
58
|
|
|
{ |
|
59
|
|
|
$query = 'UPDATE some_table SET column_1=:column_1, column_2=:column_2 WHERE condition=:value'; |
|
60
|
|
|
$row = []; |
|
61
|
|
|
$expected = []; |
|
62
|
|
|
|
|
63
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals($expected, $actual); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testExecuteGivenEmptyStatementReturnsEmptyRow() |
|
69
|
|
|
{ |
|
70
|
|
|
$query = ''; |
|
71
|
|
|
$row = ['column_1' => 'foo', 'value' => 'bar']; |
|
72
|
|
|
$expected = []; |
|
73
|
|
|
|
|
74
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals($expected, $actual); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testExecuteGivenLessColumnsThanAllowedReturnsOnlyAllowedGivenColumns() |
|
80
|
|
|
{ |
|
81
|
|
|
$query = 'UPDATE some_table SET column_1=:column_1, column_2=:column_2 WHERE condition=:value'; |
|
82
|
|
|
$row = ['column_1' => 'foo', 'value' => 'bar']; |
|
83
|
|
|
$expected = ['column_1' => 'foo', 'value' => 'bar']; |
|
84
|
|
|
|
|
85
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals($expected, $actual); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testExecuteGivenAllAllowedColumnsReturnsAllColumns() |
|
91
|
|
|
{ |
|
92
|
|
|
$query = 'UPDATE some_table SET column_1=:column_1, column_2=:column_2 WHERE condition=:value'; |
|
93
|
|
|
$row = ['column_1' => 'foo', 'column_2' => 'baz', 'value' => 'bar']; |
|
94
|
|
|
$expected = ['column_1' => 'foo', 'column_2' => 'baz', 'value' => 'bar']; |
|
95
|
|
|
|
|
96
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals($expected, $actual); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function testExecuteGivenMoreThanAllowedColumnsReturnsOnlAllowedColumns() |
|
102
|
|
|
{ |
|
103
|
|
|
$query = 'UPDATE some_table SET column_1=:column_1, column_2=:column_2 WHERE condition=:value'; |
|
104
|
|
|
$row = ['column_1' => 'foo', 'column_2' => 'baz', 'value' => 'bar', 'additional' => 'another value']; |
|
105
|
|
|
$expected = ['column_1' => 'foo', 'column_2' => 'baz', 'value' => 'bar']; |
|
106
|
|
|
|
|
107
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals($expected, $actual); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function testExecuteGivenSpecialColumnReturnsDataIncludingSpecialColumn() |
|
113
|
|
|
{ |
|
114
|
|
|
$query = 'UPDATE some_table SET column_1=:column_1, column_2=:column_2 WHERE condition=:value'; |
|
115
|
|
|
$row = [ |
|
116
|
|
|
'column_1' => 'foo', |
|
117
|
|
|
'column_2' => 'baz', |
|
118
|
|
|
'value' => 'bar', |
|
119
|
|
|
'techdivision_import_utils_entityStatus_memberName' => 'update', |
|
120
|
|
|
]; |
|
121
|
|
|
$expected = [ |
|
122
|
|
|
'column_1' => 'foo', |
|
123
|
|
|
'column_2' => 'baz', |
|
124
|
|
|
'value' => 'bar', |
|
125
|
|
|
'techdivision_import_utils_entityStatus_memberName' => 'update', |
|
126
|
|
|
]; |
|
127
|
|
|
|
|
128
|
|
|
$actual = $this->columnSanitizer->execute($row, $query); |
|
129
|
|
|
|
|
130
|
|
|
$this->assertEquals($expected, $actual); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths