3 namespace Drupal\Tests\Core\Controller;
5 use Drupal\Tests\UnitTestCase;
8 * Tests that the base controller class.
12 class ControllerBaseTest extends UnitTestCase {
15 * The tested controller base class.
17 * @var \Drupal\Core\Controller\ControllerBase|\PHPUnit_Framework_MockObject_MockObject
19 protected $controllerBase;
21 protected function setUp() {
22 $this->controllerBase = $this->getMockForAbstractClass('Drupal\Core\Controller\ControllerBase');
26 * Tests the config method.
28 public function testGetConfig() {
29 $config_factory = $this->getConfigFactoryStub([
38 $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
39 $container->expects($this->once())
41 ->with('config.factory')
42 ->will($this->returnValue($config_factory));
43 \Drupal::setContainer($container);
45 $config_method = new \ReflectionMethod('Drupal\Core\Controller\ControllerBase', 'config');
46 $config_method->setAccessible(TRUE);
48 // Call config twice to ensure that the container is just called once.
49 $config = $config_method->invoke($this->controllerBase, 'config_name');
50 $this->assertEquals('value', $config->get('key'));
52 $config = $config_method->invoke($this->controllerBase, 'config_name2');
53 $this->assertEquals('value2', $config->get('key2'));