public function setUp() { $this->ioServiceMock = $this->getMock('eZ\\Publish\\Core\\IO\\IOServiceInterface'); $this->configResolverMock = $this->getMock('eZ\\Publish\\Core\\MVC\\ConfigResolverInterface'); $this->configResolverMock->expects($this->any())->method('getParameter')->with('io.url_prefix')->will($this->returnValue($this->ioUriPrefix)); $this->eventListener = new StreamFileListener($this->ioServiceMock, $this->configResolverMock); }
public function testMatchRequestRegularPathinfo() { $matchedParameters = array('_controller' => 'AcmeBundle:myAction'); $pathinfo = '/siteaccess/foo/bar'; $request = Request::create($pathinfo); $this->configResolver->expects($this->never())->method('getParameter'); /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultRouter $router */ $router = $this->generateRouter(array('match')); $router->expects($this->once())->method('match')->with($pathinfo)->will($this->returnValue($matchedParameters)); $this->assertSame($matchedParameters, $router->matchRequest($request)); }
/** * @dataProvider onKernelRequestProvider */ public function testOnKernelRequest(array $configuredLanguages, array $convertedLocalesValueMap, $expectedLocale) { $this->configResolver->expects($this->once())->method('getParameter')->with('languages')->will($this->returnValue($configuredLanguages)); $this->localeConverter->expects($this->atLeastOnce())->method('convertToPOSIX')->will($this->returnValueMap($convertedLocalesValueMap)); $defaultLocale = 'en'; $localeListener = new LocaleListener($defaultLocale); $localeListener->setConfigResolver($this->configResolver); $localeListener->setLocaleConverter($this->localeConverter); $request = new Request(); $localeListener->onKernelRequest(new GetResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST)); $this->assertSame($expectedLocale, $request->attributes->get('_locale')); }
/** * @dataProvider onLegacyKernelWebBuildProvider */ public function testOnLegacyKernelWebBuild(array $previousSettings, array $expected) { $this->configResolver->expects($this->once())->method('getParameter')->with('legacy_mode')->will($this->returnValue(false)); $event = new PreBuildKernelWebHandlerEvent(new ParameterBag($previousSettings), new Request()); $listener = new Security($this->repository, $this->configResolver, $this->securityContext); $listener->onLegacyKernelWebBuild($event); $this->assertSame($expected, $event->getParameters()->all()); }
/** * @dataProvider generateResponseWithCustomLayoutProvider */ public function testGenerateResponseWithCustomLayout($customLayout, $content) { $contentWithLayout = "<div id=\"i-am-a-twig-layout\">{$content}</div>"; $moduleResult = array('content' => $content, 'errorCode' => 200); $this->configResolver->expects($this->any())->method('getParameter')->will($this->returnValueMap(array(array('module_default_layout', 'ezpublish_legacy', null, $customLayout), array('legacy_mode', null, null, false)))); $this->templateEngine->expects($this->once())->method('render')->with($customLayout, array('module_result' => $moduleResult))->will($this->returnValue($contentWithLayout)); $manager = new LegacyResponseManager($this->templateEngine, $this->configResolver); $kernelResult = new ezpKernelResult($content, array('module_result' => $moduleResult)); $response = $manager->generateResponseFromModuleResult($kernelResult); $this->assertInstanceOf('eZ\\Bundle\\EzPublishLegacyBundle\\LegacyResponse', $response); $this->assertSame($contentWithLayout, $response->getContent()); $this->assertSame($moduleResult['errorCode'], $response->getStatusCode()); $this->assertSame($moduleResult, $response->getModuleResult()); }
public function testMatchRequestLegacyModeAuthorizedRoute() { $pathinfo = '/siteaccess/foo/bar'; $semanticPathinfo = '/foo/bar'; $request = Request::create($pathinfo); $request->attributes->set('semanticPathinfo', $semanticPathinfo); /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultRouter $router */ $router = $this->generateRouter(array('match')); $router->setLegacyAwareRoutes(array('my_legacy_aware_route')); $matchedParameters = array('_route' => 'my_legacy_aware_route'); $router->expects($this->once())->method('match')->with($semanticPathinfo)->will($this->returnValue($matchedParameters)); $this->configResolver->expects($this->never())->method('getParameter'); $this->assertSame($matchedParameters, $router->matchRequest($request)); }
public function testRenderLocation() { $content = new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo()])]); $location = new Location(['contentInfo' => new ContentInfo()]); // Configuring view provider behaviour $templateIdentifier = 'foo:bar:baz'; $params = array('foo' => 'bar'); $this->viewConfigurator->expects($this->once())->method('configure')->will($this->returnCallback(function (View $view) use($templateIdentifier) { $view->setTemplateIdentifier($templateIdentifier); })); $languages = array('eng-GB'); $this->configResolverMock->expects($this->any())->method('getParameter')->with('languages')->will($this->returnValue($languages)); $contentService = $this->getMock('eZ\\Publish\\API\\Repository\\ContentService'); $contentService->expects($this->any())->method('loadContentByContentInfo')->with($location->contentInfo, $languages)->will($this->returnValue($content)); $this->repositoryMock->expects($this->any())->method('getContentService')->will($this->returnValue($contentService)); // Configuring template engine behaviour $expectedTemplateResult = 'This is location rendering'; $this->templateEngineMock->expects($this->once())->method('render')->with($templateIdentifier, $params + array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout))->will($this->returnValue($expectedTemplateResult)); self::assertSame($expectedTemplateResult, $this->viewManager->renderLocation($location, 'customViewType', $params)); }
public function testGetAvailableLanguagesWithoutTranslationSiteAccesses() { $this->configResolver->expects($this->any())->method('getParameter')->will($this->returnValueMap(array(array('translation_siteaccesses', null, null, array()), array('related_siteaccesses', null, null, array('fre', 'esl', 'heb')), array('languages', null, null, array('eng-GB')), array('languages', null, 'fre', array('fre-FR', 'eng-GB')), array('languages', null, 'esl', array('esl-ES', 'fre-FR', 'eng-GB')), array('languages', null, 'heb', array('heb-IL', 'eng-GB'))))); $expectedLanguages = array('eng-GB', 'esl-ES', 'fre-FR', 'heb-IL'); $this->assertSame($expectedLanguages, $this->translationHelper->getAvailableLanguages()); }