TYPO3 CMS  TYPO3_7-6
PropertyMappingConfigurationTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
28 {
33 
37  protected function setUp()
38  {
39  $this->propertyMappingConfiguration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
40  }
41 
47  {
48  $this->assertEquals('someSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someSourceProperty'));
49  $this->assertEquals('someOtherSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someOtherSourceProperty'));
50  }
51 
57  {
58  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
59  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
60  }
61 
67  {
68  $this->propertyMappingConfiguration->allowAllProperties();
69  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
70  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
71  }
72 
78  {
79  $this->propertyMappingConfiguration->allowProperties('someSourceProperty', 'someOtherProperty');
80  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
81  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
82  }
83 
89  {
90  $this->propertyMappingConfiguration->allowAllPropertiesExcept('someSourceProperty', 'someOtherProperty');
91  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
92  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
93 
94  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherPropertyWhichHasNotBeenConfigured'));
95  }
96 
102  {
103  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
104  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
105  }
106 
112  {
113  $this->propertyMappingConfiguration->skipProperties('someSourceProperty', 'someOtherSourceProperty');
114  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
115  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
116  }
117 
122  {
123  $mockTypeConverterClass = $this->getMockClass(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class);
124 
125  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
126  $this->assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
127  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
128  }
129 
134  {
135  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue('foo', 'bar'));
136  }
137 
142  {
143  $mockTypeConverterClass = $this->getMockClass(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class);
144  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
145  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k3' => 'v3']);
146 
147  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k3'));
148  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
149  }
150 
155  {
156  $mockTypeConverterClass = $this->getMockClass(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class);
157  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']);
158  $this->propertyMappingConfiguration->setTypeConverterOption($mockTypeConverterClass, 'k1', 'v3');
159 
160  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
161  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
162  }
163 
168  {
169  $this->assertNull($this->propertyMappingConfiguration->getTypeConverter());
170  }
171 
176  {
177  $mockTypeConverter = $this->getMock(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class);
178  $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
179  $this->assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
180  }
181 
186  {
187  $childConfiguration = $this->propertyMappingConfiguration->forProperty('key1.key2');
188  $childConfiguration->setTypeConverterOption('someConverter', 'foo', 'specialChildConverter');
189 
190  return $childConfiguration;
191  }
192 
197  {
198  $this->propertyMappingConfiguration->setMapping('k1', 'k1a');
199  $this->assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
200  $this->assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
201  }
202 
207  {
208  $mockTypeConverterClass = $this->getMockClass(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class);
209 
210  return [
211  ['allowAllProperties'],
212  ['allowProperties'],
213  ['allowAllPropertiesExcept'],
214  ['setMapping', ['k1', 'k1a']],
215  ['setTypeConverterOptions', [$mockTypeConverterClass, ['k1' => 'v1', 'k2' => 'v2']]],
216  ['setTypeConverterOption', [$mockTypeConverterClass, 'k1', 'v3']],
217  ['setTypeConverter', [$this->getMock(\TYPO3\CMS\Extbase\Property\TypeConverterInterface::class)]],
218  ];
219  }
220 
225  public function respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod = [])
226  {
227  $actualResult = call_user_func_array([$this->propertyMappingConfiguration, $methodToTestForFluentInterface], $argumentsForMethod);
228  $this->assertSame($this->propertyMappingConfiguration, $actualResult);
229  }
230 
235  {
236  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
237  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
238 
239  $configuration = $this->propertyMappingConfiguration->getConfigurationFor('items')->getConfigurationFor('6');
240  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
241  }
242 
247  {
248  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
249  $this->propertyMappingConfiguration->forProperty('items.*.foo')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
250 
251  $configuration = $this->propertyMappingConfiguration->forProperty('items.6.foo');
252  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
253  }
254 
259  {
260  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
261 
262  $configuration = $this->propertyMappingConfiguration->forProperty('items');
263  $this->assertTrue($configuration->shouldMap(6));
264  }
265 }
respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod=[])