TYPO3 CMS  TYPO3_8-7
FileReferenceTest.php
Go to the documentation of this file.
1 <?php
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 
20 class FileReferenceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $singletonInstances = [];
26 
27  protected function setUp()
28  {
31  }
32 
33  protected function tearDown()
34  {
36  parent::tearDown();
37  }
38 
44  protected function prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
45  {
46  $fixture = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\FileReference::class, ['dummy'], [], '', false);
47  $originalFileMock = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
48  $originalFileMock->expects($this->any())
49  ->method('getProperties')
50  ->will(
51  $this->returnValue($originalFileProperties)
52  );
53  $fixture->_set('originalFile', $originalFileMock);
54  $fixture->_set('propertiesOfFileReference', $fileReferenceProperties);
55 
56  return $fixture;
57  }
58 
62  public function propertiesDataProvider()
63  {
64  return [
65  'File properties correctly override file reference properties' => [
66  [
67  'title' => null,
68  'description' => 'fileReferenceDescription',
69  'alternative' => '',
70  ],
71  [
72  'title' => 'fileTitle',
73  'description' => 'fileDescription',
74  'alternative' => 'fileAlternative',
75  'file_only_property' => 'fileOnlyPropertyValue',
76  ],
77  [
78  'title' => 'fileTitle',
79  'description' => 'fileReferenceDescription',
80  'alternative' => '',
81  'file_only_property' => 'fileOnlyPropertyValue',
82  ],
83  ]
84  ];
85  }
86 
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 
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 
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 
138  public function getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
139  {
140  $this->expectException(\InvalidArgumentException::class);
141  $this->expectExceptionCode(1314226805);
142 
143  $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
144  $fixture->getProperty($this->getUniqueId('nothingHere'));
145  }
146 
154  public function getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
155  {
156  $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
157  $this->assertSame($originalFileProperties['file_only_property'], $fixture->getProperty('file_only_property'));
158  }
159 
168  public function getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
169  {
170  $this->expectException(\InvalidArgumentException::class);
171  $this->expectExceptionCode(1360684914);
172 
173  $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
174  $fixture->getReferenceProperty('file_only_property');
175  }
176 }
getPropertiesReturnsMergedPropertiesAndRespectsNullValues(array $fileReferenceProperties, array $originalFileProperties, array $expectedMergedProperties)
prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
hasPropertyReturnsTrueForAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
static resetSingletonInstances(array $newSingletonInstances)
getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)