Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
8dbfe82922 | |||
7322f2151c | |||
c43d2f240d | |||
bbcd267b6f | |||
bbc4acb2a4 | |||
c89cc5a919 | |||
33075940de | |||
51c09b8360 | |||
2fbf85f371 | |||
24cb614adb | |||
55f851208b | |||
990dac7727 | |||
233020ca20 | |||
0c419cde16 | |||
35f9530d8e | |||
992fe2a6e9 | |||
c2cb88f995 | |||
ba69d659ab | |||
397d988eb1 | |||
d85f2341ec | |||
2b3c288b5f | |||
8ec28a23a7 | |||
12c9623e2f | |||
8ba9fdccbc | |||
a2ef62302f | |||
24ecc879d3 | |||
a1104a7f90 | |||
aa959810e9 | |||
45b7a79277 | |||
41c8c0dae5 | |||
2aeab7aaff | |||
4fd0c4b484 | |||
d4623cf763 | |||
181c4fed08 | |||
7884dd8389 |
16
.env.sample
16
.env.sample
@ -1,2 +1,16 @@
|
|||||||
WP_TEST_PATH="/var/www/wordpress"
|
WP_TEST_PATH="/var/www/wordpress"
|
||||||
|
WP_TEST_ENABLE_NETWORK_TESTS="true"
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_API=""
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_LISTS="" // (separated with comma)
|
||||||
|
WP_TEST_MAILER_ENABLE_SENDING="true"
|
||||||
|
WP_TEST_MAILER_AMAZON_ACCESS=""
|
||||||
|
WP_TEST_MAILER_AMAZON_SECRET=""
|
||||||
|
WP_TEST_MAILER_AMAZON_REGION=""
|
||||||
|
WP_TEST_MAILER_ELASTICEMAIL_API=""
|
||||||
|
WP_TEST_MAILER_MAILGUN_API=""
|
||||||
|
WP_TEST_MAILER_MAILGUN_DOMAIN=""
|
||||||
|
WP_TEST_MAILER_MAILPOET_API=""
|
||||||
|
WP_TEST_MAILER_SENDGRID_API=""
|
||||||
|
WP_TEST_MAILER_SMTP_HOST=""
|
||||||
|
WP_TEST_MAILER_SMTP_LOGIN=""
|
||||||
|
WP_TEST_MAILER_SMTP_PASSWORD=""
|
12
RoboFile.php
12
RoboFile.php
@ -105,7 +105,17 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
function testUnit($file = null) {
|
function testUnit($file = null) {
|
||||||
$this->loadEnv();
|
$this->loadEnv();
|
||||||
$this->_exec('vendor/bin/codecept build');
|
$this->_exec('vendor/bin/codecept build');
|
||||||
$this->_exec('vendor/bin/codecept run unit '.(($file) ? $file : ''));
|
$this->_exec('vendor/bin/codecept run unit -f '.(($file) ? $file : ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCoverage() {
|
||||||
|
$this->loadEnv();
|
||||||
|
$this->_exec('vendor/bin/codecept build');
|
||||||
|
$this->_exec(join(' ', array(
|
||||||
|
'vendor/bin/codecept run',
|
||||||
|
'--coverage',
|
||||||
|
'--coverage-html'
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testJavascript() {
|
function testJavascript() {
|
||||||
|
@ -48,7 +48,7 @@ define(
|
|||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: this.props.endpoint,
|
endpoint: this.props.endpoint,
|
||||||
action: 'get',
|
action: 'get',
|
||||||
data: { id: id }
|
data: id
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response === false) {
|
if(response === false) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -125,8 +125,8 @@ const FormList = React.createClass({
|
|||||||
endpoint: 'forms',
|
endpoint: 'forms',
|
||||||
action: 'create'
|
action: 'create'
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response !== false) {
|
if(response.result && response.form_id) {
|
||||||
window.location = response;
|
window.location = mailpoet_form_edit_url + response.form_id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ define([
|
|||||||
// Does not hold newsletter content nor newsletter styles, those are
|
// Does not hold newsletter content nor newsletter styles, those are
|
||||||
// handled by other components.
|
// handled by other components.
|
||||||
Module.NewsletterModel = SuperModel.extend({
|
Module.NewsletterModel = SuperModel.extend({
|
||||||
stale: ['body'],
|
stale: ['body', 'created_at', 'deleted_at', 'updated_at'],
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.on('change', function() {
|
this.on('change', function() {
|
||||||
App.getChannel().trigger('autoSave');
|
App.getChannel().trigger('autoSave');
|
||||||
|
@ -29,7 +29,7 @@ define(
|
|||||||
action: 'save',
|
action: 'save',
|
||||||
data: template
|
data: template
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response === true) {
|
if(response.result === true) {
|
||||||
this.props.onImport(template);
|
this.props.onImport(template);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
response.map(function(error) {
|
||||||
|
@ -29,12 +29,14 @@ define(
|
|||||||
subject: 'Draft newsletter',
|
subject: 'Draft newsletter',
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.history.pushState(null, `/template/${response.id}`);
|
this.history.pushState(null, `/template/${response.newsletter.id}`);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -138,12 +138,14 @@ define(
|
|||||||
options: this.state,
|
options: this.state,
|
||||||
},
|
},
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.showTemplateSelection(response.id);
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -32,12 +32,15 @@ define(
|
|||||||
type: 'standard',
|
type: 'standard',
|
||||||
}
|
}
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
console.log(response);
|
||||||
this.showTemplateSelection(response.id);
|
if(response.result && response.newsletter.id) {
|
||||||
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -111,12 +111,14 @@ define(
|
|||||||
options: this.state,
|
options: this.state,
|
||||||
},
|
},
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response.id !== undefined) {
|
if(response.result && response.newsletter.id) {
|
||||||
this.showTemplateSelection(response.id);
|
this.showTemplateSelection(response.newsletter.id);
|
||||||
} else {
|
} else {
|
||||||
response.map(function(error) {
|
if(response.errors.length > 0) {
|
||||||
MailPoet.Notice.error(error);
|
response.errors.map(function(error) {
|
||||||
});
|
MailPoet.Notice.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
@ -19,3 +19,12 @@ modules:
|
|||||||
user: ''
|
user: ''
|
||||||
password: ''
|
password: ''
|
||||||
dump: tests/_data/dump.sql
|
dump: tests/_data/dump.sql
|
||||||
|
coverage:
|
||||||
|
enabled: true
|
||||||
|
whitelist:
|
||||||
|
include:
|
||||||
|
- lib/*
|
||||||
|
exclude:
|
||||||
|
blacklist:
|
||||||
|
include:
|
||||||
|
exclude:
|
@ -36,8 +36,9 @@ class Env {
|
|||||||
self::$views_path = self::$path . '/views';
|
self::$views_path = self::$path . '/views';
|
||||||
self::$assets_path = self::$path . '/assets';
|
self::$assets_path = self::$path . '/assets';
|
||||||
self::$assets_url = plugins_url('/assets', $file);
|
self::$assets_url = plugins_url('/assets', $file);
|
||||||
self::$temp_path = wp_upload_dir()['path'];
|
$wp_upload_dir = wp_upload_dir();
|
||||||
self::$temp_URL = wp_upload_dir()['url'];
|
self::$temp_path = $wp_upload_dir['path'];
|
||||||
|
self::$temp_URL = $wp_upload_dir['url'];
|
||||||
self::$languages_path = self::$path . '/lang';
|
self::$languages_path = self::$path . '/lang';
|
||||||
self::$lib_path = self::$path . '/lib';
|
self::$lib_path = self::$path . '/lib';
|
||||||
self::$plugin_prefix = 'mailpoet_';
|
self::$plugin_prefix = 'mailpoet_';
|
||||||
@ -72,19 +73,4 @@ class Env {
|
|||||||
);
|
);
|
||||||
return implode('', $source_name);
|
return implode('', $source_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function isPluginActivated() {
|
|
||||||
$activatesPlugins = get_option('active_plugins');
|
|
||||||
$isActivated = (
|
|
||||||
in_array(
|
|
||||||
sprintf('%s/%s.php', basename(self::$path), self::$plugin_name),
|
|
||||||
$activatesPlugins
|
|
||||||
) ||
|
|
||||||
in_array(
|
|
||||||
sprintf('%s/%s.php', explode('/', plugin_basename(__FILE__))[0], self::$plugin_name),
|
|
||||||
$activatesPlugins
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return ($isActivated) ? true : false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -9,6 +9,8 @@ use MailPoet\Settings\Pages;
|
|||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||||
|
|
||||||
class Initializer {
|
class Initializer {
|
||||||
function __construct($params = array(
|
function __construct($params = array(
|
||||||
'file' => '',
|
'file' => '',
|
||||||
@ -18,17 +20,25 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
$this->setupDB();
|
||||||
|
|
||||||
|
register_activation_hook(Env::$file, array($this, 'runMigrator'));
|
||||||
|
register_activation_hook(Env::$file, array($this, 'runPopulator'));
|
||||||
|
|
||||||
|
add_action('init', array($this, 'setup'));
|
||||||
|
add_action('widgets_init', array($this, 'setupWidget'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup() {
|
||||||
try {
|
try {
|
||||||
$this->setupDB();
|
|
||||||
$this->setupRenderer();
|
$this->setupRenderer();
|
||||||
$this->setupLocalizer();
|
$this->setupLocalizer();
|
||||||
$this->setupMenu();
|
$this->setupMenu();
|
||||||
$this->setupRouter();
|
$this->setupRouter();
|
||||||
$this->setupWidget();
|
|
||||||
$this->setupAnalytics();
|
|
||||||
$this->setupPermissions();
|
$this->setupPermissions();
|
||||||
$this->setupChangelog();
|
|
||||||
$this->setupPublicAPI();
|
$this->setupPublicAPI();
|
||||||
|
$this->setupAnalytics();
|
||||||
|
$this->setupChangelog();
|
||||||
$this->runQueueSupervisor();
|
$this->runQueueSupervisor();
|
||||||
$this->setupShortcodes();
|
$this->setupShortcodes();
|
||||||
$this->setupHooks();
|
$this->setupHooks();
|
||||||
@ -86,8 +96,12 @@ class Initializer {
|
|||||||
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runMigrator() {
|
||||||
|
$migrator = new Migrator();
|
||||||
|
$migrator->up();
|
||||||
|
}
|
||||||
|
|
||||||
function runPopulator() {
|
function runPopulator() {
|
||||||
$this->init();
|
|
||||||
$populator = new Populator();
|
$populator = new Populator();
|
||||||
$populator->up();
|
$populator->up();
|
||||||
}
|
}
|
||||||
@ -103,10 +117,7 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupMenu() {
|
function setupMenu() {
|
||||||
$menu = new Menu(
|
$menu = new Menu($this->renderer, Env::$assets_url);
|
||||||
$this->renderer,
|
|
||||||
Env::$assets_url
|
|
||||||
);
|
|
||||||
$menu->init();
|
$menu->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,9 +167,7 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runQueueSupervisor() {
|
function runQueueSupervisor() {
|
||||||
if(php_sapi_name() === 'cli' ||
|
if(php_sapi_name() === 'cli') return;
|
||||||
!Env::isPluginActivated()
|
|
||||||
) return;
|
|
||||||
try {
|
try {
|
||||||
$supervisor = new Supervisor();
|
$supervisor = new Supervisor();
|
||||||
$supervisor->checkDaemon();
|
$supervisor->checkDaemon();
|
||||||
|
@ -279,19 +279,19 @@ class FranksRoastHouseTemplate {
|
|||||||
"blocks" => array(
|
"blocks" => array(
|
||||||
array(
|
array(
|
||||||
"type" => "footer",
|
"type" => "footer",
|
||||||
"text" => __("<p><span style=\"color: #000000;\"><a href=\"[unsubscribeUrl]\" style=\"color: #000000;\">Unsubscribe</a> | <a href=\"[manageSubscriptionUrl]\" style=\"color: #000000;\">Manage subscription</a></span><br /><span style=\"color: #000000;\">12345 MailPoet Drive, EmailVille, 76543</span></p>"),
|
"text" => __("<p><a href=\"[unsubscribeUrl]\">Unsubscribe</a> | <a href=\"[manageSubscriptionUrl]\">Manage subscription</a><br />12345 MailPoet Drive, EmailVille, 76543</p>"),
|
||||||
"styles" => array(
|
"styles" => array(
|
||||||
"block" => array(
|
"block" => array(
|
||||||
"backgroundColor" => "#a9a7a7"
|
"backgroundColor" => "#a9a7a7"
|
||||||
),
|
),
|
||||||
"text" => array(
|
"text" => array(
|
||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#000000",
|
||||||
"fontFamily" => "Arial",
|
"fontFamily" => "Arial",
|
||||||
"fontSize" => "12px",
|
"fontSize" => "12px",
|
||||||
"textAlign" => "center"
|
"textAlign" => "center"
|
||||||
),
|
),
|
||||||
"link" => array(
|
"link" => array(
|
||||||
"fontColor" => "#ffffff",
|
"fontColor" => "#000000",
|
||||||
"textDecoration" => "underline"
|
"textDecoration" => "underline"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -9,13 +9,12 @@ class Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
add_action('widgets_init', array($this, 'registerWidget'));
|
$this->registerWidget();
|
||||||
|
|
||||||
if(!is_admin()) {
|
if(!is_admin()) {
|
||||||
//$this->setupActions();
|
$this->setupDependencies();
|
||||||
add_action('widgets_init', array($this, 'setupDependencies'));
|
|
||||||
} else {
|
} else {
|
||||||
add_action('widgets_init', array($this, 'setupAdminDependencies'));
|
$this->setupAdminDependencies();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +68,9 @@ class Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: extract this method into an Initializer
|
||||||
|
// - the "ajax" part might probably be useless
|
||||||
|
// - the "post" (non-ajax) part needs to be redone properly
|
||||||
function setupActions() {
|
function setupActions() {
|
||||||
// ajax requests
|
// ajax requests
|
||||||
add_action(
|
add_action(
|
||||||
|
@ -62,7 +62,7 @@ class Supervisor {
|
|||||||
list(, $message) = explode(':', $status[0]);
|
list(, $message) = explode(':', $status[0]);
|
||||||
$message = base64_decode($message);
|
$message = base64_decode($message);
|
||||||
}
|
}
|
||||||
return $this->formatResult(
|
return $this->formatResultMessage(
|
||||||
false,
|
false,
|
||||||
$message
|
$message
|
||||||
);
|
);
|
||||||
|
@ -21,11 +21,11 @@ class SendingQueue {
|
|||||||
function process() {
|
function process() {
|
||||||
// TODO: implement mailer sending frequency limits
|
// TODO: implement mailer sending frequency limits
|
||||||
foreach($this->getQueues() as $queue) {
|
foreach($this->getQueues() as $queue) {
|
||||||
$newsletter = Newsletter::findOne($queue->newsletter_id)
|
$newsletter = Newsletter::findOne($queue->newsletter_id);
|
||||||
->asArray();
|
|
||||||
if(!$newsletter) {
|
if(!$newsletter) {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
$newsletter = $newsletter->asArray();
|
||||||
$mailer = $this->configureMailerForNewsletter($newsletter);
|
$mailer = $this->configureMailerForNewsletter($newsletter);
|
||||||
$subscribers = json_decode($queue->subscribers, true);
|
$subscribers = json_decode($queue->subscribers, true);
|
||||||
$subscribers_to_process = $subscribers['to_process'];
|
$subscribers_to_process = $subscribers['to_process'];
|
||||||
|
@ -65,6 +65,8 @@ class Widget extends \WP_Widget {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$form_edit_url = admin_url('admin.php?page=mailpoet-form-editor&id=');
|
||||||
|
|
||||||
// set title
|
// set title
|
||||||
$title = isset($instance['title']) ? strip_tags($instance['title']) : '';
|
$title = isset($instance['title']) ? strip_tags($instance['title']) : '';
|
||||||
|
|
||||||
@ -102,8 +104,9 @@ class Widget extends \WP_Widget {
|
|||||||
endpoint: 'forms',
|
endpoint: 'forms',
|
||||||
action: 'create'
|
action: 'create'
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response !== false) {
|
if(response.result && response.form_id) {
|
||||||
window.location = response;
|
window.location =
|
||||||
|
"<?php echo $form_edit_url; ?>" + response.form_id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,7 +122,7 @@ class Mailer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$reply_to['address']) {
|
if(!$reply_to['address']) {
|
||||||
$reply_to['reply_to_email'] = $this->sender['from_email'];
|
$reply_to['address'] = $this->sender['from_email'];
|
||||||
}
|
}
|
||||||
return array(
|
return array(
|
||||||
'reply_to_name' => $reply_to['name'],
|
'reply_to_name' => $reply_to['name'],
|
||||||
|
@ -20,10 +20,11 @@ class SendGrid {
|
|||||||
$this->url,
|
$this->url,
|
||||||
$this->request($newsletter, $subscriber)
|
$this->request($newsletter, $subscriber)
|
||||||
);
|
);
|
||||||
|
$result_body = json_decode($result['body'], true);
|
||||||
return (
|
return (
|
||||||
!is_wp_error($result) === true &&
|
!is_wp_error($result) === true &&
|
||||||
!preg_match('!invalid!', $result['body']) === true &&
|
!preg_match('!invalid!', $result['body']) === true &&
|
||||||
!isset(json_decode($result['body'], true)['errors']) === true &&
|
!isset($result_body['errors']) === true &&
|
||||||
wp_remote_retrieve_response_code($result) === 200
|
wp_remote_retrieve_response_code($result) === 200
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,24 @@ class CustomField extends Model {
|
|||||||
function asArray() {
|
function asArray() {
|
||||||
$model = parent::asArray();
|
$model = parent::asArray();
|
||||||
|
|
||||||
$model['params'] = (
|
if(isset($model['params'])) {
|
||||||
is_serialized($this->params)
|
$model['params'] = (
|
||||||
? unserialize($this->params)
|
is_array($this->params)
|
||||||
: $this->params
|
? $this->params
|
||||||
);
|
: unserialize($this->params)
|
||||||
|
);
|
||||||
|
}
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
if(is_null($this->params)) {
|
||||||
|
$this->params = array();
|
||||||
|
}
|
||||||
$this->set('params', (
|
$this->set('params', (
|
||||||
is_serialized($this->params)
|
is_array($this->params)
|
||||||
? $this->params
|
? serialize($this->params)
|
||||||
: serialize($this->params)
|
: $this->params
|
||||||
));
|
));
|
||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
@ -66,12 +70,6 @@ class CustomField extends Model {
|
|||||||
$custom_field->set($data);
|
$custom_field->set($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return $custom_field->save();
|
||||||
$custom_field->save();
|
|
||||||
return $custom_field;
|
|
||||||
} catch(Exception $e) {
|
|
||||||
return $custom_field->getValidationErrors();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,10 @@ namespace MailPoet\Models;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Model extends \Sudzy\ValidModel {
|
class Model extends \Sudzy\ValidModel {
|
||||||
|
protected $_errors;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
$this->_errors = array();
|
||||||
$customValidators = new CustomValidator();
|
$customValidators = new CustomValidator();
|
||||||
parent::__construct($customValidators->init());
|
parent::__construct($customValidators->init());
|
||||||
}
|
}
|
||||||
@ -13,16 +16,37 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
return parent::create();
|
return parent::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getErrors() {
|
||||||
|
if(empty($this->_errors)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return $this->_errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setError($error = '') {
|
||||||
|
if(!empty($error)) {
|
||||||
|
if(is_array($error)) {
|
||||||
|
$this->_errors = array_merge($this->_errors, $error);
|
||||||
|
$this->_errors = array_unique($this->_errors);
|
||||||
|
} else {
|
||||||
|
$this->_errors[] = $error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
$this->setTimestamp();
|
$this->setTimestamp();
|
||||||
try {
|
try {
|
||||||
parent::save();
|
parent::save();
|
||||||
return true;
|
} catch(\Sudzy\ValidationException $e) {
|
||||||
} catch (\Sudzy\ValidationException $e) {
|
$this->setError($e->getValidationErrors());
|
||||||
return array_unique($e->getValidationErrors());
|
} catch(\PDOException $e) {
|
||||||
} catch (\PDOException $e) {
|
$this->setError($e->getMessage());
|
||||||
return $e->getMessage();
|
} catch(\Exception $e) {
|
||||||
|
$this->setError($e->getMessage());
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash() {
|
function trash() {
|
||||||
|
@ -8,6 +8,10 @@ class Newsletter extends Model {
|
|||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->addValidations('type', array(
|
||||||
|
'required' => __('You need to specify a type.')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
@ -15,9 +19,23 @@ class Newsletter extends Model {
|
|||||||
$this->set_expr('deleted_at', 'NULL');
|
$this->set_expr('deleted_at', 'NULL');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->set('body',
|
||||||
|
is_array($this->body)
|
||||||
|
? json_encode($this->body)
|
||||||
|
: $this->body
|
||||||
|
);
|
||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asArray() {
|
||||||
|
$model = parent::asArray();
|
||||||
|
|
||||||
|
if(isset($model['body'])) {
|
||||||
|
$model['body'] = json_decode($model['body'], true);
|
||||||
|
}
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
function delete() {
|
function delete() {
|
||||||
// delete all relations to segments
|
// delete all relations to segments
|
||||||
NewsletterSegment::where('newsletter_id', $this->id)->deleteMany();
|
NewsletterSegment::where('newsletter_id', $this->id)->deleteMany();
|
||||||
|
@ -17,6 +17,14 @@ class NewsletterTemplate extends Model {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asArray() {
|
||||||
|
$template = parent::asArray();
|
||||||
|
if(isset($template['body'])) {
|
||||||
|
$template['body'] = json_decode($template['body'], true);
|
||||||
|
}
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
static function createOrUpdate($data = array()) {
|
static function createOrUpdate($data = array()) {
|
||||||
$template = false;
|
$template = false;
|
||||||
|
|
||||||
@ -32,16 +40,7 @@ class NewsletterTemplate extends Model {
|
|||||||
$template->set($data);
|
$template->set($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$saved = $template->save();
|
$template->save();
|
||||||
|
return $template;
|
||||||
if($saved === true) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
$errors = $template->getValidationErrors();
|
|
||||||
if(!empty($errors)) {
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,8 +164,7 @@ class Segment extends Model {
|
|||||||
$segment->set($data);
|
$segment->set($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$segment->save();
|
return $segment->save();
|
||||||
return $segment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getPublic() {
|
static function getPublic() {
|
||||||
|
@ -10,8 +10,7 @@ class Setting extends Model {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->addValidations('name', array(
|
$this->addValidations('name', array(
|
||||||
'required' => 'name_is_blank',
|
'required' => __('You need to specify a name.')
|
||||||
'isString' => 'name_is_not_string'
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,10 +54,11 @@ class Setting extends Model {
|
|||||||
$value = serialize($value);
|
$value = serialize($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Setting::createOrUpdate(array(
|
$setting = Setting::createOrUpdate(array(
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'value' => $value
|
'value' => $value
|
||||||
));
|
));
|
||||||
|
return ($setting->id() > 0 && $setting->getErrors() === false);
|
||||||
} else {
|
} else {
|
||||||
$main_key = array_shift($keys);
|
$main_key = array_shift($keys);
|
||||||
|
|
||||||
@ -101,8 +101,7 @@ class Setting extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function createOrUpdate($model) {
|
public static function createOrUpdate($model) {
|
||||||
$exists = self::where('name', $model['name'])
|
$exists = self::where('name', $model['name'])->findOne();
|
||||||
->find_one();
|
|
||||||
|
|
||||||
if($exists === false) {
|
if($exists === false) {
|
||||||
$new_model = self::create();
|
$new_model = self::create();
|
||||||
|
@ -62,7 +62,7 @@ class PostTransformer {
|
|||||||
// get attachment data (src, width, height)
|
// get attachment data (src, width, height)
|
||||||
$image_info = wp_get_attachment_image_src(
|
$image_info = wp_get_attachment_image_src(
|
||||||
$thumbnail_id,
|
$thumbnail_id,
|
||||||
'single-post-thumbnail'
|
'mailpoet_newsletter_max'
|
||||||
);
|
);
|
||||||
|
|
||||||
// get alt text
|
// get alt text
|
||||||
|
@ -11,12 +11,12 @@ class AutomatedLatestContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPostTypes() {
|
function getPostTypes() {
|
||||||
wp_send_json(get_post_types(array(), 'objects'));
|
return get_post_types(array(), 'objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTaxonomies($args) {
|
function getTaxonomies($args) {
|
||||||
$post_type = (isset($args['postType'])) ? $args['postType'] : 'post';
|
$post_type = (isset($args['postType'])) ? $args['postType'] : 'post';
|
||||||
wp_send_json(get_object_taxonomies($post_type, 'objects'));
|
return get_object_taxonomies($post_type, 'objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTerms($args) {
|
function getTerms($args) {
|
||||||
@ -24,20 +24,23 @@ class AutomatedLatestContent {
|
|||||||
$search = (isset($args['search'])) ? $args['search'] : '';
|
$search = (isset($args['search'])) ? $args['search'] : '';
|
||||||
$limit = (isset($args['limit'])) ? (int)$args['limit'] : 10;
|
$limit = (isset($args['limit'])) ? (int)$args['limit'] : 10;
|
||||||
$page = (isset($args['page'])) ? (int)$args['page'] : 1;
|
$page = (isset($args['page'])) ? (int)$args['page'] : 1;
|
||||||
wp_send_json(get_terms($taxonomies, array(
|
return get_terms(
|
||||||
'hide_empty' => false,
|
$taxonomies,
|
||||||
'search' => $search,
|
array(
|
||||||
'number' => $limit,
|
'hide_empty' => false,
|
||||||
'offset' => $limit * ($page - 1),
|
'search' => $search,
|
||||||
)));
|
'number' => $limit,
|
||||||
|
'offset' => $limit * ($page - 1)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPosts($args) {
|
function getPosts($args) {
|
||||||
wp_send_json($this->ALC->getPosts($args));
|
return $this->ALC->getPosts($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTransformedPosts($args) {
|
function getTransformedPosts($args) {
|
||||||
$posts = $this->ALC->getPosts($args);
|
$posts = $this->ALC->getPosts($args);
|
||||||
wp_send_json($this->ALC->transformPosts($args, $posts));
|
return $this->ALC->transformPosts($args, $posts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ if(!defined('ABSPATH')) exit;
|
|||||||
class Cron {
|
class Cron {
|
||||||
function start() {
|
function start() {
|
||||||
$supervisor = new Supervisor($force_run = true);
|
$supervisor = new Supervisor($force_run = true);
|
||||||
wp_send_json($supervisor->checkDaemon());
|
return $supervisor->checkDaemon();
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
@ -22,17 +22,15 @@ class Cron {
|
|||||||
$daemon['status'] = 'stopping';
|
$daemon['status'] = 'stopping';
|
||||||
$result = CronHelper::saveDaemon($daemon);
|
$result = CronHelper::saveDaemon($daemon);
|
||||||
}
|
}
|
||||||
wp_send_json(
|
return array(
|
||||||
array(
|
'result' => $result
|
||||||
'result' => $result
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatus() {
|
function getStatus() {
|
||||||
$daemon = Setting::where('name', 'cron_daemon')
|
$daemon = Setting::where('name', 'cron_daemon')
|
||||||
->findOne();
|
->findOne();
|
||||||
wp_send_json(
|
return (
|
||||||
($daemon) ?
|
($daemon) ?
|
||||||
array_merge(
|
array_merge(
|
||||||
array(
|
array(
|
||||||
|
@ -33,30 +33,19 @@ class CustomFields {
|
|||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$custom_field = CustomField::createOrUpdate($data);
|
$custom_field = CustomField::createOrUpdate($data);
|
||||||
|
$errors = $custom_field->getErrors();
|
||||||
|
|
||||||
if($custom_field === false) {
|
if(!empty($errors)) {
|
||||||
$result = array(
|
return array(
|
||||||
'result' => false,
|
'result' => false,
|
||||||
'errors' => array(
|
'errors' => $errors
|
||||||
__('The custom field could not be created.')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$errors = $custom_field->getValidationErrors();
|
return array(
|
||||||
if(!empty($errors)) {
|
'result' => true,
|
||||||
$result = array(
|
'field' => $custom_field->asArray()
|
||||||
'result' => false,
|
);
|
||||||
'errors' => $errors
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$result = array(
|
|
||||||
'result' => true,
|
|
||||||
'field' => $custom_field->asArray()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($id) {
|
function get($id) {
|
||||||
|
@ -11,15 +11,12 @@ class Forms {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($id = false) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
|
||||||
|
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if($form === false) {
|
if($form === false) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$form = $form->asArray();
|
return $form->asArray();
|
||||||
wp_send_json($form);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,12 +44,7 @@ class Forms {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($listing_data);
|
return $listing_data;
|
||||||
}
|
|
||||||
|
|
||||||
function getAll() {
|
|
||||||
$collection = Form::findArray();
|
|
||||||
wp_send_json($collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
@ -88,24 +80,23 @@ class Forms {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$form = Form::createOrUpdate($form_data);
|
return $this->save($form_data);
|
||||||
|
|
||||||
if($form !== false && $form->id()) {
|
|
||||||
wp_send_json(
|
|
||||||
admin_url('admin.php?page=mailpoet-form-editor&id='.$form->id())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
wp_send_json(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$form = Form::createOrUpdate($data);
|
$form = Form::createOrUpdate($data);
|
||||||
|
$errors = $form->getErrors();
|
||||||
|
|
||||||
if($form !== false && $form->id()) {
|
if(!empty($errors)) {
|
||||||
wp_send_json($form->id());
|
return array(
|
||||||
|
'result' => false,
|
||||||
|
'errors' => $errors
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
wp_send_json($form);
|
return array(
|
||||||
|
'result' => true,
|
||||||
|
'form_id' => $form->id()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,10 +110,10 @@ class Forms {
|
|||||||
// styles
|
// styles
|
||||||
$css = new Util\Styles(FormRenderer::getStyles($data));
|
$css = new Util\Styles(FormRenderer::getStyles($data));
|
||||||
|
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'html' => $html,
|
'html' => $html,
|
||||||
'css' => $css->render()
|
'css' => $css->render()
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportsEditor($id) {
|
function exportsEditor($id) {
|
||||||
@ -134,19 +125,19 @@ class Forms {
|
|||||||
$exports = Util\Export::getAll($form->asArray());
|
$exports = Util\Export::getAll($form->asArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($exports);
|
return $exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveEditor($data = array()) {
|
function saveEditor($data = array()) {
|
||||||
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||||
$name = (isset($data['name']) ? $data['name'] : array());
|
$name = (isset($data['name']) ? $data['name'] : __('New form'));
|
||||||
$body = (isset($data['body']) ? $data['body'] : array());
|
$body = (isset($data['body']) ? $data['body'] : array());
|
||||||
$settings = (isset($data['settings']) ? $data['settings'] : array());
|
$settings = (isset($data['settings']) ? $data['settings'] : array());
|
||||||
$styles = (isset($data['styles']) ? $data['styles'] : array());
|
$styles = (isset($data['styles']) ? $data['styles'] : '');
|
||||||
|
|
||||||
if(empty($body) || empty($settings)) {
|
if(empty($body) || empty($settings)) {
|
||||||
// error
|
// error
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// check if the form is used as a widget
|
// check if the form is used as a widget
|
||||||
$is_widget = false;
|
$is_widget = false;
|
||||||
@ -178,7 +169,7 @@ class Forms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check list selectio
|
// check list selection
|
||||||
if($has_segment_selection === true) {
|
if($has_segment_selection === true) {
|
||||||
$settings['segments_selected_by'] = 'user';
|
$settings['segments_selected_by'] = 'user';
|
||||||
} else {
|
} else {
|
||||||
@ -194,45 +185,42 @@ class Forms {
|
|||||||
'styles' => $styles
|
'styles' => $styles
|
||||||
));
|
));
|
||||||
|
|
||||||
// response
|
if($form->getErrors() === false) {
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => ($form !== false),
|
'result' => true,
|
||||||
'is_widget' => $is_widget
|
'is_widget' => $is_widget
|
||||||
));
|
);
|
||||||
|
} else {
|
||||||
|
return array(
|
||||||
|
'result' => false,
|
||||||
|
'errors' => $form->getErrors()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore($id) {
|
function restore($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if($form !== false) {
|
if($form !== false) {
|
||||||
$result = $form->restore();
|
$form->restore();
|
||||||
}
|
}
|
||||||
|
return ($form->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($id) {
|
function trash($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if($form !== false) {
|
if($form !== false) {
|
||||||
$result = $form->trash();
|
$form->trash();
|
||||||
}
|
}
|
||||||
|
return ($form->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if($form !== false) {
|
if($form !== false) {
|
||||||
$form->delete();
|
$form->delete();
|
||||||
$result = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function duplicate($id) {
|
function duplicate($id) {
|
||||||
@ -246,7 +234,7 @@ class Forms {
|
|||||||
$result = $form->duplicate($data)->asArray();
|
$result = $form->duplicate($data)->asArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($result);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bulkAction($data = array()) {
|
function bulkAction($data = array()) {
|
||||||
@ -255,6 +243,6 @@ class Forms {
|
|||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
||||||
wp_send_json($bulk_action->apply());
|
return $bulk_action->apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@ if(!defined('ABSPATH')) exit;
|
|||||||
class ImportExport {
|
class ImportExport {
|
||||||
function getMailChimpLists($data) {
|
function getMailChimpLists($data) {
|
||||||
$mailChimp = new MailChimp($data['api_key']);
|
$mailChimp = new MailChimp($data['api_key']);
|
||||||
wp_send_json($mailChimp->getLists());
|
return $mailChimp->getLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMailChimpSubscribers($data) {
|
function getMailChimpSubscribers($data) {
|
||||||
$mailChimp = new MailChimp($data['api_key']);
|
$mailChimp = new MailChimp($data['api_key']);
|
||||||
wp_send_json($mailChimp->getSubscribers($data['lists']));
|
return $mailChimp->getSubscribers($data['lists']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSegment($data) {
|
function addSegment($data) {
|
||||||
$segment = Segment::createOrUpdate($data);
|
$segment = Segment::createOrUpdate($data);
|
||||||
wp_send_json(
|
return (
|
||||||
($segment->id) ?
|
($segment->id) ?
|
||||||
array(
|
array(
|
||||||
'result' => true,
|
'result' => true,
|
||||||
@ -36,7 +36,7 @@ class ImportExport {
|
|||||||
$customField = CustomField::create();
|
$customField = CustomField::create();
|
||||||
$customField->hydrate($data);
|
$customField->hydrate($data);
|
||||||
$result = $customField->save();
|
$result = $customField->save();
|
||||||
wp_send_json(
|
return (
|
||||||
($result) ?
|
($result) ?
|
||||||
array(
|
array(
|
||||||
'result' => true,
|
'result' => true,
|
||||||
@ -49,12 +49,16 @@ class ImportExport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processImport($data) {
|
function processImport($data) {
|
||||||
$import = new \MailPoet\Subscribers\ImportExport\Import\Import(json_decode($data, true));
|
$import = new \MailPoet\Subscribers\ImportExport\Import\Import(
|
||||||
wp_send_json($import->process());
|
json_decode($data, true)
|
||||||
|
);
|
||||||
|
return $import->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
function processExport($data) {
|
function processExport($data) {
|
||||||
$export = new \MailPoet\Subscribers\ImportExport\Export\Export(json_decode($data, true));
|
$export = new \MailPoet\Subscribers\ImportExport\Export\Export(
|
||||||
wp_send_json($export->process());
|
json_decode($data, true)
|
||||||
|
);
|
||||||
|
return $export->process();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,16 +5,19 @@ if(!defined('ABSPATH')) exit;
|
|||||||
|
|
||||||
class Mailer {
|
class Mailer {
|
||||||
function send($data) {
|
function send($data) {
|
||||||
$mailer = new \MailPoet\Mailer\Mailer(
|
$response = array();
|
||||||
(isset($data['mailer'])) ? $data['mailer'] : false,
|
try {
|
||||||
(isset($data['sender'])) ? $data['sender'] : false,
|
$mailer = new \MailPoet\Mailer\Mailer(
|
||||||
(isset($data['reply_to'])) ? $data['reply_to'] : false
|
(isset($data['mailer'])) ? $data['mailer'] : false,
|
||||||
);
|
(isset($data['sender'])) ? $data['sender'] : false,
|
||||||
$result = $mailer->send($data['newsletter'], $data['subscriber']);
|
(isset($data['reply_to'])) ? $data['reply_to'] : false
|
||||||
wp_send_json(
|
);
|
||||||
array(
|
$result = $mailer->send($data['newsletter'], $data['subscriber']);
|
||||||
'result' => ($result) ? true : false
|
} catch(\Exception $e) {
|
||||||
)
|
$result = false;
|
||||||
);
|
$response['errors'] = array($e->getMessage());
|
||||||
|
}
|
||||||
|
$response['result'] = ($result) ? true : false;
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,42 +9,33 @@ class NewsletterTemplates {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($id = false) {
|
||||||
$id = (isset($data['id'])) ? (int) $data['id'] : 0;
|
|
||||||
$template = NewsletterTemplate::findOne($id);
|
$template = NewsletterTemplate::findOne($id);
|
||||||
if($template === false) {
|
if($template === false) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$template->body = json_decode($template->body);
|
return $template->asArray();
|
||||||
wp_send_json($template->asArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAll() {
|
function getAll() {
|
||||||
$collection = NewsletterTemplate::findArray();
|
$collection = NewsletterTemplate::findMany();
|
||||||
$collection = array_map(function($item) {
|
return array_map(function($item) {
|
||||||
$item['body'] = json_decode($item['body']);
|
return $item->asArray();
|
||||||
return $item;
|
|
||||||
}, $collection);
|
}, $collection);
|
||||||
wp_send_json($collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$result = NewsletterTemplate::createOrUpdate($data);
|
$template = NewsletterTemplate::createOrUpdate($data);
|
||||||
if($result !== true) {
|
return ($template->getErrors() === false && $template->id() > 0);
|
||||||
wp_send_json($result);
|
|
||||||
} else {
|
|
||||||
wp_send_json(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$template = NewsletterTemplate::findOne($id);
|
$template = NewsletterTemplate::findOne($id);
|
||||||
if($template !== false) {
|
if($template !== false) {
|
||||||
$result = $template->delete();
|
return $template->delete();
|
||||||
} else {
|
} else {
|
||||||
$result = false;
|
return false;
|
||||||
}
|
}
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,10 @@ class Newsletters {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($id = false) {
|
||||||
$id = (isset($data['id'])) ? (int) $data['id'] : 0;
|
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if($newsletter === false) {
|
if($newsletter === false) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$segments = $newsletter->segments()->findArray();
|
$segments = $newsletter->segments()->findArray();
|
||||||
$options = $newsletter->options()->findArray();
|
$options = $newsletter->options()->findArray();
|
||||||
@ -34,42 +33,32 @@ class Newsletters {
|
|||||||
return $segment['id'];
|
return $segment['id'];
|
||||||
}, $segments);
|
}, $segments);
|
||||||
$newsletter['options'] = $options;
|
$newsletter['options'] = $options;
|
||||||
$newsletter['body'] = json_decode($newsletter['body']);
|
return $newsletter;
|
||||||
|
|
||||||
wp_send_json($newsletter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAll() {
|
|
||||||
$collection = Newsletter::findArray();
|
|
||||||
$collection = array_map(function($item) {
|
|
||||||
$item['body'] = json_decode($item['body']);
|
|
||||||
return $item;
|
|
||||||
}, $collection);
|
|
||||||
wp_send_json($collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
|
$segment_ids = array();
|
||||||
if(isset($data['segments'])) {
|
if(isset($data['segments'])) {
|
||||||
$segment_ids = $data['segments'];
|
$segment_ids = $data['segments'];
|
||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$options = array();
|
||||||
if(isset($data['options'])) {
|
if(isset($data['options'])) {
|
||||||
$options = $data['options'];
|
$options = $data['options'];
|
||||||
unset($data['options']);
|
unset($data['options']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = array();
|
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$newsletter = Newsletter::createOrUpdate($data);
|
$newsletter = Newsletter::createOrUpdate($data);
|
||||||
|
$errors = $newsletter->getErrors();
|
||||||
|
|
||||||
if($newsletter !== false && !$newsletter->id()) {
|
if(!empty($errors)) {
|
||||||
$errors = $newsletter->getValidationErrors();
|
return array(
|
||||||
|
'result' => false,
|
||||||
|
'errors' => $errors
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$result = true;
|
|
||||||
|
|
||||||
if(!empty($segment_ids)) {
|
if(!empty($segment_ids)) {
|
||||||
NewsletterSegment::where('newsletter_id', $newsletter->id)
|
NewsletterSegment::where('newsletter_id', $newsletter->id)
|
||||||
->deleteMany();
|
->deleteMany();
|
||||||
@ -86,132 +75,66 @@ class Newsletters {
|
|||||||
NewsletterOption::where('newsletter_id', $newsletter->id)
|
NewsletterOption::where('newsletter_id', $newsletter->id)
|
||||||
->deleteMany();
|
->deleteMany();
|
||||||
|
|
||||||
$optionFields = NewsletterOptionField::where(
|
$option_fields = NewsletterOptionField::where(
|
||||||
'newsletter_type',
|
'newsletter_type',
|
||||||
$data['type']
|
$data['type']
|
||||||
)->findArray();
|
)->findArray();
|
||||||
|
|
||||||
foreach($optionFields as $optionField) {
|
foreach($option_fields as $option_field) {
|
||||||
if(isset($options[$optionField['name']])) {
|
if(isset($options[$option_field['name']])) {
|
||||||
$relation = NewsletterOption::create();
|
$relation = NewsletterOption::create();
|
||||||
$relation->newsletter_id = $newsletter->id;
|
$relation->newsletter_id = $newsletter->id;
|
||||||
$relation->option_field_id = $optionField['id'];
|
$relation->option_field_id = $option_field['id'];
|
||||||
$relation->value = $options[$optionField['name']];
|
$relation->value = $options[$option_field['name']];
|
||||||
$relation->save();
|
$relation->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
wp_send_json(array(
|
|
||||||
'result' => $result,
|
|
||||||
'errors' => $errors
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore($id) {
|
function restore($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if($newsletter !== false) {
|
if($newsletter !== false) {
|
||||||
$result = $newsletter->restore();
|
$newsletter->restore();
|
||||||
}
|
}
|
||||||
|
return ($newsletter->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($id) {
|
function trash($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if($newsletter !== false) {
|
if($newsletter !== false) {
|
||||||
$result = $newsletter->trash();
|
$newsletter->trash();
|
||||||
}
|
}
|
||||||
|
return ($newsletter->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if($newsletter !== false) {
|
if($newsletter !== false) {
|
||||||
$newsletter->delete();
|
$newsletter->delete();
|
||||||
$result = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function duplicate($id) {
|
function duplicate($id = false) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if($newsletter !== false) {
|
if($newsletter !== false) {
|
||||||
$data = array(
|
return $newsletter->duplicate(array(
|
||||||
'subject' => sprintf(__('Copy of %s'), $newsletter->subject)
|
'subject' => sprintf(__('Copy of %s'), $newsletter->subject)
|
||||||
);
|
))->asArray();
|
||||||
$result = $newsletter->duplicate($data)->asArray();
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
wp_send_json($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function send($data = array()) {
|
|
||||||
$newsletter = Newsletter::findOne($data['id'])->asArray();
|
|
||||||
|
|
||||||
if(empty($data['segments'])) {
|
|
||||||
return wp_send_json(array(
|
|
||||||
'errors' => array(
|
|
||||||
__("You need to select a list.")
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$segments = Segment::whereIdIn($data['segments'])->findMany();
|
|
||||||
$subscribers = array();
|
|
||||||
foreach($segments as $segment) {
|
|
||||||
$segment_subscribers = $segment->subscribers()->findMany();
|
|
||||||
foreach($segment_subscribers as $segment_subscriber) {
|
|
||||||
$subscribers[$segment_subscriber->email] = $segment_subscriber
|
|
||||||
->asArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(empty($subscribers)) {
|
|
||||||
return wp_send_json(array(
|
|
||||||
'errors' => array(
|
|
||||||
__("No subscribers found.")
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: TO REMOVE once we add the columns from/reply_to
|
|
||||||
$newsletter = array_merge($newsletter, $data['newsletter']);
|
|
||||||
// END - TO REMOVE
|
|
||||||
|
|
||||||
$renderer = new Renderer(json_decode($newsletter['body'], true));
|
|
||||||
$newsletter['body'] = $renderer->render();
|
|
||||||
|
|
||||||
$subscribers = Subscriber::find_array();
|
|
||||||
$fromEmail = Setting::where('name', 'from_address')->findOne()->value;
|
|
||||||
$fromName = Setting::where('name', 'from_name')->findOne()->value;
|
|
||||||
$apiKey = Setting::where('name', 'api_key')->findOne()->value;
|
|
||||||
$mailer = new MailPoet($apiKey, $fromEmail, $fromName);
|
|
||||||
|
|
||||||
foreach ($subscribers as $subscriber) {
|
|
||||||
$result = $mailer->send(
|
|
||||||
$newsletter,
|
|
||||||
sprintf('%s %s <%s>', $subscriber['first_name'], $subscriber['last_name'], $subscriber['email'])
|
|
||||||
);
|
|
||||||
if ($result !== true) wp_send_json(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function render($data = array()) {
|
function render($data = array()) {
|
||||||
if(!isset($data['body'])) {
|
if(!isset($data['body'])) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
}
|
}
|
||||||
$renderer = new Renderer($data);
|
$renderer = new Renderer($data);
|
||||||
$rendered_newsletter = $renderer->render();
|
$rendered_newsletter = $renderer->render();
|
||||||
@ -220,7 +143,7 @@ class Newsletters {
|
|||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
$rendered_newsletter = $shortcodes->replace();
|
$rendered_newsletter = $shortcodes->replace();
|
||||||
wp_send_json(array('rendered_body' => $rendered_newsletter));
|
return array('rendered_body' => $rendered_newsletter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPreview($data = array()) {
|
function sendPreview($data = array()) {
|
||||||
@ -228,15 +151,15 @@ class Newsletters {
|
|||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
|
|
||||||
if($newsletter === false) {
|
if($newsletter === false) {
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => false
|
'result' => false
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
if(empty($data['subscriber'])) {
|
if(empty($data['subscriber'])) {
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => false,
|
'result' => false,
|
||||||
'errors' => array(__('Please specify receiver information')),
|
'errors' => array(__('Please specify receiver information'))
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$newsletter = $newsletter->asArray();
|
$newsletter = $newsletter->asArray();
|
||||||
@ -264,15 +187,14 @@ class Newsletters {
|
|||||||
$sender = false,
|
$sender = false,
|
||||||
$reply_to = false
|
$reply_to = false
|
||||||
);
|
);
|
||||||
|
$result = $mailer->send($newsletter, $data['subscriber']);
|
||||||
|
|
||||||
wp_send_json(array(
|
return array('result' => $result);
|
||||||
'result' => $mailer->send($newsletter, $data['subscriber'])
|
|
||||||
));
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => false,
|
'result' => false,
|
||||||
'errors' => array($e->getMessage()),
|
'errors' => array($e->getMessage()),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +222,7 @@ class Newsletters {
|
|||||||
$item['queue'] = ($queue !== false) ? $queue->asArray() : null;
|
$item['queue'] = ($queue !== false) ? $queue->asArray() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($listing_data);
|
return $listing_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bulkAction($data = array()) {
|
function bulkAction($data = array()) {
|
||||||
@ -308,46 +230,54 @@ class Newsletters {
|
|||||||
'\MailPoet\Models\Newsletter',
|
'\MailPoet\Models\Newsletter',
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
wp_send_json($bulk_action->apply());
|
return $bulk_action->apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
function create($data = array()) {
|
function create($data = array()) {
|
||||||
$newsletter = Newsletter::create();
|
$options = array();
|
||||||
$newsletter->type = $data['type'];
|
|
||||||
$newsletter->subject = $data['subject'];
|
|
||||||
$newsletter->body = '{}';
|
|
||||||
|
|
||||||
// try to load template data
|
|
||||||
$template_id = (!empty($data['template']) ? (int)$data['template'] : 0);
|
|
||||||
$template = NewsletterTemplate::findOne($template_id);
|
|
||||||
if($template !== false) {
|
|
||||||
$newsletter->body = $template->body;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($data['options'])) {
|
if(isset($data['options'])) {
|
||||||
$options = $data['options'];
|
$options = $data['options'];
|
||||||
unset($data['options']);
|
unset($data['options']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $newsletter->save();
|
$newsletter = Newsletter::createOrUpdate($data);
|
||||||
if($result !== true) {
|
|
||||||
wp_send_json($newsletter->getValidationErrors());
|
// try to load template data
|
||||||
|
$template_id = (!empty($data['template']) ? (int)$data['template'] : false);
|
||||||
|
$template = NewsletterTemplate::findOne($template_id);
|
||||||
|
if($template !== false) {
|
||||||
|
$newsletter->body = $template->body;
|
||||||
|
} else {
|
||||||
|
$newsletter->body = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$newsletter->save();
|
||||||
|
$errors = $newsletter->getErrors();
|
||||||
|
if(!empty($errors)) {
|
||||||
|
return array(
|
||||||
|
'result' => false,
|
||||||
|
'errors' =>$errors
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if(!empty($options)) {
|
if(!empty($options)) {
|
||||||
$optionFields = NewsletterOptionField::where('newsletter_type', $newsletter->type)->findArray();
|
$option_fields = NewsletterOptionField::where(
|
||||||
|
'newsletter_type', $newsletter->type
|
||||||
|
)->findArray();
|
||||||
|
|
||||||
foreach($optionFields as $optionField) {
|
foreach($option_fields as $option_field) {
|
||||||
if(isset($options[$optionField['name']])) {
|
if(isset($options[$option_field['name']])) {
|
||||||
$relation = NewsletterOption::create();
|
$relation = NewsletterOption::create();
|
||||||
$relation->newsletter_id = $newsletter->id;
|
$relation->newsletter_id = $newsletter->id;
|
||||||
$relation->option_field_id = $optionField['id'];
|
$relation->option_field_id = $option_field['id'];
|
||||||
$relation->value = $options[$optionField['name']];
|
$relation->value = $options[$option_field['name']];
|
||||||
$relation->save();
|
$relation->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$newsletter->body = json_decode($newsletter->body);
|
return array(
|
||||||
wp_send_json($newsletter->asArray());
|
'result' => true,
|
||||||
|
'newsletter' => $newsletter->asArray()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ class Permissions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function set($permissions = array()) {
|
function set($permissions = array()) {
|
||||||
$result = \MailPoet\Util\Permissions::set($permissions);
|
return \MailPoet\Util\Permissions::set($permissions);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,12 @@ class Segments {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($id = false) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
|
||||||
|
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if($segment === false) {
|
if($segment === false) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
wp_send_json($segment->asArray());
|
return $segment->asArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +62,7 @@ class Segments {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($listing_data);
|
return $listing_data;
|
||||||
}
|
|
||||||
|
|
||||||
function getAll() {
|
|
||||||
$collection = Segment::findArray();
|
|
||||||
wp_send_json($collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
@ -83,44 +76,35 @@ class Segments {
|
|||||||
} else {
|
} else {
|
||||||
$result = true;
|
$result = true;
|
||||||
}
|
}
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => $result,
|
'result' => $result,
|
||||||
'errors' => $errors
|
'errors' => $errors
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore($id) {
|
function restore($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
$result = $segment->restore();
|
$segment->restore();
|
||||||
}
|
}
|
||||||
|
return ($segment->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($id) {
|
function trash($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
$result = $segment->trash();
|
$segment->trash();
|
||||||
}
|
}
|
||||||
|
return ($segment->getErrors() === false);
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
$segment->delete();
|
$segment->delete();
|
||||||
$result = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
wp_send_json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function duplicate($id) {
|
function duplicate($id) {
|
||||||
@ -134,13 +118,13 @@ class Segments {
|
|||||||
$result = $segment->duplicate($data)->asArray();
|
$result = $segment->duplicate($data)->asArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($result);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function synchronize() {
|
function synchronize() {
|
||||||
$result = WP::synchronizeUsers();
|
$result = WP::synchronizeUsers();
|
||||||
|
|
||||||
wp_send_json($result);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bulkAction($data = array()) {
|
function bulkAction($data = array()) {
|
||||||
@ -149,6 +133,6 @@ class Segments {
|
|||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
||||||
wp_send_json($bulk_action->apply());
|
return $bulk_action->apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@ class Settings {
|
|||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
$settings = Setting::getAll();
|
$settings = Setting::getAll();
|
||||||
wp_send_json($settings);
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set($settings = array()) {
|
function set($settings = array()) {
|
||||||
if(empty($settings)) {
|
if(empty($settings)) {
|
||||||
wp_send_json(false);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
foreach($settings as $name => $value) {
|
foreach($settings as $name => $value) {
|
||||||
Setting::setValue($name, $value);
|
Setting::setValue($name, $value);
|
||||||
}
|
}
|
||||||
wp_send_json(true);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ class Setup {
|
|||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$result = false;
|
$result = false;
|
||||||
}
|
}
|
||||||
wp_send_json(array(
|
return array(
|
||||||
'result' => $result
|
'result' => $result
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,7 @@ class Subscribers {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($id = false) {
|
||||||
$id = (isset($data['id']) ? (int) $data['id'] : 0);
|
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if($subscriber !== false && $subscriber->id() > 0) {
|
if($subscriber !== false && $subscriber->id() > 0) {
|
||||||
$segments = $subscriber->segments()->findArray();
|
$segments = $subscriber->segments()->findArray();
|
||||||
@ -58,35 +56,30 @@ class Subscribers {
|
|||||||
return $listing_data;
|
return $listing_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAll() {
|
|
||||||
return Subscriber::findArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$errors = array();
|
|
||||||
$result = false;
|
|
||||||
$segment_ids = array();
|
$segment_ids = array();
|
||||||
|
|
||||||
if(array_key_exists('segments', $data)) {
|
if(isset($data['segments'])) {
|
||||||
$segment_ids = (array)$data['segments'];
|
$segment_ids = (array)$data['segments'];
|
||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscriber = Subscriber::createOrUpdate($data);
|
$subscriber = Subscriber::createOrUpdate($data);
|
||||||
|
$errors = $subscriber->getErrors();
|
||||||
|
|
||||||
if($subscriber !== false && !$subscriber->id()) {
|
if(!empty($errors)) {
|
||||||
$errors = $subscriber->getValidationErrors();
|
return array(
|
||||||
|
'result' => false,
|
||||||
|
'errors' => $errors
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$result = true;
|
|
||||||
|
|
||||||
if(!empty($segment_ids)) {
|
if(!empty($segment_ids)) {
|
||||||
$subscriber->addToSegments($segment_ids);
|
$subscriber->addToSegments($segment_ids);
|
||||||
}
|
}
|
||||||
|
return array(
|
||||||
|
'result' => true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return array(
|
|
||||||
'result' => $result,
|
|
||||||
'errors' => $errors
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribe($data = array()) {
|
function subscribe($data = array()) {
|
||||||
@ -193,37 +186,28 @@ class Subscribers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restore($id) {
|
function restore($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if($subscriber !== false) {
|
if($subscriber !== false) {
|
||||||
$result = $subscriber->restore();
|
$subscriber->restore();
|
||||||
}
|
}
|
||||||
|
return ($subscriber->getErrors() === false);
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($id) {
|
function trash($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if($subscriber !== false) {
|
if($subscriber !== false) {
|
||||||
$result = $subscriber->trash();
|
$subscriber->trash();
|
||||||
}
|
}
|
||||||
|
return ($subscriber->getErrors() === false);
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if($subscriber !== false) {
|
if($subscriber !== false) {
|
||||||
$subscriber->delete();
|
$subscriber->delete();
|
||||||
$result = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bulkAction($data = array()) {
|
function bulkAction($data = array()) {
|
||||||
|
@ -61,10 +61,10 @@ class WP {
|
|||||||
$segment = Segment::getWPUsers();
|
$segment = Segment::getWPUsers();
|
||||||
|
|
||||||
// count WP users
|
// count WP users
|
||||||
$users_count = \count_users()['total_users'];
|
$users_count = \count_users();
|
||||||
$linked_subscribers_count = $segment->subscribers()->count();
|
$linked_subscribers_count = $segment->subscribers()->count();
|
||||||
|
|
||||||
if($users_count !== $linked_subscribers_count) {
|
if($users_count['total_users'] !== $linked_subscribers_count) {
|
||||||
$linked_subscribers = Subscriber::select('wp_user_id')
|
$linked_subscribers = Subscriber::select('wp_user_id')
|
||||||
->whereNotNull('wp_user_id')
|
->whereNotNull('wp_user_id')
|
||||||
->findArray();
|
->findArray();
|
||||||
|
@ -16,7 +16,7 @@ class Import {
|
|||||||
public $subscribers_count;
|
public $subscribers_count;
|
||||||
public $import_time;
|
public $import_time;
|
||||||
public $profiler_start;
|
public $profiler_start;
|
||||||
|
|
||||||
public function __construct($data) {
|
public function __construct($data) {
|
||||||
$this->subscribers_data = $data['subscribers'];
|
$this->subscribers_data = $data['subscribers'];
|
||||||
$this->segments = $data['segments'];
|
$this->segments = $data['segments'];
|
||||||
@ -31,7 +31,7 @@ class Import {
|
|||||||
$this->import_time = date('Y-m-d H:i:s');
|
$this->import_time = date('Y-m-d H:i:s');
|
||||||
$this->profiler_start = microtime(true);
|
$this->profiler_start = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function process() {
|
function process() {
|
||||||
$subscriber_fields = $this->subscriber_fields;
|
$subscriber_fields = $this->subscriber_fields;
|
||||||
$subscriber_custom_fields = $this->subscriber_custom_fields;
|
$subscriber_custom_fields = $this->subscriber_custom_fields;
|
||||||
@ -89,7 +89,7 @@ class Import {
|
|||||||
'profiler' => $this->timeExecution()
|
'profiler' => $this->timeExecution()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterExistingAndNewSubscribers($subscribers_data) {
|
function filterExistingAndNewSubscribers($subscribers_data) {
|
||||||
$existing_records = array_filter(
|
$existing_records = array_filter(
|
||||||
array_map(function($subscriber_emails) {
|
array_map(function($subscriber_emails) {
|
||||||
@ -126,7 +126,7 @@ class Import {
|
|||||||
}, $new_records);
|
}, $new_records);
|
||||||
}, $subscribers_data)
|
}, $subscribers_data)
|
||||||
);
|
);
|
||||||
|
|
||||||
$existing_subscribers =
|
$existing_subscribers =
|
||||||
array_map(function($subscriber) use ($new_records) {
|
array_map(function($subscriber) use ($new_records) {
|
||||||
return array_values( // reindex array
|
return array_values( // reindex array
|
||||||
@ -142,7 +142,7 @@ class Import {
|
|||||||
$new_subscribers
|
$new_subscribers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteExistingTrashedSubscribers($subscribers_data) {
|
function deleteExistingTrashedSubscribers($subscribers_data) {
|
||||||
$existing_trashed_records = array_filter(
|
$existing_trashed_records = array_filter(
|
||||||
array_map(function($subscriber_emails) {
|
array_map(function($subscriber_emails) {
|
||||||
@ -161,7 +161,7 @@ class Import {
|
|||||||
->deleteMany();
|
->deleteMany();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function extendSubscribersAndFields($subscribers_data, $subscriber_fields) {
|
function extendSubscribersAndFields($subscribers_data, $subscriber_fields) {
|
||||||
$subscribers_data['created_at'] = $this->filterSubscriberCreatedAtDate();
|
$subscribers_data['created_at'] = $this->filterSubscriberCreatedAtDate();
|
||||||
$subscriber_fields[] = 'created_at';
|
$subscriber_fields[] = 'created_at';
|
||||||
@ -170,7 +170,7 @@ class Import {
|
|||||||
$subscriber_fields
|
$subscriber_fields
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubscriberFields($subscriber_fields) {
|
function getSubscriberFields($subscriber_fields) {
|
||||||
return array_values(
|
return array_values(
|
||||||
array_filter(
|
array_filter(
|
||||||
@ -180,7 +180,7 @@ class Import {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCustomSubscriberFields($subscriber_fields) {
|
function getCustomSubscriberFields($subscriber_fields) {
|
||||||
return array_values(
|
return array_values(
|
||||||
array_filter(
|
array_filter(
|
||||||
@ -190,11 +190,11 @@ class Import {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterSubscriberCreatedAtDate() {
|
function filterSubscriberCreatedAtDate() {
|
||||||
return array_fill(0, $this->subscribers_count, $this->import_time);
|
return array_fill(0, $this->subscribers_count, $this->import_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterSubscriberStatus($subscribers_data, $subscriber_fields) {
|
function filterSubscriberStatus($subscribers_data, $subscriber_fields) {
|
||||||
if(!in_array('status', $subscriber_fields)) {
|
if(!in_array('status', $subscriber_fields)) {
|
||||||
$subscribers_data['status'] =
|
$subscribers_data['status'] =
|
||||||
@ -242,7 +242,7 @@ class Import {
|
|||||||
$subscriber_fields
|
$subscriber_fields
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOrUpdateSubscribers(
|
function createOrUpdateSubscribers(
|
||||||
$action,
|
$action,
|
||||||
$subscribers_data,
|
$subscribers_data,
|
||||||
@ -295,7 +295,7 @@ class Import {
|
|||||||
);
|
);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOrUpdateCustomFields(
|
function createOrUpdateCustomFields(
|
||||||
$action,
|
$action,
|
||||||
$db_subscribers,
|
$db_subscribers,
|
||||||
@ -318,8 +318,8 @@ class Import {
|
|||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
}, $count, $subscribers_data[$column]);
|
}, $count, $subscribers_data[$column]);
|
||||||
}, $subscriber_custom_fields)[0];
|
}, $subscriber_custom_fields);
|
||||||
foreach(array_chunk($subscribers, 200) as $data) {
|
foreach(array_chunk($subscribers[0], 200) as $data) {
|
||||||
if($action === 'create') {
|
if($action === 'create') {
|
||||||
SubscriberCustomField::createMultiple(
|
SubscriberCustomField::createMultiple(
|
||||||
$data
|
$data
|
||||||
@ -332,13 +332,13 @@ class Import {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSubscribersToSegments($subscribers, $segments) {
|
function addSubscribersToSegments($subscribers, $segments) {
|
||||||
foreach(array_chunk($subscribers, 200) as $data) {
|
foreach(array_chunk($subscribers, 200) as $data) {
|
||||||
SubscriberSegment::createMultiple($segments, $data);
|
SubscriberSegment::createMultiple($segments, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeExecution() {
|
function timeExecution() {
|
||||||
$profiler_end = microtime(true);
|
$profiler_end = microtime(true);
|
||||||
return ($profiler_end - $this->profiler_start) / 60;
|
return ($profiler_end - $this->profiler_start) / 60;
|
||||||
|
16
mailpoet.php
16
mailpoet.php
@ -1,12 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
use \MailPoet\Config\Initializer;
|
|
||||||
use \MailPoet\Config\Migrator;
|
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
use \MailPoet\Config\Initializer;
|
||||||
/*
|
/*
|
||||||
* Plugin Name: MailPoet
|
* Plugin Name: MailPoet
|
||||||
* Version: 0.0.13
|
* Version: 0.0.14
|
||||||
* Plugin URI: http://www.mailpoet.com
|
* Plugin URI: http://www.mailpoet.com
|
||||||
* Description: MailPoet Newsletters.
|
* Description: MailPoet Newsletters.
|
||||||
* Author: MailPoet
|
* Author: MailPoet
|
||||||
@ -24,16 +22,10 @@ if(!defined('ABSPATH')) exit;
|
|||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
define('MAILPOET_VERSION', '0.0.13');
|
define('MAILPOET_VERSION', '0.0.14');
|
||||||
|
|
||||||
$initializer = new Initializer(array(
|
$initializer = new Initializer(array(
|
||||||
'file' => __FILE__,
|
'file' => __FILE__,
|
||||||
'version' => MAILPOET_VERSION
|
'version' => MAILPOET_VERSION
|
||||||
));
|
));
|
||||||
|
$initializer->init();
|
||||||
$migrator = new Migrator();
|
|
||||||
|
|
||||||
register_activation_hook(__FILE__, array($migrator, 'up'));
|
|
||||||
register_activation_hook(__FILE__, array($initializer, 'runPopulator'));
|
|
||||||
|
|
||||||
add_action('init', array($initializer, 'init'));
|
|
||||||
|
@ -9,6 +9,7 @@ $console->writeln('Loading WP core... ('.$wp_load_file.')');
|
|||||||
$console->writeln('Cleaning up database...');
|
$console->writeln('Cleaning up database...');
|
||||||
$models = array(
|
$models = array(
|
||||||
'CustomField',
|
'CustomField',
|
||||||
|
'Form',
|
||||||
'Newsletter',
|
'Newsletter',
|
||||||
'NewsletterSegment',
|
'NewsletterSegment',
|
||||||
'NewsletterTemplate',
|
'NewsletterTemplate',
|
||||||
|
@ -94,6 +94,7 @@ class MailerCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanSend() {
|
function itCanSend() {
|
||||||
|
if(getenv('WP_TEST_MAILER_ENABLE_SENDING') !== 'true') return;
|
||||||
$mailer = new Mailer($this->mailer, $this->sender, $this->reply_to);
|
$mailer = new Mailer($this->mailer, $this->sender, $this->reply_to);
|
||||||
expect($mailer->send($this->newsletter, $this->subscriber))->true();
|
expect($mailer->send($this->newsletter, $this->subscriber))->true();
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ class CustomFieldCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->saved)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveName() {
|
function itCanHaveName() {
|
||||||
@ -42,14 +43,18 @@ class CustomFieldCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveParams() {
|
function itCanHaveParams() {
|
||||||
expect(unserialize($this->customField->params))->equals($this->data['params']);
|
expect($this->customField->params)->equals($this->data['params']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
$empty_model = CustomField::create();
|
$invalid_custom_field = CustomField::create();
|
||||||
expect($empty_model->save())->notEquals(true);
|
|
||||||
$validations = $empty_model->getValidationErrors();
|
$result = $invalid_custom_field->save();
|
||||||
expect(count($validations))->equals(2);
|
$errors = $result->getErrors();
|
||||||
|
|
||||||
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
|
expect($errors[1])->equals('You need to specify a type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
|
@ -14,15 +14,17 @@ class FormCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->saved)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->saved)->equals(true);
|
$invalid_form = Form::create();
|
||||||
$empty_model = Form::create();
|
$result = $invalid_form->save();
|
||||||
expect($empty_model->save())->notEquals(true);
|
$errors = $result->getErrors();
|
||||||
$validations = $empty_model->getValidationErrors();
|
|
||||||
expect(count($validations))->equals(1);
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
|
@ -11,19 +11,20 @@ class NewsletterCest {
|
|||||||
$this->before_time = time();
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'subject' => 'new newsletter',
|
'subject' => 'new newsletter',
|
||||||
'body' => 'body',
|
|
||||||
'type' => 'standard',
|
'type' => 'standard',
|
||||||
|
'body' => 'body',
|
||||||
'preheader' => 'preheader'
|
'preheader' => 'preheader'
|
||||||
);
|
);
|
||||||
|
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->hydrate($this->data);
|
$newsletter->hydrate($this->data);
|
||||||
$this->newsletter = $newsletter;
|
$this->newsletter = $newsletter;
|
||||||
$this->result = $newsletter->save();
|
$this->saved = $newsletter->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->result)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasSubject() {
|
function itHasSubject() {
|
||||||
@ -77,10 +78,11 @@ class NewsletterCest {
|
|||||||
$is_created = Newsletter::createOrUpdate(
|
$is_created = Newsletter::createOrUpdate(
|
||||||
array(
|
array(
|
||||||
'subject' => 'new newsletter',
|
'subject' => 'new newsletter',
|
||||||
|
'type' => 'standard',
|
||||||
'body' => 'body'
|
'body' => 'body'
|
||||||
));
|
));
|
||||||
expect($is_created)->notEquals(false);
|
expect($is_created->id() > 0)->true();
|
||||||
expect($is_created->getValidationErrors())->isEmpty();
|
expect($is_created->getErrors())->false();
|
||||||
|
|
||||||
$newsletter = Newsletter::where('subject', 'new newsletter')
|
$newsletter = Newsletter::where('subject', 'new newsletter')
|
||||||
->findOne();
|
->findOne();
|
||||||
@ -89,8 +91,7 @@ class NewsletterCest {
|
|||||||
$is_updated = Newsletter::createOrUpdate(
|
$is_updated = Newsletter::createOrUpdate(
|
||||||
array(
|
array(
|
||||||
'id' => $newsletter->id,
|
'id' => $newsletter->id,
|
||||||
'subject' => 'updated newsletter',
|
'subject' => 'updated newsletter'
|
||||||
'body' => 'body'
|
|
||||||
));
|
));
|
||||||
$newsletter = Newsletter::findOne($newsletter->id);
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
expect($newsletter->subject)->equals('updated newsletter');
|
expect($newsletter->subject)->equals('updated newsletter');
|
||||||
@ -100,6 +101,7 @@ class NewsletterCest {
|
|||||||
Newsletter::createOrUpdate(
|
Newsletter::createOrUpdate(
|
||||||
array(
|
array(
|
||||||
'subject' => 'search for "pineapple"',
|
'subject' => 'search for "pineapple"',
|
||||||
|
'type' => 'standard',
|
||||||
'body' => 'body'
|
'body' => 'body'
|
||||||
));
|
));
|
||||||
$newsletter = Newsletter::filter('search', 'pineapple')
|
$newsletter = Newsletter::filter('search', 'pineapple')
|
||||||
|
@ -9,19 +9,21 @@ class NewsletterOptionFieldCest {
|
|||||||
$this->before_time = time();
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'name' => 'Event',
|
'name' => 'Event',
|
||||||
'newsletter_type' => 'welcome',
|
'newsletter_type' => 'welcome'
|
||||||
);
|
);
|
||||||
$this->optionField = NewsletterOptionField::create();
|
$this->option_field = NewsletterOptionField::create();
|
||||||
$this->optionField->hydrate($this->data);
|
$this->option_field->hydrate($this->data);
|
||||||
$this->saved = $this->optionField->save();
|
$this->saved = $this->option_field->save();
|
||||||
$this->newslettersData = array(
|
$this->newsletter_data = array(
|
||||||
array(
|
array(
|
||||||
'subject' => 'Test newsletter 1',
|
'subject' => 'Test newsletter 1',
|
||||||
|
'type' => 'standard',
|
||||||
'preheader' => '',
|
'preheader' => '',
|
||||||
'body' => '{}'
|
'body' => '{}'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'subject' => 'Test newsletter 2',
|
'subject' => 'Test newsletter 2',
|
||||||
|
'type' => 'standard',
|
||||||
'preheader' => 'A newsletter',
|
'preheader' => 'A newsletter',
|
||||||
'body' => '{}'
|
'body' => '{}'
|
||||||
)
|
)
|
||||||
@ -29,89 +31,92 @@ class NewsletterOptionFieldCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->saved)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasName() {
|
function itHasName() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($optionField->name)->equals($this->data['name']);
|
expect($option_field->name)->equals($this->data['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasNewsletterType() {
|
function itHasNewsletterType() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($optionField->newsletter_type)->equals($this->data['newsletter_type']);
|
expect($option_field->newsletter_type)->equals($this->data['newsletter_type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->saved)->equals(true);
|
$invalid_newsletter_option = NewsletterOptionField::create();
|
||||||
$empty_model = NewsletterOptionField::create();
|
$result = $invalid_newsletter_option->save();
|
||||||
expect($empty_model->save())->notEquals(true);
|
$errors = $result->getErrors();
|
||||||
$validations = $empty_model->getValidationErrors();
|
|
||||||
expect(count($validations))->equals(2);
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
|
expect($errors[1])->equals('You need to specify a newsletter type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($optionField->created_at) >= $this->before_time;
|
$time_difference = strtotime($option_field->created_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAnUpdatedAtOnCreation() {
|
function itHasAnUpdatedAtOnCreation() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($optionField->updated_at) >= $this->before_time;
|
$time_difference = strtotime($option_field->updated_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itKeepsTheCreatedAtOnUpdate() {
|
function itKeepsTheCreatedAtOnUpdate() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$old_created_at = $optionField->created_at;
|
$old_created_at = $option_field->created_at;
|
||||||
$optionField->name = 'new name';
|
$option_field->name = 'new name';
|
||||||
$optionField->save();
|
$option_field->save();
|
||||||
expect($old_created_at)->equals($optionField->created_at);
|
expect($old_created_at)->equals($option_field->created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||||
$optionField = NewsletterOptionField::where('name', $this->data['name'])
|
$option_field = NewsletterOptionField::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$update_time = time();
|
$update_time = time();
|
||||||
$optionField->name = 'new name';
|
$option_field->name = 'new name';
|
||||||
$optionField->save();
|
$option_field->save();
|
||||||
$time_difference = strtotime($optionField->updated_at) >= $update_time;
|
$time_difference = strtotime($option_field->updated_at) >= $update_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveManyNewsletters() {
|
function itCanHaveManyNewsletters() {
|
||||||
foreach ($this->newslettersData as $data) {
|
foreach($this->newsletter_data as $data) {
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->hydrate($data);
|
$newsletter->hydrate($data);
|
||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
$association = NewsletterOption::create();
|
$association = NewsletterOption::create();
|
||||||
$association->newsletter_id = $newsletter->id;
|
$association->newsletter_id = $newsletter->id;
|
||||||
$association->option_field_id = $this->optionField->id;
|
$association->option_field_id = $this->option_field->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
}
|
}
|
||||||
$optionField = NewsletterOptionField::findOne($this->optionField->id);
|
$option_field = NewsletterOptionField::findOne($this->option_field->id);
|
||||||
$newsletters = $optionField->newsletters()
|
$newsletters = $option_field->newsletters()
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(count($newsletters))->equals(2);
|
expect(count($newsletters))->equals(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanStoreOptionValue() {
|
function itCanStoreOptionValue() {
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->hydrate($this->newslettersData[0]);
|
$newsletter->hydrate($this->newsletter_data[0]);
|
||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
$association = NewsletterOption::create();
|
$association = NewsletterOption::create();
|
||||||
$association->newsletter_id = $newsletter->id;
|
$association->newsletter_id = $newsletter->id;
|
||||||
$association->option_field_id = $this->optionField->id;
|
$association->option_field_id = $this->option_field->id;
|
||||||
$association->value = 'list';
|
$association->value = 'list';
|
||||||
$association->save();
|
$association->save();
|
||||||
$optionField = NewsletterOptionField::findOne($this->optionField->id);
|
$option_field = NewsletterOptionField::findOne($this->option_field->id);
|
||||||
$newsletter = $optionField->newsletters()
|
$newsletter = $option_field->newsletters()
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($newsletter->value)->equals($association->value);
|
expect($newsletter->value)->equals($association->value);
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,27 @@ class NewsletterTemplateCest {
|
|||||||
$this->data = array(
|
$this->data = array(
|
||||||
'name' => 'Some template',
|
'name' => 'Some template',
|
||||||
'description' => 'My nice template',
|
'description' => 'My nice template',
|
||||||
'body' => '{content: {}, globalStyles: {}}',
|
'body' => '{}',
|
||||||
);
|
);
|
||||||
|
|
||||||
$template = NewsletterTemplate::create();
|
$template = NewsletterTemplate::create();
|
||||||
$template->hydrate($this->data);
|
$template->hydrate($this->data);
|
||||||
$this->result = $template->save();
|
$this->saved = $template->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->result)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
$empty_model = NewsletterTemplate::create();
|
$invalid_newsletter_template = NewsletterTemplate::create();
|
||||||
expect($empty_model->save())->notEquals(true);
|
$result = $invalid_newsletter_template->save();
|
||||||
$validations = $empty_model->getValidationErrors();
|
$errors = $result->getErrors();
|
||||||
expect(count($validations))->equals(2);
|
|
||||||
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
|
expect($errors[1])->equals('Template body cannot be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasName() {
|
function itHasName() {
|
||||||
@ -46,25 +50,28 @@ class NewsletterTemplateCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanCreateOrUpdate() {
|
function itCanCreateOrUpdate() {
|
||||||
$is_created = NewsletterTemplate::createOrUpdate(
|
$created_template = NewsletterTemplate::createOrUpdate(
|
||||||
array(
|
array(
|
||||||
'name' => 'Another template',
|
'name' => 'Another template',
|
||||||
'description' => 'Another template description',
|
'description' => 'Another template description',
|
||||||
'body' => '{content: {}, globalStyles: {}}',
|
'body' => '{content: {}, globalStyles: {}}',
|
||||||
));
|
));
|
||||||
expect($is_created)->equals(true);
|
expect($created_template->id() > 0)->true();
|
||||||
|
expect($created_template->getErrors())->false();
|
||||||
|
|
||||||
$template = NewsletterTemplate::where('name', 'Another template')
|
$template = NewsletterTemplate::where('name', 'Another template')
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($template->name)->equals('Another template');
|
expect($template->name)->equals('Another template');
|
||||||
|
|
||||||
$is_updated = NewsletterTemplate::createOrUpdate(
|
$updated_template = NewsletterTemplate::createOrUpdate(
|
||||||
array(
|
array(
|
||||||
'id' => $template->id,
|
'id' => $template->id,
|
||||||
'name' => 'Another template updated',
|
'name' => 'Another template updated',
|
||||||
'body' => '{}'
|
'body' => '{}'
|
||||||
));
|
));
|
||||||
expect($is_updated)->equals(true);
|
expect($updated_template->id() > 0)->true();
|
||||||
|
expect($updated_template->getErrors())->false();
|
||||||
|
|
||||||
$template = NewsletterTemplate::findOne($template->id);
|
$template = NewsletterTemplate::findOne($template->id);
|
||||||
expect($template->name)->equals('Another template updated');
|
expect($template->name)->equals('Another template updated');
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class SegmentCest {
|
|||||||
'name' => 'some name',
|
'name' => 'some name',
|
||||||
'description' => 'some description'
|
'description' => 'some description'
|
||||||
);
|
);
|
||||||
$this->subscribersData = array(
|
$this->subscribers_data = array(
|
||||||
array(
|
array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Mailer',
|
'last_name' => 'Mailer',
|
||||||
@ -27,21 +27,22 @@ class SegmentCest {
|
|||||||
'email' => 'mike@maipoet.com'
|
'email' => 'mike@maipoet.com'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->newslettersData = array(
|
$this->newsletters_data = array(
|
||||||
array(
|
array(
|
||||||
'subject' => 'My first newsletter'
|
'subject' => 'My first newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'subject' => 'My second newsletter'
|
'subject' => 'My second newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->segment = Segment::create();
|
$this->segment = Segment::createOrUpdate($this->data);
|
||||||
$this->segment->hydrate($this->data);
|
|
||||||
$this->saved = $this->segment->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->saved)->equals(true);
|
expect($this->segment->id() > 0)->true();
|
||||||
|
expect($this->segment->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveName() {
|
function itCanHaveName() {
|
||||||
@ -51,7 +52,11 @@ class SegmentCest {
|
|||||||
function nameMustBeUnique() {
|
function nameMustBeUnique() {
|
||||||
$segment = Segment::create();
|
$segment = Segment::create();
|
||||||
$segment->hydrate($this->data);
|
$segment->hydrate($this->data);
|
||||||
expect($segment->save())->contains('Duplicate');
|
$result = $segment->save();
|
||||||
|
$errors = $result->getErrors();
|
||||||
|
|
||||||
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->contains('Duplicate');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveDescription() {
|
function itCanHaveDescription() {
|
||||||
@ -59,11 +64,13 @@ class SegmentCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->saved)->equals(true);
|
$invalid_segment = Segment::create();
|
||||||
$empty_model = Segment::create();
|
|
||||||
expect($empty_model->save())->notEquals(true);
|
$result = $invalid_segment->save();
|
||||||
$validations = $empty_model->getValidationErrors();
|
$errors = $result->getErrors();
|
||||||
expect(count($validations))->equals(1);
|
|
||||||
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
@ -101,10 +108,10 @@ class SegmentCest {
|
|||||||
|
|
||||||
function itCanCreateOrUpdate() {
|
function itCanCreateOrUpdate() {
|
||||||
$is_created = Segment::createOrUpdate(array(
|
$is_created = Segment::createOrUpdate(array(
|
||||||
'name' => 'new list'
|
'name' => 'new list'
|
||||||
));
|
));
|
||||||
expect($is_created)->notEquals(false);
|
expect($is_created->id() > 0)->true();
|
||||||
expect($is_created->getValidationErrors())->isEmpty();
|
expect($is_created->getErrors())->false();
|
||||||
|
|
||||||
$segment = Segment::where('name', 'new list')
|
$segment = Segment::where('name', 'new list')
|
||||||
->findOne();
|
->findOne();
|
||||||
@ -121,9 +128,9 @@ class SegmentCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveManySubscribers() {
|
function itCanHaveManySubscribers() {
|
||||||
foreach ($this->subscribersData as $subscriberData) {
|
foreach($this->subscribers_data as $subscriber_data) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate($subscriberData);
|
$subscriber->hydrate($subscriber_data);
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$association = SubscriberSegment::create();
|
$association = SubscriberSegment::create();
|
||||||
$association->subscriber_id = $subscriber->id;
|
$association->subscriber_id = $subscriber->id;
|
||||||
@ -138,9 +145,9 @@ class SegmentCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveManyNewsletters() {
|
function itCanHaveManyNewsletters() {
|
||||||
foreach ($this->newslettersData as $newsletterData) {
|
foreach($this->newsletters_data as $newsletter_data) {
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->hydrate($newsletterData);
|
$newsletter->hydrate($newsletter_data);
|
||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
$association = NewsletterSegment::create();
|
$association = NewsletterSegment::create();
|
||||||
$association->newsletter_id = $newsletter->id;
|
$association->newsletter_id = $newsletter->id;
|
||||||
@ -155,9 +162,9 @@ class SegmentCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsWithSubscriberCount() {
|
function itCanGetSegmentsWithSubscriberCount() {
|
||||||
foreach ($this->subscribersData as $subscriberData) {
|
foreach($this->subscribers_data as $subscriber_data) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate($subscriberData);
|
$subscriber->hydrate($subscriber_data);
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$association = SubscriberSegment::create();
|
$association = SubscriberSegment::create();
|
||||||
$association->subscriber_id = $subscriber->id;
|
$association->subscriber_id = $subscriber->id;
|
||||||
@ -169,9 +176,9 @@ class SegmentCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsForExport() {
|
function itCanGetSegmentsForExport() {
|
||||||
foreach ($this->subscribersData as $index => $subscriberData) {
|
foreach($this->subscribers_data as $index => $subscriber_data) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate($subscriberData);
|
$subscriber->hydrate($subscriber_data);
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
if(!$index) {
|
if(!$index) {
|
||||||
$association = SubscriberSegment::create();
|
$association = SubscriberSegment::create();
|
||||||
|
@ -11,19 +11,21 @@ class SettingCest {
|
|||||||
|
|
||||||
$setting = Setting::create();
|
$setting = Setting::create();
|
||||||
$setting->hydrate($this->data);
|
$setting->hydrate($this->data);
|
||||||
$this->result = $setting->save();
|
$this->saved = $setting->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->result)->equals(true);
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->result)->equals(true);
|
$invalid_setting = Setting::create();
|
||||||
$empty_model = Setting::create();
|
$result = $invalid_setting->save();
|
||||||
expect($empty_model->save())->notEquals(true);
|
$errors = $result->getErrors();
|
||||||
$validations = $empty_model->getValidationErrors();
|
|
||||||
expect(count($validations))->equals(2);
|
expect(is_array($errors))->true();
|
||||||
|
expect($errors[0])->equals('You need to specify a name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
@ -65,18 +67,20 @@ class SettingCest {
|
|||||||
'value' => 'data'
|
'value' => 'data'
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = Setting::createOrUpdate($data);
|
$created_setting = Setting::createOrUpdate($data);
|
||||||
expect($result)->equals(true);
|
expect($created_setting->id() > 0)->true();
|
||||||
$record = Setting::where('name', $data['name'])
|
expect($created_setting->getErrors())->false();
|
||||||
->find_one();
|
|
||||||
expect($record->value)->equals($data['value']);
|
$setting = Setting::where('name', $data['name'])->findOne();
|
||||||
|
expect($setting->value)->equals($data['value']);
|
||||||
|
|
||||||
$data['value'] = 'new data';
|
$data['value'] = 'new data';
|
||||||
$result = Setting::createOrUpdate($data);
|
$updated_setting = Setting::createOrUpdate($data);
|
||||||
expect($result)->equals(true);
|
expect($updated_setting->id() > 0)->true();
|
||||||
$record = Setting::where('name', $data['name'])
|
expect($updated_setting->getErrors())->false();
|
||||||
->find_one();
|
|
||||||
expect($record->value)->equals('new data');
|
$setting = Setting::where('name', $data['name'])->findOne();
|
||||||
|
expect($setting->value)->equals('new data');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetAndSetValue() {
|
function itCanGetAndSetValue() {
|
||||||
|
@ -20,7 +20,8 @@ class SubscriberCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
expect($this->saved)->true();
|
expect($this->saved->id() > 0)->true();
|
||||||
|
expect($this->saved->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasFirstName() {
|
function itHasFirstName() {
|
||||||
@ -62,14 +63,13 @@ class SubscriberCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanChangeStatus() {
|
function itCanChangeStatus() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])->findOne();
|
||||||
->findOne();
|
|
||||||
$subscriber->status = 'subscribed';
|
$subscriber->status = 'subscribed';
|
||||||
expect($subscriber->save())->equals(true);
|
$subscriber->save();
|
||||||
$subscriber_updated = Subscriber::where(
|
|
||||||
'email',
|
expect($subscriber->id() > 0)->true();
|
||||||
$this->data['email']
|
expect($subscriber->getErrors())->false();
|
||||||
)
|
$subscriber_updated = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($subscriber_updated->status)->equals('subscribed');
|
expect($subscriber_updated->status)->equals('subscribed');
|
||||||
}
|
}
|
||||||
@ -89,91 +89,78 @@ class SubscriberCest {
|
|||||||
function itHasGroupFilter() {
|
function itHasGroupFilter() {
|
||||||
$subscribers = Subscriber::filter('groupBy', 'unconfirmed')
|
$subscribers = Subscriber::filter('groupBy', 'unconfirmed')
|
||||||
->findMany();
|
->findMany();
|
||||||
foreach ($subscribers as $subscriber) {
|
foreach($subscribers as $subscriber) {
|
||||||
expect($subscriber->status)->equals('unconfirmed');
|
expect($subscriber->status)->equals('unconfirmed');
|
||||||
}
|
}
|
||||||
$subscribers = Subscriber::filter('groupBy', 'subscribed')
|
$subscribers = Subscriber::filter('groupBy', 'subscribed')
|
||||||
->findMany();
|
->findMany();
|
||||||
foreach ($subscribers as $subscriber) {
|
foreach($subscribers as $subscriber) {
|
||||||
expect($subscriber->status)->equals('subscribed');
|
expect($subscriber->status)->equals('subscribed');
|
||||||
}
|
}
|
||||||
$subscribers = Subscriber::filter('groupBy', 'unsubscribed')
|
$subscribers = Subscriber::filter('groupBy', 'unsubscribed')
|
||||||
->findMany();
|
->findMany();
|
||||||
foreach ($subscribers as $subscriber) {
|
foreach($subscribers as $subscriber) {
|
||||||
expect($subscriber->status)->equals('unsubscribed');
|
expect($subscriber->status)->equals('unsubscribed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveSegment() {
|
function itCanHaveSegment() {
|
||||||
$segmentData = array(
|
$segment = Segment::createOrUpdate(array(
|
||||||
'name' => 'some name'
|
'name' => 'some name'
|
||||||
);
|
));
|
||||||
$segment = Segment::create();
|
expect($segment->getErrors())->false();
|
||||||
$segment->hydrate($segmentData);
|
|
||||||
$segment->save();
|
|
||||||
$association = SubscriberSegment::create();
|
$association = SubscriberSegment::create();
|
||||||
$association->subscriber_id = $this->subscriber->id;
|
$association->subscriber_id = $this->subscriber->id;
|
||||||
$association->segment_id = $segment->id;
|
$association->segment_id = $segment->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($this->subscriber->id);
|
$subscriber = Subscriber::findOne($this->subscriber->id);
|
||||||
$subscriberSegment = $subscriber->segments()
|
|
||||||
->findOne();
|
$subscriber_segment = $subscriber->segments()->findOne();
|
||||||
expect($subscriberSegment->id)->equals($segment->id);
|
expect($subscriber_segment->id)->equals($segment->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanHaveCustomFields() {
|
function itCanHaveCustomFields() {
|
||||||
$customFieldData = array(
|
$custom_field = CustomField::createOrUpdate(array(
|
||||||
'name' => 'DOB',
|
'name' => 'DOB',
|
||||||
'type' => 'date',
|
'type' => 'date',
|
||||||
);
|
));
|
||||||
$customField = CustomField::create();
|
|
||||||
$customField->hydrate($customFieldData);
|
|
||||||
$customField->save();
|
|
||||||
$association = SubscriberCustomField::create();
|
$association = SubscriberCustomField::create();
|
||||||
$association->subscriber_id = $this->subscriber->id;
|
$association->subscriber_id = $this->subscriber->id;
|
||||||
$association->custom_field_id = $customField->id;
|
$association->custom_field_id = $custom_field->id;
|
||||||
$association->value = '12/12/2012';
|
$association->value = '12/12/2012';
|
||||||
$association->save();
|
$association->save();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->findOne($this->subscriber->id);
|
->findOne($this->subscriber->id);
|
||||||
expect($subscriber->DOB)->equals($association->value);
|
expect($subscriber->DOB)->equals($association->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanFilterCustomFields() {
|
function itCanFilterCustomFields() {
|
||||||
$customFieldData = array(
|
$cf_city = CustomField::createOrUpdate(array(
|
||||||
array(
|
'name' => 'City',
|
||||||
'name' => 'City',
|
'type' => 'text'
|
||||||
'type' => 'text',
|
));
|
||||||
),
|
|
||||||
array(
|
SubscriberCustomField::createOrUpdate(array(
|
||||||
'name' => 'Country',
|
'subscriber_id' => $this->subscriber->id,
|
||||||
'type' => 'text',
|
'custom_field_id' => $cf_city->id,
|
||||||
)
|
'value' => 'Paris'
|
||||||
);
|
));
|
||||||
foreach ($customFieldData as $data) {
|
|
||||||
$customField = CustomField::create();
|
$cf_country = CustomField::createOrUpdate(array(
|
||||||
$customField->hydrate($data);
|
'name' => 'Country',
|
||||||
$customField->save();
|
'type' => 'text'
|
||||||
$createdCustomFields[] = $customField->asArray();
|
));
|
||||||
}
|
|
||||||
$subscriberCustomFieldData = array(
|
SubscriberCustomField::createOrUpdate(array(
|
||||||
array(
|
'subscriber_id' => $this->subscriber->id,
|
||||||
'subscriber_id' => $this->subscriber->id,
|
'custom_field_id' => $cf_country->id,
|
||||||
'custom_field_id' => $createdCustomFields[0]['id'],
|
'value' => 'France'
|
||||||
'value' => 'Paris'
|
));
|
||||||
),
|
|
||||||
array(
|
|
||||||
'subscriber_id' => $this->subscriber->id,
|
|
||||||
'custom_field_id' => $createdCustomFields[1]['id'],
|
|
||||||
'value' => 'France'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
foreach ($subscriberCustomFieldData as $data) {
|
|
||||||
$association = SubscriberCustomField::create();
|
|
||||||
$association->hydrate($data);
|
|
||||||
$association->save();
|
|
||||||
$createdAssociations[] = $association->asArray();
|
|
||||||
}
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -196,6 +183,7 @@ class SubscriberCest {
|
|||||||
))
|
))
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->false();
|
expect(empty($subscriber))->false();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -209,6 +197,7 @@ class SubscriberCest {
|
|||||||
), 'OR')
|
), 'OR')
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->false();
|
expect(empty($subscriber))->false();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -218,6 +207,7 @@ class SubscriberCest {
|
|||||||
), 'AND', 'LIKE')
|
), 'AND', 'LIKE')
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->false();
|
expect(empty($subscriber))->false();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -227,6 +217,7 @@ class SubscriberCest {
|
|||||||
))
|
))
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->true();
|
expect(empty($subscriber))->true();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -240,6 +231,7 @@ class SubscriberCest {
|
|||||||
))
|
))
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->true();
|
expect(empty($subscriber))->true();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -253,6 +245,7 @@ class SubscriberCest {
|
|||||||
), 'OR')
|
), 'OR')
|
||||||
->findArray();
|
->findArray();
|
||||||
expect(empty($subscriber))->true();
|
expect(empty($subscriber))->true();
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
$subscriber = Subscriber::filter('filterWithCustomFields')
|
||||||
->filter('filterSearchCustomFields', array(
|
->filter('filterSearchCustomFields', array(
|
||||||
array(
|
array(
|
||||||
@ -271,8 +264,8 @@ class SubscriberCest {
|
|||||||
'last_name' => 'Doe'
|
'last_name' => 'Doe'
|
||||||
);
|
);
|
||||||
$result = Subscriber::createOrUpdate($data);
|
$result = Subscriber::createOrUpdate($data);
|
||||||
expect($result)->notEquals(false);
|
expect($result->id() > 0)->true();
|
||||||
expect($result->getValidationErrors())->isEmpty();
|
expect($result->getErrors())->false();
|
||||||
|
|
||||||
$record = Subscriber::where('email', $data['email'])
|
$record = Subscriber::where('email', $data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
|
@ -20,7 +20,9 @@ class SubscriberCustomFieldCest {
|
|||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$subscriberCustomField = SubscriberCustomField::create();
|
$subscriberCustomField = SubscriberCustomField::create();
|
||||||
$subscriberCustomField->hydrate($this->data[0]);
|
$subscriberCustomField->hydrate($this->data[0]);
|
||||||
expect($subscriberCustomField->save())->true();
|
$subscriberCustomField->save();
|
||||||
|
expect($subscriberCustomField->id() > 0)->true();
|
||||||
|
expect($subscriberCustomField->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanCreateOrUpdateMultipleRecords() {
|
function itCanCreateOrUpdateMultipleRecords() {
|
||||||
|
172
tests/unit/Router/FormsCest.php
Normal file
172
tests/unit/Router/FormsCest.php
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\Forms;
|
||||||
|
use \MailPoet\Models\Form;
|
||||||
|
use \MailPoet\Models\Segment;
|
||||||
|
|
||||||
|
class FormsCest {
|
||||||
|
function _before() {
|
||||||
|
Form::createOrUpdate(array('name' => 'Form 1'));
|
||||||
|
Form::createOrUpdate(array('name' => 'Form 2'));
|
||||||
|
Form::createOrUpdate(array('name' => 'Form 3'));
|
||||||
|
Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||||
|
Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetAForm() {
|
||||||
|
$form = Form::where('name', 'Form 1')->findOne();
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
|
||||||
|
$response = $router->get(/* missing id */);
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get('not_an_id');
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get($form->id);
|
||||||
|
expect($response['id'])->equals($form->id);
|
||||||
|
expect($response['name'])->equals($form->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetListingData() {
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->listing();
|
||||||
|
expect($response)->hasKey('filters');
|
||||||
|
expect($response)->hasKey('groups');
|
||||||
|
expect($response['count'])->equals(3);
|
||||||
|
expect($response['items'])->count(3);
|
||||||
|
expect($response['items'][0]['name'])->equals('Form 1');
|
||||||
|
expect($response['items'][1]['name'])->equals('Form 2');
|
||||||
|
expect($response['items'][2]['name'])->equals('Form 3');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanCreateANewForm() {
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->create();
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['form_id'] > 0)->true();
|
||||||
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
|
$created_form = Form::findOne($response['form_id']);
|
||||||
|
expect($created_form->name)->equals('New form');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveAForm() {
|
||||||
|
$form_data = array(
|
||||||
|
'name' => 'My first form'
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->save(/* missing data */);
|
||||||
|
expect($response['result'])->false();
|
||||||
|
expect($response['errors'][0])->equals('You need to specify a name.');
|
||||||
|
|
||||||
|
$response = $router->save($form_data);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['form_id'] > 0)->true();
|
||||||
|
|
||||||
|
$form = Form::where('name', 'My first form')->findOne();
|
||||||
|
expect($form->id)->equals($response['form_id']);
|
||||||
|
expect($form->name)->equals('My first form');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanPreviewAForm() {
|
||||||
|
$router = new Forms();
|
||||||
|
|
||||||
|
$response = $router->create();
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['form_id'] > 0)->true();
|
||||||
|
|
||||||
|
$form = Form::findOne($response['form_id']);
|
||||||
|
$response = $router->previewEditor($form->asArray());
|
||||||
|
expect($response['html'])->notEmpty();
|
||||||
|
expect($response['css'])->notEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanExportAForm() {
|
||||||
|
$router = new Forms();
|
||||||
|
|
||||||
|
$response = $router->create();
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['form_id'] > 0)->true();
|
||||||
|
|
||||||
|
$response = $router->exportsEditor($response['form_id']);
|
||||||
|
expect($response['html'])->notEmpty();
|
||||||
|
expect($response['php'])->notEmpty();
|
||||||
|
expect($response['iframe'])->notEmpty();
|
||||||
|
expect($response['shortcode'])->notEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveFormEditor() {
|
||||||
|
$router = new Forms();
|
||||||
|
|
||||||
|
$response = $router->create();
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['form_id'] > 0)->true();
|
||||||
|
|
||||||
|
$form = Form::findOne($response['form_id'])->asArray();
|
||||||
|
$form['name'] = 'Updated form';
|
||||||
|
|
||||||
|
$response = $router->saveEditor($form);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['is_widget'])->false();
|
||||||
|
|
||||||
|
$saved_form = Form::findOne($form['id']);
|
||||||
|
expect($saved_form->name)->equals('Updated form');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanRestoreAForm() {
|
||||||
|
$form = Form::where('name', 'Form 1')->findOne();
|
||||||
|
$form->trash();
|
||||||
|
|
||||||
|
$trashed_form = Form::findOne($form->id);
|
||||||
|
expect($trashed_form->deleted_at)->notNull();
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->restore($form->id);
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$restored_form = Form::findOne($form->id);
|
||||||
|
expect($restored_form->deleted_at)->null();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanTrashAForm() {
|
||||||
|
$form = Form::where('name', 'Form 1')->findOne();
|
||||||
|
expect($form->deleted_at)->null();
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->trash($form->id);
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$trashed_form = Form::findOne($form->id);
|
||||||
|
expect($trashed_form->deleted_at)->notNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDeleteAForm() {
|
||||||
|
$form = Form::where('name', 'Form 2')->findOne();
|
||||||
|
expect($form->deleted_at)->null();
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->delete($form->id);
|
||||||
|
expect($response)->equals(1);
|
||||||
|
|
||||||
|
$deleted_form = Form::findOne($form->id);
|
||||||
|
expect($deleted_form)->false();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDuplicateAForm() {
|
||||||
|
$form = Form::where('name', 'Form 3')->findOne();
|
||||||
|
|
||||||
|
$router = new Forms();
|
||||||
|
$response = $router->duplicate($form->id);
|
||||||
|
expect($response['name'])->equals('Copy of '.$form->name);
|
||||||
|
|
||||||
|
$duplicated_form = Form::findOne($response['id']);
|
||||||
|
expect($duplicated_form->name)->equals('Copy of '.$form->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
Form::deleteMany();
|
||||||
|
Segment::deleteMany();
|
||||||
|
}
|
||||||
|
}
|
82
tests/unit/Router/NewsletterTemplatesCest.php
Normal file
82
tests/unit/Router/NewsletterTemplatesCest.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\NewsletterTemplates;
|
||||||
|
use \MailPoet\Models\NewsletterTemplate;
|
||||||
|
|
||||||
|
class NewsletterTemplatesCest {
|
||||||
|
function _before() {
|
||||||
|
NewsletterTemplate::createOrUpdate(array(
|
||||||
|
'name' => 'Template #1',
|
||||||
|
'description' => 'My First Template',
|
||||||
|
'body' => '{"key1": "value1"}'
|
||||||
|
));
|
||||||
|
|
||||||
|
NewsletterTemplate::createOrUpdate(array(
|
||||||
|
'name' => 'Template #2',
|
||||||
|
'description' => 'My Second Template',
|
||||||
|
'body' => '{"key2": "value2"}'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetANewsletterTemplate() {
|
||||||
|
$template = NewsletterTemplate::where('name', 'Template #1')->findOne();
|
||||||
|
|
||||||
|
$router = new NewsletterTemplates();
|
||||||
|
$response = $router->get(/* missing id */);
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get('not_an_id');
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get($template->id());
|
||||||
|
expect($response['name'])->equals('Template #1');
|
||||||
|
expect($response['body']['key1'])->equals('value1');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function itCanGetAllNewsletterTemplates() {
|
||||||
|
$templates = NewsletterTemplate::findArray();
|
||||||
|
|
||||||
|
$router = new NewsletterTemplates();
|
||||||
|
$response = $router->getAll();
|
||||||
|
expect($response)->count(2);
|
||||||
|
|
||||||
|
expect($response[0]['name'])->equals('Template #1');
|
||||||
|
expect($response[0]['body']['key1'])->equals('value1');
|
||||||
|
|
||||||
|
expect($response[1]['name'])->equals('Template #2');
|
||||||
|
expect($response[1]['body']['key2'])->equals('value2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveANewsletterTemplate() {
|
||||||
|
$template_data = array(
|
||||||
|
'name' => 'Template #3',
|
||||||
|
'description' => 'My Third Template',
|
||||||
|
'body' => '{"key3": "value3"}'
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new NewsletterTemplates();
|
||||||
|
$response = $router->save($template_data);
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$template = NewsletterTemplate::where('name', 'Template #3')->findOne();
|
||||||
|
expect($template->name)->equals('Template #3');
|
||||||
|
expect($template->description)->equals('My Third Template');
|
||||||
|
expect($template->body)->equals('{"key3": "value3"}');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDeleteANewsletterTemplate() {
|
||||||
|
$template = NewsletterTemplate::where('name', 'Template #2')->findOne();
|
||||||
|
expect($template->deleted_at)->null();
|
||||||
|
|
||||||
|
$router = new NewsletterTemplates();
|
||||||
|
$response = $router->delete($template->id());
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$deleted_template = NewsletterTemplate::findOne($template->id());
|
||||||
|
expect($deleted_template)->false();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
NewsletterTemplate::deleteMany();
|
||||||
|
}
|
||||||
|
}
|
208
tests/unit/Router/NewslettersCest.php
Normal file
208
tests/unit/Router/NewslettersCest.php
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\Newsletters;
|
||||||
|
use \MailPoet\Models\Newsletter;
|
||||||
|
use \MailPoet\Models\NewsletterSegment;
|
||||||
|
use \MailPoet\Models\NewsletterTemplate;
|
||||||
|
use \MailPoet\Models\Segment;
|
||||||
|
|
||||||
|
class NewslettersCest {
|
||||||
|
function _before() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetANewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
|
||||||
|
$response = $router->get($newsletter->id());
|
||||||
|
|
||||||
|
expect($response['id'])->equals($newsletter->id());
|
||||||
|
|
||||||
|
$response = $router->get('not_an_id');
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get(/* missing argument */);
|
||||||
|
expect($response)->false();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveANewNewsletter() {
|
||||||
|
$valid_data = array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->save($valid_data);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
|
$invalid_data = array(
|
||||||
|
'subject' => 'Missing newsletter type'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $router->save($invalid_data);
|
||||||
|
expect($response['result'])->false();
|
||||||
|
expect($response['errors'][0])->equals('You need to specify a type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveAnExistingNewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$newsletter_data = $newsletter->asArray();
|
||||||
|
$newsletter_data['subject'] = 'My Updated Newsletter';
|
||||||
|
|
||||||
|
$response = $router->save($newsletter_data);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
|
||||||
|
$updated_newsletter = Newsletter::findOne($newsletter->id());
|
||||||
|
expect($updated_newsletter->subject)->equals('My Updated Newsletter');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanRestoreANewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$newsletter->trash();
|
||||||
|
|
||||||
|
expect($newsletter->deleted_at)->notNull();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$router->restore($newsletter->id());
|
||||||
|
|
||||||
|
$restored_subscriber = Newsletter::findOne($newsletter->id());
|
||||||
|
expect($restored_subscriber->deleted_at)->null();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanTrashANewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->trash($newsletter->id());
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$trashed_subscriber = Newsletter::findOne($newsletter->id());
|
||||||
|
expect($trashed_subscriber->deleted_at)->notNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDeleteANewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->delete($newsletter->id());
|
||||||
|
expect($response)->equals(1);
|
||||||
|
|
||||||
|
expect(Newsletter::findOne($newsletter->id()))->false();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDuplicateANewsletter() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
expect($newsletter->id() > 0)->true();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->duplicate($newsletter->id());
|
||||||
|
expect($response['subject'])->equals('Copy of My First Newsletter');
|
||||||
|
expect($response['type'])->equals('standard');
|
||||||
|
expect($response['body'])->equals($newsletter->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanCreateANewsletter() {
|
||||||
|
$data = array(
|
||||||
|
'subject' => 'My New Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
);
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->create($data);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
expect($response['newsletter']['id'] > 0)->true();
|
||||||
|
expect($response['newsletter']['subject'])->equals('My New Newsletter');
|
||||||
|
expect($response['newsletter']['type'])->equals('standard');
|
||||||
|
expect($response['newsletter']['body'])->equals(array());
|
||||||
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
|
$response = $router->create();
|
||||||
|
expect($response['result'])->false();
|
||||||
|
expect($response['errors'][0])->equals('You need to specify a type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetListingData() {
|
||||||
|
$segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||||
|
$segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
|
||||||
|
$newsletter_1 = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My First Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
$newsletter_2 = Newsletter::createOrUpdate(array(
|
||||||
|
'subject' => 'My Second Newsletter',
|
||||||
|
'type' => 'standard'
|
||||||
|
));
|
||||||
|
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $newsletter_1->id(),
|
||||||
|
'segment_id' => $segment_1->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $newsletter_1->id(),
|
||||||
|
'segment_id' => $segment_2->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
$newsletter_segment = NewsletterSegment::create();
|
||||||
|
$newsletter_segment->hydrate(array(
|
||||||
|
'newsletter_id' => $newsletter_2->id(),
|
||||||
|
'segment_id' => $segment_2->id()
|
||||||
|
));
|
||||||
|
$newsletter_segment->save();
|
||||||
|
|
||||||
|
$router = new Newsletters();
|
||||||
|
$response = $router->listing(array('sort'));
|
||||||
|
|
||||||
|
expect($response)->hasKey('filters');
|
||||||
|
expect($response)->hasKey('groups');
|
||||||
|
|
||||||
|
expect($response['count'])->equals(2);
|
||||||
|
expect($response['items'])->count(2);
|
||||||
|
|
||||||
|
expect($response['items'][0]['subject'])->equals('My First Newsletter');
|
||||||
|
expect($response['items'][1]['subject'])->equals('My Second Newsletter');
|
||||||
|
expect($response['items'][0]['segments'])->equals(array(
|
||||||
|
$segment_1->id(),
|
||||||
|
$segment_2->id()
|
||||||
|
));
|
||||||
|
expect($response['items'][1]['segments'])->equals(array(
|
||||||
|
$segment_2->id()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
Newsletter::deleteMany();
|
||||||
|
Segment::deleteMany();
|
||||||
|
}
|
||||||
|
}
|
111
tests/unit/Router/SegmentsCest.php
Normal file
111
tests/unit/Router/SegmentsCest.php
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\Segments;
|
||||||
|
use \MailPoet\Models\Segment;
|
||||||
|
|
||||||
|
class SegmentsCest {
|
||||||
|
function _before() {
|
||||||
|
Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||||
|
Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||||
|
Segment::createOrUpdate(array('name' => 'Segment 3'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetASegment() {
|
||||||
|
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
|
||||||
|
$response = $router->get(/* missing id */);
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get('not_an_id');
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->get($segment->id());
|
||||||
|
expect($response['name'])->equals($segment->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetListingData() {
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->listing();
|
||||||
|
expect($response)->hasKey('filters');
|
||||||
|
expect($response)->hasKey('groups');
|
||||||
|
|
||||||
|
expect($response['count'])->equals(3);
|
||||||
|
expect($response['items'])->count(3);
|
||||||
|
|
||||||
|
expect($response['items'][0]['name'])->equals('Segment 1');
|
||||||
|
expect($response['items'][1]['name'])->equals('Segment 2');
|
||||||
|
expect($response['items'][2]['name'])->equals('Segment 3');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSaveASegment() {
|
||||||
|
$segment_data = array(
|
||||||
|
'name' => 'New Segment'
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->save(/* missing data */);
|
||||||
|
expect($response['result'])->false();
|
||||||
|
expect($response['errors'][0])->equals('You need to specify a name.');
|
||||||
|
|
||||||
|
$response = $router->save($segment_data);
|
||||||
|
expect($response['result'])->true();
|
||||||
|
|
||||||
|
$segment = Segment::where('name', 'New Segment')->findOne();
|
||||||
|
expect($segment->name)->equals($segment_data['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanRestoreASegment() {
|
||||||
|
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||||
|
$segment->trash();
|
||||||
|
|
||||||
|
$trashed_segment = Segment::findOne($segment->id());
|
||||||
|
expect($trashed_segment->deleted_at)->notNull();
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->restore($segment->id());
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$restored_segment = Segment::findOne($segment->id());
|
||||||
|
expect($restored_segment->deleted_at)->null();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanTrashASegment() {
|
||||||
|
$segment = Segment::where('name', 'Segment 1')->findOne();
|
||||||
|
expect($segment->deleted_at)->null();
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->trash($segment->id());
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$trashed_segment = Segment::findOne($segment->id());
|
||||||
|
expect($trashed_segment->deleted_at)->notNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDeleteASegment() {
|
||||||
|
$segment = Segment::where('name', 'Segment 2')->findOne();
|
||||||
|
expect($segment->deleted_at)->null();
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->delete($segment->id());
|
||||||
|
expect($response)->equals(1);
|
||||||
|
|
||||||
|
$deleted_segment = Segment::findOne($segment->id());
|
||||||
|
expect($deleted_segment)->false();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanDuplicateASegment() {
|
||||||
|
$segment = Segment::where('name', 'Segment 3')->findOne();
|
||||||
|
|
||||||
|
$router = new Segments();
|
||||||
|
$response = $router->duplicate($segment->id());
|
||||||
|
expect($response['name'])->equals('Copy of '.$segment->name);
|
||||||
|
|
||||||
|
$duplicated_segment = Segment::findOne($response['id']);
|
||||||
|
expect($duplicated_segment->name)->equals('Copy of '.$segment->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
ORM::forTable(Segment::$_table)->deleteMany();
|
||||||
|
}
|
||||||
|
}
|
50
tests/unit/Router/SettingsCest.php
Normal file
50
tests/unit/Router/SettingsCest.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\Settings;
|
||||||
|
use \MailPoet\Models\Setting;
|
||||||
|
|
||||||
|
class SettingsCest {
|
||||||
|
function _before() {
|
||||||
|
Setting::setValue('some.setting.key', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSettings() {
|
||||||
|
$router = new Settings();
|
||||||
|
|
||||||
|
$settings = $router->get();
|
||||||
|
expect($settings)->notEmpty();
|
||||||
|
expect($settings['some']['setting']['key'])->true();
|
||||||
|
|
||||||
|
Setting::deleteMany();
|
||||||
|
$settings = $router->get();
|
||||||
|
expect($settings)->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanSetSettings() {
|
||||||
|
$new_settings = array(
|
||||||
|
'some' => array(
|
||||||
|
'setting' => array(
|
||||||
|
'new_key' => true
|
||||||
|
),
|
||||||
|
'new_setting' => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$router = new Settings();
|
||||||
|
|
||||||
|
$response = $router->set(/* missing data */);
|
||||||
|
expect($response)->false();
|
||||||
|
|
||||||
|
$response = $router->set($new_settings);
|
||||||
|
expect($response)->true();
|
||||||
|
|
||||||
|
$settings = $router->get();
|
||||||
|
|
||||||
|
expect($settings['some']['setting'])->hasntKey('key');
|
||||||
|
expect($settings['some']['setting']['new_key'])->true();
|
||||||
|
expect($settings['some']['new_setting'])->true();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
ORM::forTable(Setting::$_table)->deleteMany();
|
||||||
|
}
|
||||||
|
}
|
22
tests/unit/Router/SetupCest.php
Normal file
22
tests/unit/Router/SetupCest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
use \MailPoet\Router\Setup;
|
||||||
|
use \MailPoet\Models\Setting;
|
||||||
|
|
||||||
|
class SetupCest {
|
||||||
|
function _before() {
|
||||||
|
Setting::setValue('signup_confirmation.enabled', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanReinstall() {
|
||||||
|
/*$router = new Setup();
|
||||||
|
$response = $router->reset();
|
||||||
|
expect($response['result'])->true();
|
||||||
|
|
||||||
|
$signup_confirmation = Setting::getValue('signup_confirmation.enabled');
|
||||||
|
expect($signup_confirmation)->true();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
Setting::deleteMany();
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,6 @@ use \MailPoet\Models\Segment;
|
|||||||
|
|
||||||
class SubscribersCest {
|
class SubscribersCest {
|
||||||
function _before() {
|
function _before() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetASubscriber() {
|
function itCanGetASubscriber() {
|
||||||
@ -17,31 +16,16 @@ class SubscribersCest {
|
|||||||
|
|
||||||
$router = new Subscribers();
|
$router = new Subscribers();
|
||||||
|
|
||||||
$response = $router->get(array('id' => $subscriber->id()));
|
$response = $router->get($subscriber->id());
|
||||||
expect($response['id'])->equals($subscriber->id());
|
expect($response['id'])->equals($subscriber->id());
|
||||||
|
|
||||||
$response = $router->get(array('id' => 'not_an_id'));
|
$response = $router->get('not_an_id');
|
||||||
expect($response)->false();
|
expect($response)->false();
|
||||||
|
|
||||||
$response = $router->get(/* missing argument */);
|
$response = $router->get(/* missing argument */);
|
||||||
expect($response)->false();
|
expect($response)->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetAllSubscribers(UnitTester $I) {
|
|
||||||
$I->generateSubscribers(10);
|
|
||||||
|
|
||||||
$router = new Subscribers();
|
|
||||||
$result = $router->getAll();
|
|
||||||
|
|
||||||
expect($result)->count(10);
|
|
||||||
|
|
||||||
$model = Subscriber::create();
|
|
||||||
foreach($result as $subscriber) {
|
|
||||||
expect($subscriber['id'] > 0)->true();
|
|
||||||
expect($subscriber['email'])->notEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function itCanSaveANewSubscriber() {
|
function itCanSaveANewSubscriber() {
|
||||||
$valid_data = array(
|
$valid_data = array(
|
||||||
'email' => 'john.doe@mailpoet.com',
|
'email' => 'john.doe@mailpoet.com',
|
||||||
@ -50,9 +34,13 @@ class SubscribersCest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$router = new Subscribers();
|
$router = new Subscribers();
|
||||||
|
|
||||||
$response = $router->save($valid_data);
|
$response = $router->save($valid_data);
|
||||||
expect($response['result'])->true();
|
expect($response['result'])->true();
|
||||||
|
expect($response)->hasntKey('errors');
|
||||||
|
|
||||||
|
$response = $router->save(/* missing data */);
|
||||||
|
expect($response['result'])->false();
|
||||||
|
expect($response['errors'][0])->equals('You need to enter your email address.');
|
||||||
|
|
||||||
$invalid_data = array(
|
$invalid_data = array(
|
||||||
'email' => 'john.doe@invalid',
|
'email' => 'john.doe@invalid',
|
||||||
|
@ -8,67 +8,76 @@ use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
|||||||
|
|
||||||
class BootStrapMenuCest {
|
class BootStrapMenuCest {
|
||||||
function _before() {
|
function _before() {
|
||||||
$this->segmentsData = array(
|
$segment_1 = Segment::createOrUpdate(array('name' => 'Unconfirmed Segment'));
|
||||||
array(
|
$segment_2 = Segment::createOrUpdate(array('name' => 'Confirmed Segment'));
|
||||||
'name' => 'first',
|
|
||||||
'description' => 'some description'
|
$subscriber_1 = Subscriber::createOrUpdate(array(
|
||||||
),
|
'first_name' => 'John',
|
||||||
array(
|
'last_name' => 'Mailer',
|
||||||
'name' => 'second',
|
'status' => 'unconfirmed',
|
||||||
'description' => 'some description'
|
'email' => 'john@mailpoet.com'
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$this->subscribersData = array(
|
$subscriber_2 = Subscriber::createOrUpdate(array(
|
||||||
array(
|
'first_name' => 'Mike',
|
||||||
'first_name' => 'John',
|
'last_name' => 'Smith',
|
||||||
'last_name' => 'Mailer',
|
'status' => 'subscribed',
|
||||||
'status' => 'unconfirmed',
|
'email' => 'mike@maipoet.com'
|
||||||
'email' => 'john@mailpoet.com'
|
));
|
||||||
),
|
|
||||||
array(
|
$association = SubscriberSegment::create();
|
||||||
'first_name' => 'Mike',
|
$association->subscriber_id = $subscriber_1->id;
|
||||||
'last_name' => 'Smith',
|
$association->segment_id = $segment_1->id;
|
||||||
'status' => 'subscribed',
|
$association->save();
|
||||||
'email' => 'mike@maipoet.com'
|
|
||||||
)
|
$association = SubscriberSegment::create();
|
||||||
);
|
$association->subscriber_id = $subscriber_2->id;
|
||||||
$this->customFieldsData = array(
|
$association->segment_id = $segment_2->id;
|
||||||
'name' => 'DOB',
|
$association->save();
|
||||||
'type' => 'date',
|
|
||||||
);
|
CustomField::createOrUpdate(array(
|
||||||
$customField = CustomField::create();
|
'name' => 'Birthday',
|
||||||
$customField->hydrate($this->customFieldsData);
|
'type' => 'date'
|
||||||
$customField->save();
|
));
|
||||||
|
|
||||||
$this->bootStrapImportMenu = new BootStrapMenu('import');
|
$this->bootStrapImportMenu = new BootStrapMenu('import');
|
||||||
$this->bootStrapExportMenu = new BootStrapMenu('export');
|
$this->bootStrapExportMenu = new BootStrapMenu('export');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsWithSubscriberCount() {
|
function itCanGetSegmentsWithSubscriberCount() {
|
||||||
// TOFIX.
|
|
||||||
/*$this->_createSegmentsAndSubscribers();
|
|
||||||
$segments = $this->bootStrapImportMenu->getSegments();
|
$segments = $this->bootStrapImportMenu->getSegments();
|
||||||
expect(count($segments))->equals(2);
|
expect(count($segments))->equals(2);
|
||||||
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
expect($segments[0]['name'])->equals('Unconfirmed Segment');
|
||||||
expect($segments[0]['subscriberCount'])->equals(1);
|
expect($segments[0]['subscriberCount'])->equals(1);
|
||||||
expect($segments[1]['subscriberCount'])->equals(1);*/
|
expect($segments[1]['name'])->equals('Confirmed Segment');
|
||||||
|
expect($segments[1]['subscriberCount'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsForImportWithoutTrashedSubscribers() {
|
function itCanGetPublicSegmentsForImport() {
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$segments = $this->bootStrapImportMenu->getSegments();
|
$segments = $this->bootStrapImportMenu->getSegments();
|
||||||
expect(count($segments))->equals(2);
|
expect(count($segments))->equals(2);
|
||||||
$subscriber = Subscriber::findOne(1);
|
|
||||||
$subscriber->deleted_at = date('Y-m-d H:i:s');
|
$subscriber = Subscriber::where(
|
||||||
$subscriber->save();
|
'email', 'john@mailpoet.com'
|
||||||
|
)->findOne();
|
||||||
|
expect($subscriber->deleted_at)->null();
|
||||||
|
$subscriber->trash();
|
||||||
|
|
||||||
|
$subscriber = Subscriber::where(
|
||||||
|
'email', 'john@mailpoet.com'
|
||||||
|
)->whereNull('deleted_at')->findOne();
|
||||||
|
expect($subscriber)->false();
|
||||||
|
|
||||||
$segments = $this->bootStrapImportMenu->getSegments();
|
$segments = $this->bootStrapImportMenu->getSegments();
|
||||||
expect(count($segments))->equals(1);
|
expect(count($segments))->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsForExportWithoutTrashedSubscribers() {
|
function itCanGetPublicSegmentsForExport() {
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$segments = $this->bootStrapExportMenu->getSegments();
|
$segments = $this->bootStrapExportMenu->getSegments();
|
||||||
expect(count($segments))->equals(2);
|
expect(count($segments))->equals(2);
|
||||||
$subscriber = Subscriber::findOne(1);
|
$subscriber = Subscriber::where('email', 'john@mailpoet.com')
|
||||||
|
->findOne();
|
||||||
$subscriber->deleted_at = date('Y-m-d H:i:s');
|
$subscriber->deleted_at = date('Y-m-d H:i:s');
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$segments = $this->bootStrapExportMenu->getSegments();
|
$segments = $this->bootStrapExportMenu->getSegments();
|
||||||
@ -76,21 +85,21 @@ class BootStrapMenuCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsForExport() {
|
function itCanGetSegmentsForExport() {
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$segments = $this->bootStrapExportMenu->getSegments();
|
$segments = $this->bootStrapExportMenu->getSegments();
|
||||||
expect(count($segments))->equals(2);
|
expect(count($segments))->equals(2);
|
||||||
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
|
||||||
|
expect($segments[0]['name'])->equals('Confirmed Segment');
|
||||||
expect($segments[0]['subscriberCount'])->equals(1);
|
expect($segments[0]['subscriberCount'])->equals(1);
|
||||||
|
expect($segments[1]['name'])->equals('Unconfirmed Segment');
|
||||||
expect($segments[1]['subscriberCount'])->equals(1);
|
expect($segments[1]['subscriberCount'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegmentsWithConfirmedSubscribersForExport() {
|
function itCanGetSegmentsWithConfirmedSubscribersForExport() {
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$segments = $this->bootStrapExportMenu->getSegments(
|
$segments = $this->bootStrapExportMenu->getSegments(
|
||||||
$withConfirmedSubscribers = true
|
$withConfirmedSubscribers = true
|
||||||
);
|
);
|
||||||
expect(count($segments))->equals(1);
|
expect(count($segments))->equals(1);
|
||||||
expect($segments[0]['name'])->equals($this->segmentsData[1]['name']);
|
expect($segments[0]['name'])->equals('Confirmed Segment');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSubscriberFields() {
|
function itCanGetSubscriberFields() {
|
||||||
@ -101,7 +110,7 @@ class BootStrapMenuCest {
|
|||||||
'last_name',
|
'last_name',
|
||||||
'status'
|
'status'
|
||||||
);
|
);
|
||||||
foreach ($fields as $field) {
|
foreach($fields as $field) {
|
||||||
expect(in_array($field, array_keys($subsriberFields)))->true();
|
expect(in_array($field, array_keys($subsriberFields)))->true();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +126,7 @@ class BootStrapMenuCest {
|
|||||||
'type',
|
'type',
|
||||||
'custom'
|
'custom'
|
||||||
);
|
);
|
||||||
foreach ($fields as $field) {
|
foreach($fields as $field) {
|
||||||
expect(in_array($field, array_keys($formattedSubscriberFields[0])))
|
expect(in_array($field, array_keys($formattedSubscriberFields[0])))
|
||||||
->true();
|
->true();
|
||||||
}
|
}
|
||||||
@ -129,7 +138,7 @@ class BootStrapMenuCest {
|
|||||||
$this->bootStrapImportMenu
|
$this->bootStrapImportMenu
|
||||||
->getSubscriberCustomFields();
|
->getSubscriberCustomFields();
|
||||||
expect($subscriberCustomFields[0]['type'])
|
expect($subscriberCustomFields[0]['type'])
|
||||||
->equals($this->customFieldsData['type']);
|
->equals('date');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanFormatSubsciberCustomFields() {
|
function itCanFormatSubsciberCustomFields() {
|
||||||
@ -143,7 +152,7 @@ class BootStrapMenuCest {
|
|||||||
'type',
|
'type',
|
||||||
'custom'
|
'custom'
|
||||||
);
|
);
|
||||||
foreach ($fields as $field) {
|
foreach($fields as $field) {
|
||||||
expect(in_array($field, array_keys($formattedSubscriberCustomFields[0])))
|
expect(in_array($field, array_keys($formattedSubscriberCustomFields[0])))
|
||||||
->true();
|
->true();
|
||||||
}
|
}
|
||||||
@ -241,10 +250,6 @@ class BootStrapMenuCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBootStrapImport() {
|
function itCanBootStrapImport() {
|
||||||
$customField = CustomField::create();
|
|
||||||
$customField->hydrate($this->customFieldsData);
|
|
||||||
$customField->save();
|
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$import = clone($this->bootStrapImportMenu);
|
$import = clone($this->bootStrapImportMenu);
|
||||||
$importMenu = $import->bootstrap();
|
$importMenu = $import->bootstrap();
|
||||||
expect(count(json_decode($importMenu['segments'], true)))
|
expect(count(json_decode($importMenu['segments'], true)))
|
||||||
@ -257,15 +262,11 @@ class BootStrapMenuCest {
|
|||||||
->equals(3);
|
->equals(3);
|
||||||
expect($importMenu['maxPostSize'])->equals(ini_get('post_max_size'));
|
expect($importMenu['maxPostSize'])->equals(ini_get('post_max_size'));
|
||||||
expect($importMenu['maxPostSizeBytes'])->equals(
|
expect($importMenu['maxPostSizeBytes'])->equals(
|
||||||
(int) ini_get('post_max_size') * 1048576
|
(int)ini_get('post_max_size') * 1048576
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBootStrapExport() {
|
function itCanBootStrapExport() {
|
||||||
$customField = CustomField::create();
|
|
||||||
$customField->hydrate($this->customFieldsData);
|
|
||||||
$customField->save();
|
|
||||||
$this->_createSegmentsAndSubscribers();
|
|
||||||
$export = clone($this->bootStrapImportMenu);
|
$export = clone($this->bootStrapImportMenu);
|
||||||
$exportMenu = $export->bootstrap();
|
$exportMenu = $export->bootstrap();
|
||||||
expect(count(json_decode($exportMenu['segments'], true)))
|
expect(count(json_decode($exportMenu['segments'], true)))
|
||||||
@ -275,27 +276,10 @@ class BootStrapMenuCest {
|
|||||||
->equals(3);
|
->equals(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _createSegmentsAndSubscribers() {
|
|
||||||
foreach ($this->segmentsData as $segmentData) {
|
|
||||||
$segment = Segment::create();
|
|
||||||
$segment->hydrate($segmentData);
|
|
||||||
$segment->save();
|
|
||||||
}
|
|
||||||
foreach ($this->subscribersData as $subscriberData) {
|
|
||||||
$subscriber = Subscriber::create();
|
|
||||||
$subscriber->hydrate($subscriberData);
|
|
||||||
$subscriber->save();
|
|
||||||
$association = SubscriberSegment::create();
|
|
||||||
$association->subscriber_id = $subscriber->id;
|
|
||||||
$association->segment_id = $subscriber->id;
|
|
||||||
$association->save();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
Subscriber::deleteMany();
|
||||||
ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
Segment::deleteMany();
|
||||||
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table);
|
SubscriberSegment::deleteMany();
|
||||||
ORM::raw_execute('TRUNCATE ' . CustomField::$_table);
|
CustomField::deleteMany();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -146,7 +146,7 @@ class ExportCest {
|
|||||||
expect($target)->equals(array($source->id => $source->name));
|
expect($target)->equals(array($source->id => $source->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanFormatsubscriber_fields() {
|
function itCanFormatSubscriberFields() {
|
||||||
$formatted_subscriber_fields = $this->export->formatSubscriberFields(
|
$formatted_subscriber_fields = $this->export->formatSubscriberFields(
|
||||||
array_keys($this->subscriber_fields),
|
array_keys($this->subscriber_fields),
|
||||||
$this->export->getSubscriberCustomFields()
|
$this->export->getSubscriberCustomFields()
|
||||||
|
@ -4,12 +4,16 @@ use MailPoet\Subscribers\ImportExport\Import\MailChimp;
|
|||||||
|
|
||||||
class MailChimpCest {
|
class MailChimpCest {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->APIKey = 'd91ae3861c4829c40bd469e40d6c0e7e-us6';
|
$this->APIKey = getenv('WP_TEST_IMPORT_MAILCHIMP_API') ?
|
||||||
|
getenv('WP_TEST_IMPORT_MAILCHIMP_API') :
|
||||||
|
'1234567890';
|
||||||
$this->mailChimp = new MailChimp($this->APIKey);
|
$this->mailChimp = new MailChimp($this->APIKey);
|
||||||
$this->lists = array(
|
$this->lists = getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS') ?
|
||||||
'edf74586e9',
|
explode(",", getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS')) :
|
||||||
'8b66f7fac8'
|
array(
|
||||||
);
|
'one',
|
||||||
|
'two'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetAPIKey() {
|
function itCanGetAPIKey() {
|
||||||
@ -24,6 +28,7 @@ class MailChimpCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itFailsWithIncorrectAPIKey() {
|
function itFailsWithIncorrectAPIKey() {
|
||||||
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$mailChimp = clone($this->mailChimp);
|
$mailChimp = clone($this->mailChimp);
|
||||||
$mailChimp->APIKey = false;
|
$mailChimp->APIKey = false;
|
||||||
$lists = $mailChimp->getLists();
|
$lists = $mailChimp->getLists();
|
||||||
@ -43,6 +48,7 @@ class MailChimpCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itFailsWithIncorrectLists() {
|
function itFailsWithIncorrectLists() {
|
||||||
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailChimp->getSubscribers();
|
$subscribers = $this->mailChimp->getSubscribers();
|
||||||
expect($subscribers['result'])->false();
|
expect($subscribers['result'])->false();
|
||||||
expect($subscribers['error'])->contains('lists');
|
expect($subscribers['error'])->contains('lists');
|
||||||
@ -52,6 +58,7 @@ class MailChimpCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSubscribers() {
|
function itCanGetSubscribers() {
|
||||||
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailChimp->getSubscribers(array($this->lists[0]));
|
$subscribers = $this->mailChimp->getSubscribers(array($this->lists[0]));
|
||||||
expect($subscribers['result'])->true();
|
expect($subscribers['result'])->true();
|
||||||
expect(isset($subscribers['data']['invalid']))->true();
|
expect(isset($subscribers['data']['invalid']))->true();
|
||||||
@ -62,15 +69,17 @@ class MailChimpCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itFailsWhenListHeadersDontMatch() {
|
function itFailsWhenListHeadersDontMatch() {
|
||||||
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailChimp->getSubscribers($this->lists);
|
$subscribers = $this->mailChimp->getSubscribers($this->lists);
|
||||||
expect($subscribers['result'])->false();
|
expect($subscribers['result'])->false();
|
||||||
expect($subscribers['error'])->contains('header');
|
expect($subscribers['error'])->contains('header');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itFailWhenSubscribersDataTooLarge() {
|
function itFailsWhenSubscribersDataTooLarge() {
|
||||||
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$mailChimp = clone($this->mailChimp);
|
$mailChimp = clone($this->mailChimp);
|
||||||
$mailChimp->maxPostSize = 10;
|
$mailChimp->maxPostSize = 10;
|
||||||
$subscribers = $mailChimp->getSubscribers(array('8b66f7fac8'));
|
$subscribers = $mailChimp->getSubscribers($this->lists);
|
||||||
expect($subscribers['result'])->false();
|
expect($subscribers['result'])->false();
|
||||||
expect($subscribers['error'])->contains('large');
|
expect($subscribers['error'])->contains('large');
|
||||||
}
|
}
|
||||||
|
@ -438,10 +438,15 @@
|
|||||||
action: 'saveEditor',
|
action: 'saveEditor',
|
||||||
data: form
|
data: form
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
if(response === false) {
|
if(response.result === false) {
|
||||||
MailPoet.Notice.error(
|
if(response.errors.length > 0) {
|
||||||
"<%= __('An error occured, please reload the page and try again.') %>"
|
MailPoet.Notice.error(response.errors.join('<br />'));
|
||||||
);
|
} else {
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
"<%= __('An error occured, please reload the page and try again.') %>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,5 +12,8 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var mailpoet_segments = <%= json_encode(segments) %>;
|
var mailpoet_segments = <%= json_encode(segments) %>;
|
||||||
|
|
||||||
|
var mailpoet_form_edit_url =
|
||||||
|
"<%= admin_url('admin.php?page=mailpoet-form-editor&id=') %>";
|
||||||
</script>
|
</script>
|
||||||
<% endblock %>
|
<% endblock %>
|
||||||
|
@ -1269,9 +1269,7 @@
|
|||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'newsletters',
|
endpoint: 'newsletters',
|
||||||
action: 'get',
|
action: 'get',
|
||||||
data: {
|
data: <%= params('id') %>
|
||||||
id: <%= params('id') %>
|
|
||||||
}
|
|
||||||
}).done(function(newsletter) {
|
}).done(function(newsletter) {
|
||||||
// start editor
|
// start editor
|
||||||
editor = EditorApplication.start({
|
editor = EditorApplication.start({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{{#if tools.layerSelector}}<a href="javascript:;" class="mailpoet_tool mailpoet_newsletter_layer_selector" title="<%= __('Switch editing layer') %>">
|
{{#if tools.layerSelector}}<a href="javascript:;" class="mailpoet_tool mailpoet_newsletter_layer_selector mailpoet_ignore_drag" title="<%= __('Switch editing layer') %>">
|
||||||
<%= source('newsletter/templates/svg/block-tools/settings-column.svg') %>
|
<%= source('newsletter/templates/svg/block-tools/settings-column.svg') %>
|
||||||
</a>{{/if}}{{#if tools.settings}}<a href="javascript:;" class="mailpoet_tool mailpoet_edit_block" title="<%= __('Edit settings') %>">
|
</a>{{/if}}{{#if tools.settings}}<a href="javascript:;" class="mailpoet_tool mailpoet_edit_block mailpoet_ignore_drag" title="<%= __('Edit settings') %>">
|
||||||
<%= source('newsletter/templates/svg/block-tools/settings.svg') %>
|
<%= source('newsletter/templates/svg/block-tools/settings.svg') %>
|
||||||
</a>{{/if}}{{#if tools.delete}}<div class="mailpoet_delete_block"><a href="javascript:;" class="mailpoet_tool mailpoet_delete_block_activate" title="<%= __('Delete') %>"><%= source('newsletter/templates/svg/block-tools/trash.svg') %></a><a href="javascript:;" class="mailpoet_delete_block_confirm" title="<%= __('Confirm deletion') %>"><%= __('Delete') %></a><a href="javascript:;" class="mailpoet_delete_block_cancel" title="<%= __('Cancel deletion') %>"><%= __('Cancel') %></a></div>{{/if}}{{#if tools.move}}<a href="javascript:;" class="mailpoet_tool mailpoet_move_block" title="<%= __('Drag to move') %>">
|
</a>{{/if}}{{#if tools.delete}}<div class="mailpoet_delete_block mailpoet_ignore_drag"><a href="javascript:;" class="mailpoet_tool mailpoet_delete_block_activate" title="<%= __('Delete') %>"><%= source('newsletter/templates/svg/block-tools/trash.svg') %></a><a href="javascript:;" class="mailpoet_delete_block_confirm" title="<%= __('Confirm deletion') %>"><%= __('Delete') %></a><a href="javascript:;" class="mailpoet_delete_block_cancel" title="<%= __('Cancel deletion') %>"><%= __('Cancel') %></a></div>{{/if}}{{#if tools.move}}<a href="javascript:;" class="mailpoet_tool mailpoet_move_block" title="<%= __('Drag to move') %>">
|
||||||
<%= source('newsletter/templates/svg/block-tools/move.svg') %>
|
<%= source('newsletter/templates/svg/block-tools/move.svg') %>
|
||||||
</a>{{/if}}
|
</a>{{/if}}
|
||||||
|
@ -766,7 +766,12 @@
|
|||||||
if(response.result === true) {
|
if(response.result === true) {
|
||||||
MailPoet.Notice.success("The email has been sent! Check your inbox.");
|
MailPoet.Notice.success("The email has been sent! Check your inbox.");
|
||||||
} else {
|
} else {
|
||||||
MailPoet.Notice.error("The email could not be sent. Please check your settings.");
|
if (response.errors) {
|
||||||
|
MailPoet.Notice.error("The email could not be sent. " + response.errors);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MailPoet.Notice.error("The email could not be sent. Please check your settings.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user