You are here

public function SimpleRecaptchaJavascriptTest::testSessionData in Simple Google reCAPTCHA 8

Submit form as anonymous user and ensure that this submission doesn't keep the session cookies.

File

tests/src/FunctionalJavascript/SimpleRecaptchaJavascriptTest.php, line 90

Class

SimpleRecaptchaJavascriptTest
JavaScripts tests for the Simple reCAPTCHA module.

Namespace

Drupal\Tests\simple_recaptcha\FunctionalJavascript

Code

public function testSessionData() {

  // Set up the module and visit password reset page.
  $this
    ->drupalGet('/user/password');
  $user = $this
    ->drupalCreateUser([]);
  $edit = [
    'name' => $user
      ->getAccountName(),
  ];

  // Handle reCAPTCHA widget.
  $this->page
    ->pressButton('Submit');
  $this
    ->assignNameToCaptchaIframe();
  $this
    ->getSession()
    ->switchToIFrame('recaptcha-iframe');
  $this
    ->click('.recaptcha-checkbox');
  $this
    ->getSession()
    ->switchToIFrame();

  // Give it a while as reCAPTCHA throbber likes to spin for a while..
  $this
    ->getSession()
    ->wait('2000');

  // Final form submission, which should leave session cookies empty.
  $this
    ->submitForm($edit, t('Submit'));
  $this
    ->assertSession()
    ->pageTextContains(t('Further instructions have been sent to your email address.'));
  $this
    ->assertEmpty($this
    ->getSessionCookies()
    ->toArray());
}