validateCaptcha example

if ($billingCountry === null) {
                throw new RuntimeException('Billing address needs a country');
            }

            $country = $this->get(CountryGatewayInterface::class)->getCountry($billingCountry->getId()$context);

            if (!$country->allowShipping()) {
                $errors['billing']['country'] = $this->get('snippets')->getNamespace('frontend/register/index')->get('CountryNotAvailableForShipping');
            }
        }

        $validCaptcha = $this->validateCaptcha($this->get(Shopware_Components_Config::class)->get('registerCaptcha')$this->request);
        if (!$validCaptcha) {
            $errors['captcha'] = [
                $this->get('snippets')
                    ->getNamespace('widgets/captcha/custom_captcha')
                    ->get('invalidCaptchaMessage'),
            ];
        }

        $errors['occurred'] = !empty($errors['personal'])
            || !empty($errors['shipping'])
            || !empty($errors['billing'])
            
public function testThrowsExceptionWhenValidationFails(): void
    {
        $event = $this->getControllerEventMock();

        $this->expectException(CaptchaInvalidException::class);

        (new CaptchaRouteListener(
            $this->getCaptchas(true, false),
            $this->getContainer()->get(ErrorController::class),
            $this->getContainer()->get(SystemConfigService::class)
        ))->validateCaptcha($event);
    }

    public function testJsonResponseWhenCaptchaValidationFails(): void
    {
        $systemConfig = $this->getContainer()->get(SystemConfigService::class);

        $systemConfig->set('core.basicInformation.activeCaptchasV2', [
            BasicCaptcha::CAPTCHA_NAME => [
                'name' => BasicCaptcha::CAPTCHA_NAME,
                'isActive' => true,
            ],
        ]);
Home | Imprint | This part of the site doesn't use cookies.