public function CSSCaptchaTestCase::testAjaxFormRebuild in CAPTCHA Pack 8
Tests that the CSS CAPTCHA is not changed on AJAX form rebuilds.
File
- css_captcha/
src/ Tests/ CSSCaptchaTestCase.php, line 220
Class
- CSSCaptchaTestCase
- Tests CSS CAPTCHA main test case sensitivity.
Namespace
Drupal\css_captcha\TestsCode
public function testAjaxFormRebuild() {
// Setup captcha point for user edit form.
\Drupal::entityManager()
->getStorage('captcha_point')
->create([
'id' => 'user_form',
'formId' => 'user_form',
'status' => TRUE,
'captchaType' => 'css_captcha/CSS CAPTCHA',
])
->save();
// Add multiple text field on user edit form.
$field_storage_config = FieldStorageConfig::create([
'field_name' => 'field_texts',
'type' => 'string',
'entity_type' => 'user',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
]);
$field_storage_config
->save();
FieldConfig::create([
'field_storage' => $field_storage_config,
'bundle' => 'user',
])
->save();
entity_get_form_display('user', 'user', 'default')
->setComponent('field_texts', [
'type' => 'string_textfield',
'weight' => 10,
])
->save();
// Create and login a user.
$user = $this
->drupalCreateUser([]);
$this
->drupalLogin($user);
// On edit form, add another item and save.
$this
->drupalGet("user/{$user->id()}/edit");
$this
->drupalPostAjaxForm(NULL, [], 'field_texts_add_more');
$this
->drupalPostForm(NULL, [
'captcha_response' => $this
->getMathCaptchaSolutionFromForm('user-form'),
], t('Save'));
// No error.
$this
->assertText(t('The changes have been saved.'));
}