[BUGFIX] Fix tests throwing errors in MapperTest
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Property / MapperTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Property;
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
24 require_once(__DIR__ . '/../../Fixture/TxClassWithGettersAndSetters.php');
25
26 /**
27 * Testcase for the Property Mapper
28 *
29 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
30 * @covers \TYPO3\CMS\Extbase\Property\Mapper
31 */
32 class MapperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Property\Mapper
36 */
37 protected $fixture;
38
39 /**
40 * Sets up this test case
41 *
42 * @return void
43 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
44 */
45 public function setUp() {
46 /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
47 $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
48
49 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager $persistenceManager */
50 $persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
51
52 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory $queryFactory */
53 $queryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
54
55 /** @var \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService */
56 $reflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
57 $reflectionService->injectObjectManager($objectManager);
58
59 /** @var \TYPO3\CMS\Extbase\Validation\ValidatorResolver $validatorResolver */
60 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver');
61
62 $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Property\\Mapper', array('dummy'));
63 $this->fixture->injectObjectManager($objectManager);
64 $this->fixture->injectPersistenceManager($persistenceManager);
65 $this->fixture->injectQueryFactory($queryFactory);
66 $this->fixture->injectReflectionService($reflectionService);
67 $this->fixture->injectValidatorResolver($validatorResolver);
68 }
69
70 public function tearDown() {
71 unset($this->fixture);
72 }
73
74 /**
75 * @test
76 */
77 public function mapReturnsObjectForNamespaceClasses() {
78 $source = array(
79 'property1' => 'foo',
80 'property2' => 'bar'
81 );
82
83 $expectedObject = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithGettersAndSetters();
84 $expectedObject->setProperty1($source['property1']);
85 $expectedObject->setProperty2($source['property2']);
86
87 $this->assertTrue($this->fixture->map(array('property1', 'property2'), $source, $expectedObject));
88 }
89
90 /**
91 * @test
92 */
93 public function mapReturnsObjectForOldTxClasses() {
94 $source = array(
95 'property1' => 'foo',
96 'property2' => 'bar'
97 );
98
99 $expectedObject = new \Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters();
100 $expectedObject->setProperty1($source['property1']);
101 $expectedObject->setProperty2($source['property2']);
102
103 $this->assertTrue($this->fixture->map(array('property1', 'property2'), $source, $expectedObject));
104 }
105 }
106
107 ?>