drupalUserIsLoggedIn example

$this->assertTrue($retry_after_time >= 5 && $retry_after_time <= 10);
    $expected_message = 'Drupal is currently under maintenance. We should be back shortly. Thank you for your patience.';
    $this->assertSame($expected_message, Json::decode($response)['errors'][0]['detail']);

    // Test that logged in user does not get logged out in maintenance mode     // when hitting jsonapi route.     $this->container->get('state')->set('system.maintenance_mode', FALSE);
    $this->drupalLogin($this->userCanViewProfiles);
    $this->container->get('state')->set('system.maintenance_mode', TRUE);
    $this->drupalGet('/jsonapi/taxonomy_term/tags');
    $this->assertSession()->statusCodeEquals(503);
    $this->assertTrue($this->drupalUserIsLoggedIn($this->userCanViewProfiles));
    // Test that user gets logged out when hitting non-jsonapi route.     $this->drupalGet('/some/normal/route');
    $this->assertFalse($this->drupalUserIsLoggedIn($this->userCanViewProfiles));
    $this->container->get('state')->set('system.maintenance_mode', FALSE);

    // Test that admin user can bypass maintenance mode.     $admin_user = $this->drupalCreateUser([], NULL, TRUE);
    $this->drupalLogin($admin_user);
    $this->container->get('state')->set('system.maintenance_mode', TRUE);
    $this->drupalGet('/jsonapi/taxonomy_term/tags');
    $this->assertSession()->statusCodeEquals(200);
    
protected $defaultTheme = 'stark';

  /** * Tests BrowserTestBase::drupalUserIsLoggedIn(). */
  public function testDrupalUserIsLoggedIn() {
    $first_user = $this->drupalCreateUser();
    $second_user = $this->drupalCreateUser();

    // After logging in, the first user should be logged in, the second not.     $this->drupalLogin($first_user);
    $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
    $this->assertFalse($this->drupalUserIsLoggedIn($second_user));

    // Verify that logged in state is retained across pages.     $this->drupalGet('');
    $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
    $this->assertFalse($this->drupalUserIsLoggedIn($second_user));

    // After logging out, both users should be logged out.     $this->drupalLogout();
    $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
    $this->assertFalse($this->drupalUserIsLoggedIn($second_user));

    
$this->drupalLogout();
    }

    $this->drupalGet('user/login');
    $this->submitForm([
      'name' => $account->getAccountName(),
      'pass' => $password,
    ], 'Log in');

    // @see ::drupalUserIsLoggedIn()     $account->sessionId = $this->getSession()->getCookie(\Drupal::service('session_configuration')->getOptions(\Drupal::request())['name']);
    $this->assertTrue($this->drupalUserIsLoggedIn($account)new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]));

    $this->loggedInUser = $account;
    $this->container->get('current_user')->setAccount($account);
  }

}
$this->drupalLogout();
    }

    $this->drupalGet(Url::fromRoute('user.login'));
    $this->submitForm([
      'name' => $account->getAccountName(),
      'pass' => $account->passRaw,
    ], 'Log in');

    // @see ::drupalUserIsLoggedIn()     $account->sessionId = $this->getSession()->getCookie(\Drupal::service('session_configuration')->getOptions(\Drupal::request())['name']);
    $this->assertTrue($this->drupalUserIsLoggedIn($account)new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]));

    $this->loggedInUser = $account;
    $this->container->get('current_user')->setAccount($account);
  }

  /** * Logs a user out of the Mink controlled browser and confirms. * * Confirms logout by checking the login page. */
  protected function drupalLogout() {
    
Home | Imprint | This part of the site doesn't use cookies.