You are here

class CurrentUserIntegrationTest 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

Hierarchy

Expanded class hierarchy of CurrentUserIntegrationTest

File

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

Namespace

Drupal\service_container\Tests
View source
class CurrentUserIntegrationTest extends ServiceContainerIntegrationTestBase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'CurrentUser',
      'description' => 'Tests the current user integration',
      'group' => 'service_container',
    );
  }
  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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentUserIntegrationTest::getInfo public static function
CurrentUserIntegrationTest::testCurrentUser public function
ServiceContainerIntegrationTestBase::$container protected property The dependency injection container usable in the test.
ServiceContainerIntegrationTestBase::$profile protected property The profile to install as a basis for testing. 1
ServiceContainerIntegrationTestBase::setUp protected function 5