function ContextualLinkManagerTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::setUp()
  3. 11.x core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php, line 75

Class

ContextualLinkManagerTest
@coversDefaultClass \Drupal\Core\Menu\ContextualLinkManager @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

protected function setUp() {
    $this->contextualLinkManager = $this->getMockBuilder('Drupal\\Core\\Menu\\ContextualLinkManager')
        ->disableOriginalConstructor()
        ->setMethods(NULL)
        ->getMock();
    $this->controllerResolver = $this->createMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
    $this->pluginDiscovery = $this->createMock('Drupal\\Component\\Plugin\\Discovery\\DiscoveryInterface');
    $this->factory = $this->createMock('Drupal\\Component\\Plugin\\Factory\\FactoryInterface');
    $this->cacheBackend = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $this->moduleHandler = $this->createMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $this->accessManager = $this->createMock('Drupal\\Core\\Access\\AccessManagerInterface');
    $this->account = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'controllerResolver');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->controllerResolver);
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'discovery');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->pluginDiscovery);
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'factory');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->factory);
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'account');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->account);
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'accessManager');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->accessManager);
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'moduleHandler');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $this->moduleHandler);
    $language_manager = $this->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
    $language_manager->expects($this->any())
        ->method('getCurrentLanguage')
        ->will($this->returnValue(new Language([
        'id' => 'en',
    ])));
    $request_stack = new RequestStack();
    $property = new \ReflectionProperty('Drupal\\Core\\Menu\\ContextualLinkManager', 'requestStack');
    $property->setAccessible(TRUE);
    $property->setValue($this->contextualLinkManager, $request_stack);
    $method = new \ReflectionMethod('Drupal\\Core\\Menu\\ContextualLinkManager', 'alterInfo');
    $method->setAccessible(TRUE);
    $method->invoke($this->contextualLinkManager, 'contextual_links_plugins');
    $this->contextualLinkManager
        ->setCacheBackend($this->cacheBackend, 'contextual_links_plugins:en');
}

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