codeception/verify 2.1 removed support for expect()->stringNotContainsString() so we need to replace it with verify()->stringNotContainsString(). [MAILPOET-5664]
111 lines
4.2 KiB
PHP
111 lines
4.2 KiB
PHP
<?php declare(strict_types = 1);
|
|
|
|
namespace MailPoet\Util\Notices;
|
|
|
|
use Codeception\Util\Stub;
|
|
use MailPoet\Settings\SettingsController;
|
|
use MailPoet\Settings\TrackingConfig;
|
|
use MailPoet\WP\Functions as WPFunctions;
|
|
|
|
class HeadersAlreadySentNoticeTest extends \MailPoetTest {
|
|
/** @var SettingsController */
|
|
private $settings;
|
|
|
|
/** @var WPFunctions */
|
|
private $wp;
|
|
|
|
public function _before() {
|
|
parent::_before();
|
|
$this->settings = SettingsController::getInstance();
|
|
$this->wp = new WPFunctions;
|
|
delete_transient(HeadersAlreadySentNotice::OPTION_NAME);
|
|
}
|
|
|
|
public function _after() {
|
|
parent::_after();
|
|
delete_transient(HeadersAlreadySentNotice::OPTION_NAME);
|
|
}
|
|
|
|
public function testItPrintsWarningWhenHeadersAreSent() {
|
|
$headersAlreadySentNotice = Stub::construct(
|
|
HeadersAlreadySentNotice::class,
|
|
[$this->settings, $this->diContainer->get(TrackingConfig::class), $this->wp],
|
|
['headersSent' => true]
|
|
);
|
|
$notice = $headersAlreadySentNotice->init(true);
|
|
verify($notice->getMessage())->stringContainsString('It looks like there\'s an issue with some of the PHP files on your website');
|
|
verify($notice->getMessage())->stringContainsString('https://kb.mailpoet.com/article/325-the-captcha-image-doesnt-show-up');
|
|
}
|
|
|
|
public function testItPrintsNoWarningWhenHeadersAreNotSent() {
|
|
$headersAlreadySentNotice = Stub::construct(
|
|
HeadersAlreadySentNotice::class,
|
|
[$this->settings, $this->diContainer->get(TrackingConfig::class), $this->wp],
|
|
['headersSent' => false]
|
|
);
|
|
$notice = $headersAlreadySentNotice->init(true);
|
|
verify($notice)->null();
|
|
}
|
|
|
|
public function testItPrintsWarningWhenWhitespaceIsInBuffer() {
|
|
ob_start();
|
|
echo " \n \t \r\n ";
|
|
$headersAlreadySentNotice = Stub::construct(
|
|
HeadersAlreadySentNotice::class,
|
|
[$this->settings, $this->diContainer->get(TrackingConfig::class), $this->wp],
|
|
['headersSent' => false]
|
|
);
|
|
$notice = $headersAlreadySentNotice->init(true);
|
|
verify($notice->getMessage())->stringContainsString('It looks like there\'s an issue with some of the PHP files on your website');
|
|
ob_end_clean();
|
|
}
|
|
|
|
public function testItPrintsNoWarningWhenDisabled() {
|
|
$headersAlreadySentNotice = Stub::construct(
|
|
HeadersAlreadySentNotice::class,
|
|
[$this->settings, $this->diContainer->get(TrackingConfig::class), $this->wp],
|
|
['headersSent' => true]
|
|
);
|
|
$warning = $headersAlreadySentNotice->init(false);
|
|
verify($warning)->null();
|
|
}
|
|
|
|
public function testItPrintsNoWarningWhenDismissed() {
|
|
$headersAlreadySentNotice = Stub::construct(
|
|
HeadersAlreadySentNotice::class,
|
|
[$this->settings, $this->diContainer->get(TrackingConfig::class), $this->wp],
|
|
['headersSent' => true]
|
|
);
|
|
$headersAlreadySentNotice->disable();
|
|
$warning = $headersAlreadySentNotice->init(true);
|
|
verify($warning)->null();
|
|
}
|
|
|
|
public function testItPrintsCaptchaAndTrackingMessagesIfEnabled() {
|
|
$headersAlreadySentNotice = Stub::make(HeadersAlreadySentNotice::class);
|
|
$notice = $headersAlreadySentNotice->display(true, true);
|
|
verify($notice->getMessage())->stringContainsString('Inaccurate tracking');
|
|
verify($notice->getMessage())->stringContainsString('CAPTCHA not rendering');
|
|
}
|
|
|
|
public function testItPrintsNoCaptchaMessageIfCaptchaDisabled() {
|
|
$headersAlreadySentNotice = Stub::make(HeadersAlreadySentNotice::class);
|
|
$notice = $headersAlreadySentNotice->display(false, true);
|
|
verify($notice->getMessage())->stringContainsString('Inaccurate tracking');
|
|
verify($notice->getMessage())->stringNotContainsString('CAPTCHA not rendering');
|
|
}
|
|
|
|
public function testItPrintsNoTrackingMessageIftrackingDisabled() {
|
|
$headersAlreadySentNotice = Stub::make(HeadersAlreadySentNotice::class);
|
|
$notice = $headersAlreadySentNotice->display(true, false);
|
|
verify($notice->getMessage())->stringNotContainsString('Inaccurate tracking');
|
|
verify($notice->getMessage())->stringContainsString('CAPTCHA not rendering');
|
|
}
|
|
|
|
public function testItPrintsNoMessagesWhenCaptchaAndTrackingDisabled() {
|
|
$headersAlreadySentNotice = Stub::make(HeadersAlreadySentNotice::class);
|
|
$notice = $headersAlreadySentNotice->display(false, false);
|
|
verify($notice)->null();
|
|
}
|
|
}
|