WebformElementCaptchaTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementCaptchaTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementCaptchaTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_captcha',
];
public static $modules = [
'webform',
'captcha',
'image_captcha',
];
public function testCaptcha() {
$this
->drupalGet('/webform/test_element_captcha');
$this
->assertRaw('<label for="edit-captcha-response" class="js-form-required form-required">Math question</label>');
$this
->assertRaw('Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.');
$this
->assertRaw('<label for="edit-captcha-response--4" class="js-form-required form-required">{captcha_math_title}</label>');
$this
->assertRaw('{captcha_math_description}');
$this
->assertLink('Get new captcha!');
\Drupal::configFactory()
->getEditable('captcha.settings')
->set('administration_mode', TRUE)
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/contact');
$this
->assertRaw('CAPTCHA should be added as an element to this webform.');
$this
->drupalGet('/webform/test_element_captcha');
$this
->assertNoRaw('/admin/structure/webform/manage/test_element_captcha/element/captcha/edit');
$this
->assertRaw('Untrusted users will see a CAPTCHA element on this webform.');
\Drupal::service('module_installer')
->install([
'webform_ui',
]);
$this
->drupalGet('/webform/contact');
$this
->assertRaw('Add CAPTCHA element to this webform for untrusted users.');
$this
->drupalGet('/webform/test_element_captcha');
$this
->assertRaw('/admin/structure/webform/manage/test_element_captcha/element/captcha/edit');
$this
->assertRaw('Untrusted users will see a CAPTCHA element on this webform.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('third_party_settings.captcha.replace_administration_mode', FALSE)
->save();
$this
->drupalGet('/webform/contact');
$this
->assertNoRaw('Add CAPTCHA element to this webform for untrusted users.');
$this
->assertRaw('Place a CAPTCHA here for untrusted users.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('element.excluded_elements', [
'captcha' => 'captcha',
])
->set('third_party_settings.captcha.replace_administration_mode', FALSE)
->save();
$this
->drupalGet('/webform/contact');
$this
->assertNoRaw('Add CAPTCHA element to this webform for untrusted users.');
$this
->assertRaw('Place a CAPTCHA here for untrusted users.');
}
}