protected function CaptchaBaseWebTestCase::getMathCaptchaSolutionFromForm in CAPTCHA 6.2
Same name and namespace in other branches
- 7 captcha.test \CaptchaBaseWebTestCase::getMathCaptchaSolutionFromForm()
Get the solution of the math CAPTCHA from the current form in the browser.
3 calls to CaptchaBaseWebTestCase::getMathCaptchaSolutionFromForm()
- CaptchaSessionReuseAttackTestCase::testCaptchaSessionReuseAttackDetectionOnCommentPreview in ./
captcha.test - CaptchaSessionReuseAttackTestCase::testCaptchaSessionReuseAttackDetectionOnLoginForm in ./
captcha.test - CaptchaSessionReuseAttackTestCase::testCaptchaSessionReuseAttackDetectionOnNodeForm in ./
captcha.test
File
- ./
captcha.test, line 174 - Tests for CAPTCHA module.
Class
- CaptchaBaseWebTestCase
- Base class for CAPTCHA tests.
Code
protected function getMathCaptchaSolutionFromForm() {
// Get the math challenge.
$elements = $this
->xpath('//div[@id="edit-captcha-response-wrapper"]/span[@class="field-prefix"]');
$challenge = (string) $elements[0];
// Extract terms and operator from challenge.
$matches = array();
$ret = preg_match('/\\s*(\\d+)\\s*(-|\\+)\\s*(\\d+)\\s*=\\s*/', $challenge, $matches);
// Solve the challenge
$a = (int) $matches[1];
$b = (int) $matches[3];
$solution = $matches[2] == '-' ? $a - $b : $a + $b;
return $solution;
}