eZ\Bundle\EzPublishCoreBundle\Tests\Routing\DefaultRouterTest::testGenerateWithSiteAccess PHP Method

testGenerateWithSiteAccess() public method

public testGenerateWithSiteAccess ( string $urlGenerated, string $relevantUri, string $expectedUrl, string $saName, boolean $isMatcherLexer, integer $referenceType, string $routeName )
$urlGenerated string The URL generated by the standard UrLGenerator
$relevantUri string The relevant URI part of the generated URL (without host and basepath)
$expectedUrl string The URL we're expecting to be finally generated, with siteaccess
$saName string The SiteAccess name
$isMatcherLexer boolean True if the siteaccess matcher is URILexer
$referenceType integer The type of reference to be generated (one of the constants)
$routeName string
    public function testGenerateWithSiteAccess($urlGenerated, $relevantUri, $expectedUrl, $saName, $isMatcherLexer, $referenceType, $routeName)
    {
        $routeName = $routeName ?: __METHOD__;
        $nonSiteAccessAwareRoutes = array('_dontwantsiteaccess');
        $generator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
        $generator->expects($this->once())->method('generate')->with($routeName)->will($this->returnValue($urlGenerated));
        /** @var DefaultRouter|\PHPUnit_Framework_MockObject_MockObject $router */
        $router = $this->generateRouter(array('getGenerator'));
        $router->expects($this->any())->method('getGenerator')->will($this->returnValue($generator));
        // If matcher is URILexer, we make it act as it's supposed to, prepending the siteaccess.
        if ($isMatcherLexer) {
            $matcher = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\URILexer');
            // Route is siteaccess aware, we're expecting analyseLink() to be called
            if (!in_array($routeName, $nonSiteAccessAwareRoutes)) {
                $matcher->expects($this->once())->method('analyseLink')->with($relevantUri)->will($this->returnValue("/{$saName}{$relevantUri}"));
            } else {
                // Non-siteaccess aware route, it's not supposed to be analysed
                $matcher->expects($this->never())->method('analyseLink');
            }
        } else {
            $matcher = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher');
        }
        $sa = new SiteAccess($saName, 'test', $matcher);
        $router->setSiteAccess($sa);
        $requestContext = new RequestContext();
        $urlComponents = parse_url($urlGenerated);
        if (isset($urlComponents['host'])) {
            $requestContext->setHost($urlComponents['host']);
            $requestContext->setScheme($urlComponents['scheme']);
            if (isset($urlComponents['port']) && $urlComponents['scheme'] === 'http') {
                $requestContext->setHttpPort($urlComponents['port']);
            } elseif (isset($urlComponents['port']) && $urlComponents['scheme'] === 'https') {
                $requestContext->setHttpsPort($urlComponents['port']);
            }
        }
        $requestContext->setBaseUrl(substr($urlComponents['path'], 0, strpos($urlComponents['path'], $relevantUri)));
        $router->setContext($requestContext);
        $router->setNonSiteAccessAwareRoutes($nonSiteAccessAwareRoutes);
        $this->assertSame($expectedUrl, $router->generate($routeName, array(), $referenceType));
    }