You are here

public function CurrentUserIntegrationTest::testCurrentUser in Service Container 7.2

Same name and namespace in other branches
  1. 7 lib/Drupal/service_container/Tests/CurrentUserIntegrationTest.php \Drupal\service_container\Tests\CurrentUserIntegrationTest::testCurrentUser()

File

lib/Drupal/service_container/Tests/CurrentUserIntegrationTest.php, line 25
Contains \Drupal\service_container\Tests\CurrentUserIntegrationTest.

Class

CurrentUserIntegrationTest

Namespace

Drupal\service_container\Tests

Code

public function testCurrentUser() {

  /** @var \Drupal\service_container\Session\Account $account */
  $account_service = $this->container
    ->get('current_user');
  $this
    ->assertTrue($account_service instanceof Account);
  $admin_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($admin_user);
  drupal_save_session(FALSE);
  $GLOBALS['user'] = $admin_user;
  $account = $this->container
    ->get('current_user');
  $this
    ->assertEqual(spl_object_hash($account_service), spl_object_hash($account), 'Ensure that the object in the container stays the same.');
  $this
    ->assertEqual($admin_user->uid, $account
    ->id());
  $this
    ->assertEqual(array_keys($admin_user->roles), $account
    ->getRoles());
  $this
    ->assertEqual(1, count($account
    ->getRoles(TRUE)));
  $this
    ->assertEqual($admin_user->name, $account
    ->getUsername());
}