ProviderBasedGeneratorTest.php in Zircon Profile 8.0
File
vendor/symfony-cmf/routing/Tests/Routing/ProviderBasedGeneratorTest.php
View source
<?php
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Cmf\Component\Routing\ProviderBasedGenerator;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class ProviderBasedGeneratorTest extends CmfUnitTestCase {
protected $routeDocument;
protected $routeCompiled;
protected $provider;
protected $generator;
protected $context;
public function setUp() {
$this->routeDocument = $this
->buildMock('Symfony\\Component\\Routing\\Route', array(
'getDefaults',
'compile',
));
$this->routeCompiled = $this
->buildMock('Symfony\\Component\\Routing\\CompiledRoute');
$this->provider = $this
->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface');
$this->context = $this
->buildMock('Symfony\\Component\\Routing\\RequestContext');
$this->generator = new TestableProviderBasedGenerator($this->provider);
}
public function testGenerateFromName() {
$name = 'foo/bar';
$this->provider
->expects($this
->once())
->method('getRouteByName')
->with($name)
->will($this
->returnValue($this->routeDocument));
$this->routeDocument
->expects($this
->once())
->method('compile')
->will($this
->returnValue($this->routeCompiled));
$this
->assertEquals('result_url', $this->generator
->generate($name));
}
public function testGenerateNotFound() {
$name = 'foo/bar';
$this->provider
->expects($this
->once())
->method('getRouteByName')
->with($name)
->will($this
->returnValue(null));
$this->generator
->generate($name);
}
public function testGenerateFromRoute() {
$this->provider
->expects($this
->never())
->method('getRouteByName');
$this->routeDocument
->expects($this
->once())
->method('compile')
->will($this
->returnValue($this->routeCompiled));
$this
->assertEquals('result_url', $this->generator
->generate($this->routeDocument));
}
public function testSupports() {
$this
->assertTrue($this->generator
->supports('foo/bar'));
$this
->assertTrue($this->generator
->supports($this->routeDocument));
$this
->assertFalse($this->generator
->supports($this));
}
public function testGetRouteDebugMessage() {
$this
->assertContains('/some/key', $this->generator
->getRouteDebugMessage(new RouteObject()));
$this
->assertContains('/de/test', $this->generator
->getRouteDebugMessage(new Route('/de/test')));
$this
->assertContains('/some/route', $this->generator
->getRouteDebugMessage('/some/route'));
$this
->assertContains('a:1:{s:10:"route_name";s:7:"example";}', $this->generator
->getRouteDebugMessage(array(
'route_name' => 'example',
)));
}
public function testGenerateByRoute() {
$this->generator = new ProviderBasedGenerator($this->provider);
$route = new Route('/test');
$route
->setPath('/test/{number}');
$route
->setRequirement('number', '\\+d');
$this->generator
->setStrictRequirements(true);
$context = new RequestContext();
$this->generator
->setContext($context);
$this
->assertSame(null, $this->generator
->generate($route, array(
'number' => 'string',
)));
}
}
class TestableProviderBasedGenerator extends ProviderBasedGenerator {
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array()) {
return 'result_url';
}
}
class RouteObject implements RouteObjectInterface {
public function getRouteKey() {
return '/some/key';
}
public function getContent() {
return null;
}
}