Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Routing / RequestFormatRouteFilterTest.php
index 3574ee195004ca24718284846eefd19e9f4341c9..83d0505f15c765a2dbf3d4af011c2d2a9cb7ca81 100644 (file)
@@ -2,7 +2,10 @@
 
 namespace Drupal\Tests\Core\Routing;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\GeneratedUrl;
 use Drupal\Core\Routing\RequestFormatRouteFilter;
+use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
@@ -59,6 +62,14 @@ class RequestFormatRouteFilterTest extends UnitTestCase {
    * @covers ::filter
    */
   public function testNoRouteFound() {
+    $url = $this->prophesize(GeneratedUrl::class);
+    $url_assembler = $this->prophesize(UnroutedUrlAssemblerInterface::class);
+    $url_assembler->assemble('http://localhost/test?_format=xml', ['query' => ['_format' => 'json'], 'external' => TRUE], TRUE)
+      ->willReturn($url);
+    $container = new ContainerBuilder();
+    $container->set('unrouted_url_assembler', $url_assembler->reveal());
+    \Drupal::setContainer($container);
+
     $collection = new RouteCollection();
     $route_with_format = $route = new Route('/test');
     $route_with_format->setRequirement('_format', 'json');
@@ -78,6 +89,16 @@ class RequestFormatRouteFilterTest extends UnitTestCase {
   public function testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats() {
     $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format html.');
 
+    $url = $this->prophesize(GeneratedUrl::class);
+    $url_assembler = $this->prophesize(UnroutedUrlAssemblerInterface::class);
+    $url_assembler->assemble('http://localhost/test', ['query' => ['_format' => 'json'], 'external' => TRUE], TRUE)
+      ->willReturn($url);
+    $url_assembler->assemble('http://localhost/test', ['query' => ['_format' => 'xml'], 'external' => TRUE], TRUE)
+      ->willReturn($url);
+    $container = new ContainerBuilder();
+    $container->set('unrouted_url_assembler', $url_assembler->reveal());
+    \Drupal::setContainer($container);
+
     $collection = new RouteCollection();
     $route_with_format = $route = new Route('/test');
     $route_with_format->setRequirement('_format', 'json|xml');