Files
piratepoet/tests/integration/Util/Notices/InactiveSubscribersNoticeTest.php
2019-11-06 16:32:32 +00:00

74 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace MailPoet\Util\Notices;
use MailPoet\Models\Subscriber;
use MailPoet\Settings\SettingsController;
use MailPoet\Settings\SettingsRepository;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\Subscriber as SubscriberFactory;
use MailPoet\WP\Functions as WPFunctions;
class InactiveSubscribersNoticeTest extends \MailPoetTest {
function testItDisplays() {
$this->createSubscribers(50);
$notice = new InactiveSubscribersNotice(SettingsController::getInstance(), new WPFunctions());
$result = $notice->init(true);
expect($result)->contains('Good news! MailPoet wont send emails to your 50 inactive subscribers.');
expect($result)->contains('https://kb.mailpoet.com/article/264-inactive-subscribers');
expect($result)->contains('<a href="admin.php?page=mailpoet-settings#advanced" class="button button-primary">Go to the Advanced Settings</a>');
}
function testItDoesntDisplayWhenDisabled() {
$this->createSubscribers(50);
$notice = new InactiveSubscribersNotice(SettingsController::getInstance(), new WPFunctions());
$notice->disable();
$result = $notice->init(true);
expect($result)->null();
}
function testItDoesntDisplayWhenInactiveTimeRangeChanged() {
$this->createSubscribers(50);
$settings_factory = new Settings();
$settings_factory->withDeactivateSubscriberAfter3Months();
$notice = new InactiveSubscribersNotice(SettingsController::getInstance(), new WPFunctions());
$result = $notice->init(true);
expect($result)->null();
}
function testItDoesntDisplayWhenNotEnoughInactiveSubscribers() {
$this->createSubscribers(49);
$notice = new InactiveSubscribersNotice(SettingsController::getInstance(), new WPFunctions());
$result = $notice->init(true);
expect($result)->null();
}
function _before() {
parent::_before();
$this->cleanup();
}
function _after() {
parent::_after();
$this->cleanup();
}
private function cleanup() {
$this->di_container->get(SettingsRepository::class)->truncate();
\ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
}
private function createSubscribers($count) {
for ($i = 0; $i < $count; $i++) {
$subscriber_factory = new SubscriberFactory();
$subscriber_factory->withStatus(Subscriber::STATUS_INACTIVE);
$subscriber_factory->create();
}
}
}