More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Controller / ControllerBaseTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Controller;
4
5 use Drupal\Tests\UnitTestCase;
6
7 /**
8  * Tests that the base controller class.
9  *
10  * @group Controller
11  */
12 class ControllerBaseTest extends UnitTestCase {
13
14   /**
15    * The tested controller base class.
16    *
17    * @var \Drupal\Core\Controller\ControllerBase|\PHPUnit_Framework_MockObject_MockObject
18    */
19   protected $controllerBase;
20
21   protected function setUp() {
22     $this->controllerBase = $this->getMockForAbstractClass('Drupal\Core\Controller\ControllerBase');
23   }
24
25   /**
26    * Tests the config method.
27    */
28   public function testGetConfig() {
29     $config_factory = $this->getConfigFactoryStub([
30       'config_name' => [
31         'key' => 'value',
32       ],
33       'config_name2' => [
34         'key2' => 'value2',
35       ],
36     ]);
37
38     $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
39     $container->expects($this->once())
40       ->method('get')
41       ->with('config.factory')
42       ->will($this->returnValue($config_factory));
43     \Drupal::setContainer($container);
44
45     $config_method = new \ReflectionMethod('Drupal\Core\Controller\ControllerBase', 'config');
46     $config_method->setAccessible(TRUE);
47
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'));
51
52     $config = $config_method->invoke($this->controllerBase, 'config_name2');
53     $this->assertEquals('value2', $config->get('key2'));
54   }
55
56 }