3e6d501723d5d510e968e885dcd88c769929964e
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Session / AccountProxyTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Session;
4
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\Core\Session\AccountProxy;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Session\AccountProxy
11  * @group Session
12  */
13 class AccountProxyTest extends UnitTestCase {
14
15   /**
16    * @covers ::id
17    * @covers ::setInitialAccountId
18    */
19   public function testId() {
20     $account_proxy = new AccountProxy();
21     $this->assertSame(0, $account_proxy->id());
22     $account_proxy->setInitialAccountId(1);
23     $this->assertFalse(\Drupal::hasContainer());
24     // If the following call loaded the user entity it would call
25     // AccountProxy::loadUserEntity() which would fail because the container
26     // does not exist.
27     $this->assertSame(1, $account_proxy->id());
28     $current_user = $this->prophesize(AccountInterface::class);
29     $current_user->id()->willReturn(2);
30     $account_proxy->setAccount($current_user->reveal());
31     $this->assertSame(2, $account_proxy->id());
32   }
33
34   /**
35    * @covers ::setInitialAccountId
36    */
37   public function testSetInitialAccountIdException() {
38     $this->setExpectedException(\LogicException::class);
39     $account_proxy = new AccountProxy();
40     $current_user = $this->prophesize(AccountInterface::class);
41     $account_proxy->setAccount($current_user->reveal());
42     $account_proxy->setInitialAccountId(1);
43   }
44
45 }
46
47 namespace Drupal\Core\Session;
48
49 if (!function_exists('drupal_get_user_timezone')) {
50
51   function drupal_get_user_timezone() {
52     return date_default_timezone_get();
53   }
54
55 }