$this->assertSession()->pageTextNotContains($this->t('Access denied'),'Admin users should be able to access the Friendlycaptcha admin page','Friendlycaptcha');
$this->assertSession()->responseContains($this->t('The configuration options have been saved.'),'[testFriendlycaptchaAdminSettingsForm]: The configuration options have been saved.');
$this->assertSession()->responseNotContains($this->t('Site key field is required.'),'[testFriendlycaptchaAdminSettingsForm]: Site key was not empty.');
$this->assertSession()->responseNotContains($this->t('Secret key field is required.'),'[testFriendlycaptchaAdminSettingsForm]: Secret key was not empty.');
$this->assertSession()->responseNotContains($this->t('The tabindex must be an integer.'),'[testFriendlycaptchaAdminSettingsForm]: Tab index had a valid input.');
$friendlyCaptchaNoScriptHtml='<noscript>'.t('You need Javascript for CAPTCHA verification to submit this form.').'</noscript>';
// Test if login works.
$this->drupalLogin($this->normalUser);
$this->drupalLogout();
$this->drupalGet('user/login');
$this->assertSession()->responseNotContains($friendlyCaptchaHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is not shown on form.');
$this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is not shown on form.');
$this->assertSession()->responseNotContains($friendlyCaptchaHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is not shown on form.');
$this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is not shown on form.');
// Enable 'friendlycaptcha/friendlycaptcha' on login form.
$this->assertNotNull($result,'A configuration has been found for CAPTCHA point: user_login_form','Friendlycaptcha');
$this->assertEquals($result->getCaptchaType(),'friendlycaptcha/friendlycaptcha','Friendlycaptcha type has been configured for CAPTCHA point: user_login_form');
// Check if a Math CAPTCHA is still shown on the login form. The site key
// and security key have not yet configured for Friendlycaptcha.
// The module needs to fall back to math captcha.
$this->drupalGet('user/login');
$this->assertSession()->responseContains($this->t('Math question'),'[testFriendlycaptchaOnLoginForm]: Math CAPTCHA is shown on form.');
// Configure site key and security key to show Friendlycaptcha
// and no fall back.
$this->config('friendlycaptcha.settings')
->set('site_key',$site_key)
->set('api_key',$api_key)
->save();
// Check if there is a Friendlycaptcha on the login form.
$this->drupalGet('user/login');
$this->assertSession()->responseContains($friendlyCaptchaHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is shown on form.');
$this->assertSession()->responseContains('friendly-challenge/widget.min.js','[testFriendlycaptchaOnLoginForm]: Friendlycaptcha widget JS is present.');
$this->assertSession()->responseContains($friendlyCaptchaNoScriptHtml,'[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is shown on form.');
// @todo Check that the widget is not only present, but also loaded!
$this->assertSession()->pageTextContains($this->t('The answer you entered for the CAPTCHA was not correct.'),'CAPTCHA should block user login form','Friendlycaptcha');
// And make sure that user is not logged in: check for name and password