You are here

public function SimpleRecaptchaWebformJavascriptTest::testRecaptchaLibraries in Simple Google reCAPTCHA 8

Verify that libraries are loaded correctly for different reCAPTCHA versions.

File

modules/simple_recaptcha_webform/tests/src/FunctionalJavascript/SimpleRecaptchaWebformJavascriptTest.php, line 44

Class

SimpleRecaptchaWebformJavascriptTest
JavaScripts tests for the Simple reCAPTCHA webform module.

Namespace

Drupal\Tests\simple_recaptcha_webform\FunctionalJavascript

Code

public function testRecaptchaLibraries() {

  // Configure v3 reCAPTCHA and visit some pages so they get cached.
  $this
    ->configureModule('v3');
  $this
    ->drupalGet('user/password');

  // reCAPTCHA badge should be present.
  $this
    ->assertSession()
    ->elementExists('css', '.grecaptcha-badge');
  $this
    ->drupalGet('webform/simple_recaptcha_v2');

  // reCAPTCHA badge shouldn't be there as it only appears for v3 reCAPTCHA.
  $this
    ->assertSession()
    ->elementNotExists('css', '.grecaptcha-badge');

  // Switch reCAPTCHA to v2.
  $this
    ->configureModule();
  $this
    ->drupalGet('user/password');

  // reCAPTCHA badge shouldn't be there as it only appears for v3 reCAPTCHA.
  $this
    ->assertSession()
    ->elementNotExists('css', '.grecaptcha-badge');
  $this
    ->drupalGet('webform/simple_recaptcha_v2');

  // reCAPTCHA badge shouldn't be there as it only appears for v3 reCAPTCHA.
  $this
    ->assertSession()
    ->elementNotExists('css', '.grecaptcha-badge');
}