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