‪TYPO3CMS  9.5
PropertyMappingConfigurationTest.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 ‪PropertyMappingConfigurationTest extends UnitTestCase
23 {
28 
32  protected function ‪setUp()
33  {
34  $this->propertyMappingConfiguration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
35  }
36 
42  {
43  $this->assertEquals('someSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someSourceProperty'));
44  $this->assertEquals('someOtherSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someOtherSourceProperty'));
45  }
46 
51  public function ‪shouldMapReturnsFalseByDefault()
52  {
53  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
54  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
55  }
56 
61  public function ‪shouldMapReturnsTrueIfConfigured()
62  {
63  $this->propertyMappingConfiguration->allowAllProperties();
64  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
65  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
66  }
67 
73  {
74  $this->propertyMappingConfiguration->allowProperties('someSourceProperty', 'someOtherProperty');
75  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
76  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
77  }
78 
84  {
85  $this->propertyMappingConfiguration->allowAllPropertiesExcept('someSourceProperty', 'someOtherProperty');
86  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
87  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
88 
89  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherPropertyWhichHasNotBeenConfigured'));
90  }
91 
96  public function ‪shouldSkipReturnsFalseByDefault()
97  {
98  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
99  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
100  }
101 
106  public function ‪shouldSkipReturnsTrueIfConfigured()
107  {
108  $this->propertyMappingConfiguration->skipProperties('someSourceProperty', 'someOtherSourceProperty');
109  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
110  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
111  }
112 
117  {
118  $mockTypeConverterClass = $this->getMockClass(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class);
119 
120  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
121  $this->assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
122  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
123  }
124 
129  {
130  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue('foo', 'bar'));
131  }
132 
137  {
138  $mockTypeConverterClass = $this->getMockClass(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class);
139  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
140  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k3' => 'v3']);
141 
142  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k3'));
143  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
144  }
145 
150  {
151  $mockTypeConverterClass = $this->getMockClass(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class);
152  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
153  $this->propertyMappingConfiguration->setTypeConverterOption($mockTypeConverterClass, 'k1', 'v3');
154 
155  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
156  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
157  }
158 
163  {
164  $this->assertNull($this->propertyMappingConfiguration->getTypeConverter());
165  }
166 
171  {
172  $mockTypeConverter = $this->createMock(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class);
173  $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
174  $this->assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
175  }
176 
181  {
182  $childConfiguration = $this->propertyMappingConfiguration->forProperty('key1.key2');
183  $childConfiguration->setTypeConverterOption('someConverter', 'foo', 'specialChildConverter');
184 
185  return $childConfiguration;
186  }
187 
192  {
193  $this->propertyMappingConfiguration->setMapping('k1', 'k1a');
194  $this->assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
195  $this->assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
196  }
197 
201  public function ‪fluentInterfaceMethodsDataProvider()
202  {
203  $mockTypeConverterClass = $this->getMockClass(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class);
204 
205  return [
206  ['allowAllProperties'],
207  ['allowProperties'],
208  ['allowAllPropertiesExcept'],
209  ['setMapping', ['k1', 'k1a']],
210  ['setTypeConverterOptions', [$mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']]],
211  ['setTypeConverterOption', [$mockTypeConverterClass, 'k1', 'v3']],
212  ['setTypeConverter', [$this->createMock(\‪TYPO3\CMS\‪Extbase\Property\TypeConverterInterface::class)]],
213  ];
214  }
215 
220  public function ‪respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod = [])
221  {
222  $actualResult = call_user_func_array([$this->propertyMappingConfiguration, $methodToTestForFluentInterface], $argumentsForMethod);
223  $this->assertSame($this->propertyMappingConfiguration, $actualResult);
224  }
225 
230  {
231  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
232  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
233 
234  $configuration = $this->propertyMappingConfiguration->getConfigurationFor('items')->getConfigurationFor('6');
235  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
236  }
237 
242  {
243  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
244  $this->propertyMappingConfiguration->forProperty('items.*.foo')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
245 
246  $configuration = $this->propertyMappingConfiguration->forProperty('items.6.foo');
247  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
248  }
249 
254  {
255  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
256 
257  $configuration = $this->propertyMappingConfiguration->forProperty('items');
258  $this->assertTrue($configuration->shouldMap(6));
259  }
260 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTargetPropertyNameShouldRespectMapping
‪getTargetPropertyNameShouldRespectMapping()
Definition: PropertyMappingConfigurationTest.php:190
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsFalseForBlacklistedProperties
‪shouldMapReturnsFalseForBlacklistedProperties()
Definition: PropertyMappingConfigurationTest.php:82
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\fluentInterfaceMethodsDataProvider
‪array fluentInterfaceMethodsDataProvider()
Definition: PropertyMappingConfigurationTest.php:200
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\respectiveMethodsProvideFluentInterface
‪respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod=[])
Definition: PropertyMappingConfigurationTest.php:219
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldSkipReturnsFalseByDefault
‪shouldSkipReturnsFalseByDefault()
Definition: PropertyMappingConfigurationTest.php:95
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsTrueForAllowedProperties
‪shouldMapReturnsTrueForAllowedProperties()
Definition: PropertyMappingConfigurationTest.php:71
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\nonexistentTypeConverterOptionsReturnNull
‪nonexistentTypeConverterOptionsReturnNull()
Definition: PropertyMappingConfigurationTest.php:127
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest
Definition: PropertyMappingConfigurationTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithGetConfigurationFor
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithGetConfigurationFor()
Definition: PropertyMappingConfigurationTest.php:228
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionsShouldOverrideAlreadySetOptions
‪setTypeConverterOptionsShouldOverrideAlreadySetOptions()
Definition: PropertyMappingConfigurationTest.php:135
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTypeConverterReturnsNullIfNoTypeConverterSet
‪getTypeConverterReturnsNullIfNoTypeConverterSet()
Definition: PropertyMappingConfigurationTest.php:161
‪TYPO3\CMS\Extbase\Tests\Unit\Property
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithForProperty
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithForProperty()
Definition: PropertyMappingConfigurationTest.php:240
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionShouldOverrideAlreadySetOptions
‪setTypeConverterOptionShouldOverrideAlreadySetOptions()
Definition: PropertyMappingConfigurationTest.php:148
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsTrueIfConfigured
‪shouldMapReturnsTrueIfConfigured()
Definition: PropertyMappingConfigurationTest.php:60
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setUp
‪setUp()
Definition: PropertyMappingConfigurationTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsFalseByDefault
‪shouldMapReturnsFalseByDefault()
Definition: PropertyMappingConfigurationTest.php:50
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap()
Definition: PropertyMappingConfigurationTest.php:252
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\buildChildConfigurationForSingleProperty
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration buildChildConfigurationForSingleProperty()
Definition: PropertyMappingConfigurationTest.php:179
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\$propertyMappingConfiguration
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration $propertyMappingConfiguration
Definition: PropertyMappingConfigurationTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTypeConverterReturnsTypeConverterIfItHasBeenSet
‪getTypeConverterReturnsTypeConverterIfItHasBeenSet()
Definition: PropertyMappingConfigurationTest.php:169
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionsCanBeRetrievedAgain
‪setTypeConverterOptionsCanBeRetrievedAgain()
Definition: PropertyMappingConfigurationTest.php:115
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldSkipReturnsTrueIfConfigured
‪shouldSkipReturnsTrueIfConfigured()
Definition: PropertyMappingConfigurationTest.php:105
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration
‪getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration()
Definition: PropertyMappingConfigurationTest.php:40