diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php index e02e0df..fa2d541 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php @@ -48,13 +48,10 @@ public function testSessionExpiration() { // number of times. $this->drupalGet(''); - $session_assert = $this->assertSession(); - $page = $this->getSession()->getPage(); for ($i = 0; $i < 25; $i++) { $page->clickLink('Link to front page'); - $session_assert->statusCodeEquals(200); } } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php index 815a26b..0eddf94 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @@ -366,4 +366,32 @@ function t(r, lx, ly) { return $this->session->evaluateScript($full_javascript_visibility_test); } + /** + * The use of statusCodeEquals() is not available in a functional JavaScript test. + * + * @throws \Exception + * Throws an exception on use. + * + * @deprecated in Drupal 8.4.x, will be removed before Drupal 8.5.x. Use an + * assertion on the DOM to validate what is expected. For example + * assert that an element is available on the page. + */ + public function statusCodeEquals($code) { + throw new \Exception('The use of statusCodeEquals() is not available in a functional JavaScript test.'); + } + + /** + * The use of statusCodeNotEquals() is not available in a functional JavaScript test. + * + * @throws \Exception + * Throws an exception on use. + * + * @deprecated in Drupal 8.4.x, will be removed before Drupal 8.5.x. Use an + * assertion on the DOM to validate what is expected. For example + * assert that an element is not available on the page. + */ + public function statusCodeNotEquals($code) { + throw new \Exception('The use of statusCodeNotEquals() is not available in a functional JavaScript test.'); + } + } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index d5156ee..807de75 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\FunctionalJavascriptTests; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Session\AnonymousUserSession; use Drupal\Tests\BrowserTestBase; use Zumba\GastonJS\Exception\DeadClient; use Zumba\Mink\Driver\PhantomJSDriver; @@ -64,6 +66,44 @@ protected function tearDown() { } /** + * {@inheritdoc} + */ + protected function drupalLogin(AccountInterface $account) { + if ($this->loggedInUser) { + $this->drupalLogout(); + } + + $this->drupalGet('user/login'); + $page = $this->getSession()->getPage(); + $page->fillField('name', $account->getAccountName()); + $page->fillField('pass', $account->passRaw); + $page->findButton('Log in')->click(); + + $account->sessionId = $this->getSession()->getCookie($this->getSessionName()); + $this->assertTrue($this->drupalUserIsLoggedIn($account)); + + $this->loggedInUser = $account; + $this->container->get('current_user')->setAccount($account); + } + + /** + * {@inheritdoc} + */ + protected function drupalLogout() { + // Make a request to the logout page, and redirect to the user page, the + // idea being if you were properly logged out you should be seeing a login + // screen. + $assert_session = $this->assertSession(); + $this->drupalGet('user/logout', array('query' => array('destination' => 'user'))); + $assert_session->fieldExists('name'); + $assert_session->fieldExists('pass'); + $this->assertFalse($this->loggedInUser); + + $this->loggedInUser = FALSE; + $this->container->get('current_user')->setAccount(new AnonymousUserSession()); + } + + /** * Asserts that the element with the given CSS selector is visible. * * @param string $css_selector