class ViewPageControllerTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest
@coversDefaultClass \Drupal\views\Routing\ViewPageController @group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest
Expanded class hierarchy of ViewPageControllerTest
File
- core/
modules/ views/ tests/ src/ Unit/ Routing/ ViewPageControllerTest.php, line 22 - Contains \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest.
Namespace
Drupal\Tests\views\Unit\RoutingView source
class ViewPageControllerTest extends UnitTestCase {
/**
* The page controller of views.
*
* @var \Drupal\views\Routing\ViewPageController
*/
public $pageController;
/**
* A render array expected for every page controller render array result.
*
* @var array
*/
protected $defaultRenderArray = [
'#cache_properties' => [
'#view_id',
'#view_display_show_admin_links',
'#view_display_plugin_id',
],
'#view_id' => 'test_page_view',
'#view_display_plugin_id' => NULL,
'#view_display_show_admin_links' => NULL,
];
protected function setUp() {
$this->pageController = new ViewPageController();
}
/**
* Tests the page controller.
*/
public function testPageController() {
$build = [
'#type' => 'view',
'#name' => 'test_page_view',
'#display_id' => 'default',
'#embed' => FALSE,
'#arguments' => [],
'#cache' => [
'keys' => [
'view',
'test_page_view',
'display',
'default',
],
],
] + $this->defaultRenderArray;
$request = new Request();
$request->attributes
->set('view_id', 'test_page_view');
$request->attributes
->set('display_id', 'default');
$options = [
'_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
];
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test', [
'view_id' => 'test_page_view',
'display_id' => 'default',
], [], $options));
$route_match = RouteMatch::createFromRequest($request);
$output = $this->pageController
->handle($route_match
->getParameter('view_id'), $route_match
->getParameter('display_id'), $route_match);
$this
->assertInternalType('array', $output);
$this
->assertEquals($build, $output);
}
/**
* Tests the page controller with arguments on a non overridden page view.
*/
public function testHandleWithArgumentsWithoutOverridden() {
$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');
$options = [
'_view_argument_map' => [
'arg_0' => 'arg_0',
],
'_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
];
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{arg_0}', [
'view_id' => 'test_page_view',
'display_id' => 'default',
], [], $options));
$route_match = RouteMatch::createFromRequest($request);
$result = $this->pageController
->handle($route_match
->getParameter('view_id'), $route_match
->getParameter('display_id'), $route_match);
$build = [
'#type' => 'view',
'#name' => 'test_page_view',
'#display_id' => 'page_1',
'#embed' => FALSE,
'#arguments' => [
'test-argument',
],
'#cache' => [
'keys' => [
'view',
'test_page_view',
'display',
'page_1',
'args',
'test-argument',
],
],
] + $this->defaultRenderArray;
$this
->assertEquals($build, $result);
}
/**
* Tests the page controller with arguments of a overridden page view.
*
* Note: This test does not care about upcasting for now.
*/
public function testHandleWithArgumentsOnOverriddenRoute() {
$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');
$options = [
'_view_argument_map' => [
'arg_0' => 'parameter',
],
'_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
];
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{parameter}', [
'view_id' => 'test_page_view',
'display_id' => 'default',
], [], $options));
$route_match = RouteMatch::createFromRequest($request);
$result = $this->pageController
->handle($route_match
->getParameter('view_id'), $route_match
->getParameter('display_id'), $route_match);
$build = [
'#type' => 'view',
'#name' => 'test_page_view',
'#display_id' => 'page_1',
'#embed' => FALSE,
'#arguments' => [
'test-argument',
],
'#cache' => [
'keys' => [
'view',
'test_page_view',
'display',
'page_1',
'args',
'test-argument',
],
],
] + $this->defaultRenderArray;
$this
->assertEquals($build, $result);
}
/**
* Tests the page controller with arguments of a overridden page view.
*
* This test care about upcasted values and ensures that the raw variables
* are pulled in.
*/
public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() {
$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);
$options = [
'_view_argument_map' => [
'arg_0' => 'test_entity',
],
'_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
];
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{test_entity}', [
'view_id' => 'test_page_view',
'display_id' => 'default',
], [], $options));
$route_match = RouteMatch::createFromRequest($request);
$result = $this->pageController
->handle($route_match
->getParameter('view_id'), $route_match
->getParameter('display_id'), $route_match);
$build = [
'#type' => 'view',
'#name' => 'test_page_view',
'#display_id' => 'page_1',
'#embed' => FALSE,
'#arguments' => [
'example_id',
],
'#cache' => [
'keys' => [
'view',
'test_page_view',
'display',
'page_1',
'args',
'example_id',
],
],
] + $this->defaultRenderArray;
$this
->assertEquals($build, $result);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
ViewPageControllerTest:: |
protected | property | A render array expected for every page controller render array result. | |
ViewPageControllerTest:: |
public | property | The page controller of views. | |
ViewPageControllerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ViewPageControllerTest:: |
public | function | Tests the page controller with arguments of a overridden page view. | |
ViewPageControllerTest:: |
public | function | Tests the page controller with arguments of a overridden page view. | |
ViewPageControllerTest:: |
public | function | Tests the page controller with arguments on a non overridden page view. | |
ViewPageControllerTest:: |
public | function | Tests the page controller. |