1
|
|
|
<?php |
2
|
|
|
namespace TildBJ\Seeder\Tests\Unit\Provider; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2016 Dennis Römmich <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
use TildBJ\Seeder\Tests\Unit\AccessibleTraitForTest; |
28
|
|
|
use TildBJ\Seeder\Traits\Language; |
29
|
|
|
use TildBJ\Seeder\Provider\TableConfiguration; |
30
|
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Test case for class \TildBJ\Seeder\Tests\Provider\TableConfigurationTest |
34
|
|
|
* |
35
|
|
|
* @author Dennis Römmich <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class TableConfigurationTest extends UnitTestCase |
38
|
|
|
{ |
39
|
|
|
use Language, AccessibleTraitForTest; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var TableConfiguration $subject |
43
|
|
|
*/ |
44
|
|
|
protected $subject; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* TABLE |
48
|
|
|
*/ |
49
|
|
|
const TABLE = 'pages'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function setUp() |
55
|
|
|
{ |
56
|
|
|
$GLOBALS['LANG'] = new \TYPO3\CMS\Lang\LanguageService(); |
57
|
|
|
$GLOBALS['LANG']->init('de'); |
58
|
|
|
|
59
|
|
|
$GLOBALS['TCA'] = [ |
60
|
|
|
'pages' => [ |
61
|
|
|
'ctrl' => [ |
62
|
|
|
'title' => 'LLL:EXT:lang/locallang_tca.xlf:pages' |
63
|
|
|
], |
64
|
|
|
'columns' => [ |
65
|
|
|
'title' => [ |
66
|
|
|
'config' => [ |
67
|
|
|
'type' => 'array', |
68
|
|
|
'size' => '50', |
69
|
|
|
'max' => '255', |
70
|
|
|
'eval' => 'trim,required', |
71
|
|
|
], |
72
|
|
|
], |
73
|
|
|
'doctype' => [ |
74
|
|
|
'exclude' => 1, |
75
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.type', |
76
|
|
|
'config' => [ |
77
|
|
|
'type' => 'select', |
78
|
|
|
'renderType' => 'selectSingle', |
79
|
|
|
'default' => '1' |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
], |
84
|
|
|
'fe_users' => [], |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
$this->subject = new TableConfiguration('pages'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @test |
92
|
|
|
*/ |
93
|
|
|
public function createTableConfigurationThrowsExceptionWhenTableNameNotExist() |
94
|
|
|
{ |
95
|
|
|
$this->expectException(\InvalidArgumentException::class); |
96
|
|
|
new TableConfiguration('LoremIpsum'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @test |
101
|
|
|
*/ |
102
|
|
|
public function createTableConfigurationThrowsExceptionWhenArgumentIsNoString() |
103
|
|
|
{ |
104
|
|
|
$this->expectException(\InvalidArgumentException::class); |
105
|
|
|
$this->subject->getColumnConfiguration(123); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
*/ |
111
|
|
|
public function tableConfigurationContainsArray() |
112
|
|
|
{ |
113
|
|
|
$tableConfiguration = $this->accessProtectedProperty($this->subject, 'tableConfiguration'); |
114
|
|
|
$this->assertTrue(is_array($tableConfiguration)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function tablePropertyContainsString() |
121
|
|
|
{ |
122
|
|
|
$table = $this->accessProtectedProperty($this->subject, 'name'); |
123
|
|
|
$this->assertSame(self::TABLE, $table); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @test |
128
|
|
|
*/ |
129
|
|
|
public function getNameReturnsTableName() |
130
|
|
|
{ |
131
|
|
|
$this->assertSame(self::TABLE, $this->subject->getName()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @test |
136
|
|
|
*/ |
137
|
|
|
public function getTitleReturnsTitleOfTable() |
138
|
|
|
{ |
139
|
|
|
$this->assertSame('Page', $this->subject->getTitle()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @test |
144
|
|
|
*/ |
145
|
|
|
public function getColumnsReturnsArray() |
146
|
|
|
{ |
147
|
|
|
$this->assertSame(['title', 'doctype'], $this->subject->getColumns()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @test |
152
|
|
|
*/ |
153
|
|
|
public function getColumnConfigurationThrowsExceptionWhenTableNotExist() |
154
|
|
|
{ |
155
|
|
|
$column = 'FooBar'; |
156
|
|
|
$this->expectException( |
157
|
|
|
'InvalidArgumentException', |
158
|
|
|
'Column ' . $column . ' does not exist for table ' . self::TABLE |
|
|
|
|
159
|
|
|
); |
160
|
|
|
$this->assertSame($this->getExpectedException(), $this->subject->getColumnConfiguration($column)); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @test |
165
|
|
|
*/ |
166
|
|
|
public function getColumnConfigurationReturnsArray() |
167
|
|
|
{ |
168
|
|
|
$expected = [ |
169
|
|
|
'title' => [ |
170
|
|
|
'type' => 'array', |
171
|
|
|
'size' => '50', |
172
|
|
|
'max' => '255', |
173
|
|
|
'eval' => 'trim,required', |
174
|
|
|
], |
175
|
|
|
]; |
176
|
|
|
$this->assertSame($expected, $this->subject->getColumnConfiguration('title')); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @test |
181
|
|
|
*/ |
182
|
|
|
public function getAllTablesReturnsArray() |
183
|
|
|
{ |
184
|
|
|
$this->assertSame(['pages' => 'pages', 'fe_users' => 'fe_users'], $this->subject->getAllTables()); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.