Added Laurent's tests/model save() method
This commit is contained in:
@ -8,4 +8,12 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
$customValidators = new CustomValidator();
|
$customValidators = new CustomValidator();
|
||||||
parent::__construct($customValidators->init());
|
parent::__construct($customValidators->init());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
if ($this->created_at === null) {
|
||||||
|
$this->created_at = date("Y-m-d H:i:s");
|
||||||
|
}
|
||||||
|
parent::save();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ use MailPoet\Models\Setting;
|
|||||||
class SettingCest {
|
class SettingCest {
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'name' => 'sending_method',
|
'name' => 'sending_method',
|
||||||
'value' => 'smtp'
|
'value' => 'smtp'
|
||||||
@ -48,6 +49,39 @@ class SettingCest {
|
|||||||
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_short');
|
expect($conflict_setting->getValidationErrors()[0])->equals('value_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itHasACreatedAtOnCreation() {
|
||||||
|
$setting = Setting::where('name', 'sending_method')
|
||||||
|
->findOne();
|
||||||
|
$time_difference = strtotime($setting->created_at) >= $this->before_time;
|
||||||
|
expect($time_difference)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itHasAnUpdatedAtOnCreation() {
|
||||||
|
$setting = Setting::where('name', 'sending_method')
|
||||||
|
->findOne();
|
||||||
|
$time_difference = strtotime($setting->updated_at) >= $this->before_time;
|
||||||
|
expect($time_difference)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itKeepsTheCreatedAtOnUpdate() {
|
||||||
|
$setting = Setting::where('name', 'sending_method')
|
||||||
|
->findOne();
|
||||||
|
$old_created_at = $setting->created_at;
|
||||||
|
$setting->value = 'http_api';
|
||||||
|
$setting->save();
|
||||||
|
expect($old_created_at)->equals($setting->created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||||
|
$setting = Setting::where('name', 'sending_method')
|
||||||
|
->findOne();
|
||||||
|
$update_time = time();
|
||||||
|
$setting->value = 'http_api';
|
||||||
|
$setting->save();
|
||||||
|
$time_difference = strtotime($setting->updated_at) >= $update_time;
|
||||||
|
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()
|
||||||
|
@ -4,6 +4,7 @@ use MailPoet\Models\Subscriber;
|
|||||||
class SubscriberCest {
|
class SubscriberCest {
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Mailer',
|
'last_name' => 'Mailer',
|
||||||
@ -82,6 +83,45 @@ class SubscriberCest {
|
|||||||
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_short');
|
expect($conflict_subscriber->getValidationErrors()[0])->equals('last_name_is_short');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itHasACreatedAtOnCreation() {
|
||||||
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
|
->findOne();
|
||||||
|
$time_difference = strtotime($subscriber->created_at) >= $this->before_time;
|
||||||
|
expect($time_difference)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itHasAnUpdatedAtOnCreation() {
|
||||||
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
|
->findOne();
|
||||||
|
$time_difference = strtotime($subscriber->updated_at) >= $this->before_time;
|
||||||
|
expect($time_difference)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itKeepsTheCreatedAtOnUpdate() {
|
||||||
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
$old_created_at = $subscriber->created_at;
|
||||||
|
|
||||||
|
$subscriber->first_name = 'New Name';
|
||||||
|
$subscriber->save();
|
||||||
|
|
||||||
|
expect($old_created_at)->equals($subscriber->created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itUpdatesTheUpdatedAtOnUpdate() {
|
||||||
|
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
$update_time = time();
|
||||||
|
$subscriber->first_name = 'New Name';
|
||||||
|
$subscriber->save();
|
||||||
|
|
||||||
|
$time_difference = strtotime($subscriber->updated_at) >= $update_time;
|
||||||
|
|
||||||
|
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()
|
||||||
|
Reference in New Issue
Block a user