Files
piratepoet/mailpoet/tests/integration/Util/Notices/PendingApprovalNoticeTest.php
Rostislav Wolny 8ce8524ee3 Adjust conditions for displaying pending approval notice
The method was displayed even when MSS was set but key was not valid.
This may happen when a key loses the access to MSS.
[MAILPOET-5103]
2023-04-26 10:57:40 +02:00

66 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 declare(strict_types = 1);
namespace MailPoet\Util\Notices;
use MailPoet\Mailer\Mailer;
use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController;
class PendingApprovalNoticeTest extends \MailPoetTest {
/** @var PendingApprovalNotice */
private $notice;
/** @var SettingsController */
private $settings;
public function _before() {
parent::_before();
$this->settings = SettingsController::getInstance();
$this->notice = new PendingApprovalNotice($this->settings);
$this->settings->set('mta.mailpoet_api_key_state.state', Bridge::KEY_VALID);
}
public function testItDisplays(): void {
$this->settings->set('mta.mailpoet_api_key_state.data.is_approved', false);
$this->settings->set('mta.method', Mailer::METHOD_MAILPOET);
$result = $this->notice->init(true);
// check that the notice is displayed. We cannot check the whole string because it contains HTML tags
expect($result)->stringContainsString('Your subscription is currently');
expect($result)->stringContainsString('if you havent heard from our team about your subscription status in the past 48 hours.');
}
public function testItDoesNotDisplayWhenMSSKeyIsNotValid(): void {
$this->settings->set('mta.mailpoet_api_key_state.data.is_approved', false);
$this->settings->set('mta.mailpoet_api_key_state.state', Bridge::KEY_VALID_UNDERPRIVILEGED);
$this->settings->set('mta.method', Mailer::METHOD_MAILPOET);
$result = $this->notice->init(true);
expect($result)->null();
}
public function testItDoesNotDisplayWhenDisabled(): void {
$this->settings->set('mta.mailpoet_api_key_state.data.is_approved', false);
$this->settings->set('mta.method', Mailer::METHOD_MAILPOET);
$result = $this->notice->init(false);
expect($result)->null();
}
public function testItDoesNotDisplayWhenNotUsingMailPoet(): void {
$this->settings->set('mta.mailpoet_api_key_state.data.is_approved', false);
$this->settings->set('mta.method', Mailer::METHOD_PHPMAIL);
$result = $this->notice->init(true);
expect($result)->null();
}
public function testItDoesNotDisplayWhenApproved(): void {
$this->settings->set('mta.mailpoet_api_key_state.data.is_approved', true);
$this->settings->set('mta.method', Mailer::METHOD_MAILPOET);
$result = $this->notice->init(true);
expect($result)->null();
}
}