Beispiel #1
0
 /**
  * Login a user on a specific domain.
  *
  * @param Drupal\domain\DomainInterface $domain
  *  The domain to log the user into.
  * @param Drupal\Core\Session\AccountInterface $account
  *  The user account to login.
  */
 public function domainLogin(DomainInterface $domain, AccountInterface $account)
 {
     if ($this->loggedInUser) {
         $this->drupalLogout();
     }
     // For this to work, we must reset the password to a known value.
     $pass = '******';
     $user = \Drupal::entityManager()->getStorage('user')->load($account->id());
     $user->setPassword($pass)->save();
     $url = $domain->getPath() . '/user/login';
     $edit = ['name' => $account->getUsername(), 'pass' => $pass];
     $this->drupalPostForm($url, $edit, t('Log in'));
     // @see WebTestBase::drupalUserIsLoggedIn()
     if (isset($this->sessionId)) {
         $account->session_id = $this->sessionId;
     }
     $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', array('%name' => $account->getUsername())), 'User login');
     if ($pass) {
         $this->loggedInUser = $account;
         $this->container->get('current_user')->setAccount($account);
     }
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function checkResponse(DomainInterface $domain)
 {
     $url = $domain->getPath() . drupal_get_path('module', 'domain') . '/tests/200.png';
     try {
         // GuzzleHttp no longer allows for bogus URL calls.
         $request = $this->httpClient->get($url);
     } catch (RequestException $e) {
         watchdog_exception('domain', $e);
         // File a general server failure.
         $domain->setResponse(500);
         return;
     }
     // Expected result (i.e. no exception thrown.)
     $domain->setResponse($request->getStatusCode());
 }