Merge pull request #531 from mailpoet/unit_test_catchup
Unit test update
This commit is contained in:
@ -34,16 +34,13 @@ define(
|
|||||||
// show sending methods
|
// show sending methods
|
||||||
jQuery('.mailpoet_sending_methods').fadeIn();
|
jQuery('.mailpoet_sending_methods').fadeIn();
|
||||||
} else {
|
} else {
|
||||||
// toggle SPF/DKIM (hidden if the sending method is MailPoet)
|
// toggle SPF (hidden if the sending method is MailPoet)
|
||||||
jQuery('#mailpoet_mta_spf')[
|
jQuery('#mailpoet_mta_spf')[
|
||||||
(group === 'mailpoet')
|
(group === 'mailpoet')
|
||||||
? 'hide'
|
? 'hide'
|
||||||
: 'show'
|
: 'show'
|
||||||
]();
|
]();
|
||||||
|
|
||||||
// (HIDDEN FOR BETA)
|
|
||||||
jQuery('#mailpoet_mta_dkim').hide();
|
|
||||||
|
|
||||||
// hide sending methods
|
// hide sending methods
|
||||||
jQuery('.mailpoet_sending_methods').hide();
|
jQuery('.mailpoet_sending_methods').hide();
|
||||||
|
|
||||||
|
83
composer.lock
generated
83
composer.lock
generated
@ -1847,16 +1847,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "5.4.4",
|
"version": "5.4.6",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "02d5b64aa0837a038a5a4faeeefa5ef44bdcb928"
|
"reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/02d5b64aa0837a038a5a4faeeefa5ef44bdcb928",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2f1fc94b77ea6418bd6a06c64a1dac0645fbce59",
|
||||||
"reference": "02d5b64aa0837a038a5a4faeeefa5ef44bdcb928",
|
"reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -1875,7 +1875,7 @@
|
|||||||
"phpunit/phpunit-mock-objects": "^3.2",
|
"phpunit/phpunit-mock-objects": "^3.2",
|
||||||
"sebastian/comparator": "~1.1",
|
"sebastian/comparator": "~1.1",
|
||||||
"sebastian/diff": "~1.2",
|
"sebastian/diff": "~1.2",
|
||||||
"sebastian/environment": "~1.3",
|
"sebastian/environment": "^1.3 || ^2.0",
|
||||||
"sebastian/exporter": "~1.2",
|
"sebastian/exporter": "~1.2",
|
||||||
"sebastian/global-state": "~1.0",
|
"sebastian/global-state": "~1.0",
|
||||||
"sebastian/object-enumerator": "~1.0",
|
"sebastian/object-enumerator": "~1.0",
|
||||||
@ -1921,7 +1921,7 @@
|
|||||||
"testing",
|
"testing",
|
||||||
"xunit"
|
"xunit"
|
||||||
],
|
],
|
||||||
"time": "2016-06-09 09:09:27"
|
"time": "2016-06-16 06:01:15"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit-mock-objects",
|
"name": "phpunit/phpunit-mock-objects",
|
||||||
@ -2295,16 +2295,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/exporter",
|
"name": "sebastian/exporter",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/exporter.git",
|
"url": "https://github.com/sebastianbergmann/exporter.git",
|
||||||
"reference": "7ae5513327cb536431847bcc0c10edba2701064e"
|
"reference": "42c4c2eec485ee3e159ec9884f95b431287edde4"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
|
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4",
|
||||||
"reference": "7ae5513327cb536431847bcc0c10edba2701064e",
|
"reference": "42c4c2eec485ee3e159ec9884f95b431287edde4",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -2312,12 +2312,13 @@
|
|||||||
"sebastian/recursion-context": "~1.0"
|
"sebastian/recursion-context": "~1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"ext-mbstring": "*",
|
||||||
"phpunit/phpunit": "~4.4"
|
"phpunit/phpunit": "~4.4"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "1.2.x-dev"
|
"dev-master": "1.3.x-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -2357,7 +2358,7 @@
|
|||||||
"export",
|
"export",
|
||||||
"exporter"
|
"exporter"
|
||||||
],
|
],
|
||||||
"time": "2015-06-21 07:55:53"
|
"time": "2016-06-17 09:04:28"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/global-state",
|
"name": "sebastian/global-state",
|
||||||
@ -2596,7 +2597,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/browser-kit",
|
"name": "symfony/browser-kit",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/browser-kit.git",
|
"url": "https://github.com/symfony/browser-kit.git",
|
||||||
@ -2706,16 +2707,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/console.git",
|
"url": "https://github.com/symfony/console.git",
|
||||||
"reference": "f62db5b8afec27073a4609b8c84b1f9936652259"
|
"reference": "64a4d43b045f07055bb197650159769604cb2a92"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/console/zipball/f62db5b8afec27073a4609b8c84b1f9936652259",
|
"url": "https://api.github.com/repos/symfony/console/zipball/64a4d43b045f07055bb197650159769604cb2a92",
|
||||||
"reference": "f62db5b8afec27073a4609b8c84b1f9936652259",
|
"reference": "64a4d43b045f07055bb197650159769604cb2a92",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -2762,20 +2763,20 @@
|
|||||||
],
|
],
|
||||||
"description": "Symfony Console Component",
|
"description": "Symfony Console Component",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"time": "2016-05-30 06:58:39"
|
"time": "2016-06-14 11:18:07"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/css-selector",
|
"name": "symfony/css-selector",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/css-selector.git",
|
"url": "https://github.com/symfony/css-selector.git",
|
||||||
"reference": "e17f386efef7258ac671c24e727673abd086b0cf"
|
"reference": "c526d7b3cb4fe1673c6a34e13be2ff63f519df99"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/css-selector/zipball/e17f386efef7258ac671c24e727673abd086b0cf",
|
"url": "https://api.github.com/repos/symfony/css-selector/zipball/c526d7b3cb4fe1673c6a34e13be2ff63f519df99",
|
||||||
"reference": "e17f386efef7258ac671c24e727673abd086b0cf",
|
"reference": "c526d7b3cb4fe1673c6a34e13be2ff63f519df99",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -2815,11 +2816,11 @@
|
|||||||
],
|
],
|
||||||
"description": "Symfony CssSelector Component",
|
"description": "Symfony CssSelector Component",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"time": "2016-03-04 07:56:56"
|
"time": "2016-06-06 11:42:41"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/dom-crawler",
|
"name": "symfony/dom-crawler",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/dom-crawler.git",
|
"url": "https://github.com/symfony/dom-crawler.git",
|
||||||
@ -2984,7 +2985,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/finder",
|
"name": "symfony/finder",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/finder.git",
|
"url": "https://github.com/symfony/finder.git",
|
||||||
@ -3294,16 +3295,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/process",
|
"name": "symfony/process",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/process.git",
|
"url": "https://github.com/symfony/process.git",
|
||||||
"reference": "1574f3451b40fa9bbae518ef71d19a56f409cac0"
|
"reference": "6350e63ed9c232da50e00f00a7e0330f066387a2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/process/zipball/1574f3451b40fa9bbae518ef71d19a56f409cac0",
|
"url": "https://api.github.com/repos/symfony/process/zipball/6350e63ed9c232da50e00f00a7e0330f066387a2",
|
||||||
"reference": "1574f3451b40fa9bbae518ef71d19a56f409cac0",
|
"reference": "6350e63ed9c232da50e00f00a7e0330f066387a2",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3339,7 +3340,7 @@
|
|||||||
],
|
],
|
||||||
"description": "Symfony Process Component",
|
"description": "Symfony Process Component",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"time": "2016-04-12 19:11:33"
|
"time": "2016-06-06 11:42:41"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/property-access",
|
"name": "symfony/property-access",
|
||||||
@ -3559,16 +3560,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/yaml",
|
"name": "symfony/yaml",
|
||||||
"version": "v3.1.0",
|
"version": "v3.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/yaml.git",
|
"url": "https://github.com/symfony/yaml.git",
|
||||||
"reference": "eca51b7b65eb9be6af88ad7cc91685f1556f5c9a"
|
"reference": "c5a7e7fc273c758b92b85dcb9c46149ccda89623"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/eca51b7b65eb9be6af88ad7cc91685f1556f5c9a",
|
"url": "https://api.github.com/repos/symfony/yaml/zipball/c5a7e7fc273c758b92b85dcb9c46149ccda89623",
|
||||||
"reference": "eca51b7b65eb9be6af88ad7cc91685f1556f5c9a",
|
"reference": "c5a7e7fc273c758b92b85dcb9c46149ccda89623",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3604,7 +3605,7 @@
|
|||||||
],
|
],
|
||||||
"description": "Symfony Yaml Component",
|
"description": "Symfony Yaml Component",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"time": "2016-05-26 21:46:24"
|
"time": "2016-06-14 11:18:07"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "twig/extensions",
|
"name": "twig/extensions",
|
||||||
@ -3709,16 +3710,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "vlucas/phpdotenv",
|
"name": "vlucas/phpdotenv",
|
||||||
"version": "v2.2.1",
|
"version": "v2.3.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/vlucas/phpdotenv.git",
|
"url": "https://github.com/vlucas/phpdotenv.git",
|
||||||
"reference": "63f37b9395e8041cd4313129c08ece896d06ca8e"
|
"reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/63f37b9395e8041cd4313129c08ece896d06ca8e",
|
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/9ca5644c536654e9509b9d257f53c58630eb2a6a",
|
||||||
"reference": "63f37b9395e8041cd4313129c08ece896d06ca8e",
|
"reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3730,7 +3731,7 @@
|
|||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.2-dev"
|
"dev-master": "2.3-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -3755,7 +3756,7 @@
|
|||||||
"env",
|
"env",
|
||||||
"environment"
|
"environment"
|
||||||
],
|
],
|
||||||
"time": "2016-04-15 10:48:49"
|
"time": "2016-06-14 14:14:52"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "webmozart/assert",
|
"name": "webmozart/assert",
|
||||||
|
@ -12,7 +12,6 @@ use MailPoet\Settings\Charsets;
|
|||||||
use MailPoet\Settings\Hosts;
|
use MailPoet\Settings\Hosts;
|
||||||
use MailPoet\Settings\Pages;
|
use MailPoet\Settings\Pages;
|
||||||
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||||
use MailPoet\Util\DKIM;
|
|
||||||
use MailPoet\Util\Permissions;
|
use MailPoet\Util\Permissions;
|
||||||
use MailPoet\Listing;
|
use MailPoet\Listing;
|
||||||
use MailPoet\WP\DateTime;
|
use MailPoet\WP\DateTime;
|
||||||
@ -294,21 +293,6 @@ class Menu {
|
|||||||
$settings = Setting::getAll();
|
$settings = Setting::getAll();
|
||||||
$flags = $this->_getFlags();
|
$flags = $this->_getFlags();
|
||||||
|
|
||||||
// dkim: check if public/private keys have been generated
|
|
||||||
if(
|
|
||||||
empty($settings['dkim'])
|
|
||||||
or empty($settings['dkim']['public_key'])
|
|
||||||
or empty($settings['dkim']['private_key'])
|
|
||||||
) {
|
|
||||||
// generate public/private keys
|
|
||||||
$keys = DKIM::generateKeys();
|
|
||||||
$settings['dkim'] = array(
|
|
||||||
'public_key' => $keys['public'],
|
|
||||||
'private_key' => $keys['private'],
|
|
||||||
'domain' => preg_replace('/^www\./', '', $_SERVER['SERVER_NAME'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'segments' => Segment::getPublic()->findArray(),
|
'segments' => Segment::getPublic()->findArray(),
|
||||||
|
@ -25,7 +25,7 @@ class BulkAction {
|
|||||||
$bulk_action_method = 'bulk'.ucfirst($this->action);
|
$bulk_action_method = 'bulk'.ucfirst($this->action);
|
||||||
|
|
||||||
if(!method_exists($this->model_class, $bulk_action_method)) {
|
if(!method_exists($this->model_class, $bulk_action_method)) {
|
||||||
throw new Exception(
|
throw new \Exception(
|
||||||
$this->model_class. ' has not method "'.$bulk_action_method.'"'
|
$this->model_class. ' has not method "'.$bulk_action_method.'"'
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
@ -87,16 +87,6 @@ class Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectionIds() {
|
|
||||||
$models = $this->getSelection()
|
|
||||||
->select('id')
|
|
||||||
->findArray();
|
|
||||||
|
|
||||||
return array_map(function($model) {
|
|
||||||
return (int)$model['id'];
|
|
||||||
}, $models);
|
|
||||||
}
|
|
||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
// get groups
|
// get groups
|
||||||
$groups = array();
|
$groups = array();
|
||||||
|
@ -59,8 +59,6 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
default:
|
default:
|
||||||
$this->setError($e->getMessage());
|
$this->setError($e->getMessage());
|
||||||
}
|
}
|
||||||
} catch(\Exception $e) {
|
|
||||||
$this->setError($e->getMessage());
|
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MailPoet\Util;
|
|
||||||
use \phpseclib\Crypt\RSA;
|
|
||||||
|
|
||||||
class DKIM {
|
|
||||||
static function generateKeys() {
|
|
||||||
try {
|
|
||||||
$rsa = new RSA();
|
|
||||||
$rsa_keys = $rsa->createKey();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'public' => self::trimKey($rsa_keys['publickey']),
|
|
||||||
'private' => self::trimKey($rsa_keys['privatekey'])
|
|
||||||
);
|
|
||||||
} catch(\Exception $e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function trimKey($key) {
|
|
||||||
$lines = explode("\n", trim($key));
|
|
||||||
// remove first line
|
|
||||||
array_shift($lines);
|
|
||||||
// remove last line
|
|
||||||
array_pop($lines);
|
|
||||||
return join('', $lines);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,11 +11,9 @@ class Security {
|
|||||||
static function generateRandomString($length = 5) {
|
static function generateRandomString($length = 5) {
|
||||||
// non-cryptographically strong random generator
|
// non-cryptographically strong random generator
|
||||||
return substr(
|
return substr(
|
||||||
md5(
|
md5(uniqid(mt_rand(), true)),
|
||||||
uniqid(
|
|
||||||
mt_rand(), true)
|
|
||||||
),
|
|
||||||
0,
|
0,
|
||||||
(!is_int($length) || $length <= 5 || $length >= 32) ? 5 : $length);
|
min(max(5, (int)$length), 32)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,9 +2,6 @@
|
|||||||
namespace MailPoet\Util;
|
namespace MailPoet\Util;
|
||||||
|
|
||||||
class Url {
|
class Url {
|
||||||
function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getCurrentUrl() {
|
static function getCurrentUrl() {
|
||||||
return home_url(add_query_arg(null, null));
|
return home_url(add_query_arg(null, null));
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MailPoet\WP;
|
|
||||||
|
|
||||||
class Option {
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
$this->prefix = 'mailpoet_';
|
|
||||||
}
|
|
||||||
|
|
||||||
function get($name) {
|
|
||||||
return get_option($this->prefix . $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function set($name, $value) {
|
|
||||||
return update_option($this->prefix .$name, $value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,6 +34,19 @@ class CustomFieldTest extends MailPoetTest {
|
|||||||
expect($this->custom_field->getErrors())->false();
|
expect($this->custom_field->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanBeUpdated() {
|
||||||
|
expect($this->custom_field->name)->equals($this->data['name']);
|
||||||
|
|
||||||
|
$updated_custom_field = CustomField::createOrUpdate(array(
|
||||||
|
'id' => $this->custom_field->id,
|
||||||
|
'name' => 'Country'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($updated_custom_field->getErrors())->false();
|
||||||
|
expect($updated_custom_field->name)->equals('Country');
|
||||||
|
expect($updated_custom_field->id)->equals($this->custom_field->id);
|
||||||
|
}
|
||||||
|
|
||||||
function testItHasAName() {
|
function testItHasAName() {
|
||||||
expect($this->custom_field->name)->equals($this->data['name']);
|
expect($this->custom_field->name)->equals($this->data['name']);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,15 @@ class SettingTest extends MailPoetTest {
|
|||||||
expect($default_settings['signup_confirmation']['enabled'])->true();
|
expect($default_settings['signup_confirmation']['enabled'])->true();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanLoadDefaults() {
|
||||||
|
Setting::$defaults = null;
|
||||||
|
expect(Setting::$defaults)->null();
|
||||||
|
|
||||||
|
$default_settings = Setting::getDefaults();
|
||||||
|
expect(Setting::$defaults)->notEmpty();
|
||||||
|
expect($default_settings['signup_confirmation']['enabled'])->true();
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanGetAllSettingsIncludingDefaults() {
|
function testItCanGetAllSettingsIncludingDefaults() {
|
||||||
Setting::setValue('key_1', 'value_1');
|
Setting::setValue('key_1', 'value_1');
|
||||||
Setting::setValue('key_2', 'value_2');
|
Setting::setValue('key_2', 'value_2');
|
||||||
|
@ -28,6 +28,14 @@ class StatisticsFormsTest extends MailPoetTest {
|
|||||||
expect(StatisticsForms::count())->equals(3);
|
expect(StatisticsForms::count())->equals(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCannotRecordStatsWithoutFormOrSubscriber() {
|
||||||
|
$record = StatisticsForms::record($form_id = null, $subscriber_id = 1);
|
||||||
|
expect($record)->false();
|
||||||
|
|
||||||
|
$record = StatisticsForms::record($form_id = 1, $subscriber_id = null);
|
||||||
|
expect($record)->false();
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
StatisticsForms::deleteMany();
|
StatisticsForms::deleteMany();
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,27 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
->equals($this->data['email']);
|
->equals($this->data['email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItShouldSetErrors() {
|
||||||
|
// model validation
|
||||||
|
$subscriber = Subscriber::create();
|
||||||
|
$subscriber->hydrate(array(
|
||||||
|
'email' => 'invalid_email'
|
||||||
|
));
|
||||||
|
$subscriber->save();
|
||||||
|
$errors = $subscriber->getErrors();
|
||||||
|
expect($errors)->contains("Your email address is invalid.");
|
||||||
|
|
||||||
|
// pdo error
|
||||||
|
$subscriber = Subscriber::create();
|
||||||
|
$subscriber->hydrate(array(
|
||||||
|
'email' => 'test@test.com',
|
||||||
|
'invalid_column' => true
|
||||||
|
));
|
||||||
|
$subscriber->save();
|
||||||
|
$errors = $subscriber->getErrors();
|
||||||
|
expect($errors[0])->contains("Unknown column 'invalid_column' in 'field list'");
|
||||||
|
}
|
||||||
|
|
||||||
function emailMustBeUnique() {
|
function emailMustBeUnique() {
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->hydrate($this->data);
|
$conflict_subscriber->hydrate($this->data);
|
||||||
@ -124,7 +145,7 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
function testItCanHaveCustomFields() {
|
function testItCanHaveCustomFields() {
|
||||||
$custom_field = CustomField::createOrUpdate(array(
|
$custom_field = CustomField::createOrUpdate(array(
|
||||||
'name' => 'DOB',
|
'name' => 'DOB',
|
||||||
'type' => 'date',
|
'type' => 'date'
|
||||||
));
|
));
|
||||||
|
|
||||||
$association = SubscriberCustomField::create();
|
$association = SubscriberCustomField::create();
|
||||||
@ -138,6 +159,63 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
expect($subscriber->DOB)->equals($association->value);
|
expect($subscriber->DOB)->equals($association->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanCreateSubscriberWithCustomFields() {
|
||||||
|
$custom_field = CustomField::createOrUpdate(array(
|
||||||
|
'name' => 'City',
|
||||||
|
'type' => 'text'
|
||||||
|
));
|
||||||
|
|
||||||
|
$custom_field_2 = CustomField::createOrUpdate(array(
|
||||||
|
'name' => 'Age',
|
||||||
|
'type' => 'text'
|
||||||
|
));
|
||||||
|
|
||||||
|
$subscriber_with_custom_field = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'user.with.cf@mailpoet.com',
|
||||||
|
'cf_'.$custom_field->id => 'Paris',
|
||||||
|
'cf_'.$custom_field_2->id => array(12, 23, 34)
|
||||||
|
));
|
||||||
|
|
||||||
|
$subscriber = Subscriber::findOne($subscriber_with_custom_field->id)
|
||||||
|
->withCustomFields();
|
||||||
|
|
||||||
|
expect($subscriber->id)->equals($subscriber_with_custom_field->id);
|
||||||
|
expect($subscriber->email)->equals('user.with.cf@mailpoet.com');
|
||||||
|
expect($subscriber->{'cf_'.$custom_field->id})->equals('Paris');
|
||||||
|
// array values are not supported so it should have assigned the first value
|
||||||
|
expect($subscriber->{'cf_'.$custom_field_2->id})->equals(12);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItShouldUnsubscribeFromAllSegments() {
|
||||||
|
$segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||||
|
$segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
|
||||||
|
$subscriber = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'jean.louis@mailpoet.com',
|
||||||
|
'status' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
|
'segments' => array(
|
||||||
|
$segment_1->id,
|
||||||
|
$segment_2->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$subscriber = Subscriber::findOne($subscriber->id);
|
||||||
|
|
||||||
|
$subscribed_segments = $subscriber->segments()->findArray();
|
||||||
|
expect($subscribed_segments)->count(2);
|
||||||
|
expect($subscribed_segments[0]['name'] = 'Segment 1');
|
||||||
|
expect($subscribed_segments[1]['name'] = 'Segment 2');
|
||||||
|
|
||||||
|
// update subscriber status
|
||||||
|
$unsubscribed_subscriber = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'jean.louis@mailpoet.com',
|
||||||
|
'status' => Subscriber::STATUS_UNSUBSCRIBED
|
||||||
|
));
|
||||||
|
|
||||||
|
$subscribed_segments = $subscriber->segments()->findArray();
|
||||||
|
expect($subscribed_segments)->count(0);
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanCreateOrUpdate() {
|
function testItCanCreateOrUpdate() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'email' => 'john.doe@mailpoet.com',
|
'email' => 'john.doe@mailpoet.com',
|
||||||
@ -313,7 +391,7 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
expect($subscribed_subscribers_in_segment)->count(2);
|
expect($subscribed_subscribers_in_segment)->count(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCannotTrashAWPUser() {
|
function testItCannotTrashWpUser() {
|
||||||
$wp_subscriber = Subscriber::createOrUpdate(array(
|
$wp_subscriber = Subscriber::createOrUpdate(array(
|
||||||
'email' => 'some.wp.user@mailpoet.com',
|
'email' => 'some.wp.user@mailpoet.com',
|
||||||
'first_name' => 'Some',
|
'first_name' => 'Some',
|
||||||
@ -327,7 +405,7 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
expect($subscriber->deleted_at)->equals(null);
|
expect($subscriber->deleted_at)->equals(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCannotDeleteAWPUser() {
|
function testItCannotDeleteWpUser() {
|
||||||
$wp_subscriber = Subscriber::createOrUpdate(array(
|
$wp_subscriber = Subscriber::createOrUpdate(array(
|
||||||
'email' => 'some.wp.user@mailpoet.com',
|
'email' => 'some.wp.user@mailpoet.com',
|
||||||
'first_name' => 'Some',
|
'first_name' => 'Some',
|
||||||
|
@ -9,12 +9,12 @@ class NewslettersTest extends MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
$this->newsletter = Newsletter::createOrUpdate(array(
|
$this->newsletter = Newsletter::createOrUpdate(array(
|
||||||
'subject' => 'My Standard Newsletter',
|
'subject' => 'My Standard Newsletter',
|
||||||
'type' => 'standard'
|
'type' => Newsletter::TYPE_STANDARD
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->post_notification = Newsletter::createOrUpdate(array(
|
$this->post_notification = Newsletter::createOrUpdate(array(
|
||||||
'subject' => 'My Post Notification',
|
'subject' => 'My Post Notification',
|
||||||
'type' => 'notification'
|
'type' => Newsletter::TYPE_NOTIFICATION
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class NewslettersTest extends MailPoetTest {
|
|||||||
function testItCanSaveANewNewsletter() {
|
function testItCanSaveANewNewsletter() {
|
||||||
$valid_data = array(
|
$valid_data = array(
|
||||||
'subject' => 'My First Newsletter',
|
'subject' => 'My First Newsletter',
|
||||||
'type' => 'standard'
|
'type' => Newsletter::TYPE_STANDARD
|
||||||
);
|
);
|
||||||
|
|
||||||
$router = new Newsletters();
|
$router = new Newsletters();
|
||||||
@ -98,26 +98,26 @@ class NewslettersTest extends MailPoetTest {
|
|||||||
$router = new Newsletters();
|
$router = new Newsletters();
|
||||||
$response = $router->duplicate($this->newsletter->id());
|
$response = $router->duplicate($this->newsletter->id());
|
||||||
expect($response['subject'])->equals('Copy of My Standard Newsletter');
|
expect($response['subject'])->equals('Copy of My Standard Newsletter');
|
||||||
expect($response['type'])->equals('standard');
|
expect($response['type'])->equals(Newsletter::TYPE_STANDARD);
|
||||||
expect($response['body'])->equals($this->newsletter->body);
|
expect($response['body'])->equals($this->newsletter->body);
|
||||||
|
|
||||||
$response = $router->duplicate($this->post_notification->id());
|
$response = $router->duplicate($this->post_notification->id());
|
||||||
expect($response['subject'])->equals('Copy of My Post Notification');
|
expect($response['subject'])->equals('Copy of My Post Notification');
|
||||||
expect($response['type'])->equals('notification');
|
expect($response['type'])->equals(Newsletter::TYPE_NOTIFICATION);
|
||||||
expect($response['body'])->equals($this->post_notification->body);
|
expect($response['body'])->equals($this->post_notification->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanCreateANewsletter() {
|
function testItCanCreateANewsletter() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'subject' => 'My New Newsletter',
|
'subject' => 'My New Newsletter',
|
||||||
'type' => 'standard'
|
'type' => Newsletter::TYPE_STANDARD
|
||||||
);
|
);
|
||||||
$router = new Newsletters();
|
$router = new Newsletters();
|
||||||
$response = $router->create($data);
|
$response = $router->create($data);
|
||||||
expect($response['result'])->true();
|
expect($response['result'])->true();
|
||||||
expect($response['newsletter']['id'] > 0)->true();
|
expect($response['newsletter']['id'] > 0)->true();
|
||||||
expect($response['newsletter']['subject'])->equals('My New Newsletter');
|
expect($response['newsletter']['subject'])->equals('My New Newsletter');
|
||||||
expect($response['newsletter']['type'])->equals('standard');
|
expect($response['newsletter']['type'])->equals(Newsletter::TYPE_STANDARD);
|
||||||
expect($response['newsletter']['body'])->equals(array());
|
expect($response['newsletter']['body'])->equals(array());
|
||||||
expect($response)->hasntKey('errors');
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
@ -176,6 +176,110 @@ class NewslettersTest extends MailPoetTest {
|
|||||||
->equals($segment_2->id);
|
->equals($segment_2->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanFilterListing() {
|
||||||
|
// create 2 segments
|
||||||
|
$segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||||
|
$segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
|
||||||
|
// link standard newsletter to the 2 segments
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $this->newsletter->id(),
|
||||||
|
'segment_id' => $segment_1->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $this->newsletter->id(),
|
||||||
|
'segment_id' => $segment_2->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
// link post notification to the 2nd segment
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $this->post_notification->id(),
|
||||||
|
'segment_id' => $segment_2->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
|
||||||
|
// filter by 1st segment
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'filter' => array(
|
||||||
|
'segment' => $segment_1->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// we should only get the standard newsletter
|
||||||
|
expect($response['count'])->equals(1);
|
||||||
|
expect($response['items'][0]['subject'])->equals($this->newsletter->subject);
|
||||||
|
|
||||||
|
// filter by 2nd segment
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'filter' => array(
|
||||||
|
'segment' => $segment_2->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// we should have the 2 newsletters
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanLimitListing() {
|
||||||
|
$router = new Newsletters();
|
||||||
|
// get 1st page (limit items per page to 1)
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'limit' => 1,
|
||||||
|
'sort_by' => 'subject',
|
||||||
|
'sort_order' => 'asc'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'])->count(1);
|
||||||
|
expect($response['items'][0]['subject'])->equals(
|
||||||
|
$this->post_notification->subject
|
||||||
|
);
|
||||||
|
|
||||||
|
// get 1st page (limit items per page to 1)
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'limit' => 1,
|
||||||
|
'offset' => 1,
|
||||||
|
'sort_by' => 'subject',
|
||||||
|
'sort_order' => 'asc'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'])->count(1);
|
||||||
|
expect($response['items'][0]['subject'])->equals(
|
||||||
|
$this->newsletter->subject
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanBulkDeleteSelectionOfNewsletters() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'To be deleted',
|
||||||
|
'type' => Newsletter::TYPE_STANDARD
|
||||||
|
));
|
||||||
|
|
||||||
|
$selection_ids = array(
|
||||||
|
$newsletter->id,
|
||||||
|
$this->newsletter->id
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->bulkAction(array(
|
||||||
|
'listing' => array(
|
||||||
|
'selection' => $selection_ids
|
||||||
|
),
|
||||||
|
'action' => 'delete'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response)->equals(count($selection_ids));
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanBulkDeleteNewsletters() {
|
function testItCanBulkDeleteNewsletters() {
|
||||||
expect(Newsletter::count())->equals(2);
|
expect(Newsletter::count())->equals(2);
|
||||||
|
|
||||||
|
@ -10,14 +10,16 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
|
||||||
$this->subscriber_1 = Subscriber::createOrUpdate(array(
|
$this->subscriber_1 = Subscriber::createOrUpdate(array(
|
||||||
'email' => 'john.doe@mailpoet.com',
|
'email' => 'john@mailpoet.com',
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Doe'
|
'last_name' => 'Doe',
|
||||||
|
'status' => Subscriber::STATUS_UNCONFIRMED
|
||||||
));
|
));
|
||||||
$this->subscriber_2 = Subscriber::createOrUpdate(array(
|
$this->subscriber_2 = Subscriber::createOrUpdate(array(
|
||||||
'email' => 'jane.doe@mailpoet.com',
|
'email' => 'jane@mailpoet.com',
|
||||||
'first_name' => 'Jane',
|
'first_name' => 'Jane',
|
||||||
'last_name' => 'Doe',
|
'last_name' => 'Doe',
|
||||||
|
'status' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
'segments' => array(
|
'segments' => array(
|
||||||
$this->segment_1->id(),
|
$this->segment_1->id(),
|
||||||
$this->segment_2->id()
|
$this->segment_2->id()
|
||||||
@ -43,8 +45,8 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
|
|
||||||
function testItCanSaveANewSubscriber() {
|
function testItCanSaveANewSubscriber() {
|
||||||
$valid_data = array(
|
$valid_data = array(
|
||||||
'email' => 'john.doe@mailpoet.com',
|
'email' => 'raul.doe@mailpoet.com',
|
||||||
'first_name' => 'John',
|
'first_name' => 'Raul',
|
||||||
'last_name' => 'Doe',
|
'last_name' => 'Doe',
|
||||||
'segments' => array(
|
'segments' => array(
|
||||||
$this->segment_1->id(),
|
$this->segment_1->id(),
|
||||||
@ -57,7 +59,7 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
expect($response['result'])->true();
|
expect($response['result'])->true();
|
||||||
expect($response)->hasntKey('errors');
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
$subscriber = Subscriber::where('email', 'john.doe@mailpoet.com')->findOne();
|
$subscriber = Subscriber::where('email', 'raul.doe@mailpoet.com')->findOne();
|
||||||
$subscriber_segments = $subscriber->segments()->findMany();
|
$subscriber_segments = $subscriber->segments()->findMany();
|
||||||
expect($subscriber_segments)->count(2);
|
expect($subscriber_segments)->count(2);
|
||||||
expect($subscriber_segments[0]->name)->equals($this->segment_1->name);
|
expect($subscriber_segments[0]->name)->equals($this->segment_1->name);
|
||||||
@ -68,9 +70,7 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
expect($response['errors'][0])->equals('Please enter your email address.');
|
expect($response['errors'][0])->equals('Please enter your email address.');
|
||||||
|
|
||||||
$invalid_data = array(
|
$invalid_data = array(
|
||||||
'email' => 'john.doe@invalid',
|
'email' => 'john.doe@invalid'
|
||||||
'first_name' => 'John',
|
|
||||||
'last_name' => 'Doe'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $router->save($invalid_data);
|
$response = $router->save($invalid_data);
|
||||||
@ -89,7 +89,7 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
expect($response['result'])->true();
|
expect($response['result'])->true();
|
||||||
|
|
||||||
$updated_subscriber = Subscriber::findOne($this->subscriber_2->id());
|
$updated_subscriber = Subscriber::findOne($this->subscriber_2->id());
|
||||||
expect($updated_subscriber->email)->equals('jane.doe@mailpoet.com');
|
expect($updated_subscriber->email)->equals($this->subscriber_2->email);
|
||||||
expect($updated_subscriber->first_name)->equals('Super Jane');
|
expect($updated_subscriber->first_name)->equals('Super Jane');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +122,180 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
expect(Subscriber::findOne($this->subscriber_1->id()))->false();
|
expect(Subscriber::findOne($this->subscriber_1->id()))->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanFilterListing() {
|
||||||
|
$router = new Subscribers();
|
||||||
|
|
||||||
|
// filter by non existing segment
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'filter' => array(
|
||||||
|
'segment' => '### invalid_segment_id ###'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// it should return all subscribers
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
|
||||||
|
// filter by 1st segment
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'filter' => array(
|
||||||
|
'segment' => $this->segment_1->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(1);
|
||||||
|
expect($response['items'][0]['email'])->equals($this->subscriber_2->email);
|
||||||
|
|
||||||
|
// filter by 2nd segment
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'filter' => array(
|
||||||
|
'segment' => $this->segment_2->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(1);
|
||||||
|
expect($response['items'][0]['email'])->equals($this->subscriber_2->email);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSearchListing() {
|
||||||
|
$new_subscriber = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'search.me@find.me',
|
||||||
|
'first_name' => 'Billy Bob',
|
||||||
|
'last_name' => 'Thornton'
|
||||||
|
));
|
||||||
|
|
||||||
|
$router = new Subscribers();
|
||||||
|
|
||||||
|
// empty search returns everything
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'search' => ''
|
||||||
|
));
|
||||||
|
expect($response['count'])->equals(3);
|
||||||
|
|
||||||
|
// search by email
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'search' => '.me'
|
||||||
|
));
|
||||||
|
expect($response['count'])->equals(1);
|
||||||
|
expect($response['items'][0]['email'])->equals($new_subscriber->email);
|
||||||
|
|
||||||
|
// search by last name
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'search' => 'doe'
|
||||||
|
));
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'][0]['email'])->equals($this->subscriber_1->email);
|
||||||
|
expect($response['items'][1]['email'])->equals($this->subscriber_2->email);
|
||||||
|
|
||||||
|
// search by first name
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'search' => 'billy'
|
||||||
|
));
|
||||||
|
expect($response['count'])->equals(1);
|
||||||
|
expect($response['items'][0]['email'])->equals($new_subscriber->email);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanGroupListing() {
|
||||||
|
$router = new Subscribers();
|
||||||
|
|
||||||
|
$subscribed_group = $router->listing(array(
|
||||||
|
'group' => Subscriber::STATUS_SUBSCRIBED
|
||||||
|
));
|
||||||
|
expect($subscribed_group['count'])->equals(1);
|
||||||
|
expect($subscribed_group['items'][0]['email'])->equals(
|
||||||
|
$this->subscriber_2->email
|
||||||
|
);
|
||||||
|
|
||||||
|
$unsubscribed_group = $router->listing(array(
|
||||||
|
'group' => Subscriber::STATUS_UNSUBSCRIBED
|
||||||
|
));
|
||||||
|
expect($unsubscribed_group['count'])->equals(0);
|
||||||
|
|
||||||
|
$unconfirmed_group = $router->listing(array(
|
||||||
|
'group' => Subscriber::STATUS_UNCONFIRMED
|
||||||
|
));
|
||||||
|
expect($unconfirmed_group['count'])->equals(1);
|
||||||
|
expect($unconfirmed_group['items'][0]['email'])->equals(
|
||||||
|
$this->subscriber_1->email
|
||||||
|
);
|
||||||
|
|
||||||
|
$trashed_group = $router->listing(array(
|
||||||
|
'group' => 'trash'
|
||||||
|
));
|
||||||
|
expect($trashed_group['count'])->equals(0);
|
||||||
|
|
||||||
|
// trash 1st subscriber
|
||||||
|
$this->subscriber_1->trash();
|
||||||
|
|
||||||
|
$trashed_group = $router->listing(array(
|
||||||
|
'group' => 'trash'
|
||||||
|
));
|
||||||
|
expect($trashed_group['count'])->equals(1);
|
||||||
|
expect($trashed_group['items'][0]['email'])->equals(
|
||||||
|
$this->subscriber_1->email
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSortAndLimitListing() {
|
||||||
|
$router = new Subscribers();
|
||||||
|
// get 1st page (limit items per page to 1)
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'limit' => 1,
|
||||||
|
'sort_by' => 'first_name',
|
||||||
|
'sort_order' => 'asc'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'])->count(1);
|
||||||
|
expect($response['items'][0]['email'])->equals(
|
||||||
|
$this->subscriber_2->email
|
||||||
|
);
|
||||||
|
|
||||||
|
// get 1st page (limit items per page to 1)
|
||||||
|
$response = $router->listing(array(
|
||||||
|
'limit' => 1,
|
||||||
|
'offset' => 1,
|
||||||
|
'sort_by' => 'first_name',
|
||||||
|
'sort_order' => 'asc'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'])->count(1);
|
||||||
|
expect($response['items'][0]['email'])->equals(
|
||||||
|
$this->subscriber_1->email
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanBulkDeleteSelectionOfSubscribers() {
|
||||||
|
$deletable_subscriber = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'to.be.removed@mailpoet.com'
|
||||||
|
));
|
||||||
|
|
||||||
|
$selection_ids = array(
|
||||||
|
$this->subscriber_1->id,
|
||||||
|
$deletable_subscriber->id
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Subscribers();
|
||||||
|
$response = $router->bulkAction(array(
|
||||||
|
'listing' => array(
|
||||||
|
'selection' => $selection_ids
|
||||||
|
),
|
||||||
|
'action' => 'delete'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($response)->equals(count($selection_ids));
|
||||||
|
|
||||||
|
$is_subscriber_1_deleted = (
|
||||||
|
Subscriber::findOne($this->subscriber_1->id) === false
|
||||||
|
);
|
||||||
|
$is_deletable_subscriber_deleted = (
|
||||||
|
Subscriber::findOne($deletable_subscriber->id) === false
|
||||||
|
);
|
||||||
|
|
||||||
|
expect($is_subscriber_1_deleted)->true();
|
||||||
|
expect($is_deletable_subscriber_deleted)->true();
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanBulkDeleteSubscribers() {
|
function testItCanBulkDeleteSubscribers() {
|
||||||
expect(Subscriber::count())->equals(2);
|
expect(Subscriber::count())->equals(2);
|
||||||
|
|
||||||
@ -144,6 +318,21 @@ class SubscribersTest extends MailPoetTest {
|
|||||||
expect($response)->equals(0);
|
expect($response)->equals(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCannotRunAnInvalidBulkAction() {
|
||||||
|
try {
|
||||||
|
$router = new Subscribers();
|
||||||
|
$response = $router->bulkAction(array(
|
||||||
|
'action' => 'invalidAction',
|
||||||
|
'listing' => array()
|
||||||
|
));
|
||||||
|
$this->fail('Bulk Action class did not throw an exception');
|
||||||
|
} catch(Exception $e) {
|
||||||
|
expect($e->getMessage())->equals(
|
||||||
|
'\MailPoet\Models\Subscriber has not method "bulkInvalidAction"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
Segment::deleteMany();
|
Segment::deleteMany();
|
||||||
Subscriber::deleteMany();
|
Subscriber::deleteMany();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UtilCSSTest extends MailPoetTest {
|
class CSSTest extends MailPoetTest {
|
||||||
public function _before() {
|
public function _before() {
|
||||||
$this->css = new \MailPoet\Util\CSS();
|
$this->css = new \MailPoet\Util\CSS();
|
||||||
}
|
}
|
32
tests/unit/Util/SecurityTest.php
Normal file
32
tests/unit/Util/SecurityTest.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Util\Security;
|
||||||
|
|
||||||
|
class SecurityTest extends MailPoetTest {
|
||||||
|
|
||||||
|
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() {
|
||||||
|
// it has a default length of 5
|
||||||
|
$hash = Security::generateRandomString();
|
||||||
|
expect(strlen($hash))->equals(5);
|
||||||
|
|
||||||
|
// it has a min length of 5
|
||||||
|
$short_hash = Security::generateRandomString(1);
|
||||||
|
expect(strlen($short_hash))->equals(5);
|
||||||
|
|
||||||
|
// it has a max length of 32
|
||||||
|
$long_hash = Security::generateRandomString(64);
|
||||||
|
expect(strlen($long_hash))->equals(32);
|
||||||
|
|
||||||
|
// expect only alphanumerical characters
|
||||||
|
expect(ctype_alnum($hash))->true();
|
||||||
|
expect(ctype_alnum($short_hash))->true();
|
||||||
|
expect(ctype_alnum($long_hash))->true();
|
||||||
|
}
|
||||||
|
}
|
9
tests/unit/Util/UrlTest.php
Normal file
9
tests/unit/Util/UrlTest.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Util\Url;
|
||||||
|
|
||||||
|
class UtilUrlTest extends MailPoetTest {
|
||||||
|
function testItCanReturnCurrentUrl() {
|
||||||
|
$current_url = Url::getCurrentUrl();
|
||||||
|
expect($current_url)->startsWith('http');
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class UtilDKIMTest extends MailPoetTest {
|
|
||||||
|
|
||||||
public function testItCanGenerateKeys() {
|
|
||||||
$keys = \MailPoet\Util\DKIM::generateKeys();
|
|
||||||
|
|
||||||
$public_header = 'PUBLIC KEY-----';
|
|
||||||
$private_header = 'PRIVATE KEY-----';
|
|
||||||
|
|
||||||
expect($keys['public'])->notEmpty();
|
|
||||||
expect($keys['private'])->notEmpty();
|
|
||||||
|
|
||||||
expect($keys['public'])->notContains($public_header);
|
|
||||||
expect($keys['private'])->notContains($private_header);
|
|
||||||
}
|
|
||||||
}
|
|
@ -77,6 +77,6 @@ class DateTimeTest extends MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _afterStep() {
|
function _afterStep() {
|
||||||
WordPress::releaseAllFunctions();
|
WordPressHelper::releaseAllFunctions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,23 +38,6 @@
|
|||||||
name="mta[frequency][interval]"
|
name="mta[frequency][interval]"
|
||||||
value="<%= settings.mta.frequency.interval %>"
|
value="<%= settings.mta.frequency.interval %>"
|
||||||
/>
|
/>
|
||||||
<!-- dkim: public / private keys -->
|
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
name="dkim[public_key]"
|
|
||||||
value="<%= settings.dkim.public_key %>"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
name="dkim[private_key]"
|
|
||||||
value="<%= settings.dkim.private_key %>"
|
|
||||||
/>
|
|
||||||
<!-- dkim: domain -->
|
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
name="dkim[domain]"
|
|
||||||
value="<%= settings.dkim.domain %>"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- smtp: available sending methods -->
|
<!-- smtp: available sending methods -->
|
||||||
<ul class="mailpoet_sending_methods clearfix">
|
<ul class="mailpoet_sending_methods clearfix">
|
||||||
@ -616,70 +599,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- dkim -->
|
|
||||||
<tr id="mailpoet_mta_dkim" style="display:none;">
|
|
||||||
<th scope="row">
|
|
||||||
<label for="settings[dkim_enabled]">
|
|
||||||
<%= __('DKIM Signature (Highly recommended!)') %>
|
|
||||||
<p class="description">
|
|
||||||
<%= __('Improve your spam score. MailPoet can sign all your emails with DKIM.') %>
|
|
||||||
<a
|
|
||||||
href="#todo/guide-to-dkim-in-wysija/"
|
|
||||||
target="_blank"
|
|
||||||
title=""
|
|
||||||
><%= __('Read more.') %></a>
|
|
||||||
</p>
|
|
||||||
</label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<p>
|
|
||||||
<input
|
|
||||||
data-toggle="mailpoet_mta_dkim_content"
|
|
||||||
type="checkbox"
|
|
||||||
value="1"
|
|
||||||
id="settings[dkim_enabled]"
|
|
||||||
name="dkim[enabled]"
|
|
||||||
<% if(settings.dkim.enabled) %>checked="checked"<% endif %>
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
<div id="mailpoet_mta_dkim_content">
|
|
||||||
<fieldset style="border: 1px solid #ccc;margin: 0;padding: 10px;">
|
|
||||||
<legend>
|
|
||||||
<%= __('Configure your DNS by adding a key/value record in TXT as shown below.') %>
|
|
||||||
<a
|
|
||||||
href="http://support.mailpoet.com/knowledgebase/guide-to-dkim-in-wysija/?utm_source=wpadmin&utm_campaign=settings"
|
|
||||||
target="_blank"
|
|
||||||
><%= __('Read more.') %></a>
|
|
||||||
</legend>
|
|
||||||
<p>
|
|
||||||
<label>
|
|
||||||
<%= __('Key') %>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
class="regular-text"
|
|
||||||
onClick="this.focus();this.select();"
|
|
||||||
readonly="readonly"
|
|
||||||
value="wys._domainkey"
|
|
||||||
size="12"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<%= __('Value') %>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
class="regular-text"
|
|
||||||
|
|
||||||
onClick="this.focus();this.select();"
|
|
||||||
readonly="readonly"
|
|
||||||
value="v=DKIM1;s=email;t=s;p=<%= settings.dkim.public_key %>"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</p>
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<!-- test method -->
|
<!-- test method -->
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
|
Reference in New Issue
Block a user