‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪FileReferenceTest extends UnitTestCase
23 {
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 
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 
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 
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 
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 
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 
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 
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 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile
‪getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:153
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile
‪getPropertyDoesNotThrowExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:139
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyThrowsExceptionForNotAvailableProperty
‪getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
Definition: FileReferenceTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\hasPropertyReturnsTrueForAllMergedPropertyKeys
‪hasPropertyReturnsTrueForAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
Definition: FileReferenceTest.php:93
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest
Definition: FileReferenceTest.php:23
‪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:29
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertyReturnsAllMergedPropertyKeys
‪getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)
Definition: FileReferenceTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\getPropertiesReturnsMergedPropertiesAndRespectsNullValues
‪getPropertiesReturnsMergedPropertiesAndRespectsNullValues(array $fileReferenceProperties, array $originalFileProperties, array $expectedMergedProperties)
Definition: FileReferenceTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Resource\FileReferenceTest\propertiesDataProvider
‪array propertiesDataProvider()
Definition: FileReferenceTest.php:47