The current Captcha class has a lot of responsibilities. It renders the captcha image, can check if a certain captcha type is a Google captcha, if a captcha is required for a certain email. The SubscriberSubscribeController is not only in charge of "controlling" the subscription process but also validates, whether a captcha is correct or not. This architecture made it difficult to extend the functionality and introduce the audio captcha feature. Therefore this commit refactors the captcha architecture and tries to seperate the different concerns into several classes and objects. Validation is now done by validators. The CaptchaPhrase now is in charge of keeping the captcha phrase consistent between the image and the new audio, so that you can renew the captcha and both captchas are in sync. [MAILPOET-4514]
63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace MailPoet\Test\API\JSON\v1;
|
|
|
|
use Codeception\Stub;
|
|
use Helper\WordPressHooks as WPHooksHelper;
|
|
use MailPoet\API\JSON\Response as APIResponse;
|
|
use MailPoet\API\JSON\v1\Setup;
|
|
use MailPoet\Config\Activator;
|
|
use MailPoet\Config\Populator;
|
|
use MailPoet\Cron\ActionScheduler\ActionScheduler;
|
|
use MailPoet\Migrator\Migrator;
|
|
use MailPoet\Referrals\ReferralDetector;
|
|
use MailPoet\Settings\SettingsController;
|
|
use MailPoet\Settings\SettingsRepository;
|
|
use MailPoet\Subscription\Captcha\CaptchaConstants;
|
|
use MailPoet\Subscription\Captcha\CaptchaRenderer;
|
|
use MailPoet\WP\Functions as WPFunctions;
|
|
|
|
class SetupTest extends \MailPoetTest {
|
|
public function _before() {
|
|
parent::_before();
|
|
$settings = SettingsController::getInstance();
|
|
$settings->set('signup_confirmation.enabled', false);
|
|
}
|
|
|
|
public function testItCanReinstall() {
|
|
$wpStub = Stub::make(new WPFunctions, [
|
|
'doAction' => asCallable([WPHooksHelper::class, 'doAction']),
|
|
]);
|
|
|
|
$settings = SettingsController::getInstance();
|
|
$referralDetector = new ReferralDetector($wpStub, $settings);
|
|
$populator = $this->getServiceWithOverrides(Populator::class, ['wp' => $wpStub, 'referralDetector' => $referralDetector]);
|
|
$captchaRenderer = $this->diContainer->get(CaptchaRenderer::class);
|
|
$migrator = $this->diContainer->get(Migrator::class);
|
|
$cronActionScheduler = $this->diContainer->get(ActionScheduler::class);
|
|
$router = new Setup($wpStub, new Activator($this->connection, $settings, $populator, $wpStub, $migrator, $cronActionScheduler));
|
|
$response = $router->reset();
|
|
expect($response->status)->equals(APIResponse::STATUS_OK);
|
|
|
|
$settings = SettingsController::getInstance();
|
|
$signupConfirmation = $settings->fetch('signup_confirmation.enabled');
|
|
expect($signupConfirmation)->true();
|
|
|
|
$captcha = $settings->fetch('captcha');
|
|
$captchaType = $captchaRenderer->isSupported() ? CaptchaConstants::TYPE_BUILTIN : CaptchaConstants::TYPE_DISABLED;
|
|
expect($captcha['type'])->equals($captchaType);
|
|
expect($captcha['recaptcha_site_token'])->equals('');
|
|
expect($captcha['recaptcha_secret_token'])->equals('');
|
|
|
|
$woocommerceOptinOnCheckout = $settings->fetch('woocommerce.optin_on_checkout');
|
|
expect($woocommerceOptinOnCheckout['enabled'])->true();
|
|
|
|
$hookName = 'mailpoet_setup_reset';
|
|
expect(WPHooksHelper::isActionDone($hookName))->true();
|
|
}
|
|
|
|
public function _after() {
|
|
$this->diContainer->get(SettingsRepository::class)->truncate();
|
|
}
|
|
}
|