class ControllerBaseTest

Same name in this branch
  1. main core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
  2. 11.x core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
  3. 10 core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
  4. 10 core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
  5. 9 core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
  6. 8.9.x core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest

Tests that the base controller class.

Attributes

#[Group('Controller')]

Hierarchy

Expanded class hierarchy of ControllerBaseTest

File

core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php, line 13

Namespace

Drupal\Tests\Core\Controller
View source
class ControllerBaseTest extends UnitTestCase {
  
  /**
   * The tested controller base class.
   */
  protected StubControllerBase $controllerBase;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->controllerBase = new StubControllerBase();
  }
  
  /**
   * Tests the config method.
   */
  public function testGetConfig() : void {
    $config_factory = $this->getConfigFactoryStub([
      'config_name' => [
        'key' => 'value',
      ],
      'config_name2' => [
        'key2' => 'value2',
      ],
    ]);
    $container = $this->createMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
    $container->expects($this->once())
      ->method('get')
      ->with('config.factory')
      ->willReturn($config_factory);
    \Drupal::setContainer($container);
    $config_method = new \ReflectionMethod(StubControllerBase::class, 'config');
    // Call config twice to ensure that the container is just called once.
    $config = $config_method->invoke($this->controllerBase, 'config_name');
    $this->assertEquals('value', $config->get('key'));
    $config = $config_method->invoke($this->controllerBase, 'config_name2');
    $this->assertEquals('value2', $config->get('key2'));
  }

}

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