diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 9f059ad..1e81b6b 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -75,7 +75,7 @@ public function handle(Request $request) { // Determine the request parameters that should be passed to the resource // plugin. - $route_parameters = $route_match->getParameter('_route_params'); + $route_parameters = $route_match->getParameter('_route_params') ?: array(); $parameters = array(); // Filter out all internal parameters starting with "_". foreach ($route_parameters as $key => $parameter) { diff --git a/core/modules/views/tests/src/Routing/ViewPageControllerTest.php b/core/modules/views/tests/src/Routing/ViewPageControllerTest.php index 94ce9a7..4099af5 100644 --- a/core/modules/views/tests/src/Routing/ViewPageControllerTest.php +++ b/core/modules/views/tests/src/Routing/ViewPageControllerTest.php @@ -9,10 +9,7 @@ use Drupal\Tests\UnitTestCase; use Drupal\views\Routing\ViewPageController; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; -use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\Routing\Route; /** @@ -46,6 +43,13 @@ class ViewPageControllerTest extends UnitTestCase { */ protected $executableFactory; + /** + * The current route match. + * + * @var \Drupal\Core\Routing\RouteMatchInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $routeMatch; + public static function getInfo() { return array( 'name' => 'View page controller test', @@ -61,8 +65,9 @@ protected function setUp() { $this->executableFactory = $this->getMockBuilder('Drupal\views\ViewExecutableFactory') ->disableOriginalConstructor() ->getMock(); + $this->routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); - $this->pageController = new ViewPageController($this->storage, $this->executableFactory); + $this->pageController = new ViewPageController($this->storage, $this->executableFactory, $this->routeMatch); } /** @@ -89,17 +94,20 @@ public function testPageController() { ->with('default', array()) ->will($this->returnValue(array('#markup' => 'example output'))); + $request = new Request(); + $executable->expects($this->once()) + ->method('setRequest') + ->with($request); + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); + $this->routeMatch->expects($this->once()) + ->method('getRouteObject') + ->will($this->returnValue(new Route(''))); - $request = new Request(); - $request->attributes->set('view_id', 'test_page_view'); - $request->attributes->set('display_id', 'default'); - $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('')); - - $output = $this->pageController->handle($request); + $output = $this->pageController->handle($request, 'test_page_view', 'default'); $this->assertInternalType('array', $output); $this->assertEquals(array('#markup' => 'example output'), $output); } @@ -134,19 +142,25 @@ public function testHandleWithArgumentsWithoutOverridden() { ->method('executeDisplay') ->with('page_1', array('test-argument')); + $request = new Request(); + $executable->expects($this->once()) + ->method('setRequest') + ->with($request); + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); - $request = new Request(); - $request->attributes->set('view_id', 'test_page_view'); - $request->attributes->set('display_id', 'page_1'); - // Add the argument to the request. - $request->attributes->set('arg_0', 'test-argument'); - $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('')); + $this->routeMatch->expects($this->once()) + ->method('getRouteObject') + ->will($this->returnValue(new Route(''))); + $this->routeMatch->expects($this->once()) + ->method('getParameter') + ->with('arg_0') + ->will($this->returnValue('test-argument')); - $this->pageController->handle($request); + $this->pageController->handle($request, 'test_page_view', 'page_1'); } /** @@ -181,21 +195,27 @@ public function testHandleWithArgumentsOnOveriddenRoute() { ->method('executeDisplay') ->with('page_1', array('test-argument')); + $request = new Request(); + $executable->expects($this->once()) + ->method('setRequest') + ->with($request); + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); - $request = new Request(); - $request->attributes->set('view_id', 'test_page_view'); - $request->attributes->set('display_id', 'page_1'); - // Add the argument to the request. - $request->attributes->set('parameter', 'test-argument'); - $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('', array(), array(), array('_view_argument_map' => array( - 'arg_0' => 'parameter', - )))); + $this->routeMatch->expects($this->once()) + ->method('getRouteObject') + ->will($this->returnValue(new Route('', array(), array(), array('_view_argument_map' => array( + 'arg_0' => 'parameter', + ))))); + $this->routeMatch->expects($this->once()) + ->method('getParameter') + ->with('parameter') + ->will($this->returnValue('test-argument')); - $this->pageController->handle($request); + $this->pageController->handle($request, 'test_page_view', 'page_1'); } /** @@ -231,24 +251,29 @@ public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() { ->method('executeDisplay') ->with('page_1', array('example_id')); + $request = new Request(); + $executable->expects($this->once()) + ->method('setRequest') + ->with($request); + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); - $request = new Request(); - $request->attributes->set('view_id', 'test_page_view'); - $request->attributes->set('display_id', 'page_1'); - // Add the argument to the request. - $request->attributes->set('test_entity', $this->getMock('Drupal\Core\Entity\EntityInterface')); - $raw_variables = new ParameterBag(array('test_entity' => 'example_id')); - $request->attributes->set('_raw_variables', $raw_variables); + $this->routeMatch->expects($this->once()) + ->method('getRouteObject') + ->will($this->returnValue(new Route('', array(), array(), array('_view_argument_map' => array( + 'arg_0' => 'test_entity', + ))))); + $this->routeMatch->expects($this->never()) + ->method('getParameter'); + $this->routeMatch->expects($this->once()) + ->method('getRawParameter') + ->with('test_entity') + ->will($this->returnValue('example_id')); - $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('', array(), array(), array('_view_argument_map' => array( - 'arg_0' => 'test_entity', - )))); - - $this->pageController->handle($request); + $this->pageController->handle($request, 'test_page_view', 'page_1'); } /** @@ -261,9 +286,7 @@ public function testHandleWithNotExistingView() { $random_view_id = $this->randomName(); $request = new Request(); - $request->attributes->set('view_id', $random_view_id); - $request->attributes->set('display_id', 'default'); - $this->pageController->handle($request); + $this->pageController->handle($request, $random_view_id, 'default'); } } diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index bd21c24..4ee948a 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -26,17 +26,13 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, $display_id = NULL) { - $this->displayID = $display_id; - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function init(array &$form_state) { + protected function init(array &$form_state) { parent::init($form_state); + if (isset($form_state['display_id'])) { + $this->displayID = $form_state['display_id']; + } + // @todo Remove the need for this. form_load_include($form_state, 'inc', 'views_ui', 'admin'); $form_state['view'] = $this->entity; diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php index 5ec7f81..92c82b3 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php @@ -86,9 +86,7 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); - $this->route = $this->getMockBuilder('Symfony\Component\Routing\Route') - ->disableOriginalConstructor() - ->getMock(); + $this->route = new Route(''); $this->request->attributes = $this->parameterBag; @@ -113,14 +111,18 @@ public function setUp() { public function testAccessSubscriberThrowsAccessDeniedException() { $this->parameterBag->expects($this->any()) + ->method('all') + ->will($this->returnValue(array())); + $this->parameterBag->expects($this->any()) ->method('has') ->with(RouteObjectInterface::ROUTE_OBJECT) ->will($this->returnValue(TRUE)); $this->parameterBag->expects($this->any()) ->method('get') - ->with(RouteObjectInterface::ROUTE_OBJECT) - ->will($this->returnValue($this->route)); + ->will($this->returnValueMap(array( + array(RouteObjectInterface::ROUTE_OBJECT, NULL, FALSE, $this->route), + ))); $this->accessManager->expects($this->any()) ->method('check') @@ -151,14 +153,18 @@ public function testAccessSubscriberOnlyChecksForRequestsWithRouteObject() { */ public function testAccessSubscriberDoesNotAlterRequestIfAccessManagerGrantsAccess() { $this->parameterBag->expects($this->any()) + ->method('all') + ->will($this->returnValue(array())); + $this->parameterBag->expects($this->any()) ->method('has') ->with(RouteObjectInterface::ROUTE_OBJECT) ->will($this->returnValue(TRUE)); $this->parameterBag->expects($this->any()) ->method('get') - ->with(RouteObjectInterface::ROUTE_OBJECT) - ->will($this->returnValue($this->route)); + ->will($this->returnValueMap(array( + array(RouteObjectInterface::ROUTE_OBJECT, NULL, FALSE, $this->route), + ))); $this->accessManager->expects($this->any()) ->method('check')