SimpleRecaptchaJavascriptTestBase.php in Simple Google reCAPTCHA 8
File
tests/src/FunctionalJavascript/SimpleRecaptchaJavascriptTestBase.php
View source
<?php
namespace Drupal\Tests\simple_recaptcha\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class SimpleRecaptchaJavascriptTestBase extends WebDriverTestBase {
protected $webAssert;
protected $page;
protected static $modules = [
'simple_recaptcha',
'simple_recaptcha_test',
];
protected $defaultTheme = 'bartik';
private $user;
protected function setUp() : void {
parent::setUp();
$this->page = $this
->getSession()
->getPage();
$this->webAssert = $this
->assertSession();
$this->user = $this
->drupalCreateUser([
'administer site configuration',
'administer simple_recaptcha',
], 'webadmin');
$this
->configureModule();
}
public function configureModule() {
$config = [
'recaptcha_type' => 'v2',
'site_key' => '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
'secret_key' => '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe',
'form_ids' => 'user_login_form,user_pass,user_register_form,simple_recaptcha_test',
];
\Drupal::configFactory()
->getEditable('simple_recaptcha.config')
->setData($config)
->save();
}
public function testLoginPage() {
$config = $this
->config('simple_recaptcha.config');
$this
->drupalGet('/user/login');
$this
->assertJsCondition('drupalSettings.simple_recaptcha.sitekey === "' . $config
->get('site_key') . '";');
}
}