protected function ViewAjaxControllerTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php \Drupal\Tests\views\Unit\Controller\ViewAjaxControllerTest::setUp()
Overrides UnitTestCase::setUp
File
- core/
modules/ views/ tests/ src/ Unit/ Controller/ ViewAjaxControllerTest.php, line 69
Class
- ViewAjaxControllerTest
- @coversDefaultClass \Drupal\views\Controller\ViewAjaxController @group views
Namespace
Drupal\Tests\views\Unit\ControllerCode
protected function setUp() : void {
$this->viewStorage = $this
->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$this->executableFactory = $this
->getMockBuilder('Drupal\\views\\ViewExecutableFactory')
->disableOriginalConstructor()
->getMock();
$this->renderer = $this
->createMock('\\Drupal\\Core\\Render\\RendererInterface');
$this->renderer
->expects($this
->any())
->method('render')
->willReturnCallback(function (array &$elements) {
$elements['#attached'] = [];
return isset($elements['#markup']) ? $elements['#markup'] : '';
});
$this->renderer
->expects($this
->any())
->method('executeInRenderContext')
->willReturnCallback(function (RenderContext $context, callable $callable) {
return $callable();
});
$this->currentPath = $this
->getMockBuilder('Drupal\\Core\\Path\\CurrentPathStack')
->disableOriginalConstructor()
->getMock();
$this->redirectDestination = $this
->createMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
$this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
$element_info_manager = $this
->createMock('\\Drupal\\Core\\Render\\ElementInfoManagerInterface');
$request_stack = new RequestStack();
$request_stack
->push(new Request());
$args = [
$this
->createMock('\\Drupal\\Core\\Controller\\ControllerResolverInterface'),
$this
->createMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface'),
$element_info_manager,
$this
->createMock('\\Drupal\\Core\\Render\\PlaceholderGeneratorInterface'),
$this
->createMock('\\Drupal\\Core\\Render\\RenderCacheInterface'),
$request_stack,
[
'required_cache_contexts' => [
'languages:language_interface',
'theme',
],
],
];
$this->renderer = $this
->getMockBuilder('Drupal\\Core\\Render\\Renderer')
->setConstructorArgs($args)
->setMethods(NULL)
->getMock();
$container = new ContainerBuilder();
$container
->set('renderer', $this->renderer);
\Drupal::setContainer($container);
}