/**
  * @test
  */
 public function renderWithoutValueInvokesRenderChildren()
 {
     $object = new \stdClass();
     $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($object));
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue('b59292c5-1a28-4b36-8615-10d3c5b3a4d8'));
     $this->assertEquals('b59292c5-1a28-4b36-8615-10d3c5b3a4d8', $this->viewHelper->render());
 }
Пример #2
0
 /**
  * @test
  */
 public function getAssignedPartyOfAccountCachesParty()
 {
     $this->mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('723e3913-f803-42c8-a44c-fd7115f555c3'));
     $this->mockPartyRepository->expects($this->once())->method('findOneHavingAccount')->with($this->account)->will($this->returnValue($this->party));
     $this->party->addAccount($this->account);
     $assignedParty = $this->partyService->getAssignedPartyOfAccount($this->account);
     $this->assertSame($this->party, $assignedParty);
     $assignedParty = $this->partyService->getAssignedPartyOfAccount($this->account);
     $this->assertSame($this->party, $assignedParty);
 }
 /**
  * @test
  * @return void
  */
 public function generateUuidGeneratesUuidAndRegistersProxyAsNewObject()
 {
     $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
     eval('class ' . $className . ' implements \\TYPO3\\Flow\\Persistence\\Aspect\\PersistenceMagicInterface { public $Persistence_Object_Identifier = NULL; }');
     $object = new $className();
     $this->mockJoinPoint->expects($this->atLeastOnce())->method('getProxy')->will($this->returnValue($object));
     $this->mockPersistenceManager->expects($this->atLeastOnce())->method('registerNewObject')->with($object);
     $this->persistenceMagicAspect->generateUuid($this->mockJoinPoint);
     $this->assertEquals(36, strlen($object->Persistence_Object_Identifier));
 }
 /**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->mockObjectManager = $this->getMock(\TYPO3\Flow\Object\ObjectManagerInterface::class);
     $this->route = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Routing\Route::class, array('dummy'));
     $this->route->_set('objectManager', $this->mockObjectManager);
     $this->mockPersistenceManager = $this->getMock(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class);
     $this->mockPersistenceManager->expects($this->any())->method('convertObjectsToIdentityArrays')->will($this->returnCallback(function ($array) {
         return $array;
     }));
     $this->inject($this->route, 'persistenceManager', $this->mockPersistenceManager);
 }
Пример #5
0
 /**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface');
     $this->mockObjectManager->expects($this->any())->method('create')->will($this->returnCallback(array($this, 'objectManagerCallBack')));
     $this->route = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Routing\\Route', array('dummy'));
     $this->route->_set('objectManager', $this->mockObjectManager);
     $this->mockRouter = $this->getMock('TYPO3\\Flow\\Mvc\\Routing\\RouterInterface');
     $this->mockRouter->expects($this->any())->method('getControllerObjectName')->will($this->returnValue('SomeControllerObjectName'));
     $this->inject($this->route, 'router', $this->mockRouter);
     $this->mockPersistenceManager = $this->getMock('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface');
     $this->mockPersistenceManager->expects($this->any())->method('convertObjectsToIdentityArrays')->will($this->returnCallback(function ($array) {
         return $array;
     }));
     $this->inject($this->route, 'persistenceManager', $this->mockPersistenceManager);
 }
 /**
  * @param array $elements
  * @return \TYPO3\Eel\FlowQuery\FlowQuery
  */
 protected function createFlowQuery(array $elements)
 {
     $flowQuery = $this->getAccessibleMock(\TYPO3\Eel\FlowQuery\FlowQuery::class, array('dummy'), array($elements));
     // Set up mock persistence manager to return dummy object identifiers
     $this->mockPersistenceManager = $this->getMock(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class);
     $this->mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(function ($object) {
         if (isset($object->__identity)) {
             return $object->__identity;
         }
     }));
     $mockPersistenceManager = $this->mockPersistenceManager;
     $objectManager = $this->getMock(\TYPO3\Flow\Object\ObjectManagerInterface::class);
     $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) use($mockPersistenceManager) {
         $instance = new $className();
         // Special case to inject the mock persistence manager into the filter operation
         if ($className === \TYPO3\Eel\FlowQuery\Operations\Object\FilterOperation::class) {
             \TYPO3\Flow\Reflection\ObjectAccess::setProperty($instance, 'persistenceManager', $mockPersistenceManager, true);
         }
         return $instance;
     }));
     $operationResolver = $this->getAccessibleMock(\TYPO3\Eel\FlowQuery\OperationResolver::class, array('dummy'));
     $operationResolver->_set('objectManager', $objectManager);
     $operationResolver->_set('finalOperationNames', array('count' => 'count', 'get' => 'get', 'is' => 'is', 'property' => 'property'));
     $operationResolver->_set('operations', array('count' => array(300 => \TYPO3\Eel\FlowQuery\Operations\CountOperation::class), 'first' => array(300 => \TYPO3\Eel\FlowQuery\Operations\FirstOperation::class), 'last' => array(300 => \TYPO3\Eel\FlowQuery\Operations\LastOperation::class), 'slice' => array(300 => \TYPO3\Eel\FlowQuery\Operations\SliceOperation::class), 'get' => array(300 => \TYPO3\Eel\FlowQuery\Operations\GetOperation::class), 'is' => array(300 => \TYPO3\Eel\FlowQuery\Operations\IsOperation::class), 'filter' => array(300 => \TYPO3\Eel\FlowQuery\Operations\Object\FilterOperation::class), 'children' => array(300 => \TYPO3\Eel\FlowQuery\Operations\Object\ChildrenOperation::class), 'property' => array(300 => \TYPO3\Eel\FlowQuery\Operations\Object\PropertyOperation::class)));
     $flowQuery->_set('operationResolver', $operationResolver);
     return $flowQuery;
 }
 /**
  * @test
  */
 public function convertFromReturnsNullIfSpecifiedResourceCantBeFound()
 {
     $source = array('error' => \UPLOAD_ERR_NO_FILE, 'originallySubmittedResource' => array('__identity' => '79ecda60-1a27-69ca-17bf-a5d9e80e6c39'));
     $this->inject($this->resourceTypeConverter, 'persistenceManager', $this->mockPersistenceManager);
     $this->mockPersistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('79ecda60-1a27-69ca-17bf-a5d9e80e6c39', \TYPO3\Flow\Resource\Resource::class)->will($this->returnValue(null));
     $actualResource = $this->resourceTypeConverter->convertFrom($source, \TYPO3\Flow\Resource\Resource::class);
     $this->assertNull($actualResource);
 }
 /**
  * @test
  */
 public function getCachedResolvedUriPathSkipsCacheIfRouteValuesContainObjectsThatCantBeConvertedToHashes()
 {
     $mockObject = new \stdClass();
     $routeValues = array('b' => 'route values', 'someObject' => $mockObject);
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($mockObject)->will($this->returnValue(null));
     $this->mockResolveCache->expects($this->never())->method('has');
     $this->mockResolveCache->expects($this->never())->method('set');
     $this->routerCachingService->getCachedResolvedUriPath($routeValues);
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Mvc\Exception\InfiniteLoopException
  */
 public function resolveValueThrowsInfiniteLoopExceptionIfNoUniquePathSegmentCantBeFound()
 {
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->atLeastOnce())->method('getIdentifierByObject')->with($object)->will($this->returnValue('TheIdentifier'));
     $this->mockPersistenceManager->expects($this->atLeastOnce())->method('getObjectByIdentifier')->with('TheIdentifier')->will($this->returnValue($object));
     $this->mockObjectPathMappingRepository->expects($this->once())->method('findOneByObjectTypeUriPatternAndIdentifier')->with('stdClass', 'SomeUriPattern', 'TheIdentifier')->will($this->returnValue(null));
     $existingObjectPathMapping = new ObjectPathMapping();
     $existingObjectPathMapping->setObjectType('stdClass');
     $existingObjectPathMapping->setUriPattern('SomeUriPattern');
     $existingObjectPathMapping->setPathSegment('The/Path/Segment');
     $existingObjectPathMapping->setIdentifier('AnotherIdentifier');
     $this->identityRoutePart->expects($this->once())->method('createPathSegmentForObject')->with($object)->will($this->returnValue('The/Path/Segment'));
     $this->mockObjectPathMappingRepository->expects($this->atLeastOnce())->method('findOneByObjectTypeUriPatternAndPathSegment')->will($this->returnValue($existingObjectPathMapping));
     $this->identityRoutePart->setObjectType('stdClass');
     $this->identityRoutePart->setUriPattern('SomeUriPattern');
     $this->identityRoutePart->_call('resolveValue', $object);
 }
 /**
  * @param integer $numberOfResults
  * @param \PHPUnit_Framework_MockObject_Matcher_Invocation $howOftenIsGetFirstCalled
  * @return \stdClass
  */
 public function setupMockQuery($numberOfResults, $howOftenIsGetFirstCalled)
 {
     $mockClassSchema = $this->createMock(\TYPO3\Flow\Reflection\ClassSchema::class, array(), array('Dummy'));
     $mockClassSchema->expects($this->once())->method('getIdentityProperties')->will($this->returnValue(array('key1' => 'someType')));
     $this->mockReflectionService->expects($this->once())->method('getClassSchema')->with('SomeType')->will($this->returnValue($mockClassSchema));
     $mockConstraint = $this->getMockBuilder(\TYPO3\Flow\Persistence\Generic\Qom\Comparison::class)->disableOriginalConstructor()->getMock();
     $mockObject = new \stdClass();
     $mockQuery = $this->createMock(\TYPO3\Flow\Persistence\QueryInterface::class);
     $mockQueryResult = $this->createMock(\TYPO3\Flow\Persistence\QueryResultInterface::class);
     $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue($numberOfResults));
     $mockQueryResult->expects($howOftenIsGetFirstCalled)->method('getFirst')->will($this->returnValue($mockObject));
     $mockQuery->expects($this->once())->method('equals')->with('key1', 'value1')->will($this->returnValue($mockConstraint));
     $mockQuery->expects($this->once())->method('matching')->with($mockConstraint)->will($this->returnValue($mockQuery));
     $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
     $this->mockPersistenceManager->expects($this->once())->method('createQueryForType')->with('SomeType')->will($this->returnValue($mockQuery));
     return $mockObject;
 }
 /**
  * @test
  */
 public function convertFromReturnsNullIfSpecifiedResourcePointerCantBeFound()
 {
     $source = array('error' => \UPLOAD_ERR_NO_FILE, 'submittedFile' => array('filename' => 'SomeFilename', 'resourcePointer' => 'someNonExistingResourcePointer'));
     $this->mockPersistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('someNonExistingResourcePointer', 'TYPO3\\Flow\\Resource\\ResourcePointer')->will($this->returnValue(NULL));
     $this->assertNull($this->resourceTypeConverter->convertFrom($source, 'TYPO3\\Flow\\Resource\\Resource'));
 }
 /**
  * Objects that are unknown to the persistence manager cannot be resolved by the standard DynamicRoutePart handler.
  *
  * @test
  */
 public function resolveValueReturnsFalseIfTheValueToBeResolvedIsAnObjectThatIsUnknownToThePersistenceManager()
 {
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue(NULL));
     $this->assertFalse($this->dynamicRoutPart->_call('resolveValue', $object));
 }
 /**
  * @test
  */
 public function resolveValueReturnsFalseIfTheValueToBeResolvedIsAnObjectWithAnIdentifierThatIsNoString()
 {
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue(array('foo', 'bar')));
     $this->assertFalse($this->dynamicRoutPart->_call('resolveValue', $object));
 }