1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfBanners\Test\Unit\Domain\Model; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the Extension "sf_banners" for TYPO3 CMS. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use DERHANSEN\SfBanners\Domain\Model\Banner; |
12
|
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase; |
13
|
|
|
use TYPO3\CMS\Core\Resource\File; |
14
|
|
|
use TYPO3\CMS\Extbase\Domain\Model\FileReference; |
15
|
|
|
use TYPO3\CMS\Extbase\Persistence\ObjectStorage; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for class \DERHANSEN\SfBanners\Domain\Model\Banner. |
19
|
|
|
*/ |
20
|
|
|
class BannerTest extends UnitTestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var \DERHANSEN\SfBanners\Domain\Model\Banner |
24
|
|
|
*/ |
25
|
|
|
protected $fixture; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Set up |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->fixture = new Banner(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Tear down |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function tearDown() |
43
|
|
|
{ |
44
|
|
|
unset($this->fixture); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test if title can be set |
49
|
|
|
* |
50
|
|
|
* @test |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function titleCanBeSetTest() |
54
|
|
|
{ |
55
|
|
|
$title = 'a title'; |
56
|
|
|
$this->fixture->setTitle($title); |
57
|
|
|
$this->assertEquals($title, $this->fixture->getTitle()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test if description can be set |
62
|
|
|
* |
63
|
|
|
* @test |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function descriptionCanBeSetTest() |
67
|
|
|
{ |
68
|
|
|
$description = 'a description'; |
69
|
|
|
$this->fixture->setDescription($description); |
70
|
|
|
$this->assertEquals($description, $this->fixture->getDescription()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test if type can be set |
75
|
|
|
* |
76
|
|
|
* @test |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
public function typeCanBeSetTest() |
80
|
|
|
{ |
81
|
|
|
$type = 0; |
82
|
|
|
$this->fixture->setType($type); |
83
|
|
|
$this->assertEquals($type, $this->fixture->getType()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Test if margin can be set |
88
|
|
|
* |
89
|
|
|
* @test |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
public function marginTopCanBeSetTest() |
93
|
|
|
{ |
94
|
|
|
$margin = 100; |
95
|
|
|
$this->fixture->setMarginTop($margin); |
96
|
|
|
$this->assertEquals($margin, $this->fixture->getMarginTop()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test if margin can be set |
101
|
|
|
* |
102
|
|
|
* @test |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function marginRightCanBeSetTest() |
106
|
|
|
{ |
107
|
|
|
$margin = 100; |
108
|
|
|
$this->fixture->setMarginRight($margin); |
109
|
|
|
$this->assertEquals($margin, $this->fixture->getMarginRight()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Test if margin can be set |
114
|
|
|
* |
115
|
|
|
* @test |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function marginBottomCanBeSetTest() |
119
|
|
|
{ |
120
|
|
|
$margin = 100; |
121
|
|
|
$this->fixture->setMarginBottom($margin); |
122
|
|
|
$this->assertEquals($margin, $this->fixture->getMarginBottom()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Test if margin can be set |
127
|
|
|
* |
128
|
|
|
* @test |
129
|
|
|
* @return void |
130
|
|
|
*/ |
131
|
|
|
public function marginLeftCanBeSetTest() |
132
|
|
|
{ |
133
|
|
|
$margin = 100; |
134
|
|
|
$this->fixture->setMarginLeft($margin); |
135
|
|
|
$this->assertEquals($margin, $this->fixture->getMarginLeft()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @test |
140
|
|
|
*/ |
141
|
|
|
public function getLinkRespectsFalMediaSetting() |
142
|
|
|
{ |
143
|
|
|
$mockFile = $this->getMockBuilder(File::class) |
144
|
|
|
->setMethods(['getForLocalProcessing', 'getLink']) |
145
|
|
|
->disableOriginalConstructor() |
146
|
|
|
->getMock(); |
147
|
|
|
$mockFile->expects($this->any())->method('getForLocalProcessing')->will($this->returnValue('/path/to/somefile.png')); |
148
|
|
|
$mockFile->expects($this->any())->method('getLink')->will($this->returnValue('https://www.typo3.org')); |
149
|
|
|
|
150
|
|
|
$mockFileRef = $this->getMockBuilder(FileReference::class) |
151
|
|
|
->setMethods(['getOriginalResource']) |
152
|
|
|
->disableOriginalConstructor() |
153
|
|
|
->getMock(); |
154
|
|
|
$mockFileRef->expects($this->any())->method('getOriginalResource')->will($this->returnValue($mockFile)); |
155
|
|
|
|
156
|
|
|
$this->fixture->setType(0); |
157
|
|
|
$this->fixture->addAsset($mockFileRef); |
158
|
|
|
$this->assertEquals('https://www.typo3.org', $this->fixture->getLink()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Test if html can be set |
163
|
|
|
* |
164
|
|
|
* @test |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
public function htmlCanBeSetTest() |
168
|
|
|
{ |
169
|
|
|
$html = '<p>test</p>'; |
170
|
|
|
$this->fixture->setHtml($html); |
171
|
|
|
$this->assertEquals($html, $this->fixture->getHtml()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Test if impressionsmax can be set |
176
|
|
|
* |
177
|
|
|
* @test |
178
|
|
|
* @return void |
179
|
|
|
*/ |
180
|
|
|
public function impressionsMaxCanBeSetTest() |
181
|
|
|
{ |
182
|
|
|
$impressionsMax = 100; |
183
|
|
|
$this->fixture->setImpressionsMax($impressionsMax); |
184
|
|
|
$this->assertEquals($impressionsMax, $this->fixture->getImpressionsMax()); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Test if clicksmax can be set |
189
|
|
|
* |
190
|
|
|
* @test |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
|
|
public function clicksMaxCanBeSetTest() |
194
|
|
|
{ |
195
|
|
|
$clicksMax = 100; |
196
|
|
|
$this->fixture->setClicksMax($clicksMax); |
197
|
|
|
$this->assertEquals($clicksMax, $this->fixture->getClicksMax()); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Test if impressions can be set |
202
|
|
|
* |
203
|
|
|
* @test |
204
|
|
|
* @return void |
205
|
|
|
*/ |
206
|
|
|
public function impressionsCanBeSetTest() |
207
|
|
|
{ |
208
|
|
|
$impressions = 100; |
209
|
|
|
$this->fixture->setImpressions($impressions); |
210
|
|
|
$this->assertEquals($impressions, $this->fixture->getImpressions()); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Test if clicks can be set |
215
|
|
|
* |
216
|
|
|
* @test |
217
|
|
|
* @return void |
218
|
|
|
*/ |
219
|
|
|
public function clicksCanBeSetTest() |
220
|
|
|
{ |
221
|
|
|
$clicks = 100; |
222
|
|
|
$this->fixture->setClicks($clicks); |
223
|
|
|
$this->assertEquals($clicks, $this->fixture->getClicks()); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Test if recursive flag can be set |
228
|
|
|
* |
229
|
|
|
* @test |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
|
|
public function recursiveCanBeSet() |
233
|
|
|
{ |
234
|
|
|
$this->fixture->setRecursive(true); |
235
|
|
|
$this->assertTrue($this->fixture->getRecursive()); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @test |
240
|
|
|
*/ |
241
|
|
|
public function getCategoryReturnsInitialValueForCategory() |
242
|
|
|
{ |
243
|
|
|
$newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
244
|
|
|
$this->assertEquals( |
245
|
|
|
$newObjectStorage, |
246
|
|
|
$this->fixture->getCategory() |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @test |
252
|
|
|
*/ |
253
|
|
|
public function setCategoryForObjectStorageContainingCategorySetsCategory() |
254
|
|
|
{ |
255
|
|
|
$category = new \TYPO3\CMS\Extbase\Domain\Model\Category(); |
256
|
|
|
$objectStorageHoldingExactlyOneCategory = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
257
|
|
|
$objectStorageHoldingExactlyOneCategory->attach($category); |
258
|
|
|
$this->fixture->setCategory($objectStorageHoldingExactlyOneCategory); |
259
|
|
|
$this->assertEquals($objectStorageHoldingExactlyOneCategory, $this->fixture->getCategory()); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @test |
264
|
|
|
*/ |
265
|
|
View Code Duplication |
public function addCategoryToObjectStorageHoldingCategory() |
|
|
|
|
266
|
|
|
{ |
267
|
|
|
$category = new \TYPO3\CMS\Extbase\Domain\Model\Category(); |
268
|
|
|
$categoryObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['attach'])->getMock(); |
269
|
|
|
$categoryObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($category)); |
270
|
|
|
$this->inject($this->fixture, 'category', $categoryObjectStorageMock); |
271
|
|
|
$this->fixture->addCategory($category); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @test |
276
|
|
|
*/ |
277
|
|
View Code Duplication |
public function removeCategoryFromObjectStorageHoldingCategory() |
|
|
|
|
278
|
|
|
{ |
279
|
|
|
$category = new \TYPO3\CMS\Extbase\Domain\Model\Category(); |
280
|
|
|
$categoryObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['detach'])->getMock(); |
281
|
|
|
$categoryObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($category)); |
282
|
|
|
$this->inject($this->fixture, 'category', $categoryObjectStorageMock); |
283
|
|
|
$this->fixture->removeCategory($category); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @test |
288
|
|
|
*/ |
289
|
|
|
public function getExcludePagesReturnsInitialValueForExcudePages() |
290
|
|
|
{ |
291
|
|
|
$newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
292
|
|
|
$this->assertEquals( |
293
|
|
|
$newObjectStorage, |
294
|
|
|
$this->fixture->getExcludepages() |
295
|
|
|
); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @test |
300
|
|
|
*/ |
301
|
|
|
public function setExcludePagesForObjectStorageContainingExcludePagesSetsExcludePages() |
302
|
|
|
{ |
303
|
|
|
$page = new \DERHANSEN\SfBanners\Domain\Model\Page(); |
304
|
|
|
$objectStorageHoldingExactlyOnePage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
305
|
|
|
$objectStorageHoldingExactlyOnePage->attach($page); |
306
|
|
|
$this->fixture->setExcludepages($objectStorageHoldingExactlyOnePage); |
307
|
|
|
$this->assertEquals($objectStorageHoldingExactlyOnePage, $this->fixture->getExcludepages()); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @test |
312
|
|
|
*/ |
313
|
|
View Code Duplication |
public function addExludePagesToObjectStorageHoldingExcludePages() |
|
|
|
|
314
|
|
|
{ |
315
|
|
|
$page = new \DERHANSEN\SfBanners\Domain\Model\Page(); |
316
|
|
|
$pageObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['attach'])->getMock(); |
317
|
|
|
$pageObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($page)); |
318
|
|
|
$this->inject($this->fixture, 'excludepages', $pageObjectStorageMock); |
319
|
|
|
$this->fixture->addExcludepages($page); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @test |
324
|
|
|
*/ |
325
|
|
View Code Duplication |
public function removeExludePagesFromObjectStorageHoldingExcludePages() |
|
|
|
|
326
|
|
|
{ |
327
|
|
|
$page = new \DERHANSEN\SfBanners\Domain\Model\Page(); |
328
|
|
|
$pageObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['detach'])->getMock(); |
329
|
|
|
$pageObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($page)); |
330
|
|
|
$this->inject($this->fixture, 'excludepages', $pageObjectStorageMock); |
331
|
|
|
$this->fixture->removeExcludepages($page); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @test |
336
|
|
|
*/ |
337
|
|
|
public function getAssetsReturnsInitialValueForAsset() |
338
|
|
|
{ |
339
|
|
|
$newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
340
|
|
|
$this->assertEquals( |
341
|
|
|
$newObjectStorage, |
342
|
|
|
$this->fixture->getAssets() |
343
|
|
|
); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @test |
348
|
|
|
*/ |
349
|
|
|
public function setAssetForObjectStorageContainingAssetSetsAsset() |
350
|
|
|
{ |
351
|
|
|
$file = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); |
352
|
|
|
$objectStorageHoldingExactlyOneFile = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
353
|
|
|
$objectStorageHoldingExactlyOneFile->attach($file); |
354
|
|
|
$this->fixture->setAssets($objectStorageHoldingExactlyOneFile); |
355
|
|
|
$this->assertEquals($objectStorageHoldingExactlyOneFile, $this->fixture->getAssets()); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @test |
360
|
|
|
*/ |
361
|
|
View Code Duplication |
public function addAssetToObjectStorageHoldingAsses() |
|
|
|
|
362
|
|
|
{ |
363
|
|
|
$file = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); |
364
|
|
|
$assetsObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['attach'])->getMock(); |
365
|
|
|
$assetsObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($file)); |
366
|
|
|
$this->inject($this->fixture, 'assets', $assetsObjectStorageMock); |
367
|
|
|
$this->fixture->addAsset($file); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @test |
372
|
|
|
*/ |
373
|
|
View Code Duplication |
public function removeAssetFromObjectStorageHoldingAsset() |
|
|
|
|
374
|
|
|
{ |
375
|
|
|
$file = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); |
376
|
|
|
$assetsObjectStorageMock = $this->getMockBuilder(ObjectStorage::class)->setMethods(['detach'])->getMock(); |
377
|
|
|
$assetsObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($file)); |
378
|
|
|
$this->inject($this->fixture, 'assets', $assetsObjectStorageMock); |
379
|
|
|
$this->fixture->removeAsset($file); |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.