Use submit button label of form for captcha submit button
[MAILPOET-4496]
This commit is contained in:
@ -48,38 +48,12 @@ class CaptchaRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getCaptchaPageContent($sessionId) {
|
public function getCaptchaPageContent($sessionId) {
|
||||||
|
|
||||||
$this->captchaSession->init($sessionId);
|
$this->captchaSession->init($sessionId);
|
||||||
$fields = [
|
|
||||||
[
|
|
||||||
'id' => 'captcha',
|
|
||||||
'type' => 'text',
|
|
||||||
'params' => [
|
|
||||||
'label' => __('Type in the characters you see in the picture above:', 'mailpoet'),
|
|
||||||
'value' => '',
|
|
||||||
'obfuscate' => false,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$form = array_merge(
|
|
||||||
$fields,
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'id' => 'submit',
|
|
||||||
'type' => 'submit',
|
|
||||||
'params' => [
|
|
||||||
'label' => __('Subscribe', 'mailpoet'),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$captchaSessionForm = $this->captchaSession->getFormData();
|
$captchaSessionForm = $this->captchaSession->getFormData();
|
||||||
$formId = 0;
|
|
||||||
|
|
||||||
$showSuccessMessage = !empty($_GET['mailpoet_success']);
|
$showSuccessMessage = !empty($_GET['mailpoet_success']);
|
||||||
$showErrorMessage = !empty($_GET['mailpoet_error']);
|
$showErrorMessage = !empty($_GET['mailpoet_error']);
|
||||||
|
$formId = 0;
|
||||||
if (isset($captchaSessionForm['form_id'])) {
|
if (isset($captchaSessionForm['form_id'])) {
|
||||||
$formId = (int)$captchaSessionForm['form_id'];
|
$formId = (int)$captchaSessionForm['form_id'];
|
||||||
} elseif ($showSuccessMessage) {
|
} elseif ($showSuccessMessage) {
|
||||||
@ -93,6 +67,33 @@ class CaptchaRenderer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
[
|
||||||
|
'id' => 'captcha',
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'label' => __('Type in the characters you see in the picture above:', 'mailpoet'),
|
||||||
|
'value' => '',
|
||||||
|
'obfuscate' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$submitBlocks = $formModel->getBlocksByTypes(['submit']);
|
||||||
|
$submitLabel = count($submitBlocks) && $submitBlocks[0]['params']['label'] ? $submitBlocks[0]['params']['label'] : __('Subscribe', 'mailpoet');
|
||||||
|
$form = array_merge(
|
||||||
|
$fields,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'id' => 'submit',
|
||||||
|
'type' => 'submit',
|
||||||
|
'params' => [
|
||||||
|
'label' => $submitLabel,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
if ($showSuccessMessage) {
|
if ($showSuccessMessage) {
|
||||||
// Display a success message in a no-JS flow
|
// Display a success message in a no-JS flow
|
||||||
return $this->renderFormMessages($formModel, $showSuccessMessage);
|
return $this->renderFormMessages($formModel, $showSuccessMessage);
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\Subscription;
|
||||||
|
|
||||||
|
use MailPoet\Entities\FormEntity;
|
||||||
|
use MailPoet\Form\FormsRepository;
|
||||||
|
use MailPoet\Subscription\CaptchaRenderer;
|
||||||
|
use MailPoet\Subscription\CaptchaSession;
|
||||||
|
|
||||||
|
class CaptchaRendererTest extends \MailPoetTest
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testCaptchaSubmitTextIsConfigurable() {
|
||||||
|
|
||||||
|
$expectedLabel = 'EXPECTED_LABEL';
|
||||||
|
$formRepository = $this->diContainer->get(FormsRepository::class);
|
||||||
|
$form = new FormEntity('captcha-render-test-form');
|
||||||
|
$form->setBody([
|
||||||
|
[
|
||||||
|
'type' => 'text',
|
||||||
|
'id' => 'email',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'type' => 'submit',
|
||||||
|
'params' => [
|
||||||
|
'label' => $expectedLabel,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$form->setSettings([
|
||||||
|
'success_message' => 'tada!',
|
||||||
|
]);
|
||||||
|
$form->setId(1);
|
||||||
|
$formRepository->persist($form);
|
||||||
|
$formRepository->flush();
|
||||||
|
$captchaSession = $this->diContainer->get(CaptchaSession::class);
|
||||||
|
$captchaSession->init();
|
||||||
|
$captchaSession->setFormData(['form_id' => $form->getId()]);
|
||||||
|
|
||||||
|
$testee = $this->diContainer->get(CaptchaRenderer::class);
|
||||||
|
$result = $testee->getCaptchaPageContent($captchaSession->getId());
|
||||||
|
$this->assertStringContainsString('value="' . $expectedLabel . '"', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCaptchaSubmitTextHasDefault() {
|
||||||
|
|
||||||
|
$formRepository = $this->diContainer->get(FormsRepository::class);
|
||||||
|
$form = new FormEntity('captcha-render-test-form');
|
||||||
|
$form->setBody([
|
||||||
|
[
|
||||||
|
'type' => 'text',
|
||||||
|
'id' => 'email',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'type' => 'submit',
|
||||||
|
'params' => [
|
||||||
|
'label' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$form->setSettings([
|
||||||
|
'success_message' => 'tada!',
|
||||||
|
]);
|
||||||
|
$form->setId(1);
|
||||||
|
$formRepository->persist($form);
|
||||||
|
$formRepository->flush();
|
||||||
|
$captchaSession = $this->diContainer->get(CaptchaSession::class);
|
||||||
|
$captchaSession->init();
|
||||||
|
$captchaSession->setFormData(['form_id' => $form->getId()]);
|
||||||
|
|
||||||
|
$testee = $this->diContainer->get(CaptchaRenderer::class);
|
||||||
|
$result = $testee->getCaptchaPageContent($captchaSession->getId());
|
||||||
|
$this->assertStringContainsString('value="Subscribe"', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
$this->diContainer->get(FormsRepository::class)->truncate();
|
||||||
|
parent::_before();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user