71 lines
2.8 KiB
PHP
71 lines
2.8 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;
|
|
use MailPoet\WP\Functions as WPFunctions;
|
|
|
|
/**
|
|
* The "created_at" column must be NULL in some tables to avoid "there can be only one
|
|
* TIMESTAMP column with CURRENT_TIMESTAMP" error on MySQL version < 5.6.5 that occurs
|
|
* even when other timestamp is simply "NOT NULL".
|
|
*
|
|
* Additionally, having multiple timestamp columns with "NOT NULL" seems to produce the
|
|
* following error in some SQL modes:
|
|
* SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at'"
|
|
*/
|
|
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);
|
|
$subscriptionCaptcha = $this->diContainer->get(Captcha::class);
|
|
$populator = $this->getServiceWithOverrides(Populator::class, ['wp' => $wpStub, 'referralDetector' => $referralDetector]);
|
|
$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 = $subscriptionCaptcha->isSupported() ? Captcha::TYPE_BUILTIN : Captcha::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();
|
|
}
|
|
}
|