TYPO3 CMS  TYPO3_6-2
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  public function setUp() {
38  $this->propertyMappingConfiguration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
39  }
40 
46  $this->assertEquals('someSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someSourceProperty'));
47  $this->assertEquals('someOtherSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someOtherSourceProperty'));
48  }
49 
54  public function shouldMapReturnsFalseByDefault() {
55  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
56  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
57  }
58 
64  $this->propertyMappingConfiguration->allowAllProperties();
65  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
66  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
67  }
68 
74  $this->propertyMappingConfiguration->allowProperties('someSourceProperty', 'someOtherProperty');
75  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
76  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
77  }
78 
84  $this->propertyMappingConfiguration->allowAllPropertiesExcept('someSourceProperty', 'someOtherProperty');
85  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
86  $this->assertFalse($this->propertyMappingConfiguration->shouldMap('someOtherProperty'));
87 
88  $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherPropertyWhichHasNotBeenConfigured'));
89  }
90 
95  public function shouldSkipReturnsFalseByDefault() {
96  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
97  $this->assertFalse($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
98  }
99 
105  $this->propertyMappingConfiguration->skipProperties('someSourceProperty', 'someOtherSourceProperty');
106  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someSourceProperty'));
107  $this->assertTrue($this->propertyMappingConfiguration->shouldSkip('someOtherSourceProperty'));
108  }
109 
114  $mockTypeConverterClass = $this->getMockClass('TYPO3\CMS\Extbase\Property\TypeConverterInterface');
115 
116  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, array('k1' => 'v1', 'k2' => 'v2'));
117  $this->assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
118  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
119  }
120 
125  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue('foo', 'bar'));
126  }
127 
132  $mockTypeConverterClass = $this->getMockClass('TYPO3\CMS\Extbase\Property\TypeConverterInterface');
133  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, array('k1' => 'v1', 'k2' => 'v2'));
134  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, array('k3' => 'v3'));
135 
136  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k3'));
137  $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
138  }
139 
144  $mockTypeConverterClass = $this->getMockClass('TYPO3\CMS\Extbase\Property\TypeConverterInterface');
145  $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, array('k1' => 'v1', 'k2' => 'v2'));
146  $this->propertyMappingConfiguration->setTypeConverterOption($mockTypeConverterClass, 'k1', 'v3');
147 
148  $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
149  $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
150  }
151 
156  $this->assertNull($this->propertyMappingConfiguration->getTypeConverter());
157  }
158 
163  $mockTypeConverter = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\TypeConverterInterface');
164  $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
165  $this->assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
166  }
167 
172  $childConfiguration = $this->propertyMappingConfiguration->forProperty('key1.key2');
173  $childConfiguration->setTypeConverterOption('someConverter', 'foo', 'specialChildConverter');
174 
175  return $childConfiguration;
176  }
177 
182  $this->propertyMappingConfiguration->setMapping('k1', 'k1a');
183  $this->assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
184  $this->assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
185  }
186 
191  $mockTypeConverterClass = $this->getMockClass('TYPO3\CMS\Extbase\Property\TypeConverterInterface');
192 
193  return array(
194  array('allowAllProperties'),
195  array('allowProperties'),
196  array('allowAllPropertiesExcept'),
197  array('setMapping', array('k1', 'k1a')),
198  array('setTypeConverterOptions', array($mockTypeConverterClass, array('k1' => 'v1', 'k2' => 'v2'))),
199  array('setTypeConverterOption', array($mockTypeConverterClass, 'k1', 'v3')),
200  array('setTypeConverter', array($this->getMock('TYPO3\CMS\Extbase\Property\TypeConverterInterface'))),
201  );
202  }
203 
208  public function respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod = array()) {
209  $actualResult = call_user_func_array(array($this->propertyMappingConfiguration, $methodToTestForFluentInterface), $argumentsForMethod);
210  $this->assertSame($this->propertyMappingConfiguration, $actualResult);
211  }
212 
217  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
218  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', array('k1' => 'v1'));
219 
220  $configuration = $this->propertyMappingConfiguration->getConfigurationFor('items')->getConfigurationFor('6');
221  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
222  }
223 
228  // using stdClass so that class_parents() in getTypeConvertersWithParentClasses() is happy
229  $this->propertyMappingConfiguration->forProperty('items.*.foo')->setTypeConverterOptions('stdClass', array('k1' => 'v1'));
230 
231  $configuration = $this->propertyMappingConfiguration->forProperty('items.6.foo');
232  $this->assertSame('v1', $configuration->getConfigurationValue('stdClass', 'k1'));
233  }
234 
239  $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', array('k1' => 'v1'));
240 
241  $configuration = $this->propertyMappingConfiguration->forProperty('items');
242  $this->assertTrue($configuration->shouldMap(6));
243  }
244 
245 }
respectiveMethodsProvideFluentInterface($methodToTestForFluentInterface, array $argumentsForMethod=array())