
| Current Path : /var/www/html/ift/web/core/tests/Drupal/Tests/Core/Controller/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/ift/web/core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php |
<?php
namespace Drupal\Tests\Core\Controller;
use Drupal\Tests\UnitTestCase;
/**
* Tests that the base controller class.
*
* @group Controller
*/
class ControllerBaseTest extends UnitTestCase {
/**
* The tested controller base class.
*
* @var \Drupal\Core\Controller\ControllerBase|\PHPUnit\Framework\MockObject\MockObject
*/
protected $controllerBase;
protected function setUp() {
$this->controllerBase = $this->getMockForAbstractClass('Drupal\Core\Controller\ControllerBase');
}
/**
* Tests the config method.
*/
public function testGetConfig() {
$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')
->will($this->returnValue($config_factory));
\Drupal::setContainer($container);
$config_method = new \ReflectionMethod('Drupal\Core\Controller\ControllerBase', 'config');
$config_method->setAccessible(TRUE);
// 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'));
}
}