Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / routing / Tests / RouteCollectionBuilderTest.php
index 058a100d1f689044b095a640c079f3a7fac66b34..76a042d670b29114005a984be58d1ea48fbda8f0 100644 (file)
@@ -12,7 +12,9 @@
 namespace Symfony\Component\Routing\Tests;
 
 use PHPUnit\Framework\TestCase;
+use Symfony\Component\Config\FileLocator;
 use Symfony\Component\Config\Resource\FileResource;
+use Symfony\Component\Routing\Loader\YamlFileLoader;
 use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
 use Symfony\Component\Routing\RouteCollectionBuilder;
@@ -59,7 +61,18 @@ class RouteCollectionBuilderTest extends TestCase
         $this->assertCount(1, $addedCollection->getResources());
 
         // make sure the routes were imported into the top-level builder
+        $routeCollection = $routes->build();
         $this->assertCount(1, $routes->build());
+        $this->assertCount(1, $routeCollection->getResources());
+    }
+
+    public function testImportAddResources()
+    {
+        $routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
+        $routeCollectionBuilder->import('file_resource.yml');
+        $routeCollection = $routeCollectionBuilder->build();
+
+        $this->assertCount(1, $routeCollection->getResources());
     }
 
     /**
@@ -322,4 +335,30 @@ class RouteCollectionBuilderTest extends TestCase
         // there are 2 routes (i.e. with non-conflicting names)
         $this->assertCount(3, $collection->all());
     }
+
+    public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
+    {
+        $firstCollection = new RouteCollection();
+        $firstCollection->add('a', new Route('/a'));
+
+        $secondCollection = new RouteCollection();
+        $secondCollection->add('b', new Route('/b'));
+
+        $loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
+        $loader->expects($this->any())
+            ->method('supports')
+            ->will($this->returnValue(true));
+        $loader
+            ->expects($this->any())
+            ->method('load')
+            ->will($this->returnValue(array($firstCollection, $secondCollection)));
+
+        $routeCollectionBuilder = new RouteCollectionBuilder($loader);
+        $routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
+        $routes = $routeCollectionBuilder->build()->all();
+
+        $this->assertCount(2, $routes);
+        $this->assertEquals('/other/a', $routes['a']->getPath());
+        $this->assertEquals('/other/b', $routes['b']->getPath());
+    }
 }