class ContentAwareGeneratorTest

Hierarchy

  • class \Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase extends \Symfony\Cmf\Component\Routing\Test\PHPUnit_Framework_TestCase

Expanded class hierarchy of ContentAwareGeneratorTest

File

drupal/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/Routing/ContentAwareGeneratorTest.php, line 10

Namespace

Symfony\Cmf\Component\Routing\Tests\Routing
View source
class ContentAwareGeneratorTest extends CmfUnitTestCase {
  protected $contentDocument;
  protected $routeDocument;
  protected $routeCompiled;
  protected $provider;

  /**
   * @var ContentAwareGenerator
   */
  protected $generator;
  protected $context;
  public function setUp() {
    $this->contentDocument = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteAwareInterface');
    $this->routeDocument = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', 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 TestableContentAwareGenerator($this->provider);
  }
  public function testGenerateFromContent() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $this->routeDocument,
    )));
    $this->routeDocument
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($this->contentDocument));
  }
  public function testGenerateFromContentId() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $contentRepository = $this
      ->buildMock("Symfony\\Cmf\\Component\\Routing\\ContentRepositoryInterface", array(
      'findById',
      'getContentId',
    ));
    $contentRepository
      ->expects($this
      ->once())
      ->method('findById')
      ->with('/content/id')
      ->will($this
      ->returnValue($this->contentDocument));
    $this->generator
      ->setContentRepository($contentRepository);
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $this->routeDocument,
    )));
    $this->routeDocument
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate('', array(
      'content_id' => '/content/id',
    )));
  }
  public function testGenerateEmptyRouteString() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $this->routeDocument,
    )));
    $this->routeDocument
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($this->contentDocument));
  }
  public function testGenerateRouteMultilang() {
    $route_en = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array(
      'getDefaults',
      'compile',
      'getRouteContent',
    ));
    $route_en
      ->setLocale('en');
    $route_de = $this->routeDocument;
    $route_de
      ->setLocale('de');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $route_en,
      $route_de,
    )));
    $route_en
      ->expects($this
      ->once())
      ->method('getRouteContent')
      ->will($this
      ->returnValue($this->contentDocument));
    $route_en
      ->expects($this
      ->never())
      ->method('compile');
    $route_de
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($route_en, array(
      '_locale' => 'de',
    )));
  }
  public function testGenerateRouteMultilangLocaleNomatch() {
    $route_en = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array(
      'getDefaults',
      'compile',
      'getRouteContent',
    ));
    $route_en
      ->setLocale('en');
    $route_de = $this->routeDocument;
    $route_de
      ->setLocale('de');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $route_en,
      $route_de,
    )));
    $route_en
      ->expects($this
      ->once())
      ->method('getRouteContent')
      ->will($this
      ->returnValue($this->contentDocument));
    $route_en
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $route_de
      ->expects($this
      ->never())
      ->method('compile');
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($route_en, array(
      '_locale' => 'fr',
    )));
  }
  public function testGenerateNoncmfRouteMultilang() {
    $route_en = $this
      ->buildMock('Symfony\\Component\\Routing\\Route', array(
      'getDefaults',
      'compile',
      'getRouteContent',
    ));
    $route_en
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($route_en, array(
      '_locale' => 'de',
    )));
  }
  public function testGenerateRoutenameMultilang() {
    $name = 'foo/bar';
    $route_en = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array(
      'getDefaults',
      'compile',
      'getRouteContent',
    ));
    $route_en
      ->setLocale('en');
    $route_de = $this->routeDocument;
    $route_de
      ->setLocale('de');
    $this->provider
      ->expects($this
      ->once())
      ->method('getRouteByName')
      ->with($name)
      ->will($this
      ->returnValue($route_en));
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $route_en,
      $route_de,
    )));
    $route_en
      ->expects($this
      ->once())
      ->method('getRouteContent')
      ->will($this
      ->returnValue($this->contentDocument));
    $route_en
      ->expects($this
      ->never())
      ->method('compile');
    $route_de
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($name, array(
      '_locale' => 'de',
    )));
  }

  /**
   * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateRoutenameMultilangNotFound() {
    $name = 'foo/bar';
    $this->provider
      ->expects($this
      ->once())
      ->method('getRouteByName')
      ->with($name)
      ->will($this
      ->returnValue(null));
    $this->generator
      ->generate($name, array(
      '_locale' => 'de',
    ));
  }
  public function testGenerateDocumentMultilang() {
    $route_en = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array(
      'getDefaults',
      'compile',
    ));
    $route_en
      ->setLocale('en');
    $route_de = $this->routeDocument;
    $route_de
      ->setLocale('de');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $route_en,
      $route_de,
    )));
    $route_en
      ->expects($this
      ->never())
      ->method('compile');
    $route_de
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($this->contentDocument, array(
      '_locale' => 'de',
    )));
  }
  public function testGenerateDocumentMultilangLocaleNomatch() {
    $route_en = $this
      ->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array(
      'getDefaults',
      'compile',
    ));
    $route_en
      ->setLocale('en');
    $route_de = $this->routeDocument;
    $route_de
      ->setLocale('de');
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $route_en,
      $route_de,
    )));
    $route_en
      ->expects($this
      ->once())
      ->method('compile')
      ->will($this
      ->returnValue($this->routeCompiled));
    $route_de
      ->expects($this
      ->never())
      ->method('compile');
    $this
      ->assertEquals('result_url', $this->generator
      ->generate($this->contentDocument, array(
      '_locale' => 'fr',
    )));
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateNoContent() {
    $this->generator
      ->generate('', array());
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateInvalidContent() {
    $this->generator
      ->generate($this);
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateNoContentRepository() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $this->generator
      ->generate('', array(
      'content_id' => '/content/id',
    ));
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateNoContentFoundInRepository() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $contentRepository = $this
      ->buildMock("Symfony\\Cmf\\Component\\Routing\\ContentRepositoryInterface", array(
      'findById',
      'getContentId',
    ));
    $contentRepository
      ->expects($this
      ->once())
      ->method('findById')
      ->with('/content/id')
      ->will($this
      ->returnValue(null));
    $this->generator
      ->setContentRepository($contentRepository);
    $this->generator
      ->generate('', array(
      'content_id' => '/content/id',
    ));
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateWrongContentClassInRepository() {
    $this->provider
      ->expects($this
      ->never())
      ->method('getRouteByName');
    $contentRepository = $this
      ->buildMock("Symfony\\Cmf\\Component\\Routing\\ContentRepositoryInterface", array(
      'findById',
      'getContentId',
    ));
    $contentRepository
      ->expects($this
      ->once())
      ->method('findById')
      ->with('/content/id')
      ->will($this
      ->returnValue($this));
    $this->generator
      ->setContentRepository($contentRepository);
    $this->generator
      ->generate('', array(
      'content_id' => '/content/id',
    ));
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateNoRoutes() {
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array()));
    $this->generator
      ->generate($this->contentDocument);
  }

  /**
   * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
   */
  public function testGenerateInvalidRoute() {
    $this->contentDocument
      ->expects($this
      ->once())
      ->method('getRoutes')
      ->will($this
      ->returnValue(array(
      $this,
    )));
    $this->generator
      ->generate($this->contentDocument);
  }
  public function testSupports() {
    $this
      ->assertTrue($this->generator
      ->supports(''));
    $this
      ->assertTrue($this->generator
      ->supports(null));
    $this
      ->assertTrue($this->generator
      ->supports($this->contentDocument));
    $this
      ->assertFalse($this->generator
      ->supports($this));
  }
  public function testGetRouteDebugMessage() {
    $this
      ->assertContains('/some/content', $this->generator
      ->getRouteDebugMessage(null, array(
      'content_id' => '/some/content',
    )));
    $this
      ->assertContains('/some/content', $this->generator
      ->getRouteDebugMessage(new RouteAware()));
    $this
      ->assertContains('/some/content', $this->generator
      ->getRouteDebugMessage('/some/content'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CmfUnitTestCase::buildMock protected function
ContentAwareGeneratorTest::$contentDocument protected property
ContentAwareGeneratorTest::$context protected property
ContentAwareGeneratorTest::$generator protected property
ContentAwareGeneratorTest::$provider protected property
ContentAwareGeneratorTest::$routeCompiled protected property
ContentAwareGeneratorTest::$routeDocument protected property
ContentAwareGeneratorTest::setUp public function
ContentAwareGeneratorTest::testGenerateDocumentMultilang public function
ContentAwareGeneratorTest::testGenerateDocumentMultilangLocaleNomatch public function
ContentAwareGeneratorTest::testGenerateEmptyRouteString public function
ContentAwareGeneratorTest::testGenerateFromContent public function
ContentAwareGeneratorTest::testGenerateFromContentId public function
ContentAwareGeneratorTest::testGenerateInvalidContent public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateInvalidRoute public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateNoContent public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateNoContentFoundInRepository public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateNoContentRepository public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateNoncmfRouteMultilang public function
ContentAwareGeneratorTest::testGenerateNoRoutes public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateRouteMultilang public function
ContentAwareGeneratorTest::testGenerateRouteMultilangLocaleNomatch public function
ContentAwareGeneratorTest::testGenerateRoutenameMultilang public function
ContentAwareGeneratorTest::testGenerateRoutenameMultilangNotFound public function @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGenerateWrongContentClassInRepository public function @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
ContentAwareGeneratorTest::testGetRouteDebugMessage public function
ContentAwareGeneratorTest::testSupports public function