Show notice when migration affects tracking settings

[MAILPOET-3185]
This commit is contained in:
Rostislav Wolny
2021-11-25 15:13:59 +01:00
committed by Veljko V
parent 432b2e6ff5
commit 7b69efea13
4 changed files with 64 additions and 0 deletions

View File

@@ -4,6 +4,8 @@ namespace MailPoet\Config;
use MailPoet\Settings\SettingsController;
use MailPoet\Settings\TrackingConfig;
use MailPoet\Util\Notices\ChangedTrackingNotice;
use MailPoet\WP\Functions;
class PopulatorTest extends \MailPoetTest {
@@ -20,36 +22,43 @@ class PopulatorTest extends \MailPoetTest {
}
public function testItMigratesTrackingSettings() {
$wp = $this->diContainer->get(Functions::class);
// WooCommerce disabled and Tracking enabled
$this->settings->set('db_version', '3.74.1');
$this->settings->set('tracking', ['enabled' => true]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', null);
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_FULL);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->false();
// WooCommerce disabled and Tracking disabled
$this->settings->set('tracking', ['enabled' => false]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', null);
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_BASIC);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->false();
// WooCommerce enabled with cookie enabled and Tracking enabled
$this->settings->set('tracking', ['enabled' => true]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', "1");
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_FULL);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->false();
// WooCommerce enabled with cookie disabled and Tracking enabled
$this->settings->set('tracking', ['enabled' => true]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', "");
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_PARTIAL);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->false();
// WooCommerce enabled with cookie disabled and Tracking disabled
$this->settings->set('tracking', ['enabled' => false]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', "");
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_BASIC);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->false();
// WooCommerce enabled with cookie enabled and Tracking disabled
$this->settings->set('tracking', ['enabled' => false]);
$this->settings->set('woocommerce.accept_cookie_revenue_tracking.enabled', "1");
$this->populator->up();
expect($this->settings->get('tracking.level'))->equals(TrackingConfig::LEVEL_FULL);
expect($wp->getTransient(ChangedTrackingNotice::OPTION_NAME))->equals(true);
}
}