function ViewExecutableTest::setUp

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::setUp()
  2. 8.9.x core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::setUp()
  3. 10 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/views/tests/src/Unit/ViewExecutableTest.php, line 126

Class

ViewExecutableTest
@coversDefaultClass \Drupal\views\ViewExecutable @group views

Namespace

Drupal\Tests\views\Unit

Code

protected function setUp() : void {
    parent::setUp();
    $this->view = $this->createMock('Drupal\\views\\ViewEntityInterface');
    $this->user = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
    $this->viewsData = $this->getMockBuilder('Drupal\\views\\ViewsData')
        ->disableOriginalConstructor()
        ->getMock();
    $this->displayHandler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface')
        ->disableOriginalConstructor()
        ->getMock();
    $this->routeProvider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
    $this->displayHandlers = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
        ->disableOriginalConstructor()
        ->getMock();
    $this->displayPluginManager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')
        ->disableOriginalConstructor()
        ->getMock();
    $this->executable = new ViewExecutable($this->view, $this->user, $this->viewsData, $this->routeProvider, $this->displayPluginManager);
    $this->executable->display_handler = $this->displayHandler;
    $this->executable->displayHandlers = $this->displayHandlers;
    $this->viewExecutableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')
        ->disableOriginalConstructor()
        ->getMock();
    $module_handler = $this->getMockBuilder(ModuleHandlerInterface::class)
        ->getMock();
    $this->noneCache = $this->getMockBuilder(NoneCache::class)
        ->disableOriginalConstructor()
        ->getMock();
    $success_cache = $this->prophesize(CachePluginBase::class);
    $success_cache->cacheGet('results')
        ->willReturn(TRUE);
    $this->successCache = $success_cache->reveal();
    $cache_manager = $this->prophesize(PluginManagerInterface::class);
    $cache_manager->createInstance('none')
        ->willReturn($this->noneCache);
    $translation = $this->getStringTranslationStub();
    $container = new ContainerBuilder();
    $container->set('string_translation', $translation);
    $container->set('views.executable', $this->viewExecutableFactory);
    $container->set('module_handler', $module_handler);
    $container->set('plugin.manager.views.cache', $cache_manager->reveal());
    \Drupal::setContainer($container);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.