‪TYPO3CMS  11.5
PropertyMappingConfigurationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪PropertyMappingConfigurationTest extends UnitTestCase
28 {
30 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->propertyMappingConfiguration = new ‪PropertyMappingConfiguration();
38  }
39 
45  {
46  self::assertEquals('someSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someSourceProperty'));
47  self::assertEquals('someOtherSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someOtherSourceProperty'));
48  }
49 
54  public function ‪shouldMapReturnsFalseByDefault(): void
55  {
56  self::assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
57  self::assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
58  }
59 
64  public function ‪shouldMapReturnsTrueIfConfigured(): void
65  {
66  $this->propertyMappingConfiguration->allowAllProperties();
67  self::assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
68  self::assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
69  }
70 
76  {
77  $this->propertyMappingConfiguration->allowProperties('someSourceProperty', 'someOtherProperty');
78  self::assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
79  self::assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
80  }
81 
87  {
88  $this->propertyMappingConfiguration->allowAllPropertiesExcept('someSourceProperty', 'someOtherProperty');
89  self::assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
90  self::assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
91 
92  self::assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherPropertyWhichHasNotBeenConfigured'));
93  }
94 
99  public function ‪shouldSkipReturnsFalseByDefault(): void
100  {
101  self::assertFalse($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
102  self::assertFalse($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
103  }
104 
109  public function ‪shouldSkipReturnsTrueIfConfigured(): void
110  {
111  $this->propertyMappingConfiguration->skipProperties('someSourceProperty', 'someOtherSourceProperty');
112  self::assertTrue($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
113  self::assertTrue($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
114  }
115 
120  {
121  $mockTypeConverterClass = get_class($this->createMock(TypeConverterInterface::class));
122 
123  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
124  self::assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
125  self::assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
126  }
127 
132  {
133  self::assertNull($this->propertyMappingConfiguration->getConfigurationValue('foo', 'bar'));
134  }
135 
140  {
141  $mockTypeConverterClass = get_class($this->createMock(TypeConverterInterface::class));
142  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
143  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k3' => 'v3']);
144 
145  self::assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k3'));
146  self::assertNull($this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
147  }
148 
153  {
154  $mockTypeConverterClass = get_class($this->createMock(TypeConverterInterface::class));
155  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
156  $this->propertyMappingConfiguration->setTypeConverterOption($mockTypeConverterClass, 'k1', 'v3');
157 
158  self::assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
159  self::assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
160  }
161 
166  {
167  self::assertNull($this->propertyMappingConfiguration->getTypeConverter());
168  }
169 
174  {
175  $mockTypeConverter = $this->createMock(TypeConverterInterface::class);
176  $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
177  self::assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
178  }
179 
184  {
185  $childConfiguration = $this->propertyMappingConfiguration->forProperty('key1.key2');
186  $childConfiguration->setTypeConverterOption('someConverter', 'foo', 'specialChildConverter');
187 
188  return $childConfiguration;
189  }
190 
195  {
196  $this->propertyMappingConfiguration->setMapping('k1', 'k1a');
197  self::assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
198  self::assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
199  }
200 
204  public function ‪fluentInterfaceMethodsDataProvider(): array
205  {
206  $mockTypeConverter = $this->createMock(TypeConverterInterface::class);
207  $mockTypeConverterClass = get_class($mockTypeConverter);
208 
209  return [
210  ['allowAllProperties'],
211  ['allowProperties'],
212  ['allowAllPropertiesExcept'],
213  ['setMapping', ['k1', 'k1a']],
214  ['setTypeConverterOptions', [$mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']]],
215  ['setTypeConverterOption', [$mockTypeConverterClass, 'k1', 'v3']],
216  ['setTypeConverter', [$mockTypeConverter]],
217  ];
218  }
219 
224  public function ‪respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod = []): void
225  {
226  $actualResult = $this->propertyMappingConfiguration->$methodToTestForFluentInterface(...$argumentsForMethod);
227  self::assertSame($this->propertyMappingConfiguration, $actualResult);
228  }
229 
234  {
235  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
236  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions(\stdClass::class, ['k1' => 'v1']);
237 
238  $configuration = $this->propertyMappingConfiguration->getConfigurationFor('items')->getConfigurationFor('6');
239  self::assertSame('v1', $configuration->getConfigurationValue(\stdClass::class, 'k1'));
240  }
241 
246  {
247  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
248  $this->propertyMappingConfiguration->forProperty('items.*.foo')->setTypeConverterOptions(\stdClass::class, ['k1' => 'v1']);
249 
250  $configuration = $this->propertyMappingConfiguration->forProperty('items.6.foo');
251  self::assertSame('v1', $configuration->getConfigurationValue(\stdClass::class, 'k1'));
252  }
253 
258  {
259  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions(\stdClass::class, ['k1' => 'v1']);
260 
261  $configuration = $this->propertyMappingConfiguration->forProperty('items');
262  self::assertTrue($configuration->shouldMap(6));
263  }
264 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTargetPropertyNameShouldRespectMapping
‪getTargetPropertyNameShouldRespectMapping()
Definition: PropertyMappingConfigurationTest.php:194
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsFalseForBlacklistedProperties
‪shouldMapReturnsFalseForBlacklistedProperties()
Definition: PropertyMappingConfigurationTest.php:86
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\$propertyMappingConfiguration
‪PropertyMappingConfiguration $propertyMappingConfiguration
Definition: PropertyMappingConfigurationTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\fluentInterfaceMethodsDataProvider
‪array fluentInterfaceMethodsDataProvider()
Definition: PropertyMappingConfigurationTest.php:204
‪TYPO3\CMS\Extbase\Property\TypeConverterInterface
Definition: TypeConverterInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\respectiveMethodsProvideFluentInterface
‪respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod=[])
Definition: PropertyMappingConfigurationTest.php:224
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldSkipReturnsFalseByDefault
‪shouldSkipReturnsFalseByDefault()
Definition: PropertyMappingConfigurationTest.php:99
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsTrueForAllowedProperties
‪shouldMapReturnsTrueForAllowedProperties()
Definition: PropertyMappingConfigurationTest.php:75
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\nonexistentTypeConverterOptionsReturnNull
‪nonexistentTypeConverterOptionsReturnNull()
Definition: PropertyMappingConfigurationTest.php:131
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest
Definition: PropertyMappingConfigurationTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithGetConfigurationFor
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithGetConfigurationFor()
Definition: PropertyMappingConfigurationTest.php:233
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionsShouldOverrideAlreadySetOptions
‪setTypeConverterOptionsShouldOverrideAlreadySetOptions()
Definition: PropertyMappingConfigurationTest.php:139
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTypeConverterReturnsNullIfNoTypeConverterSet
‪getTypeConverterReturnsNullIfNoTypeConverterSet()
Definition: PropertyMappingConfigurationTest.php:165
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Property
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithForProperty
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithForProperty()
Definition: PropertyMappingConfigurationTest.php:245
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionShouldOverrideAlreadySetOptions
‪setTypeConverterOptionShouldOverrideAlreadySetOptions()
Definition: PropertyMappingConfigurationTest.php:152
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsTrueIfConfigured
‪shouldMapReturnsTrueIfConfigured()
Definition: PropertyMappingConfigurationTest.php:64
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setUp
‪setUp()
Definition: PropertyMappingConfigurationTest.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldMapReturnsFalseByDefault
‪shouldMapReturnsFalseByDefault()
Definition: PropertyMappingConfigurationTest.php:54
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap
‪forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap()
Definition: PropertyMappingConfigurationTest.php:257
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\buildChildConfigurationForSingleProperty
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration buildChildConfigurationForSingleProperty()
Definition: PropertyMappingConfigurationTest.php:183
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTypeConverterReturnsTypeConverterIfItHasBeenSet
‪getTypeConverterReturnsTypeConverterIfItHasBeenSet()
Definition: PropertyMappingConfigurationTest.php:173
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\setTypeConverterOptionsCanBeRetrievedAgain
‪setTypeConverterOptionsCanBeRetrievedAgain()
Definition: PropertyMappingConfigurationTest.php:119
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\shouldSkipReturnsTrueIfConfigured
‪shouldSkipReturnsTrueIfConfigured()
Definition: PropertyMappingConfigurationTest.php:109
‪TYPO3\CMS\Extbase\Tests\Unit\Property\PropertyMappingConfigurationTest\getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration
‪getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration()
Definition: PropertyMappingConfigurationTest.php:44