public function CaptchaPersistenceTest::testPersistencePerFormType in CAPTCHA 8
Test Persistence per form type.
File
- tests/
src/ Functional/ CaptchaPersistenceTest.php, line 142
Class
- CaptchaPersistenceTest
- Tests CAPTCHA Persistence.
Namespace
Drupal\Tests\captcha\FunctionalCode
public function testPersistencePerFormType() {
// Set up of persistence and CAPTCHAs.
$this
->setUpPersistence(CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE);
// Go to login form and check if there is a CAPTCHA on the login form.
$this
->drupalGet('<front>');
$this
->assertCaptchaPresence(TRUE);
$captcha_sid_initial = $this
->getCaptchaSidFromForm();
// Try to with wrong user name and password, but correct CAPTCHA.
$edit = [
'name' => 'foobar',
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
];
$this
->submitForm($edit, $this
->t('Log in'), self::LOGIN_HTML_FORM_ID);
// Check that there was no error message for the CAPTCHA.
$this
->assertCaptchaResponseAccepted();
// There shouldn't be a CAPTCHA on the new form.
$this
->assertCaptchaPresence(FALSE);
$this
->assertPreservedCsid($captcha_sid_initial);
// Start a new form instance/session.
$this
->drupalGet('node');
$this
->drupalGet('user');
$this
->assertCaptchaPresence(FALSE);
$this
->assertDifferentCsid($captcha_sid_initial);
// Check another form.
/* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
$captcha_point = \Drupal::entityTypeManager()
->getStorage('captcha_point')
->load('user_register_form');
$captcha_point
->enable()
->save();
$this
->drupalGet('user/register');
$this
->assertCaptchaPresence(TRUE);
$this
->assertDifferentCsid($captcha_sid_initial);
}