diff --git a/composer.json b/composer.json index d6cdc7f..67095fe 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "easyrdf/easyrdf": "0.8.*", "phpunit/phpunit": "4.1.*", "phpunit/phpunit-mock-objects": "dev-master#e60bb929c50ae4237aaf680a4f6773f4ee17f0a2", + "willdurand/negotiation": "1.3.*", "zendframework/zend-feed": "2.2.*", "mikey179/vfsStream": "1.*" }, diff --git a/core/core.services.yml b/core/core.services.yml index a58f779..a5ec2a8 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -391,7 +391,7 @@ services: - { name: event_subscriber } router.route_preloader: class: Drupal\Core\Routing\RoutePreloader - arguments: ['@router.route_provider', '@state', '@content_negotiation'] + arguments: ['@router.route_provider', '@state'] tags: - { name: 'event_subscriber' } router.matcher.final_matcher: @@ -477,7 +477,6 @@ services: arguments: [16] accept_header_matcher: class: Drupal\Core\Routing\AcceptHeaderMatcher - arguments: ['@content_negotiation'] tags: - { name: route_filter } content_type_header_matcher: @@ -578,12 +577,12 @@ services: - { name: event_subscriber } arguments: ['@router', '@router.request_context', NULL, '@request_stack'] content_negotiation: - class: Drupal\Core\ContentNegotiation + class: Negotiation\FormatNegotiator view_subscriber: class: Drupal\Core\EventSubscriber\ViewSubscriber tags: - { name: event_subscriber } - arguments: ['@content_negotiation', '@title_resolver', '@ajax_response_renderer'] + arguments: ['@title_resolver', '@ajax_response_renderer'] html_view_subscriber: class: Drupal\Core\EventSubscriber\HtmlViewSubscriber tags: @@ -685,7 +684,7 @@ services: arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot'] exception_controller: class: Drupal\Core\Controller\ExceptionController - arguments: ['@content_negotiation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer', '@string_translation', '@url_generator'] + arguments: ['@title_resolver', '@html_page_renderer', '@html_fragment_renderer', '@string_translation', '@url_generator'] calls: - [setContainer, ['@service_container']] exception_listener: diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php deleted file mode 100644 index 500200c..0000000 --- a/core/lib/Drupal/Core/ContentNegotiation.php +++ /dev/null @@ -1,64 +0,0 @@ -. - if ($request->get('ajax_iframe_upload', FALSE)) { - return 'iframeupload'; - } - - // Check all formats, if priority format is found return it. - $first_found_format = FALSE; - $priority = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog'); - foreach ($request->getAcceptableContentTypes() as $mime_type) { - $format = $request->getFormat($mime_type); - if (in_array($format, $priority, TRUE)) { - return $format; - } - if (!is_null($format) && !$first_found_format) { - $first_found_format = $format; - } - } - - // No HTML found, return first found. - if ($first_found_format) { - return $first_found_format; - } - - if ($request->isXmlHttpRequest()) { - return 'ajax'; - } - - // Do HTML last so that it always wins. - return 'html'; - } -} diff --git a/core/lib/Drupal/Core/Controller/ExceptionController.php b/core/lib/Drupal/Core/Controller/ExceptionController.php index dbd227f..52ace0b 100644 --- a/core/lib/Drupal/Core/Controller/ExceptionController.php +++ b/core/lib/Drupal/Core/Controller/ExceptionController.php @@ -20,7 +20,6 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\String; use Symfony\Component\Debug\Exception\FlattenException; -use Drupal\Core\ContentNegotiation; use Drupal\Core\Utility\Error; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; @@ -32,13 +31,6 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn use StringTranslationTrait; /** - * The content negotiation library. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $negotiation; - - /** * The service container. * * @var \Symfony\Component\DependencyInjection\ContainerInterface @@ -62,9 +54,6 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn /** * Constructor. * - * @param \Drupal\Core\ContentNegotiation $negotiation - * The content negotiation library to use to determine the correct response - * format. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. * @param \Drupal\Core\Page\HtmlPageRendererInterface $renderer @@ -75,9 +64,8 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn * The url generator. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator */ - public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, HtmlFragmentRendererInterface $fragment_renderer, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator) { + public function __construct(TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, HtmlFragmentRendererInterface $fragment_renderer, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator) { parent::__construct($title_resolver, $url_generator); - $this->negotiation = $negotiation; $this->htmlPageRenderer = $renderer; $this->fragmentRenderer = $fragment_renderer; $this->stringTranslation = $string_translation; @@ -107,7 +95,7 @@ public function setContainer(ContainerInterface $container = NULL) { * A response object. */ public function execute(FlattenException $exception, Request $request) { - $method = 'on' . $exception->getStatusCode() . $this->negotiation->getContentType($request); + $method = 'on' . $exception->getStatusCode() . $request->getRequestFormat(); if (method_exists($this, $method)) { return $this->$method($exception, $request); diff --git a/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php index 377ae93..9fae03e 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\ContentNegotiation; +use Negotiation\FormatNegotiatorInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -20,17 +20,17 @@ class ContentControllerSubscriber implements EventSubscriberInterface { /** * Content negotiation library. * - * @var \Drupal\Core\ContentNegotiation + * @var \Negotiation\FormatNegotiatorInterface */ protected $negotiation; /** * Constructs a new ContentControllerSubscriber object. * - * @param \Drupal\Core\ContentNegotiation $negotiation + * @param \Negotiation\FormatNegotiatorInterface $negotiation * The Content Negotiation service. */ - public function __construct(ContentNegotiation $negotiation) { + public function __construct(FormatNegotiatorInterface $negotiation) { $this->negotiation = $negotiation; } @@ -56,7 +56,16 @@ public function onRequestDeriveFormat(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->attributes->get('_format')) { - $request->setRequestFormat($this->negotiation->getContentType($request)); + // The following formats have special high-priority according to Drupal. + // Any other formats should negotiate in order as appropriate. + $priorities = array('text/html', 'application/vnd.drupal-ajax', 'application/vnd.drupal-modal', 'application/vnd.drupal-dialog'); + + // Because we're registering new formats on the Request object, we will + // retrieve the raw mime type and then let the request map that to + // the format machine name. That way we only need to register new formats + // on the one object. + $format = $this->negotiation->getBest($accept_header = $request->headers->get('Accept'), $priorities); + $request->setRequestFormat($request->getFormat($format->getValue())); } } @@ -84,7 +93,7 @@ public function onRequestDeriveContentWrapper(GetResponseEvent $event) { * An array of event listener definitions. */ static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = array('onRequestDeriveFormat', 31); + $events[KernelEvents::REQUEST][] = array('onRequestDeriveFormat', 33); $events[KernelEvents::REQUEST][] = array('onRequestDeriveContentWrapper', 30); return $events; diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php index 84b94c9..696b104 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php @@ -18,8 +18,6 @@ use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Drupal\Core\ContentNegotiation; - /** * Main subscriber for VIEW HTTP responses. * @@ -30,13 +28,6 @@ class ViewSubscriber implements EventSubscriberInterface { /** - * The content negotiation. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $negotiation; - - /** * The title resolver. * * @var \Drupal\Core\Controller\TitleResolverInterface @@ -53,15 +44,12 @@ class ViewSubscriber implements EventSubscriberInterface { /** * Constructs a new ViewSubscriber. * - * @param \Drupal\Core\ContentNegotiation $negotiation - * The content negotiation. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. * @param \Drupal\Core\Ajax\AjaxResponseRenderer $ajax_renderer * The ajax response renderer. */ - public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, AjaxResponseRenderer $ajax_renderer) { - $this->negotiation = $negotiation; + public function __construct(TitleResolverInterface $title_resolver, AjaxResponseRenderer $ajax_renderer) { $this->titleResolver = $title_resolver; $this->ajaxRenderer = $ajax_renderer; } @@ -88,7 +76,7 @@ public function onView(GetResponseForControllerResultEvent $event) { // object. The subrequest's response will get dissected and placed into // the larger page as needed. if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { - $method = 'on' . $this->negotiation->getContentType($request); + $method = 'on' . $request->getRequestFormat(); if (method_exists($this, $method)) { $event->setResponse($this->$method($event)); diff --git a/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php b/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php index 34f0ae5..5ba6285 100644 --- a/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php +++ b/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Routing; use Drupal\Component\Utility\String; -use Drupal\Core\ContentNegotiation; +use Negotiation\FormatNegotiatorInterface; use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; @@ -20,23 +20,6 @@ class AcceptHeaderMatcher implements RouteFilterInterface { /** - * The content negotiation library. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $contentNegotiation; - - /** - * Constructs a new AcceptHeaderMatcher. - * - * @param \Drupal\Core\ContentNegotiation $cotent_negotiation - * The content negotiation library. - */ - public function __construct(ContentNegotiation $content_negotiation) { - $this->contentNegotiation = $content_negotiation; - } - - /** * {@inheritdoc} */ public function filter(RouteCollection $collection, Request $request) { @@ -44,11 +27,11 @@ public function filter(RouteCollection $collection, Request $request) { // @todo replace by proper content negotiation library. $acceptable_mime_types = $request->getAcceptableContentTypes(); $acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types)); - $primary_format = $this->contentNegotiation->getContentType($request); + $primary_format = $request->getRequestFormat(); foreach ($collection as $name => $route) { // _format could be a |-delimited list of supported formats. - $supported_formats = array_filter(explode('|', $route->getRequirement('_format'))); + $supported_formats = array_unique(array_filter(explode('|', $route->getRequirement('_format')))); if (empty($supported_formats)) { // No format restriction on the route, so it always matches. Move it to diff --git a/core/lib/Drupal/Core/Routing/Enhancer/AjaxEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/AjaxEnhancer.php index 4d0c707..be82238 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/AjaxEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/AjaxEnhancer.php @@ -9,7 +9,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; -use Drupal\Core\ContentNegotiation; /** * Enhances an ajax route with the appropriate controller. @@ -17,30 +16,13 @@ class AjaxEnhancer implements RouteEnhancerInterface { /** - * Content negotiation library. - * - * @var \Drupal\CoreContentNegotiation - */ - protected $negotiation; - - /** - * Constructs a new \Drupal\Core\Routing\Enhancer\AjaxEnhancer object. - * - * @param \Drupal\Core\ContentNegotiation $negotiation - * The Content Negotiation service. - */ - public function __construct(ContentNegotiation $negotiation) { - $this->negotiation = $negotiation; - } - - /** * {@inheritdoc} */ public function enhance(array $defaults, Request $request) { // A request can have the 'ajax' content type when the controller supports // basically both simple HTML and Ajax routes by returning a render array. // In those cases we want to convert it to a proper ajax response as well. - if (empty($defaults['_content']) && $defaults['_controller'] != 'controller.ajax:content' && in_array($this->negotiation->getContentType($request), array('drupal_ajax', 'ajax', 'iframeupload'))) { + if (empty($defaults['_content']) && $defaults['_controller'] != 'controller.ajax:content' && in_array($request->getRequestFormat(), array('drupal_ajax', 'ajax', 'iframeupload'))) { $defaults['_content'] = isset($defaults['_controller']) ? $defaults['_controller'] : NULL; $defaults['_controller'] = 'controller.ajax:content'; } diff --git a/core/lib/Drupal/Core/Routing/RoutePreloader.php b/core/lib/Drupal/Core/Routing/RoutePreloader.php index 7952d17..8e8d230 100644 --- a/core/lib/Drupal/Core/Routing/RoutePreloader.php +++ b/core/lib/Drupal/Core/Routing/RoutePreloader.php @@ -38,13 +38,6 @@ class RoutePreloader implements EventSubscriberInterface { protected $state; /** - * The content negotiation. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $negotiation; - - /** * Contains the non-admin routes while rebuilding the routes. * * @var array @@ -58,13 +51,10 @@ class RoutePreloader implements EventSubscriberInterface { * The route provider. * @param \Drupal\Core\State\StateInterface $state * The state key value store. - * @param \Drupal\Core\ContentNegotiation $negotiation - * The content negotiation. */ - public function __construct(RouteProviderInterface $route_provider, StateInterface $state, ContentNegotiation $negotiation) { + public function __construct(RouteProviderInterface $route_provider, StateInterface $state) { $this->routeProvider = $route_provider; $this->state = $state; - $this->negotiation = $negotiation; } /** @@ -75,7 +65,7 @@ public function __construct(RouteProviderInterface $route_provider, StateInterfa */ public function onRequest(KernelEvent $event) { // Just preload on normal HTML pages, as they will display menu links. - if ($this->negotiation->getContentType($event->getRequest()) == 'html') { + if ($event->getRequest()->getRequestFormat() == 'html') { $this->loadNonAdminRoutes(); } } diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index e41fef0..ac7485d 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -11,7 +11,6 @@ use Drupal\Core\Form\FormErrorInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteProviderInterface; -use Drupal\Core\ContentNegotiation; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\PathPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -73,13 +72,6 @@ class RestExport extends PathPluginBase { protected $mimeType; /** - * The content negotiation library. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $contentNegotiation; - - /** * Constructs a Drupal\rest\Plugin\ResourceBase object. * * @param array $configuration @@ -94,12 +86,9 @@ class RestExport extends PathPluginBase { * The state key value store. * @param \Drupal\Core\Form\FormErrorInterface $form_error * The form error helper. - * @param \Drupal\Core\ContentNegotiation $content_negotiation - * The content negotiation library. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, FormErrorInterface $form_error, ContentNegotiation $content_negotiation) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, FormErrorInterface $form_error) { parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state, $form_error); - $this->contentNegotiation = $content_negotiation; } /** @@ -112,8 +101,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('router.route_provider'), $container->get('state'), - $container->get('form_validator'), - $container->get('content_negotiation') + $container->get('form_validator') ); } @@ -123,7 +111,7 @@ public static function create(ContainerInterface $container, array $configuratio public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) { parent::initDisplay($view, $display, $options); - $request_content_type = $this->contentNegotiation->getContentType($this->view->getRequest()); + $request_content_type = $this->view->getRequest()->getRequestFormat(); // Only use the requested content type if it's not 'html'. If it is then // default to 'json' to aid debugging. // @todo Remove the need for this when we have better content negotiation. diff --git a/core/modules/rest/tests/src/CollectRoutesTest.php b/core/modules/rest/tests/src/CollectRoutesTest.php index 5a0cac6..c010364 100644 --- a/core/modules/rest/tests/src/CollectRoutesTest.php +++ b/core/modules/rest/tests/src/CollectRoutesTest.php @@ -40,16 +40,10 @@ protected function setUp() { $container = new ContainerBuilder(); - $content_negotiation = $this->getMockBuilder('\Drupal\Core\ContentNegotiation') - ->disableOriginalConstructor() - ->getMock(); - $request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request') ->disableOriginalConstructor() ->getMock(); - $container->set('content_negotiation', $content_negotiation); - $this->view = $this->getMock('\Drupal\views\Entity\View', array('initHandlers'), array( array('id' => 'test_view'), 'view', diff --git a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php index 7307780..64e210e 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php @@ -30,13 +30,11 @@ public function test405HTML() { $translation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'); $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $content_negotiation = $this->getMock('Drupal\Core\ContentNegotiation'); - $content_negotiation->expects($this->any()) - ->method('getContentType') - ->will($this->returnValue('html')); + $request = new Request(); + $request->setRequestFormat('html'); - $exception_controller = new ExceptionController($content_negotiation, $title_resolver, $html_page_renderer, $html_fragment_renderer, $translation, $url_generator); - $response = $exception_controller->execute($flat_exception, new Request()); + $exception_controller = new ExceptionController($title_resolver, $html_page_renderer, $html_fragment_renderer, $translation, $url_generator); + $response = $exception_controller->execute($flat_exception, $request); $this->assertEquals($response->getStatusCode(), 405, 'HTTP status of response is correct.'); $this->assertEquals($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.'); } diff --git a/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php b/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php index 22ffa8f..bb1feb2 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php @@ -7,10 +7,10 @@ namespace Drupal\Tests\Core\Routing; -use Drupal\Core\ContentNegotiation; use Drupal\Core\Routing\AcceptHeaderMatcher; use Drupal\Tests\Core\Routing\RoutingFixtures; use Drupal\Tests\UnitTestCase; +use Negotiation\FormatNegotiator; use Symfony\Component\HttpFoundation\Request; /** @@ -35,13 +35,21 @@ class AcceptHeaderMatcherTest extends UnitTestCase { protected $matcher; /** + * The content type negotiation library. + * + * @var \Negotiation\FormatNegotiator + */ + protected $negotiator; + + /** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->fixtures = new RoutingFixtures(); - $this->matcher = new AcceptHeaderMatcher(new ContentNegotiation()); + $this->matcher = new AcceptHeaderMatcher(); + $this->negotiator = new FormatNegotiator(); } /** @@ -77,6 +85,9 @@ public function testAcceptFiltering($accept_header, $included_route, $excluded_r $request = Request::create('path/two', 'GET'); $request->headers->set('Accept', $accept_header); + + $format = $this->negotiator->getBest($accept_header = $request->headers->get('Accept')); + $request->setRequestFormat($request->getFormat($format->getValue())); $routes = $this->matcher->filter($collection, $request); $this->assertEquals(count($routes), 4, 'The correct number of routes was found.'); $this->assertNotNull($routes->get($included_route), "Route $included_route was found when matching $accept_header."); @@ -103,8 +114,9 @@ public function testNoRouteFound() { $request = Request::create('path/two', 'GET'); $request->headers->set('Accept', 'application/json, text/xml;q=0.9'); + $format = $this->negotiator->getBest($accept_header = $request->headers->get('Accept')); + $request->setRequestFormat($request->getFormat($format->getValue())); $this->matcher->filter($routes, $request); $this->fail('No exception was thrown.'); } - } diff --git a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php index a928c97..98bfdcd 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php @@ -34,12 +34,6 @@ class RoutePreloaderTest extends UnitTestCase { */ protected $state; - /** - * The mocked content negotiator. - * - * @var \Drupal\Core\ContentNegotiation|\PHPUnit_Framework_MockObject_MockObject - */ - protected $negotiation; /** * The tested preloader. @@ -54,10 +48,7 @@ class RoutePreloaderTest extends UnitTestCase { protected function setUp() { $this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); $this->state = $this->getMock('\Drupal\Core\State\StateInterface'); - $this->negotiation = $this->getMockBuilder('\Drupal\Core\ContentNegotiation') - ->disableOriginalConstructor() - ->getMock(); - $this->preloader = new RoutePreloader($this->routeProvider, $this->state, $this->negotiation); + $this->preloader = new RoutePreloader($this->routeProvider, $this->state); } /** @@ -136,12 +127,10 @@ public function testOnRequestNonHtml() { ->disableOriginalConstructor() ->getMock(); $request = new Request(); + $request->setRequestFormat('non-html'); $event->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)); - $this->negotiation->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('non-html')); $this->routeProvider->expects($this->never()) ->method('getRoutesByNames'); @@ -159,12 +148,10 @@ public function testOnRequestOnHtml() { ->disableOriginalConstructor() ->getMock(); $request = new Request(); + $request->setRequestFormat('html'); $event->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)); - $this->negotiation->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('html')); $this->routeProvider->expects($this->once()) ->method('getRoutesByNames')