Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Symfony\Component\Config\Loader\FileLoader
 public function runTest()
 {
     $locator = new FileLocator(array(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "config"));
     $loader = new XmlFileLoader($locator);
     $routes = $loader->load("routing.xml");
     $validator = new RouteValidator(new UrlMatcher($routes, new RequestContext("/")));
     $validator->validate();
 }
Example #2
0
 /**
  * @covers Symfony\Component\Routing\Loader\XmlFileLoader::supports
  */
 public function testSupports()
 {
     $loader = new XmlFileLoader();
     $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
     $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
     $this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
     $this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
 }
Example #3
0
 /**
  * @covers Symfony\Component\Routing\Loader\XmlFileLoader::supports
  */
 public function testSupports()
 {
     $loader = new XmlFileLoader($this->getMock('Symfony\\Component\\Config\\FileLocator'));
     $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
     $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
     $this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
     $this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
 }
 public function testLoadTokenRouting()
 {
     $locator = new FileLocator();
     $loader = new XmlFileLoader($locator);
     $collection = $loader->load(__DIR__ . '/../../Resources/config/routing/token.xml');
     $tokenRoute = $collection->get('fos_oauth_server_token');
     $this->assertEquals('/oauth/v2/token', $tokenRoute->getPath());
     $this->assertEquals(array('GET', 'POST'), $tokenRoute->getMethods());
 }
 public function setUp()
 {
     date_default_timezone_set('Europe/London');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->pool = new Pool($container, '', '');
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->twigExtension = new SonataAdminExtension($this->pool, $this->logger);
     $loader = new StubFilesystemLoader(array(__DIR__ . '/../../../Resources/views/CRUD'));
     $this->environment = new \Twig_Environment($loader, array('strict_variables' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0));
     $this->environment->addExtension($this->twigExtension);
     // translation extension
     $translator = new Translator('en', new MessageSelector());
     $translator->addLoader('xlf', new XliffFileLoader());
     $translator->addResource('xlf', __DIR__ . '/../../../Resources/translations/SonataAdminBundle.en.xliff', 'en', 'SonataAdminBundle');
     $this->environment->addExtension(new TranslationExtension($translator));
     // routing extension
     $xmlFileLoader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../../../Resources/config/routing')));
     $routeCollection = $xmlFileLoader->load('sonata_admin.xml');
     $xmlFileLoader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../../Fixtures/Resources/config/routing')));
     $testRouteCollection = $xmlFileLoader->load('routing.xml');
     $routeCollection->addCollection($testRouteCollection);
     $requestContext = new RequestContext();
     $urlGenerator = new UrlGenerator($routeCollection, $requestContext);
     $this->environment->addExtension(new RoutingExtension($urlGenerator));
     $this->environment->addExtension(new \Twig_Extensions_Extension_Text());
     $this->twigExtension->initRuntime($this->environment);
     // initialize object
     $this->object = new \stdClass();
     // initialize admin
     $this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $this->admin->expects($this->any())->method('isGranted')->will($this->returnValue(true));
     $this->admin->expects($this->any())->method('getCode')->will($this->returnValue('xyz'));
     $this->admin->expects($this->any())->method('id')->with($this->equalTo($this->object))->will($this->returnValue(12345));
     $this->admin->expects($this->any())->method('getNormalizedIdentifier')->with($this->equalTo($this->object))->will($this->returnValue(12345));
     $this->admin->expects($this->any())->method('trans')->will($this->returnCallback(function ($id) {
         return $id;
     }));
     // for php5.3 BC
     $admin = $this->admin;
     $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($admin) {
         if ($id == 'sonata_admin_foo_service') {
             return $admin;
         }
         return;
     }));
     // initialize field description
     $this->fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $this->fieldDescription->expects($this->any())->method('getName')->will($this->returnValue('fd_name'));
     $this->fieldDescription->expects($this->any())->method('getAdmin')->will($this->returnValue($this->admin));
     $this->fieldDescription->expects($this->any())->method('getLabel')->will($this->returnValue('Data'));
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function load($data, $type = null)
 {
     $routeCollection = new RouteCollection();
     $routeCollection->addCollection($this->fileLoader->load('json_ld.xml'));
     $routeCollection->addCollection($this->fileLoader->load('hydra.xml'));
     foreach ($this->resourceCollection as $resource) {
         foreach ($resource->getCollectionOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
         foreach ($resource->getItemOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
     }
     return $routeCollection;
 }
 public function __construct(FileLocatorInterface $locator, I18nRouteCollectionBuilder $collectionBuilder = null)
 {
     parent::__construct($locator);
     if ($collectionBuilder === null) {
         $collectionBuilder = new I18nRouteCollectionBuilder();
     }
     $this->collectionBuilder = $collectionBuilder;
 }
Example #8
0
 /**
  * @dataProvider loadRoutingProvider
  */
 public function testLoadRouting($routeName, $path, array $methods)
 {
     $locator = new FileLocator();
     $loader = new XmlFileLoader($locator);
     $collection = new RouteCollection();
     $collection->addCollection($loader->load(__DIR__ . '/../../Resources/config/routing/change_password.xml'));
     $subCollection = $loader->load(__DIR__ . '/../../Resources/config/routing/group.xml');
     $subCollection->addPrefix('/group');
     $collection->addCollection($subCollection);
     $subCollection = $loader->load(__DIR__ . '/../../Resources/config/routing/profile.xml');
     $subCollection->addPrefix('/profile');
     $collection->addCollection($subCollection);
     $subCollection = $loader->load(__DIR__ . '/../../Resources/config/routing/registration.xml');
     $subCollection->addPrefix('/register');
     $collection->addCollection($subCollection);
     $subCollection = $loader->load(__DIR__ . '/../../Resources/config/routing/resetting.xml');
     $subCollection->addPrefix('/resetting');
     $collection->addCollection($subCollection);
     $collection->addCollection($loader->load(__DIR__ . '/../../Resources/config/routing/security.xml'));
     $route = $collection->get($routeName);
     $this->assertNotNull($route, sprintf('The route "%s" should exists', $routeName));
     $this->assertEquals($path, $route->getPath());
     $this->assertEquals($methods, $route->getMethods());
 }
 public function testNullValues()
 {
     $loader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $routeCollection = $loader->load('null_values.xml');
     $route = $routeCollection->get('blog_show');
     $this->assertTrue($route->hasDefault('foo'));
     $this->assertNull($route->getDefault('foo'));
     $this->assertTrue($route->hasDefault('bar'));
     $this->assertNull($route->getDefault('bar'));
     $this->assertEquals('foo', $route->getDefault('foobar'));
     $this->assertEquals('bar', $route->getDefault('baz'));
 }
Example #10
0
 public function __construct(FileLocatorInterface $locator, RestRouteProcessor $processor)
 {
     parent::__construct($locator);
     $this->processor = $processor;
 }
 /**
  * @expectedException \InvalidArgumentException
  * @dataProvider getPathsToInvalidFiles
  */
 public function testLoadThrowsExceptionWithInvalidFile($filePath)
 {
     $loader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $loader->load($filePath);
 }
 /**
  * {@inheritDoc}
  */
 protected function loadFile($file)
 {
     if (class_exists('Symfony\\Component\\Config\\Util\\XmlUtils')) {
         $dom = XmlUtils::loadFile($file);
         $this->validate($dom);
         return $dom;
     }
     return parent::loadFile($file);
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Document types are not allowed.
  */
 public function testDocTypeIsNotAllowed()
 {
     $loader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $loader->load('withdoctype.xml');
 }
                // nested arrays are not supported
                return $v;
            }
            if (strlen($val) === 0) {
                $escaped[$k] = null;
                continue;
            }
            $escaped[$k] = htmlspecialchars($val, ENT_QUOTES);
        }
        return $escaped;
    }
    return $v;
});
$deserializer = new HTTPQueryStringDeserializer($dispatcher, $mdFactory);
$eventDispatcher->addSubscriber(new RequestDeserializer($deserializer));
// application routes ...
$stack = new \Symfony\Component\HttpFoundation\RequestStack();
$fl = new FileLocator('config');
$loader = new XmlFileLoader($fl);
$collection = $loader->load('routing/routes.xml');
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($collection, $context);
$rResolver = new RouterListener($matcher, $context, null, $stack);
$eventDispatcher->addSubscriber($rResolver);
// finally create the kernel ...
$app = new HttpKernel($eventDispatcher, $conrollerResolver);
// ... submit the request ...
$response = $app->handle($request);
// ... and return the response to the client
$response->send();
Example #15
0
    public function testNullValuesInMap()
    {
        $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
        $routeCollection = $loader->load('map_null_values.xml');
        $route = $routeCollection->get('blog');

        $this->assertSame(
            array(
                'boolean' => null,
                'integer' => null,
                'float' => null,
                'string' => null,
                'list' => null,
                'map' => null,
            ),
            $route->getDefault('map')
        );
    }
 /**
  * {@inheritDoc}
  */
 protected function loadFile($file)
 {
     if (class_exists('Symfony\\Component\\Config\\Util\\XmlUtils')) {
         return XmlUtils::loadFile($file, __DIR__ . '/../../Resources/config/schema/routing/rest_routing-1.0.xsd');
     }
     return parent::loadFile($file);
 }