public function testCreateItemWithAbsoluteRoute()
 {
     $generator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $generator->expects($this->once())->method('generate')->with('homepage', array(), true)->will($this->returnValue('http://php.net'));
     $factory = new RouterAwareFactory($generator);
     $item = $factory->createItem('test_item', array('route' => 'homepage', 'routeAbsolute' => true));
     $this->assertEquals('http://php.net', $item->getUri());
 }
Ejemplo n.º 2
0
 public function createItem($name, array $options = array())
 {
     if (!empty($options['content'])) {
         $options['uri'] = $this->content_router->generate($options['content']);
         unset($options['route']);
     }
     return parent::createItem($name, $options);
 }
 public function testCreateItemWithRoute()
 {
     $generator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $generator->expects($this->once())->method('generate')->with('homepage', array(), false)->will($this->returnValue('/foobar'));
     $deprecatedErrorCatched = false;
     set_error_handler(function ($errorNumber, $message, $file, $line) use(&$deprecatedErrorCatched) {
         if ($errorNumber & E_USER_DEPRECATED) {
             $deprecatedErrorCatched = true;
             return true;
         }
         return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
     });
     try {
         $factory = new RouterAwareFactory($generator);
     } catch (\Exception $e) {
         restore_error_handler();
         throw $e;
     }
     restore_error_handler();
     $this->assertTrue($deprecatedErrorCatched, 'The RouterAwareFactory throws a E_USER_DEPRECATED when instantiating it.');
     $item = $factory->createItem('test_item', array('uri' => '/hello', 'route' => 'homepage'));
     $this->assertEquals('/foobar', $item->getUri());
 }
 public function createItem($name, array $options = array())
 {
     $current = false;
     if (!empty($options['content'])) {
         try {
             $request = $this->container->get('request');
             if ($request->attributes->get($this->contentKey) == $options['content']) {
                 $current = true;
             }
         } catch (\Exception $e) {
         }
         $routeParameters = $options['routeParameters'];
         $routeParameters['content'] = $options['content'];
         $options['uri'] = $this->contentRouter->generate($this->routeName, $routeParameters, $options['routeAbsolute']);
         unset($options['route']);
     }
     $item = parent::createItem($name, $options);
     if ($current) {
         $item->setCurrent(true);
     }
     return $item;
 }