‪TYPO3CMS  10.4
FileReferenceTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪FileReferenceTest extends UnitTestCase
27 {
33  protected function ‪prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
34  {
35  $fixture = $this->getAccessibleMock(FileReference::class, ['dummy'], [], '', false);
36  $originalFileMock = $this->getAccessibleMock(File::class, [], [], '', false);
37  $originalFileMock->expects(self::any())
38  ->method('getProperties')
39  ->willReturn(
40  $originalFileProperties
41  );
42  $fixture->_set('originalFile', $originalFileMock);
43  $fixture->_set('propertiesOfFileReference', $fileReferenceProperties);
44 
45  return $fixture;
46  }
47 
51  public function ‪propertiesDataProvider()
52  {
53  return [
54  'File properties correctly override file reference properties' => [
55  [
56  'title' => null,
57  'description' => 'fileReferenceDescription',
58  'alternative' => '',
59  ],
60  [
61  'title' => 'fileTitle',
62  'description' => 'fileDescription',
63  'alternative' => 'fileAlternative',
64  'file_only_property' => 'fileOnlyPropertyValue',
65  ],
66  [
67  'title' => 'fileTitle',
68  'description' => 'fileReferenceDescription',
69  'alternative' => '',
70  'file_only_property' => 'fileOnlyPropertyValue',
71  ],
72  ]
73  ];
74  }
75 
83  public function ‪getPropertiesReturnsMergedPropertiesAndRespectsNullValues(array $fileReferenceProperties, array $originalFileProperties, array $expectedMergedProperties)
84  {
85  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
86  $actual = $fixture->getProperties();
87  self::assertSame($expectedMergedProperties, $actual);
88  }
89 
97  public function ‪hasPropertyReturnsTrueForAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
98  {
99  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
100  foreach ($expectedMergedProperties as $key => $_) {
101  self::assertTrue($fixture->hasProperty($key));
102  }
103  }
104 
112  public function ‪getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
113  {
114  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
115  foreach ($expectedMergedProperties as $key => $expectedValue) {
116  self::assertSame($expectedValue, $fixture->getProperty($key));
117  }
118  }
119 
127  public function ‪getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
128  {
129  $this->expectException(\InvalidArgumentException::class);
130  $this->expectExceptionCode(1314226805);
131 
132  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
133  $fixture->getProperty(‪StringUtility::getUniqueId('nothingHere'));
134  }
135 
143  public function ‪getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
144  {
145  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
146  self::assertSame($originalFileProperties['file_only_property'], $fixture->getProperty('file_only_property'));
147  }
148 
157  public function ‪getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
158  {
159  $this->expectException(\InvalidArgumentException::class);
160  $this->expectExceptionCode(1360684914);
161 
162  $fixture = $this->‪prepareFixture($fileReferenceProperties, $originalFileProperties);
163  $fixture->getReferenceProperty('file_only_property');
164  }
165 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile
‪getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:157
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile
‪getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:143
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyThrowsExceptionForNotAvailableProperty
‪getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:127
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\hasPropertyReturnsTrueForAllMergedPropertyKeys
‪hasPropertyReturnsTrueForAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
Definition: FileReferenceTest.php:97
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\prepareFixture
‪TYPO3 CMS Core Resource FileReference PHPUnit Framework MockObject MockObject TYPO3 TestingFramework Core AccessibleObjectInterface prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
Definition: FileReferenceTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest
Definition: FileReferenceTest.php:27
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyReturnsAllMergedPropertyKeys
‪getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
Definition: FileReferenceTest.php:112
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertiesReturnsMergedPropertiesAndRespectsNullValues
‪getPropertiesReturnsMergedPropertiesAndRespectsNullValues(array $fileReferenceProperties, array $originalFileProperties, array $expectedMergedProperties)
Definition: FileReferenceTest.php:83
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\propertiesDataProvider
‪array propertiesDataProvider()
Definition: FileReferenceTest.php:51