Reverted back to Model class
This commit is contained in:
@ -1,90 +1,90 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||||
|
|
||||||
class Migrator {
|
class Migrator {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->prefix = Env::$db_prefix;
|
$this->prefix = Env::$db_prefix;
|
||||||
$this->charset = Env::$db_charset;
|
$this->charset = Env::$db_charset;
|
||||||
$this->models = array(
|
$this->models = array(
|
||||||
'subscribers',
|
'subscribers',
|
||||||
'settings',
|
'settings',
|
||||||
'newsletters'
|
'newsletters'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function up() {
|
function up() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$_this = $this;
|
$_this = $this;
|
||||||
$migrate = function($model) use($_this) {
|
$migrate = function($model) use($_this) {
|
||||||
dbDelta($_this->$model());
|
dbDelta($_this->$model());
|
||||||
};
|
};
|
||||||
|
|
||||||
array_map($migrate, $this->models);
|
array_map($migrate, $this->models);
|
||||||
}
|
}
|
||||||
|
|
||||||
function down() {
|
function down() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$drop_table = function($model) {
|
$drop_table = function($model) {
|
||||||
$table = $this->prefix . $model;
|
$table = $this->prefix . $model;
|
||||||
$wpdb->query("DROP TABLE {$table}");
|
$wpdb->query("DROP TABLE {$table}");
|
||||||
};
|
};
|
||||||
|
|
||||||
array_map($drop_table, $this->models);
|
array_map($drop_table, $this->models);
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribers() {
|
function subscribers() {
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'first_name tinytext NOT NULL,',
|
'first_name tinytext NOT NULL,',
|
||||||
'last_name tinytext NOT NULL,',
|
'last_name tinytext NOT NULL,',
|
||||||
'email varchar(150) NOT NULL,',
|
'email varchar(150) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY email (email)'
|
'UNIQUE KEY email (email)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function settings() {
|
function settings() {
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'name varchar(20) NOT NULL,',
|
'name varchar(20) NOT NULL,',
|
||||||
'value varchar(255) NOT NULL,',
|
'value varchar(255) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY name (name)'
|
'UNIQUE KEY name (name)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function newsletters() {
|
function newsletters() {
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'subject varchar(250) NOT NULL,',
|
'subject varchar(250) NOT NULL,',
|
||||||
'body longtext,',
|
'body longtext,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id)'
|
'PRIMARY KEY (id)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sqlify($model, $attributes) {
|
private function sqlify($model, $attributes) {
|
||||||
$table = $this->prefix . $model;
|
$table = $this->prefix . $model;
|
||||||
|
|
||||||
$sql = array();
|
$sql = array();
|
||||||
$sql[] = "CREATE TABLE " . $table . " (";
|
$sql[] = "CREATE TABLE " . $table . " (";
|
||||||
$sql = array_merge($sql, $attributes);
|
$sql = array_merge($sql, $attributes);
|
||||||
$sql[] = ") " . $this->charset . ";";
|
$sql[] = ") " . $this->charset . ";";
|
||||||
|
|
||||||
return implode("\n", $sql);
|
return implode("\n", $sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ namespace MailPoet\Models;
|
|||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class BaseModel extends \Sudzy\ValidModel {
|
class Model extends \Sudzy\ValidModel {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$customValidators = new CustomValidator();
|
$customValidators = new CustomValidator();
|
||||||
parent::__construct($customValidators->init());
|
parent::__construct($customValidators->init());
|
@ -3,7 +3,7 @@ namespace MailPoet\Models;
|
|||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Newsletter extends BaseModel {
|
class Newsletter extends Model {
|
||||||
public static $_table = MP_NEWSLETTERS_TABLE;
|
public static $_table = MP_NEWSLETTERS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Models;
|
namespace MailPoet\Models;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Setting extends BaseModel {
|
class Setting extends Model {
|
||||||
public static $_table = MP_SETTINGS_TABLE;
|
public static $_table = MP_SETTINGS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->addValidations("name", array(
|
$this->addValidations("name", array(
|
||||||
"required" => "name_is_blank",
|
"required" => "name_is_blank",
|
||||||
"isString" => "name_is_not_string",
|
"isString" => "name_is_not_string",
|
||||||
"minLength|2" => "name_is_short"
|
"minLength|2" => "name_is_short"
|
||||||
));
|
));
|
||||||
$this->addValidations("value", array(
|
$this->addValidations("value", array(
|
||||||
"required" => "value_is_blank",
|
"required" => "value_is_blank",
|
||||||
"isString" => "value_is_not_string",
|
"isString" => "value_is_not_string",
|
||||||
"minLength|2" => "value_is_short"
|
"minLength|2" => "value_is_short"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Models;
|
namespace MailPoet\Models;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Subscriber extends BaseModel {
|
class Subscriber extends Model {
|
||||||
public static $_table = MP_SUBSCRIBERS_TABLE;
|
public static $_table = MP_SUBSCRIBERS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->addValidations('email', array(
|
$this->addValidations('email', array(
|
||||||
'required' => "email_is_blank",
|
'required' => "email_is_blank",
|
||||||
'isEmail' => "email_is_invalid"
|
'isEmail' => "email_is_invalid"
|
||||||
));
|
));
|
||||||
$this->addValidations('first_name', array(
|
$this->addValidations('first_name', array(
|
||||||
'required' => "first_name_is_blank",
|
'required' => "first_name_is_blank",
|
||||||
'minLength|2' => "first_name_is_short"
|
'minLength|2' => "first_name_is_short"
|
||||||
));
|
));
|
||||||
$this->addValidations('last_name', array(
|
$this->addValidations('last_name', array(
|
||||||
'required' => "last_name_is_blank",
|
'required' => "last_name_is_blank",
|
||||||
'minLength|2' => "last_name_is_short"
|
'minLength|2' => "last_name_is_short"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$console = new \Codeception\Lib\Console\Output([]);
|
$console = new \Codeception\Lib\Console\Output([]);
|
||||||
|
|
||||||
$console->writeln('Loading WP core...');
|
$console->writeln('Loading WP core...');
|
||||||
require_once(getenv('WP_TEST_PATH') . '/wp-load.php');
|
require_once(getenv('WP_TEST_PATH') . '/wp-load.php');
|
||||||
|
|
||||||
$console->writeln('Cleaning up database...');
|
$console->writeln('Cleaning up database...');
|
||||||
$models = array(
|
$models = array(
|
||||||
"Subscriber",
|
"Subscriber",
|
||||||
"Setting",
|
"Setting",
|
||||||
"Newsletter"
|
"Newsletter"
|
||||||
);
|
);
|
||||||
$destroy = function ($model) {
|
$destroy = function ($model) {
|
||||||
Model::factory("\MailPoet\Models\\" . $model)
|
Model::factory("\MailPoet\Models\\" . $model)
|
||||||
->delete_many();
|
->delete_many();
|
||||||
};
|
};
|
||||||
array_map($destroy, $models);
|
array_map($destroy, $models);
|
||||||
|
@ -1,90 +1,90 @@
|
|||||||
<?php
|
<?php
|
||||||
use MailPoet\Models\Setting;
|
use MailPoet\Models\Setting;
|
||||||
|
|
||||||
class SettingCest {
|
class SettingCest {
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
$this->before_time = time();
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'name' => 'sending_method',
|
'name' => 'sending_method',
|
||||||
'value' => 'smtp'
|
'value' => 'smtp'
|
||||||
);
|
);
|
||||||
|
|
||||||
$setting = Setting::create();
|
$setting = Setting::create();
|
||||||
$setting->hydrate($this->data);
|
$setting->hydrate($this->data);
|
||||||
$setting->save();
|
$setting->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($setting->id)->notNull();
|
expect($setting->id)->notNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
function nameShouldValidate() {
|
function nameShouldValidate() {
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('name', '');
|
$conflict_setting->validateField('name', '');
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_blank');
|
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_blank');
|
||||||
|
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('name', 31337);
|
$conflict_setting->validateField('name', 31337);
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_not_string');
|
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_not_string');
|
||||||
|
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('name', 'a');
|
$conflict_setting->validateField('name', 'a');
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_short');
|
expect($conflict_setting->getValidationErrors()[0])->equals('name_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
function valueShouldValidate() {
|
function valueShouldValidate() {
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('value', '');
|
$conflict_setting->validateField('value', '');
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_blank');
|
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_blank');
|
||||||
|
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('value', 31337);
|
$conflict_setting->validateField('value', 31337);
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_not_string');
|
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_not_string');
|
||||||
|
|
||||||
$conflict_setting = Setting::create();
|
$conflict_setting = Setting::create();
|
||||||
$conflict_setting->validateField('value', 'a');
|
$conflict_setting->validateField('value', 'a');
|
||||||
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_short');
|
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($setting->created_at) >= $this->before_time;
|
$time_difference = strtotime($setting->created_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAnUpdatedAtOnCreation() {
|
function itHasAnUpdatedAtOnCreation() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($setting->updated_at) >= $this->before_time;
|
$time_difference = strtotime($setting->updated_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itKeepsTheCreatedAtOnUpdate() {
|
function itKeepsTheCreatedAtOnUpdate() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$old_created_at = $setting->created_at;
|
$old_created_at = $setting->created_at;
|
||||||
$setting->value = 'http_api';
|
$setting->value = 'http_api';
|
||||||
$setting->save();
|
$setting->save();
|
||||||
expect($old_created_at)->equals($setting->created_at);
|
expect($old_created_at)->equals($setting->created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$update_time = time();
|
$update_time = time();
|
||||||
$setting->value = 'http_api';
|
$setting->value = 'http_api';
|
||||||
$setting->save();
|
$setting->save();
|
||||||
$time_difference = strtotime($setting->updated_at) >= $update_time;
|
$time_difference = strtotime($setting->updated_at) >= $update_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
$setting = Setting::where('name', $this->data['name'])
|
||||||
->findOne()
|
->findOne()
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,131 +1,131 @@
|
|||||||
<?php
|
<?php
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
class SubscriberCest {
|
class SubscriberCest {
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
$this->before_time = time();
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Mailer',
|
'last_name' => 'Mailer',
|
||||||
'email' => 'john@mailpoet.com'
|
'email' => 'john@mailpoet.com'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->subscriber = Subscriber::create();
|
$this->subscriber = Subscriber::create();
|
||||||
$this->subscriber->hydrate($this->data);
|
$this->subscriber->hydrate($this->data);
|
||||||
$this->subscriber->save();
|
$this->subscriber->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($subscriber->id)->notNull();
|
expect($subscriber->id)->notNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAFirstName() {
|
function itHasAFirstName() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($subscriber->first_name)->equals($this->data['first_name']);
|
expect($subscriber->first_name)->equals($this->data['first_name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasALastName() {
|
function itHasALastName() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($subscriber->last_name)->equals($this->data['last_name']);
|
expect($subscriber->last_name)->equals($this->data['last_name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAnEmail() {
|
function itHasAnEmail() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
expect($subscriber->email)->equals($this->data['email']);
|
expect($subscriber->email)->equals($this->data['email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emailMustBeUnique() {
|
function emailMustBeUnique() {
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->hydrate($this->data);
|
$conflict_subscriber->hydrate($this->data);
|
||||||
$conflicted = false;
|
$conflicted = false;
|
||||||
try {
|
try {
|
||||||
$conflict_subscriber->save();
|
$conflict_subscriber->save();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$conflicted = true;
|
$conflicted = true;
|
||||||
}
|
}
|
||||||
expect($conflicted)->equals(true);
|
expect($conflicted)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emailShouldValidate() {
|
function emailShouldValidate() {
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('email', '');
|
$conflict_subscriber->validateField('email', '');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('email_is_blank');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('email_is_blank');
|
||||||
|
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('email', 'some @ email . com');
|
$conflict_subscriber->validateField('email', 'some @ email . com');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('email_is_invalid');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('email_is_invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
function firstNameShouldValidate() {
|
function firstNameShouldValidate() {
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('first_name', '');
|
$conflict_subscriber->validateField('first_name', '');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('first_name_is_blank');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('first_name_is_blank');
|
||||||
|
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('first_name', 'a');
|
$conflict_subscriber->validateField('first_name', 'a');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('first_name_is_short');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('first_name_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function lastNameShouldValidate() {
|
function lastNameShouldValidate() {
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('last_name', '');
|
$conflict_subscriber->validateField('last_name', '');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_blank');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_blank');
|
||||||
|
|
||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->validateField('last_name', 'a');
|
$conflict_subscriber->validateField('last_name', 'a');
|
||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_short');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
function itHasACreatedAtOnCreation() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($subscriber->created_at) >= $this->before_time;
|
$time_difference = strtotime($subscriber->created_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAnUpdatedAtOnCreation() {
|
function itHasAnUpdatedAtOnCreation() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
$time_difference = strtotime($subscriber->updated_at) >= $this->before_time;
|
$time_difference = strtotime($subscriber->updated_at) >= $this->before_time;
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itKeepsTheCreatedAtOnUpdate() {
|
function itKeepsTheCreatedAtOnUpdate() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
$old_created_at = $subscriber->created_at;
|
$old_created_at = $subscriber->created_at;
|
||||||
|
|
||||||
$subscriber->first_name = 'New Name';
|
$subscriber->first_name = 'New Name';
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
|
|
||||||
expect($old_created_at)->equals($subscriber->created_at);
|
expect($old_created_at)->equals($subscriber->created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
$update_time = time();
|
$update_time = time();
|
||||||
$subscriber->first_name = 'New Name';
|
$subscriber->first_name = 'New Name';
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
|
|
||||||
$time_difference = strtotime($subscriber->updated_at) >= $update_time;
|
$time_difference = strtotime($subscriber->updated_at) >= $update_time;
|
||||||
|
|
||||||
expect($time_difference)->equals(true);
|
expect($time_difference)->equals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
->findOne()
|
->findOne()
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UtilCSSCest {
|
class UtilCSSCest {
|
||||||
public function _before() {
|
public function _before() {
|
||||||
$this->css = new \MailPoet\Util\CSS();
|
$this->css = new \MailPoet\Util\CSS();
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests
|
// tests
|
||||||
public function itCanBeInstantiated() {
|
public function itCanBeInstantiated() {
|
||||||
expect_that($this->css instanceof \MailPoet\Util\CSS);
|
expect_that($this->css instanceof \MailPoet\Util\CSS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user