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

testGenerateReverseSiteAccessMatch() public method

    public function testGenerateReverseSiteAccessMatch()
    {
        $routeName = 'some_route_name';
        $urlGenerated = 'http://phoenix-rises.fm/foo/bar';
        $siteAccessName = 'foo_test';
        $siteAccessRouter = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\SiteAccessRouterInterface');
        $versatileMatcher = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher');
        $simplifiedRequest = new SimplifiedRequest(array('host' => 'phoenix-rises.fm', 'scheme' => 'http'));
        $versatileMatcher->expects($this->once())->method('getRequest')->will($this->returnValue($simplifiedRequest));
        $siteAccessRouter->expects($this->once())->method('matchByName')->with($siteAccessName)->will($this->returnValue(new SiteAccess($siteAccessName, 'foo', $versatileMatcher)));
        $generator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
        $generator->expects($this->at(0))->method('setContext')->with($this->isInstanceOf('Symfony\\Component\\Routing\\RequestContext'));
        $generator->expects($this->at(1))->method('generate')->with($routeName)->will($this->returnValue($urlGenerated));
        $generator->expects($this->at(2))->method('setContext')->with($this->requestContext);
        $router = new DefaultRouter($this->container, 'foo', array(), $this->requestContext);
        $router->setConfigResolver($this->configResolver);
        $router->setSiteAccess(new SiteAccess('test', 'test', $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher')));
        $router->setSiteAccessRouter($siteAccessRouter);
        $refRouter = new ReflectionObject($router);
        $refGenerator = $refRouter->getProperty('generator');
        $refGenerator->setAccessible(true);
        $refGenerator->setValue($router, $generator);
        $this->assertSame($urlGenerated, $router->generate($routeName, array('siteaccess' => $siteAccessName), DefaultRouter::ABSOLUTE_PATH));
    }