Tests cleanup.
This commit is contained in:
@@ -7,11 +7,15 @@ class Newsletter extends Model {
|
|||||||
public static $_table = MP_NEWSLETTERS_TABLE;
|
public static $_table = MP_NEWSLETTERS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
$this->addValidations('subject', array(
|
$this->addValidations('subject', array(
|
||||||
'required' => "subject_is_blank"
|
'required' => 'subject_is_blank',
|
||||||
|
'isString' => 'subject_is_not_string'
|
||||||
));
|
));
|
||||||
$this->addValidations('body', array(
|
$this->addValidations('body', array(
|
||||||
'required' => "body_is_blank"
|
'required' => 'body_is_blank',
|
||||||
|
'isString' => 'body_is_not_string'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@ class Subscriber extends Model {
|
|||||||
public static $_table = MP_SUBSCRIBERS_TABLE;
|
public static $_table = MP_SUBSCRIBERS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
parent::__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"
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
|
|
||||||
class NewsletterCest {
|
class NewsletterCest {
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
$this->before_time = time();
|
$this->before_time = time();
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
@@ -13,63 +12,18 @@ class NewsletterCest {
|
|||||||
|
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->hydrate($this->data);
|
$newsletter->hydrate($this->data);
|
||||||
$newsletter->save();
|
$this->saved = $newsletter->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
expect($this->saved)->equals(true);
|
||||||
->findOne();
|
|
||||||
expect($newsletter->id)->notNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
function subjectShouldValidate() {
|
|
||||||
$conflict_newsletter = Newsletter::create();
|
|
||||||
$conflict_newsletter->validateField('subject', '');
|
|
||||||
expect($conflict_newsletter->getValidationErrors()[0])->equals('subject_is_blank');
|
|
||||||
}
|
|
||||||
|
|
||||||
function bodyShouldValidate() {
|
|
||||||
$conflict_newsletter = Newsletter::create();
|
|
||||||
$conflict_newsletter->validateField('body', '');
|
|
||||||
expect($conflict_newsletter->getValidationErrors()[0])->equals('body_is_blank');
|
|
||||||
}
|
|
||||||
|
|
||||||
function itHasACreatedAtOnCreation() {
|
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
|
||||||
->findOne();
|
|
||||||
$time_difference = strtotime($newsletter->created_at) >= $this->before_time;
|
|
||||||
expect($time_difference)->equals(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function itHasAnUpdatedAtOnCreation() {
|
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
|
||||||
->findOne();
|
|
||||||
$time_difference = strtotime($newsletter->updated_at) >= $this->before_time;
|
|
||||||
expect($time_difference)->equals(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function itKeepsTheCreatedAtOnUpdate() {
|
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
|
||||||
->findOne();
|
|
||||||
$old_created_at = $newsletter->created_at;
|
|
||||||
$newsletter->subject = $this->data['subject'];
|
|
||||||
$newsletter->save();
|
|
||||||
expect($old_created_at)->equals($newsletter->created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
function itUpdatesTheUpdatedAtOnUpdate() {
|
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
|
||||||
->findOne();
|
|
||||||
$update_time = time();
|
|
||||||
$newsletter->subject = $this->data['subject'];
|
|
||||||
$newsletter->save();
|
|
||||||
$time_difference = strtotime($newsletter->updated_at) >= $update_time;
|
|
||||||
expect($time_difference)->equals(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
$newsletter =
|
||||||
->findOne()
|
Newsletter::where(
|
||||||
->delete();
|
'subject',
|
||||||
|
$this->data['subject']
|
||||||
|
)->findOne()->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
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(
|
||||||
@@ -16,9 +15,7 @@ class SettingCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$setting = Setting::where('name', $this->data['name'])
|
expect($this->result)->equals(true);
|
||||||
->findOne();
|
|
||||||
expect($setting->id)->notNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
|
@@ -13,31 +13,35 @@ class SubscriberCest {
|
|||||||
|
|
||||||
$this->subscriber = Subscriber::create();
|
$this->subscriber = Subscriber::create();
|
||||||
$this->subscriber->hydrate($this->data);
|
$this->subscriber->hydrate($this->data);
|
||||||
$this->subscriber->save();
|
$this->saved = $this->subscriber->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBeCreated() {
|
function itCanBeCreated() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
expect($this->saved)->equals(true);
|
||||||
->findOne();
|
|
||||||
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() {
|
||||||
@@ -48,7 +52,8 @@ class SubscriberCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
$subscriber =
|
||||||
|
Subscriber::where('email', $this->data['email'])
|
||||||
->findOne()
|
->findOne()
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user