TYPO3 CMS  TYPO3_6-2
MapperTest.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 
24 require_once __DIR__ . '/../../Fixture/TxClassWithGettersAndSetters.php';
25 
30 
34  protected $subject;
35 
42  public function setUp() {
44  $persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
45 
47  $queryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
48 
50  $reflectionService = $this-> getAccessibleMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
51 
53  $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver');
54 
55  $this->subject = $this->getAccessibleMock('TYPO3\CMS\Extbase\Property\Mapper', array('dummy'));
56  $this->subject->_set('persistenceManager', $persistenceManager);
57  $this->subject->_set('queryFactory', $queryFactory);
58  $this->subject->_set('reflectionService', $reflectionService);
59  $this->subject->_set('validatorResolver', $validatorResolver);
60  }
61 
65  public function mapReturnsObjectForNamespaceClasses() {
67  $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
68  $objectManager->expects($this->at(0))->method('get')->will($this->returnValue($this->getMock('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithGettersAndSetters')));
69  $this->subject->_set('objectManager', $objectManager);
70 
71  $source = array(
72  'property1' => 'foo',
73  'property2' => 'bar'
74  );
75 
76  $expectedObject = $this->getMock('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithGettersAndSetters');
77  $expectedObject->setProperty1($source['property1']);
78  $expectedObject->setProperty2($source['property2']);
79 
80  $this->assertEquals($expectedObject, $this->subject->map(array('property1', 'property2'), $source, 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithGettersAndSetters'));
81  }
82 
86  public function mapReturnsObjectForOldTxClasses() {
87 
89  $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
90  $objectManager->expects($this->at(0))->method('get')->will($this->returnValue($this->getMock('Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters')));
91  $this->subject->_set('objectManager', $objectManager);
92  $source = array(
93  'property1' => 'foo',
94  'property2' => 'bar'
95  );
96 
97  $expectedObject = $this->getMock('Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters');
98  $expectedObject->setProperty1($source['property1']);
99  $expectedObject->setProperty2($source['property2']);
100 
101  $this->assertEquals($expectedObject, $this->subject->map(array('property1', 'property2'), $source, 'Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters'));
102  }
103 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)