/** * 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); }
/** * @test */ public function buildPrependsIndexFileIfRewriteUrlsIsOff() { $this->mockRouter->expects($this->once())->method('resolve')->will($this->returnValue('resolvedUri')); $mockEnvironment = $this->getMock('TYPO3\\Flow\\Utility\\Environment', array('isRewriteEnabled'), array(), '', FALSE); $this->inject($this->uriBuilder, 'environment', $mockEnvironment); $expectedResult = 'index.php/resolvedUri'; $actualResult = $this->uriBuilder->build(); $this->assertEquals($expectedResult, $actualResult); }
/** * @test */ public function buildPrependsIndexFileIfRewriteUrlsIsOff() { $this->mockRouter->expects($this->once())->method('resolve')->will($this->returnValue('resolvedUri')); $mockEnvironment = $this->getMockBuilder(\TYPO3\Flow\Utility\Environment::class)->disableOriginalConstructor()->setMethods(array('isRewriteEnabled'))->getMock(); $this->inject($this->uriBuilder, 'environment', $mockEnvironment); $expectedResult = 'index.php/resolvedUri'; $actualResult = $this->uriBuilder->build(); $this->assertEquals($expectedResult, $actualResult); }
/** * Builds the URI * * @param array $arguments optional URI arguments. Will be merged with $this->arguments with precedence to $arguments * @return string The URI * @api */ public function build(array $arguments = array()) { $arguments = Arrays::arrayMergeRecursiveOverrule($this->arguments, $arguments); $arguments = $this->mergeArgumentsWithRequestArguments($arguments); $uri = $this->router->resolve($arguments); $this->lastArguments = $arguments; if (!$this->environment->isRewriteEnabled()) { $uri = 'index.php/' . $uri; } $httpRequest = $this->request->getHttpRequest(); if ($this->createAbsoluteUri === true) { $uri = $httpRequest->getBaseUri() . $uri; } elseif (!$this->createRelativePaths) { $uri = $httpRequest->getScriptRequestPath() . $uri; } if ($this->section !== '') { $uri .= '#' . $this->section; } return $uri; }
/** * Initialize the injected router-object * * @return void */ protected function initializeRouter() { $routesConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router->setRoutesConfiguration($routesConfiguration); }