function RouteSubscriberTest::setupMocks
Same name in other branches
- 8.9.x core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php \Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest::setupMocks()
- 10 core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php \Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest::setupMocks()
- 11.x core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php \Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest::setupMocks()
Sets up mocks of Views objects needed for testing.
Return value
\Drupal\views\Plugin\views\display\DisplayRouterInterface[]|\PHPUnit\Framework\MockObject\MockObject[] An array of two mocked view displays.
2 calls to RouteSubscriberTest::setupMocks()
- RouteSubscriberTest::testOnAlterRoutes in core/
modules/ views/ tests/ src/ Unit/ EventSubscriber/ RouteSubscriberTest.php - Tests the onAlterRoutes method.
- RouteSubscriberTest::testRouteRebuildFinished in core/
modules/ views/ tests/ src/ Unit/ EventSubscriber/ RouteSubscriberTest.php - @covers ::routeRebuildFinished
File
-
core/
modules/ views/ tests/ src/ Unit/ EventSubscriber/ RouteSubscriberTest.php, line 149
Class
- RouteSubscriberTest
- @coversDefaultClass \Drupal\views\EventSubscriber\RouteSubscriber @group views
Namespace
Drupal\Tests\views\Unit\EventSubscriberCode
protected function setupMocks() {
$executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->getMock();
$view = $this->getMockBuilder('Drupal\\views\\Entity\\View')
->disableOriginalConstructor()
->getMock();
$this->viewStorage
->expects($this->any())
->method('load')
->willReturn($view);
$view->expects($this->any())
->method('getExecutable')
->willReturn($executable);
$view->expects($this->any())
->method('id')
->willReturn('test_id');
$executable->storage = $view;
$executable->expects($this->any())
->method('setDisplay')
->willReturnMap([
[
'page_1',
TRUE,
],
[
'page_2',
TRUE,
],
[
'page_3',
FALSE,
],
]);
// Ensure that only the first two displays are actually called.
$display_1 = $this->createMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface');
$display_2 = $this->createMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface');
$display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
->disableOriginalConstructor()
->getMock();
$display_collection->expects($this->any())
->method('get')
->willReturnMap([
[
'page_1',
$display_1,
],
[
'page_2',
$display_2,
],
]);
$executable->displayHandlers = $display_collection;
$this->routeSubscriber->applicableViews = [];
$this->routeSubscriber->applicableViews[] = [
'test_id',
'page_1',
];
$this->routeSubscriber->applicableViews[] = [
'test_id',
'page_2',
];
$this->routeSubscriber->applicableViews[] = [
'test_id',
'page_3',
];
return [
$display_1,
$display_2,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.