[TASK] Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Property / PropertyMappingConfigurationTest.php
1 <?php
2 /* *
3 * This script belongs to the Extbase framework. *
4 * *
5 * It is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU Lesser General Public License as published by the *
7 * Free Software Foundation, either version 3 of the License, or (at your *
8 * option) any later version. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
13 * General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with the script. *
17 * If not, see http://www.gnu.org/licenses/lgpl.html *
18 * *
19 * The TYPO3 project - inspiring people to share! *
20 * */
21 require_once __DIR__ . '/../Fixtures/ClassWithSetters.php';
22 namespace TYPO3\CMS\Extbase\Tests\Unit\Property;
23
24 /**
25 * Testcase for the Property Mapper
26 *
27 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
28 * @covers \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
29 */
30 class PropertyMappingConfigurationTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
34 */
35 protected $propertyMappingConfiguration;
36
37 public function setUp() {
38 $this->propertyMappingConfiguration = new \Tx_Extbase_Property_PropertyMappingConfiguration();
39 }
40
41 /**
42 * @test
43 * @author Sebastian Kurfürst <sebastian@typo3.org>
44 * @covers Tx_Extbase_Property_PropertyMappingConfiguration::getTargetPropertyName
45 */
46 public function getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration() {
47 $this->assertEquals('someSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someSourceProperty'));
48 $this->assertEquals('someOtherSourceProperty', $this->propertyMappingConfiguration->getTargetPropertyName('someOtherSourceProperty'));
49 }
50
51 /**
52 * @test
53 * @covers Tx_Extbase_Property_PropertyMappingConfiguration::shouldMap
54 * @author Sebastian Kurfürst <sebastian@typo3.org>
55 */
56 public function shouldMapReturnsTrue() {
57 $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someSourceProperty'));
58 $this->assertTrue($this->propertyMappingConfiguration->shouldMap('someOtherSourceProperty'));
59 }
60
61 /**
62 * @test
63 * @author Sebastian Kurfürst <sebastian@typo3.org>
64 */
65 public function setTypeConverterOptionsCanBeRetrievedAgain() {
66 $this->propertyMappingConfiguration->setTypeConverterOptions('someConverter', array('k1' => 'v1', 'k2' => 'v2'));
67 $this->assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k1'));
68 $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k2'));
69 }
70
71 /**
72 * @test
73 * @author Sebastian Kurfürst <sebastian@typo3.org>
74 */
75 public function inexistentTypeConverterOptionsReturnNull() {
76 $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue('foo', 'bar'));
77 }
78
79 /**
80 * @test
81 * @author Sebastian Kurfürst <sebastian@typo3.org>
82 */
83 public function setTypeConverterOptionsShouldOverrideAlreadySetOptions() {
84 $this->propertyMappingConfiguration->setTypeConverterOptions('someConverter', array('k1' => 'v1', 'k2' => 'v2'));
85 $this->propertyMappingConfiguration->setTypeConverterOptions('someConverter', array('k3' => 'v3'));
86 $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k3'));
87 $this->assertNull($this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k2'));
88 }
89
90 /**
91 * @test
92 * @author Sebastian Kurfürst <sebastian@typo3.org>
93 */
94 public function setTypeConverterOptionShouldOverrideAlreadySetOptions() {
95 $this->propertyMappingConfiguration->setTypeConverterOptions('someConverter', array('k1' => 'v1', 'k2' => 'v2'));
96 $this->propertyMappingConfiguration->setTypeConverterOption('someConverter', 'k1', 'v3');
97 $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k1'));
98 $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k2'));
99 }
100
101 /**
102 * @test
103 * @author Sebastian Kurfürst <sebastian@typo3.org>
104 */
105 public function getTypeConverterReturnsNullIfNoTypeConverterSet() {
106 $this->assertNull($this->propertyMappingConfiguration->getTypeConverter());
107 }
108
109 /**
110 * @test
111 * @author Sebastian Kurfürst <sebastian@typo3.org>
112 */
113 public function getTypeConverterReturnsTypeConverterIfItHasBeenSet() {
114 $mockTypeConverter = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\TypeConverterInterface');
115 $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
116 $this->assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
117 }
118
119 /**
120 * @return \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
121 * @author Sebastian Kurfürst <sebastian@typo3.org>
122 */
123 protected function buildChildConfigurationForSingleProperty() {
124 $childConfiguration = $this->propertyMappingConfiguration->forProperty('key1.key2');
125 $childConfiguration->setTypeConverterOption('someConverter', 'foo', 'specialChildConverter');
126 return $childConfiguration;
127 }
128
129 /**
130 * @test
131 * @author Sebastian Kurfürst <sebastian@typo3.org>
132 */
133 public function getTargetPropertyNameShouldRespectMapping() {
134 $this->propertyMappingConfiguration->setMapping('k1', 'k1a');
135 $this->assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
136 $this->assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
137 }
138
139 }
140
141
142 ?>