3 namespace Drupal\Tests\Core\Session;
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\Core\Session\AccountProxy;
10 * @coversDefaultClass \Drupal\Core\Session\AccountProxy
13 class AccountProxyTest extends UnitTestCase {
17 * @covers ::setInitialAccountId
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
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());
35 * @covers ::setInitialAccountId
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);
47 namespace Drupal\Core\Session;
49 if (!function_exists('drupal_get_user_timezone')) {
50 function drupal_get_user_timezone() {
51 return date_default_timezone_get();