TYPO3 CMS  TYPO3_7-6
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 
22 {
26  protected $singletonInstances = [];
27 
28  protected function setUp()
29  {
32  }
33 
34  protected function tearDown()
35  {
37  parent::tearDown();
38  }
39 
45  protected function prepareFixture(array $fileReferenceProperties, array $originalFileProperties)
46  {
47  $fixture = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\FileReference::class, ['dummy'], [], '', false);
48  $originalFileMock = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', 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 
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 
139  public function getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
140  {
141  $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
142  $fixture->getProperty($this->getUniqueId('nothingHere'));
143  }
144 
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 
166  public function getReferencePropertyThrowsExceptionForPropertyOnlyAvailableInOriginalFile($fileReferenceProperties, $originalFileProperties)
167  {
168  $fixture = $this->prepareFixture($fileReferenceProperties, $originalFileProperties);
169  $fixture->getReferenceProperty('file_only_property');
170  }
171 }
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)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
getPropertyThrowsExceptionForNotAvailableProperty($fileReferenceProperties, $originalFileProperties)
getPropertyReturnsAllMergedPropertyKeys($fileReferenceProperties, $originalFileProperties, $expectedMergedProperties)