TYPO3 CMS  TYPO3_6-2
BackendTest.php
Go to the documentation of this file.
1 <?php
3 
21 
26  /* \TYPO3\CMS\Extbase\Persistence\Generic\Backend|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
27  $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array(), '', FALSE);
28  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject */
29  $dataMapper = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
30  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
31  $dataMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array(), array(), '', FALSE);
32  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
33  $columnMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
34  /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
35  $storageBackend = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Storage\\BackendInterface');
36  /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
37  $domainObject = $this->getMock('TYPO3\\CMS\Extbase\\DomainObject\\DomainObjectInterface');
38 
39  $mmMatchFields = array(
40  'identifier' => 'myTable:myField',
41  );
42 
43  $expectedRow = array(
44  'identifier' => 'myTable:myField',
45  '' => 0
46  );
47 
48  $columnMap
49  ->expects($this->once())
50  ->method('getRelationTableMatchFields')
51  ->will($this->returnValue($mmMatchFields));
52  $columnMap
53  ->expects($this->any())
54  ->method('getChildSortByFieldName')
55  ->will($this->returnValue(''));
56  $dataMap
57  ->expects($this->any())
58  ->method('getColumnMap')
59  ->will($this->returnValue($columnMap));
60  $dataMapper
61  ->expects($this->any())
62  ->method('getDataMap')
63  ->will($this->returnValue($dataMap));
64  $storageBackend
65  ->expects($this->once())
66  ->method('addRow')
67  ->with(NULL, $expectedRow, TRUE);
68 
69  $fixture->_set('dataMapper', $dataMapper);
70  $fixture->_set('storageBackend', $storageBackend);
71  $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
72  }
73 
78  $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array(), '', FALSE);
79  $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('column_name', 'propertyName');
80  $columnMap->setDateTimeStorageFormat('datetime');
81  $datetimeAsString = '2013-04-15 09:30:00';
82  $input = new \DateTime($datetimeAsString);
83  $this->assertEquals('2013-04-15 09:30:00', $fixture->_call('getPlainValue', $input, $columnMap));
84  $columnMap->setDateTimeStorageFormat('date');
85  $this->assertEquals('2013-04-15', $fixture->_call('getPlainValue', $input, $columnMap));
86  }
87 
91  public function getIdentifierByObjectReturnsIdentifierForNonlazyObject() {
92  $fakeUuid = 'fakeUuid';
93  $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
94  $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
95  $object = new \stdClass();
96 
97  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
98 
100  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
101  $backend->_set('session', $session);
102 
103  $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
104  }
105 
109  public function getIdentifierByObjectReturnsIdentifierForLazyObject() {
110  $fakeUuid = 'fakeUuid';
111  $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
112  $parentObject = new \stdClass();
113  $proxy = $this->getMock('TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy', array('_loadRealInstance'), array($parentObject, 'y', 'z'), '', FALSE);
114  $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
115  $object = new \stdClass();
116 
117  $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
118  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
119 
121  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
122  $backend->_set('session', $session);
123 
124  $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
125  }
126 
127 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)