/**
  * @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());
 }
 /**
  * @test
  * @return void
  */
 public function generateUuidGeneratesUuidAndRegistersProxyAsNewObject()
 {
     $className = 'Class' . md5(uniqid(mt_rand(), true));
     eval('class ' . $className . ' implements \\Neos\\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));
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class);
     $this->route = $this->getAccessibleMock(Routing\Route::class, ['dummy']);
     $this->route->_set('objectManager', $this->mockObjectManager);
     $this->mockPersistenceManager = $this->createMock(PersistenceManagerInterface::class);
     $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 FlowQuery
  */
 protected function createFlowQuery(array $elements)
 {
     $flowQuery = $this->getAccessibleMock(FlowQuery::class, ['dummy'], [$elements]);
     // Set up mock persistence manager to return dummy object identifiers
     $this->mockPersistenceManager = $this->createMock(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->createMock(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 === Operations\Object\FilterOperation::class) {
             ObjectAccess::setProperty($instance, 'persistenceManager', $mockPersistenceManager, true);
         }
         return $instance;
     }));
     $operationResolver = $this->getAccessibleMock(OperationResolver::class, ['dummy']);
     $operationResolver->_set('objectManager', $objectManager);
     $operationResolver->_set('finalOperationNames', ['count' => 'count', 'get' => 'get', 'is' => 'is', 'property' => 'property']);
     $operationResolver->_set('operations', ['count' => [300 => Operations\CountOperation::class], 'first' => [300 => Operations\FirstOperation::class], 'last' => [300 => Operations\LastOperation::class], 'slice' => [300 => Operations\SliceOperation::class], 'get' => [300 => Operations\GetOperation::class], 'is' => [300 => Operations\IsOperation::class], 'filter' => [300 => Operations\Object\FilterOperation::class], 'children' => [300 => Operations\Object\ChildrenOperation::class], 'property' => [300 => Operations\Object\PropertyOperation::class]]);
     $flowQuery->_set('operationResolver', $operationResolver);
     return $flowQuery;
 }
 /**
  * @test
  */
 public function convertFromReturnsNullIfSpecifiedResourceCantBeFound()
 {
     $source = ['error' => \UPLOAD_ERR_NO_FILE, 'originallySubmittedResource' => ['__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', PersistentResource::class)->will($this->returnValue(null));
     $actualResource = $this->resourceTypeConverter->convertFrom($source, PersistentResource::class);
     $this->assertNull($actualResource);
 }
 /**
  * @test
  */
 public function getCachedResolvedUriPathSkipsCacheIfRouteValuesContainObjectsThatCantBeConvertedToHashes()
 {
     $mockObject = new \stdClass();
     $routeValues = ['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);
 }
 /**
  * @param integer $numberOfResults
  * @param \PHPUnit_Framework_MockObject_Matcher_Invocation $howOftenIsGetFirstCalled
  * @return \stdClass
  */
 public function setupMockQuery($numberOfResults, $howOftenIsGetFirstCalled)
 {
     $mockClassSchema = $this->createMock(ClassSchema::class, [], ['Dummy']);
     $mockClassSchema->expects($this->once())->method('getIdentityProperties')->will($this->returnValue(['key1' => 'someType']));
     $this->mockReflectionService->expects($this->once())->method('getClassSchema')->with('SomeType')->will($this->returnValue($mockClassSchema));
     $mockConstraint = $this->getMockBuilder(Persistence\Generic\Qom\Comparison::class)->disableOriginalConstructor()->getMock();
     $mockObject = new \stdClass();
     $mockQuery = $this->createMock(Persistence\QueryInterface::class);
     $mockQueryResult = $this->createMock(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
  * @expectedException \Neos\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);
 }
 /**
  * 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));
 }