[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / FileReferenceTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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\TestingFramework\Core\Unit\UnitTestCase;
18
19 /**
20 * Test case
21 */
22 class FileReferenceTest extends UnitTestCase
23 {
24 /**
25 * @param array $fileReferenceProperties
26 * @param array $originalFileProperties
27 * @return \TYPO3\CMS\Core\Resource\FileReference|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
28 */
29 protected function prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
30 {
31 $fixture = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\FileReference::class, ['dummy'], [], '', false);
32 $originalFileMock = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
33 $originalFileMock->expects($this->any())
34 ->method('getProperties')
35 ->will(
36 $this->returnValue($originalFileProperties)
37 );
38 $fixture->_set('originalFile', $originalFileMock);
39 $fixture->_set('propertiesOfFileReference', $fileReferenceProperties);
40
41 return $fixture;
42 }
43
44 /**
45 * @return array
46 */
47 public function propertiesDataProvider()
48 {
49 return [
50 'File properties correctly override file reference properties' => [
51 [
52 'title' => null,
53 'description' => 'fileReferenceDescription',
54 'alternative' => '',
55 ],
56 [
57 'title' => 'fileTitle',
58 'description' => 'fileDescription',
59 'alternative' => 'fileAlternative',
60 'file_only_property' => 'fileOnlyPropertyValue',
61 ],
62 [
63 'title' => 'fileTitle',
64 'description' => 'fileReferenceDescription',
65 'alternative' => '',
66 'file_only_property' => 'fileOnlyPropertyValue',
67 ],
68 ]
69 ];
70 }
71
72 /**
73 * @param array $fileReferenceProperties
74 * @param array $originalFileProperties
75 * @param array $expectedMergedProperties
76 * @test
77 * @dataProvider propertiesDataProvider
78 */
79 public function getPropertiesReturnsMergedPropertiesAndRespectsNullValues(array $fileReferenceProperties, array $originalFileProperties, array $expectedMergedProperties)
80 {
81 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
82 $actual = $fixture->getProperties();
83 $this->assertSame($expectedMergedProperties, $actual);
84 }
85
86 /**
87 * @param array $fileReferenceProperties
88 * @param array $originalFileProperties
89 * @param array $expectedMergedProperties
90 * @test
91 * @dataProvider propertiesDataProvider
92 */
93 public function hasPropertyReturnsTrueForAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
94 {
95 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
96 foreach ($expectedMergedProperties as $key => $_) {
97 $this->assertTrue($fixture->hasProperty($key));
98 }
99 }
100
101 /**
102 * @param array $fileReferenceProperties
103 * @param array $originalFileProperties
104 * @param array $expectedMergedProperties
105 * @test
106 * @dataProvider propertiesDataProvider
107 */
108 public function getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
109 {
110 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
111 foreach ($expectedMergedProperties as $key => $expectedValue) {
112 $this->assertSame($expectedValue, $fixture->getProperty($key));
113 }
114 }
115
116 /**
117 * @test
118 * @dataProvider propertiesDataProvider
119 *
120 * @param array $fileReferenceProperties
121 * @param array $originalFileProperties
122 */
123 public function getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
124 {
125 $this->expectException(\InvalidArgumentException::class);
126 $this->expectExceptionCode(1314226805);
127
128 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
129 $fixture->getProperty($this->getUniqueId('nothingHere'));
130 }
131
132 /**
133 * @test
134 * @dataProvider propertiesDataProvider
135 *
136 * @param array $fileReferenceProperties
137 * @param array $originalFileProperties
138 */
139 public function getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
140 {
141 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
142 $this->assertSame($originalFileProperties['file_only_property'], $fixture->getProperty('file_only_property'));
143 }
144
145 /**
146 * @test
147 * @dataProvider propertiesDataProvider
148 *
149 * @param array $fileReferenceProperties
150 * @param array $originalFileProperties
151 * @param array $expectedMergedProperties
152 */
153 public function getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
154 {
155 $this->expectException(\InvalidArgumentException::class);
156 $this->expectExceptionCode(1360684914);
157
158 $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
159 $fixture->getReferenceProperty('file_only_property');
160 }
161 }