Move assorted tests from integration to unit [MAILPOET-2009]

This commit is contained in:
wxa
2019-04-25 11:11:41 +03:00
committed by M. Shull
parent 994fae79d2
commit 2fd244528d
14 changed files with 59 additions and 33 deletions

View File

@ -3,8 +3,6 @@
namespace MailPoet\API\JSON; namespace MailPoet\API\JSON;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
class ErrorResponse extends Response { class ErrorResponse extends Response {
public $errors; public $errors;

View File

@ -2,8 +2,6 @@
namespace MailPoet\API\JSON; namespace MailPoet\API\JSON;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
abstract class Response { abstract class Response {
const STATUS_OK = 200; const STATUS_OK = 200;
const STATUS_BAD_REQUEST = 400; const STATUS_BAD_REQUEST = 400;

View File

@ -1,8 +1,6 @@
<?php <?php
namespace MailPoet\Form\Block; namespace MailPoet\Form\Block;
if (!defined('ABSPATH')) exit;
use Carbon\Carbon; use Carbon\Carbon;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;

View File

@ -4,8 +4,6 @@ namespace MailPoet\Newsletter\Editor;
use MailPoet\WooCommerce\Helper as WooCommerceHelper; use MailPoet\WooCommerce\Helper as WooCommerceHelper;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
class PostContentManager { class PostContentManager {
const WP_POST_CLASS = 'mailpoet_wp_post'; const WP_POST_CLASS = 'mailpoet_wp_post';

View File

@ -5,8 +5,6 @@ use MailPoet\WooCommerce\Helper as WooCommerceHelper;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
use MailPoet\Config\Env; use MailPoet\Config\Env;
if (!defined('ABSPATH')) exit;
class PostTransformer { class PostTransformer {
private $args; private $args;

View File

@ -5,8 +5,6 @@ use pQuery;
use pQuery\DomNode; use pQuery\DomNode;
use MailPoet\Util\DOM as DOMUtil; use MailPoet\Util\DOM as DOMUtil;
if (!defined('ABSPATH')) exit;
class StructureTransformer { class StructureTransformer {
function transform($content, $image_full_width) { function transform($content, $image_full_width) {

View File

@ -3,8 +3,6 @@ namespace MailPoet\Util;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
class Security { class Security {
const HASH_LENGTH = 12; const HASH_LENGTH = 12;

View File

@ -2,10 +2,17 @@
namespace MailPoet\Test\API\JSON; namespace MailPoet\Test\API\JSON;
use Codeception\Stub;
use MailPoet\API\JSON\ErrorResponse; use MailPoet\API\JSON\ErrorResponse;
use MailPoet\WP\Functions as WPFunctions;
class ErrorResponseTest extends \MailPoetTest { class ErrorResponseTest extends \MailPoetUnitTest {
function testItSanitizesSqlErrorsWhenReturningResponse() { function testItSanitizesSqlErrorsWhenReturningResponse() {
WPFunctions::set(Stub::make(new WPFunctions, [
'__' => function ($value) {
return $value;
}
]));
$errors = array( $errors = array(
'valid error', 'valid error',
'SQLSTATE[22001]: Some SQL error', 'SQLSTATE[22001]: Some SQL error',
@ -31,4 +38,8 @@ class ErrorResponseTest extends \MailPoetTest {
) )
); );
} }
function _after() {
WPFunctions::set(new WPFunctions);
}
} }

View File

@ -3,7 +3,7 @@ namespace MailPoet\Test\Form\Block;
use MailPoet\Form\Block\Date; use MailPoet\Form\Block\Date;
class DateTest extends \MailPoetTest { class DateTest extends \MailPoetUnitTest {
function testItCanConvertDateMonthYearFormatToDatetime() { function testItCanConvertDateMonthYearFormatToDatetime() {
$date = array( $date = array(
'MM/DD/YYYY' => '05/10/2016', 'MM/DD/YYYY' => '05/10/2016',

View File

@ -3,7 +3,7 @@ namespace MailPoet\Test\Newsletter\Editor;
use MailPoet\Newsletter\Editor\StructureTransformer; use MailPoet\Newsletter\Editor\StructureTransformer;
class StructureTransformerTest extends \MailPoetTest { class StructureTransformerTest extends \MailPoetUnitTest {
function _before() { function _before() {
parent::_before(); parent::_before();

View File

@ -1,9 +1,11 @@
<?php <?php
namespace MailPoet\Test\Subscribers\ImportExport\Import; namespace MailPoet\Test\Subscribers\ImportExport\Import;
use Codeception\Stub;
use MailPoet\Subscribers\ImportExport\Import\MailChimp; use MailPoet\Subscribers\ImportExport\Import\MailChimp;
use MailPoet\WP\Functions as WPFunctions;
class MailChimpTest extends \MailPoetTest { class MailChimpTest extends \MailPoetUnitTest {
function __construct() { function __construct() {
parent::__construct(); parent::__construct();
$this->api_key = getenv('WP_TEST_IMPORT_MAILCHIMP_API'); $this->api_key = getenv('WP_TEST_IMPORT_MAILCHIMP_API');
@ -11,6 +13,14 @@ class MailChimpTest extends \MailPoetTest {
$this->lists = explode(",", getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS')); $this->lists = explode(",", getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS'));
} }
function _before() {
WPFunctions::set(Stub::make(new WPFunctions, [
'__' => function ($value) {
return $value;
}
]));
}
function testItCanGetAPIKey() { function testItCanGetAPIKey() {
$valid_api_key_format = '12345678901234567890123456789012-ab1'; $valid_api_key_format = '12345678901234567890123456789012-ab1';
// key must consist of two parts separated by hyphen // key must consist of two parts separated by hyphen
@ -108,4 +118,8 @@ class MailChimpTest extends \MailPoetTest {
->contains('The information received from MailChimp is too large for processing'); ->contains('The information received from MailChimp is too large for processing');
} }
} }
function _after() {
WPFunctions::set(new WPFunctions);
}
} }

View File

@ -3,15 +3,7 @@ namespace MailPoet\Test\Util;
use MailPoet\Util\Security; use MailPoet\Util\Security;
class SecurityTest extends \MailPoetTest { class SecurityTest extends \MailPoetUnitTest {
function testItCanGenerateWPNonce() {
$wp_nonce = Security::generateToken();
// expect length of nonce to be exactly 10
expect(strlen($wp_nonce))->equals(10);
// expect only alphanumerical characters
expect(ctype_alnum($wp_nonce))->true();
}
function testItCanGenerateARandomString() { function testItCanGenerateARandomString() {
// it has a default length of 5 // it has a default length of 5

View File

@ -5,7 +5,7 @@ use Codeception\Stub;
use MailPoet\WP\DateTime as WPDateTime; use MailPoet\WP\DateTime as WPDateTime;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class DateTimeTest extends \MailPoetTest { class DateTimeTest extends \MailPoetUnitTest {
function testGetTimeFormat() { function testGetTimeFormat() {
$date_time = new WPDateTime(Stub::make(new WPFunctions(), [ $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
@ -40,17 +40,29 @@ class DateTimeTest extends \MailPoetTest {
} }
function testGetCurrentDate() { function testGetCurrentDate() {
$date_time = new WPDateTime(); $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
'currentTime' => function($format) {
return date($format);
}
]));
expect($date_time->getCurrentDate("Y-m"))->equals(date("Y-m")); expect($date_time->getCurrentDate("Y-m"))->equals(date("Y-m"));
} }
function testGetCurrentTime() { function testGetCurrentTime() {
$date_time = new WPDateTime(); $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
'currentTime' => function($format) {
return date($format);
}
]));
expect($date_time->getCurrentTime("i:s"))->regExp('/\d\d:\d\d/'); expect($date_time->getCurrentTime("i:s"))->regExp('/\d\d:\d\d/');
} }
function testFormatTime() { function testFormatTime() {
$date_time = new WPDateTime(); $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
'getOption' => function($key) {
return 'H:i';
}
]));
$timestamp = 1234567; $timestamp = 1234567;
$format = "H:i:s"; $format = "H:i:s";
expect($date_time->formatTime($timestamp))->equals(date($date_time->getTimeFormat(), $timestamp)); expect($date_time->formatTime($timestamp))->equals(date($date_time->getTimeFormat(), $timestamp));
@ -58,7 +70,11 @@ class DateTimeTest extends \MailPoetTest {
} }
function testFormatDate() { function testFormatDate() {
$date_time = new WPDateTime(); $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
'getOption' => function($key) {
return 'm-d';
}
]));
$timestamp = 1234567; $timestamp = 1234567;
$format = "Y-m-d"; $format = "Y-m-d";
expect($date_time->formatDate($timestamp))->equals(date($date_time->getDateFormat(), $timestamp)); expect($date_time->formatDate($timestamp))->equals(date($date_time->getDateFormat(), $timestamp));
@ -66,7 +82,11 @@ class DateTimeTest extends \MailPoetTest {
} }
function testTimeInterval() { function testTimeInterval() {
$date_time = new WPDateTime(); $date_time = new WPDateTime(Stub::make(new WPFunctions(), [
'getOption' => function($key) {
return 'H:i';
}
]));
$one_hour_interval = array_keys($date_time->getTimeInterval( $one_hour_interval = array_keys($date_time->getTimeInterval(
'00:00:00', '00:00:00',
'+1 hour', '+1 hour',

View File

@ -54,4 +54,7 @@ class PostsTest extends \MailPoetUnitTest {
expect($result['arguments'][1])->equals(array_diff_key($args, array('taxonomy' => ''))); expect($result['arguments'][1])->equals(array_diff_key($args, array('taxonomy' => '')));
} }
function _after() {
WPFunctions::set(new WPFunctions);
}
} }