public function setUp()
 {
     $this->candidatesMock = $this->buildMock('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Phpcr\\PrefixCandidates');
     $this->candidatesMock->expects($this->any())->method('getPrefixes')->will($this->returnValue(array('/cms/routes', '/cms/simple')));
     $this->listener = new LocaleListener($this->candidatesMock, array('en', 'de'));
     $this->routeMock = $this->buildMock('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Phpcr\\Route');
     $this->dmMock = $this->buildMock('Doctrine\\ODM\\PHPCR\\DocumentManager');
 }
 /**
  * Use getRouteByName() with two different document managers.
  * The two document managers will return different route objects when searching for the same path.
  */
 public function testChangingDocumentManager()
 {
     $this->routeMock->expects($this->any())->method('getPath')->will($this->returnValue('/cms/routes/test-route'));
     $this->route2Mock->expects($this->any())->method('getPath')->will($this->returnValue('/cms/routes/new-route'));
     $this->dmMock->expects($this->any())->method('find')->with(null, '/cms/routes/test-route')->will($this->returnValue($this->routeMock));
     $this->dm2Mock->expects($this->any())->method('find')->with(null, '/cms/routes/test-route')->will($this->returnValue($this->route2Mock));
     $objectManagers = array('default' => $this->dmMock, 'new_manager' => $this->dm2Mock);
     $this->managerRegistryMock = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $this->managerRegistryMock->expects($this->any())->method('getManager')->will($this->returnCallback(function ($name) use($objectManagers) {
         return $objectManagers[$name];
     }));
     $this->candidatesMock->expects($this->any())->method('isCandidate')->will($this->returnValue(true));
     $routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock);
     $routeProvider->setManagerName('default');
     $foundRoute = $routeProvider->getRouteByName('/cms/routes/test-route');
     $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $foundRoute);
     $this->assertEquals('/cms/routes/test-route', $foundRoute->getPath());
     $routeProvider->setManagerName('new_manager');
     $newFoundRoute = $routeProvider->getRouteByName('/cms/routes/test-route');
     $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $newFoundRoute);
     $this->assertEquals('/cms/routes/new-route', $newFoundRoute->getPath());
 }
 public function testRestrictQueryGlobal()
 {
     $qb = $this->getMock('Doctrine\\ODM\\PHPCR\\Query\\Builder\\QueryBuilder', array('andWhere'));
     $qb->expects($this->never())->method('andWhere');
     $candidates = new PrefixCandidates(array('/routes', '', '/other'));
     $candidates->restrictQuery($qb);
 }
 /**
  * @return array
  */
 protected function getPrefixes()
 {
     return $this->candidates->getPrefixes();
 }