Make separate setups for integration and unit tests
This commit is contained in:
34
RoboFile.php
34
RoboFile.php
@@ -158,6 +158,26 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
|
|
||||||
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml';
|
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml';
|
||||||
|
|
||||||
|
if($opts['file']) {
|
||||||
|
$command .= ' -f ' . $opts['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($opts['xml']) {
|
||||||
|
$command .= ' --xml';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($opts['debug']) {
|
||||||
|
$command .= ' --debug';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_exec($command);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIntegration(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) {
|
||||||
|
$this->loadEnv();
|
||||||
|
|
||||||
|
$command = 'vendor/bin/codecept run integration -c codeception.integration.yml';
|
||||||
|
|
||||||
if($opts['multisite']) {
|
if($opts['multisite']) {
|
||||||
$command = 'MULTISITE=true ' . $command;
|
$command = 'MULTISITE=true ' . $command;
|
||||||
}
|
}
|
||||||
@@ -177,8 +197,8 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
return $this->_exec($command);
|
return $this->_exec($command);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMultisiteUnit($opts=['file' => null, 'xml' => false, 'multisite' => true]) {
|
function testMultisiteIntegration($opts=['file' => null, 'xml' => false, 'multisite' => true]) {
|
||||||
return $this->testUnit($opts);
|
return $this->testIntegration($opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testCoverage($opts=['file' => null, 'xml' => false]) {
|
function testCoverage($opts=['file' => null, 'xml' => false]) {
|
||||||
@@ -219,10 +239,14 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
return $this->_exec('vendor/bin/security-checker security:check --format=simple');
|
return $this->_exec('vendor/bin/security-checker security:check --format=simple');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDebug($opts=['file' => null, 'xml' => false, 'debug' => true]) {
|
function testDebugUnit($opts=['file' => null, 'xml' => false, 'debug' => true]) {
|
||||||
return $this->testUnit($opts);
|
return $this->testUnit($opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDebugIntegration($opts=['file' => null, 'xml' => false, 'debug' => true]) {
|
||||||
|
return $this->testIntegration($opts);
|
||||||
|
}
|
||||||
|
|
||||||
function testAcceptance($opts=['file' => null, 'skip-deps' => false]) {
|
function testAcceptance($opts=['file' => null, 'skip-deps' => false]) {
|
||||||
return $this->_exec(
|
return $this->_exec(
|
||||||
'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' .
|
'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' .
|
||||||
@@ -290,8 +314,8 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
'./vendor/bin/phpcs '.
|
'./vendor/bin/phpcs '.
|
||||||
'--standard=./tasks/code_sniffer/MailPoet '.
|
'--standard=./tasks/code_sniffer/MailPoet '.
|
||||||
'--runtime-set testVersion 5.5-7.2 '.
|
'--runtime-set testVersion 5.5-7.2 '.
|
||||||
'--ignore=./tests/unit/_bootstrap.php '.
|
'--ignore=./tests/unit/_bootstrap.php,./tests/unit/_fixtures.php,./tests/integration/_bootstrap.php,./tests/integration/_fixtures.php '.
|
||||||
'tests/unit/ tests/acceptance tests/DataFactories '.
|
'tests/unit tests/integration tests/acceptance tests/DataFactories '.
|
||||||
$severityFlag
|
$severityFlag
|
||||||
)
|
)
|
||||||
->run();
|
->run();
|
||||||
|
34
codeception.integration.yml
Normal file
34
codeception.integration.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
actor: Tester
|
||||||
|
paths:
|
||||||
|
tests: tests
|
||||||
|
log: tests/_output
|
||||||
|
data: tests/_data
|
||||||
|
support: tests/_support
|
||||||
|
envs: tests/_envs
|
||||||
|
settings:
|
||||||
|
bootstrap: _bootstrap.php
|
||||||
|
colors: true
|
||||||
|
memory_limit: 1024M
|
||||||
|
log: true
|
||||||
|
strict_xml: true
|
||||||
|
extensions:
|
||||||
|
enabled:
|
||||||
|
- Codeception\Extension\RunFailed
|
||||||
|
modules:
|
||||||
|
config:
|
||||||
|
Db:
|
||||||
|
dsn: ''
|
||||||
|
user: ''
|
||||||
|
password: ''
|
||||||
|
dump: tests/_data/dump.sql
|
||||||
|
coverage:
|
||||||
|
enabled: true
|
||||||
|
whitelist:
|
||||||
|
include:
|
||||||
|
- lib/*
|
||||||
|
exclude:
|
||||||
|
- lib/Config/PopulatorData/*
|
||||||
|
- lib/Util/Sudzy/*
|
||||||
|
- lib/Util/CSS.php
|
||||||
|
- lib/Util/Helpers.php
|
||||||
|
- lib/Util/XLSXWriter.php
|
@@ -1,147 +1 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if((boolean)getenv('MULTISITE') === true) {
|
|
||||||
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
|
||||||
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
|
|
||||||
$wp_load_file = getenv('WP_TEST_PATH_MULTISITE') . '/wp-load.php';
|
|
||||||
} else {
|
|
||||||
$wp_load_file = getenv('WP_TEST_PATH') . '/wp-load.php';
|
|
||||||
}
|
|
||||||
require_once($wp_load_file);
|
|
||||||
|
|
||||||
$console = new \Codeception\Lib\Console\Output([]);
|
|
||||||
$console->writeln('Loading WP core... (' . $wp_load_file . ')');
|
|
||||||
|
|
||||||
$console->writeln('Cleaning up database...');
|
|
||||||
$models = array(
|
|
||||||
'CustomField',
|
|
||||||
'Form',
|
|
||||||
'Newsletter',
|
|
||||||
'NewsletterLink',
|
|
||||||
'NewsletterPost',
|
|
||||||
'NewsletterSegment',
|
|
||||||
'NewsletterTemplate',
|
|
||||||
'NewsletterOption',
|
|
||||||
'NewsletterOptionField',
|
|
||||||
'Segment',
|
|
||||||
'Log',
|
|
||||||
'ScheduledTask',
|
|
||||||
'ScheduledTaskSubscriber',
|
|
||||||
'SendingQueue',
|
|
||||||
'Setting',
|
|
||||||
'Subscriber',
|
|
||||||
'SubscriberCustomField',
|
|
||||||
'SubscriberSegment',
|
|
||||||
'SubscriberIP',
|
|
||||||
'StatisticsOpens',
|
|
||||||
'StatisticsClicks',
|
|
||||||
'StatisticsNewsletters',
|
|
||||||
'StatisticsUnsubscribes'
|
|
||||||
);
|
|
||||||
$destroy = function($model) {
|
|
||||||
$class = new \ReflectionClass('\MailPoet\Models\\' . $model);
|
|
||||||
$table = $class->getStaticPropertyValue('_table');
|
|
||||||
$db = ORM::getDb();
|
|
||||||
$db->beginTransaction();
|
|
||||||
$db->exec('TRUNCATE ' . $table);
|
|
||||||
$db->commit();
|
|
||||||
};
|
|
||||||
array_map($destroy, $models);
|
|
||||||
|
|
||||||
$cacheDir = '/tmp';
|
|
||||||
if(is_dir(getenv('WP_TEST_CACHE_PATH'))) {
|
|
||||||
$cacheDir = getenv('WP_TEST_CACHE_PATH');
|
|
||||||
}
|
|
||||||
|
|
||||||
$console->writeln('Clearing AspectMock cache...');
|
|
||||||
exec('rm -rf ' . $cacheDir . '/_transformation.cache');
|
|
||||||
|
|
||||||
$console->writeln('Initializing AspectMock library...');
|
|
||||||
$kernel = \AspectMock\Kernel::getInstance();
|
|
||||||
$kernel->init(
|
|
||||||
array(
|
|
||||||
'debug' => true,
|
|
||||||
'appDir' => __DIR__ . '/../',
|
|
||||||
'cacheDir' => $cacheDir,
|
|
||||||
'includePaths' => [__DIR__ . '/../lib'],
|
|
||||||
'appDir' => __DIR__ . '/../'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// This hook throws an 'Undefined index: SERVER_NAME' error in CLI mode,
|
|
||||||
// the action is called in ConflictResolverTest
|
|
||||||
remove_filter('admin_print_styles', 'wp_resource_hints', 1);
|
|
||||||
|
|
||||||
abstract class MailPoetTest extends \Codeception\TestCase\Test {
|
|
||||||
protected $backupGlobals = true;
|
|
||||||
protected $backupGlobalsBlacklist = array(
|
|
||||||
'app',
|
|
||||||
'post',
|
|
||||||
'authordata',
|
|
||||||
'currentday',
|
|
||||||
'currentmonth',
|
|
||||||
'page',
|
|
||||||
'pages',
|
|
||||||
'multipage',
|
|
||||||
'more',
|
|
||||||
'numpages',
|
|
||||||
'is_iphone',
|
|
||||||
'is_chrome',
|
|
||||||
'is_safari',
|
|
||||||
'is_NS4',
|
|
||||||
'is_opera',
|
|
||||||
'is_macIE',
|
|
||||||
'is_winIE',
|
|
||||||
'is_gecko',
|
|
||||||
'is_lynx',
|
|
||||||
'is_IE',
|
|
||||||
'is_apache',
|
|
||||||
'is_IIS',
|
|
||||||
'is_iis7',
|
|
||||||
'wp_version',
|
|
||||||
'wp_db_version',
|
|
||||||
'tinymce_version',
|
|
||||||
'manifest_version',
|
|
||||||
'required_php_version',
|
|
||||||
'required_mysql_version',
|
|
||||||
'super_admins',
|
|
||||||
'wp_query',
|
|
||||||
'wp_rewrite',
|
|
||||||
'wp',
|
|
||||||
'wpdb',
|
|
||||||
'wp_locale',
|
|
||||||
'wp_admin_bar',
|
|
||||||
'wp_roles',
|
|
||||||
'wp_meta_boxes',
|
|
||||||
'wp_registered_sidebars',
|
|
||||||
'wp_registered_widgets',
|
|
||||||
'wp_registered_widget_controls',
|
|
||||||
'wp_registered_widget_updates',
|
|
||||||
'pagenow',
|
|
||||||
'post_type',
|
|
||||||
'allowedposttags',
|
|
||||||
'allowedtags',
|
|
||||||
'menu'
|
|
||||||
);
|
|
||||||
protected $backupStaticAttributes = false;
|
|
||||||
protected $runTestInSeparateProcess = false;
|
|
||||||
protected $preserveGlobalState = false;
|
|
||||||
protected $inIsolation = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call protected/private method of a class.
|
|
||||||
*
|
|
||||||
* @param object &$object Instantiated object that we will run method on.
|
|
||||||
* @param string $methodName Method name to call
|
|
||||||
* @param array $parameters Array of parameters to pass into method.
|
|
||||||
*
|
|
||||||
* @return mixed Method return.
|
|
||||||
*/
|
|
||||||
public function invokeMethod(&$object, $methodName, array $parameters = array()) {
|
|
||||||
$reflection = new \ReflectionClass(get_class($object));
|
|
||||||
$method = $reflection->getMethod($methodName);
|
|
||||||
$method->setAccessible(true);
|
|
||||||
|
|
||||||
return $method->invokeArgs($object, $parameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
63
tests/_support/IntegrationTester.php
Normal file
63
tests/_support/IntegrationTester.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited Methods
|
||||||
|
* @method void wantToTest($text)
|
||||||
|
* @method void wantTo($text)
|
||||||
|
* @method void execute($callable)
|
||||||
|
* @method void expectTo($prediction)
|
||||||
|
* @method void expect($prediction)
|
||||||
|
* @method void amGoingTo($argumentation)
|
||||||
|
* @method void am($role)
|
||||||
|
* @method void lookForwardTo($achieveValue)
|
||||||
|
* @method void comment($description)
|
||||||
|
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD)
|
||||||
|
*/
|
||||||
|
class IntegrationTester extends \Codeception\Actor {
|
||||||
|
use _generated\IntegrationTesterActions;
|
||||||
|
|
||||||
|
// generate random users
|
||||||
|
function generateSubscribers($count, $data = array()) {
|
||||||
|
for($i = 0; $i < $count; $i++) {
|
||||||
|
$this->generateSubscriber($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateSubscriber($data = array()) {
|
||||||
|
$subscriber_data = array(
|
||||||
|
'email' => sprintf('user%s@mailpoet.com', uniqid()),
|
||||||
|
'first_name' => $this->generateName(),
|
||||||
|
'last_name' => $this->generateName()
|
||||||
|
);
|
||||||
|
|
||||||
|
$subscriber = \MailPoet\Models\Subscriber::create();
|
||||||
|
$subscriber->hydrate(array_merge($subscriber_data, $data));
|
||||||
|
$subscriber->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateName() {
|
||||||
|
$name = '';
|
||||||
|
$length = mt_rand(6, 12);
|
||||||
|
|
||||||
|
$vowels = 'aeiouy';
|
||||||
|
$consonants = 'bcdfgjklmnpqrstvwxz';
|
||||||
|
$specials = ' \'';
|
||||||
|
$alphabet = $consonants.$vowels;
|
||||||
|
$charset = $specials.$alphabet;
|
||||||
|
|
||||||
|
// pick first letter in alphabet
|
||||||
|
$name .= $alphabet{mt_rand(0, strlen($alphabet) - 1)};
|
||||||
|
|
||||||
|
for($i = 0; $i < $length; $i++) {
|
||||||
|
$name .= $charset{mt_rand(0, strlen($charset) - 1)};
|
||||||
|
}
|
||||||
|
|
||||||
|
// pick last letter in alphabet
|
||||||
|
$name .= $alphabet{mt_rand(0, strlen($alphabet) - 1)};
|
||||||
|
|
||||||
|
return ucfirst($name);
|
||||||
|
}
|
||||||
|
}
|
13
tests/integration.suite.yml
Normal file
13
tests/integration.suite.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Codeception Test Suite Configuration
|
||||||
|
#
|
||||||
|
# Suite for unit (internal) tests.
|
||||||
|
|
||||||
|
actor: IntegrationTester
|
||||||
|
settings:
|
||||||
|
bootstrap: _bootstrap.php
|
||||||
|
modules:
|
||||||
|
enabled:
|
||||||
|
- Asserts
|
||||||
|
- \Helper\Unit
|
||||||
|
- \Helper\WordPress
|
||||||
|
error_level: E_ALL
|
@@ -1,182 +1,149 @@
|
|||||||
<?php
|
<?php
|
||||||
use Codeception\Util\Fixtures;
|
|
||||||
use MailPoet\Models\Subscriber;
|
|
||||||
|
|
||||||
$newsletter_body_text =
|
if((boolean)getenv('MULTISITE') === true) {
|
||||||
|
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
||||||
|
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
|
||||||
|
$wp_load_file = getenv('WP_TEST_PATH_MULTISITE') . '/wp-load.php';
|
||||||
|
} else {
|
||||||
|
$wp_load_file = getenv('WP_TEST_PATH') . '/wp-load.php';
|
||||||
|
}
|
||||||
|
require_once($wp_load_file);
|
||||||
|
|
||||||
Fixtures::add(
|
$console = new \Codeception\Lib\Console\Output([]);
|
||||||
'newsletter_body_template',
|
$console->writeln('Loading WP core... (' . $wp_load_file . ')');
|
||||||
'{
|
|
||||||
"content": {
|
$console->writeln('Cleaning up database...');
|
||||||
"type": "container",
|
$models = array(
|
||||||
"orientation": "vertical",
|
'CustomField',
|
||||||
"blocks": [
|
'Form',
|
||||||
{
|
'Newsletter',
|
||||||
"type": "container",
|
'NewsletterLink',
|
||||||
"styles": { "block": {} },
|
'NewsletterPost',
|
||||||
"orientation": "horizontal",
|
'NewsletterSegment',
|
||||||
"blocks": [
|
'NewsletterTemplate',
|
||||||
{
|
'NewsletterOption',
|
||||||
"type": "container",
|
'NewsletterOptionField',
|
||||||
"orientation": "vertical",
|
'Segment',
|
||||||
"styles": { "block": {} },
|
'Log',
|
||||||
"blocks": [
|
'ScheduledTask',
|
||||||
{
|
'ScheduledTaskSubscriber',
|
||||||
"type": "text",
|
'SendingQueue',
|
||||||
"text": "<a href=\"[link:newsletter_view_in_browser_url]\">View in browser link</a> <a data-post-id=\"10\" href=\"http://example.com\">Post link</a> Hello [subscriber:firstname | default:test] <a href=\"[link:subscription_unsubscribe_url]\">Unsubscribe link</a> <a href=\"[link:subscription_manage_url]\">Manage subscription link</a> <img src=\"http://example.com/image with space.jpg\"> <a href=\"http://example.com/link with space.jpg\">Link with space</a>"
|
'Setting',
|
||||||
}
|
'Subscriber',
|
||||||
]
|
'SubscriberCustomField',
|
||||||
}
|
'SubscriberSegment',
|
||||||
]
|
'SubscriberIP',
|
||||||
}
|
'StatisticsOpens',
|
||||||
]
|
'StatisticsClicks',
|
||||||
}
|
'StatisticsNewsletters',
|
||||||
}'
|
'StatisticsUnsubscribes'
|
||||||
);
|
);
|
||||||
|
$destroy = function($model) {
|
||||||
|
$class = new \ReflectionClass('\MailPoet\Models\\' . $model);
|
||||||
|
$table = $class->getStaticPropertyValue('_table');
|
||||||
|
$db = ORM::getDb();
|
||||||
|
$db->beginTransaction();
|
||||||
|
$db->exec('TRUNCATE ' . $table);
|
||||||
|
$db->commit();
|
||||||
|
};
|
||||||
|
array_map($destroy, $models);
|
||||||
|
|
||||||
Fixtures::add(
|
$cacheDir = '/tmp';
|
||||||
'newsletter_subject_template',
|
if(is_dir(getenv('WP_TEST_CACHE_PATH'))) {
|
||||||
'Newsletter for [subscriber:firstname]'
|
$cacheDir = getenv('WP_TEST_CACHE_PATH');
|
||||||
);
|
}
|
||||||
|
|
||||||
Fixtures::add(
|
$console->writeln('Clearing AspectMock cache...');
|
||||||
'subscriber_template',
|
exec('rm -rf ' . $cacheDir . '/_transformation.cache');
|
||||||
|
|
||||||
|
$console->writeln('Initializing AspectMock library...');
|
||||||
|
$kernel = \AspectMock\Kernel::getInstance();
|
||||||
|
$kernel->init(
|
||||||
array(
|
array(
|
||||||
'first_name' => 'John',
|
'debug' => true,
|
||||||
'last_name' => 'John',
|
'appDir' => __DIR__ . '/../',
|
||||||
'email' => 'john.doe@example.com'
|
'cacheDir' => $cacheDir,
|
||||||
|
'includePaths' => [__DIR__ . '/../lib'],
|
||||||
|
'appDir' => __DIR__ . '/../'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Fixtures::add(
|
// This hook throws an 'Undefined index: SERVER_NAME' error in CLI mode,
|
||||||
'form_body_template',
|
// the action is called in ConflictResolverTest
|
||||||
array(
|
remove_filter('admin_print_styles', 'wp_resource_hints', 1);
|
||||||
array(
|
|
||||||
'type' => 'text',
|
abstract class MailPoetTest extends \Codeception\TestCase\Test {
|
||||||
'name' => 'First name',
|
protected $backupGlobals = true;
|
||||||
'id' => 'first_name',
|
protected $backupGlobalsBlacklist = array(
|
||||||
'unique' => '1',
|
'app',
|
||||||
'static' => '0',
|
'post',
|
||||||
'params' =>
|
'authordata',
|
||||||
array(
|
'currentday',
|
||||||
'label' => 'First name',
|
'currentmonth',
|
||||||
),
|
'page',
|
||||||
'position' => '1',
|
'pages',
|
||||||
),
|
'multipage',
|
||||||
array(
|
'more',
|
||||||
'type' => 'text',
|
'numpages',
|
||||||
'name' => 'Nickname',
|
'is_iphone',
|
||||||
'id' => '4',
|
'is_chrome',
|
||||||
'unique' => '1',
|
'is_safari',
|
||||||
'static' => '0',
|
'is_NS4',
|
||||||
'params' =>
|
'is_opera',
|
||||||
array(
|
'is_macIE',
|
||||||
'label' => 'Nickname',
|
'is_winIE',
|
||||||
),
|
'is_gecko',
|
||||||
'position' => '2',
|
'is_lynx',
|
||||||
),
|
'is_IE',
|
||||||
array(
|
'is_apache',
|
||||||
'type' => 'text',
|
'is_IIS',
|
||||||
'name' => 'Age',
|
'is_iis7',
|
||||||
'id' => '2',
|
'wp_version',
|
||||||
'unique' => '1',
|
'wp_db_version',
|
||||||
'static' => '0',
|
'tinymce_version',
|
||||||
'params' =>
|
'manifest_version',
|
||||||
array(
|
'required_php_version',
|
||||||
'required' => '',
|
'required_mysql_version',
|
||||||
'validate' => 'number',
|
'super_admins',
|
||||||
'label' => 'Age',
|
'wp_query',
|
||||||
),
|
'wp_rewrite',
|
||||||
'position' => '3',
|
'wp',
|
||||||
),
|
'wpdb',
|
||||||
array (
|
'wp_locale',
|
||||||
'type' => 'divider',
|
'wp_admin_bar',
|
||||||
'name' => 'Divider',
|
'wp_roles',
|
||||||
'id' => 'divider',
|
'wp_meta_boxes',
|
||||||
'unique' => '0',
|
'wp_registered_sidebars',
|
||||||
'static' => '0',
|
'wp_registered_widgets',
|
||||||
'params' => '',
|
'wp_registered_widget_controls',
|
||||||
'position' => '4',
|
'wp_registered_widget_updates',
|
||||||
),
|
'pagenow',
|
||||||
array (
|
'post_type',
|
||||||
'type' => 'radio',
|
'allowedposttags',
|
||||||
'name' => '3-way choice',
|
'allowedtags',
|
||||||
'id' => '3',
|
'menu'
|
||||||
'unique' => '1',
|
|
||||||
'static' => '0',
|
|
||||||
'params' =>
|
|
||||||
array (
|
|
||||||
'values' =>
|
|
||||||
array (
|
|
||||||
0 =>
|
|
||||||
array (
|
|
||||||
'value' => '1',
|
|
||||||
),
|
|
||||||
1 =>
|
|
||||||
array (
|
|
||||||
'value' => '2',
|
|
||||||
),
|
|
||||||
2 =>
|
|
||||||
array (
|
|
||||||
'value' => '3',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'required' => '',
|
|
||||||
'label' => '3-way choice',
|
|
||||||
),
|
|
||||||
'position' => '5',
|
|
||||||
),
|
|
||||||
array (
|
|
||||||
'type' => 'html',
|
|
||||||
'name' => 'Custom text or HTML',
|
|
||||||
'id' => 'html',
|
|
||||||
'unique' => '0',
|
|
||||||
'static' => '0',
|
|
||||||
'params' =>
|
|
||||||
array (
|
|
||||||
'text' => 'Subscribe to our newsletter and join [mailpoet_subscribers_count] other subscribers.',
|
|
||||||
),
|
|
||||||
'position' => '6',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'type' => 'text',
|
|
||||||
'name' => 'Email',
|
|
||||||
'id' => 'email',
|
|
||||||
'unique' => '0',
|
|
||||||
'static' => '1',
|
|
||||||
'params' =>
|
|
||||||
array(
|
|
||||||
'label' => 'Email',
|
|
||||||
'required' => 'true',
|
|
||||||
),
|
|
||||||
'position' => '7',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'type' => 'submit',
|
|
||||||
'name' => 'Submit',
|
|
||||||
'id' => 'submit',
|
|
||||||
'unique' => '0',
|
|
||||||
'static' => '1',
|
|
||||||
'params' =>
|
|
||||||
array(
|
|
||||||
'label' => 'Subscribe!',
|
|
||||||
),
|
|
||||||
'position' => '8',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
protected $backupStaticAttributes = false;
|
||||||
|
protected $runTestInSeparateProcess = false;
|
||||||
|
protected $preserveGlobalState = false;
|
||||||
|
protected $inIsolation = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple class mocking dynamic segment filter.
|
* Call protected/private method of a class.
|
||||||
|
*
|
||||||
|
* @param object &$object Instantiated object that we will run method on.
|
||||||
|
* @param string $methodName Method name to call
|
||||||
|
* @param array $parameters Array of parameters to pass into method.
|
||||||
|
*
|
||||||
|
* @return mixed Method return.
|
||||||
*/
|
*/
|
||||||
class DynamicSegmentFilter {
|
public function invokeMethod(&$object, $methodName, array $parameters = array()) {
|
||||||
protected $ids;
|
$reflection = new \ReflectionClass(get_class($object));
|
||||||
|
$method = $reflection->getMethod($methodName);
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
function __construct($ids) {
|
return $method->invokeArgs($object, $parameters);
|
||||||
$this->ids = $ids;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toSql($orm) {
|
include '_fixtures.php';
|
||||||
return $orm->whereIn(Subscriber::$_table . '.id', $this->ids);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
182
tests/integration/_fixtures.php
Normal file
182
tests/integration/_fixtures.php
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
<?php
|
||||||
|
use Codeception\Util\Fixtures;
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
|
$newsletter_body_text =
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'newsletter_body_template',
|
||||||
|
'{
|
||||||
|
"content": {
|
||||||
|
"type": "container",
|
||||||
|
"orientation": "vertical",
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"styles": { "block": {} },
|
||||||
|
"orientation": "horizontal",
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"orientation": "vertical",
|
||||||
|
"styles": { "block": {} },
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": "<a href=\"[link:newsletter_view_in_browser_url]\">View in browser link</a> <a data-post-id=\"10\" href=\"http://example.com\">Post link</a> Hello [subscriber:firstname | default:test] <a href=\"[link:subscription_unsubscribe_url]\">Unsubscribe link</a> <a href=\"[link:subscription_manage_url]\">Manage subscription link</a> <img src=\"http://example.com/image with space.jpg\"> <a href=\"http://example.com/link with space.jpg\">Link with space</a>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'newsletter_subject_template',
|
||||||
|
'Newsletter for [subscriber:firstname]'
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'subscriber_template',
|
||||||
|
array(
|
||||||
|
'first_name' => 'John',
|
||||||
|
'last_name' => 'John',
|
||||||
|
'email' => 'john.doe@example.com'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'form_body_template',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'First name',
|
||||||
|
'id' => 'first_name',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'First name',
|
||||||
|
),
|
||||||
|
'position' => '1',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Nickname',
|
||||||
|
'id' => '4',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Nickname',
|
||||||
|
),
|
||||||
|
'position' => '2',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Age',
|
||||||
|
'id' => '2',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'required' => '',
|
||||||
|
'validate' => 'number',
|
||||||
|
'label' => 'Age',
|
||||||
|
),
|
||||||
|
'position' => '3',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'divider',
|
||||||
|
'name' => 'Divider',
|
||||||
|
'id' => 'divider',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '0',
|
||||||
|
'params' => '',
|
||||||
|
'position' => '4',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'radio',
|
||||||
|
'name' => '3-way choice',
|
||||||
|
'id' => '3',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array (
|
||||||
|
'values' =>
|
||||||
|
array (
|
||||||
|
0 =>
|
||||||
|
array (
|
||||||
|
'value' => '1',
|
||||||
|
),
|
||||||
|
1 =>
|
||||||
|
array (
|
||||||
|
'value' => '2',
|
||||||
|
),
|
||||||
|
2 =>
|
||||||
|
array (
|
||||||
|
'value' => '3',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'required' => '',
|
||||||
|
'label' => '3-way choice',
|
||||||
|
),
|
||||||
|
'position' => '5',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'html',
|
||||||
|
'name' => 'Custom text or HTML',
|
||||||
|
'id' => 'html',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array (
|
||||||
|
'text' => 'Subscribe to our newsletter and join [mailpoet_subscribers_count] other subscribers.',
|
||||||
|
),
|
||||||
|
'position' => '6',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Email',
|
||||||
|
'id' => 'email',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '1',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Email',
|
||||||
|
'required' => 'true',
|
||||||
|
),
|
||||||
|
'position' => '7',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'submit',
|
||||||
|
'name' => 'Submit',
|
||||||
|
'id' => 'submit',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '1',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Subscribe!',
|
||||||
|
),
|
||||||
|
'position' => '8',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple class mocking dynamic segment filter.
|
||||||
|
*/
|
||||||
|
class DynamicSegmentFilter {
|
||||||
|
protected $ids;
|
||||||
|
|
||||||
|
function __construct($ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toSql($orm) {
|
||||||
|
return $orm->whereIn(Subscriber::$_table . '.id', $this->ids);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Suite for unit (internal) tests.
|
# Suite for unit (internal) tests.
|
||||||
|
|
||||||
class_name: UnitTester
|
actor: UnitTester
|
||||||
settings:
|
settings:
|
||||||
bootstrap: _bootstrap.php
|
bootstrap: _bootstrap.php
|
||||||
modules:
|
modules:
|
||||||
|
99
tests/unit/_bootstrap.php
Normal file
99
tests/unit/_bootstrap.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$console = new \Codeception\Lib\Console\Output([]);
|
||||||
|
|
||||||
|
$cacheDir = '/tmp';
|
||||||
|
if(is_dir(getenv('WP_TEST_CACHE_PATH'))) {
|
||||||
|
$cacheDir = getenv('WP_TEST_CACHE_PATH');
|
||||||
|
}
|
||||||
|
|
||||||
|
$console->writeln('Clearing AspectMock cache...');
|
||||||
|
exec('rm -rf ' . $cacheDir . '/_transformation.cache');
|
||||||
|
|
||||||
|
$console->writeln('Initializing AspectMock library...');
|
||||||
|
$kernel = \AspectMock\Kernel::getInstance();
|
||||||
|
$kernel->init(
|
||||||
|
array(
|
||||||
|
'debug' => true,
|
||||||
|
'appDir' => __DIR__ . '/../',
|
||||||
|
'cacheDir' => $cacheDir,
|
||||||
|
'includePaths' => [__DIR__ . '/../lib'],
|
||||||
|
'appDir' => __DIR__ . '/../'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
abstract class MailPoetTest extends \Codeception\TestCase\Test {
|
||||||
|
protected $backupGlobals = true;
|
||||||
|
protected $backupGlobalsBlacklist = array(
|
||||||
|
'app',
|
||||||
|
'post',
|
||||||
|
'authordata',
|
||||||
|
'currentday',
|
||||||
|
'currentmonth',
|
||||||
|
'page',
|
||||||
|
'pages',
|
||||||
|
'multipage',
|
||||||
|
'more',
|
||||||
|
'numpages',
|
||||||
|
'is_iphone',
|
||||||
|
'is_chrome',
|
||||||
|
'is_safari',
|
||||||
|
'is_NS4',
|
||||||
|
'is_opera',
|
||||||
|
'is_macIE',
|
||||||
|
'is_winIE',
|
||||||
|
'is_gecko',
|
||||||
|
'is_lynx',
|
||||||
|
'is_IE',
|
||||||
|
'is_apache',
|
||||||
|
'is_IIS',
|
||||||
|
'is_iis7',
|
||||||
|
'wp_version',
|
||||||
|
'wp_db_version',
|
||||||
|
'tinymce_version',
|
||||||
|
'manifest_version',
|
||||||
|
'required_php_version',
|
||||||
|
'required_mysql_version',
|
||||||
|
'super_admins',
|
||||||
|
'wp_query',
|
||||||
|
'wp_rewrite',
|
||||||
|
'wp',
|
||||||
|
'wpdb',
|
||||||
|
'wp_locale',
|
||||||
|
'wp_admin_bar',
|
||||||
|
'wp_roles',
|
||||||
|
'wp_meta_boxes',
|
||||||
|
'wp_registered_sidebars',
|
||||||
|
'wp_registered_widgets',
|
||||||
|
'wp_registered_widget_controls',
|
||||||
|
'wp_registered_widget_updates',
|
||||||
|
'pagenow',
|
||||||
|
'post_type',
|
||||||
|
'allowedposttags',
|
||||||
|
'allowedtags',
|
||||||
|
'menu'
|
||||||
|
);
|
||||||
|
protected $backupStaticAttributes = false;
|
||||||
|
protected $runTestInSeparateProcess = false;
|
||||||
|
protected $preserveGlobalState = false;
|
||||||
|
protected $inIsolation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call protected/private method of a class.
|
||||||
|
*
|
||||||
|
* @param object &$object Instantiated object that we will run method on.
|
||||||
|
* @param string $methodName Method name to call
|
||||||
|
* @param array $parameters Array of parameters to pass into method.
|
||||||
|
*
|
||||||
|
* @return mixed Method return.
|
||||||
|
*/
|
||||||
|
public function invokeMethod(&$object, $methodName, array $parameters = array()) {
|
||||||
|
$reflection = new \ReflectionClass(get_class($object));
|
||||||
|
$method = $reflection->getMethod($methodName);
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
return $method->invokeArgs($object, $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include '_fixtures.php';
|
182
tests/unit/_fixtures.php
Normal file
182
tests/unit/_fixtures.php
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
<?php
|
||||||
|
use Codeception\Util\Fixtures;
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
|
$newsletter_body_text =
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'newsletter_body_template',
|
||||||
|
'{
|
||||||
|
"content": {
|
||||||
|
"type": "container",
|
||||||
|
"orientation": "vertical",
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"styles": { "block": {} },
|
||||||
|
"orientation": "horizontal",
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"orientation": "vertical",
|
||||||
|
"styles": { "block": {} },
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": "<a href=\"[link:newsletter_view_in_browser_url]\">View in browser link</a> <a data-post-id=\"10\" href=\"http://example.com\">Post link</a> Hello [subscriber:firstname | default:test] <a href=\"[link:subscription_unsubscribe_url]\">Unsubscribe link</a> <a href=\"[link:subscription_manage_url]\">Manage subscription link</a> <img src=\"http://example.com/image with space.jpg\"> <a href=\"http://example.com/link with space.jpg\">Link with space</a>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'newsletter_subject_template',
|
||||||
|
'Newsletter for [subscriber:firstname]'
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'subscriber_template',
|
||||||
|
array(
|
||||||
|
'first_name' => 'John',
|
||||||
|
'last_name' => 'John',
|
||||||
|
'email' => 'john.doe@example.com'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Fixtures::add(
|
||||||
|
'form_body_template',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'First name',
|
||||||
|
'id' => 'first_name',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'First name',
|
||||||
|
),
|
||||||
|
'position' => '1',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Nickname',
|
||||||
|
'id' => '4',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Nickname',
|
||||||
|
),
|
||||||
|
'position' => '2',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Age',
|
||||||
|
'id' => '2',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'required' => '',
|
||||||
|
'validate' => 'number',
|
||||||
|
'label' => 'Age',
|
||||||
|
),
|
||||||
|
'position' => '3',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'divider',
|
||||||
|
'name' => 'Divider',
|
||||||
|
'id' => 'divider',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '0',
|
||||||
|
'params' => '',
|
||||||
|
'position' => '4',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'radio',
|
||||||
|
'name' => '3-way choice',
|
||||||
|
'id' => '3',
|
||||||
|
'unique' => '1',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array (
|
||||||
|
'values' =>
|
||||||
|
array (
|
||||||
|
0 =>
|
||||||
|
array (
|
||||||
|
'value' => '1',
|
||||||
|
),
|
||||||
|
1 =>
|
||||||
|
array (
|
||||||
|
'value' => '2',
|
||||||
|
),
|
||||||
|
2 =>
|
||||||
|
array (
|
||||||
|
'value' => '3',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'required' => '',
|
||||||
|
'label' => '3-way choice',
|
||||||
|
),
|
||||||
|
'position' => '5',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'type' => 'html',
|
||||||
|
'name' => 'Custom text or HTML',
|
||||||
|
'id' => 'html',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '0',
|
||||||
|
'params' =>
|
||||||
|
array (
|
||||||
|
'text' => 'Subscribe to our newsletter and join [mailpoet_subscribers_count] other subscribers.',
|
||||||
|
),
|
||||||
|
'position' => '6',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'name' => 'Email',
|
||||||
|
'id' => 'email',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '1',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Email',
|
||||||
|
'required' => 'true',
|
||||||
|
),
|
||||||
|
'position' => '7',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'submit',
|
||||||
|
'name' => 'Submit',
|
||||||
|
'id' => 'submit',
|
||||||
|
'unique' => '0',
|
||||||
|
'static' => '1',
|
||||||
|
'params' =>
|
||||||
|
array(
|
||||||
|
'label' => 'Subscribe!',
|
||||||
|
),
|
||||||
|
'position' => '8',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple class mocking dynamic segment filter.
|
||||||
|
*/
|
||||||
|
class DynamicSegmentFilter {
|
||||||
|
protected $ids;
|
||||||
|
|
||||||
|
function __construct($ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toSql($orm) {
|
||||||
|
return $orm->whereIn(Subscriber::$_table . '.id', $this->ids);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user