Beispiel #1
0
 /**
  * @test
  */
 public function unregisterObjectRemovesRegisteredObject()
 {
     $object1 = new \stdClass();
     $object2 = new \stdClass();
     $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
     $session->registerObject($object1, 12345);
     $session->registerObject($object2, 67890);
     $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
     $session->unregisterObject($object1);
     $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
     $this->assertFalse($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
 }
Beispiel #2
0
 /**
  * Test if mapObjectToClassProperty method returns objects
  * that are already registered in the persistence session
  * without query it from the persistence layer
  *
  * @test
  */
 public function mapObjectToClassPropertyReturnsExistingObjectWithoutCallingFetchRelated()
 {
     $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
     $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_ONE);
     $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
     $className = $this->getUniqueId('Class1');
     $classNameWithNS = __NAMESPACE__ . '\\' . $className;
     eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity { public $relationProperty; }');
     $object = new $classNameWithNS();
     $classSchema1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Reflection\\ClassSchema', array('dummy'), array($classNameWithNS));
     $classSchema1->_set('typeHandlingService', new \TYPO3\CMS\Extbase\Service\TypeHandlingService());
     $className2 = $this->getUniqueId('Class2');
     $className2WithNS = __NAMESPACE__ . '\\' . $className2;
     eval('namespace ' . __NAMESPACE__ . '; class ' . $className2 . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity { }');
     $child = new $className2WithNS();
     $classSchema2 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Reflection\\ClassSchema', array('dummy'), array($className2WithNS));
     $classSchema2->_set('typeHandlingService', new \TYPO3\CMS\Extbase\Service\TypeHandlingService());
     $classSchema1->addProperty('relationProperty', $className2WithNS);
     $identifier = 1;
     $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
     $session->registerObject($child, $identifier);
     $mockReflectionService = $this->getMock('\\TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getClassSchema'), array(), '', FALSE);
     $mockReflectionService->expects($this->any())->method('getClassSchema')->will($this->returnValue($classSchema1));
     $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
     $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'getNonEmptyRelationValue'));
     $dataMapper->_set('reflectionService', $mockReflectionService);
     $dataMapper->_set('persistenceSession', $session);
     $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
     $dataMapper->expects($this->never())->method('getNonEmptyRelationValue');
     $result = $dataMapper->_call('mapObjectToClassProperty', $object, 'relationProperty', $identifier);
     $this->assertEquals($child, $result);
 }