Tests cleanup.
This commit is contained in:
@@ -7,11 +7,15 @@ class Newsletter extends Model {
|
||||
public static $_table = MP_NEWSLETTERS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('subject', array(
|
||||
'required' => "subject_is_blank"
|
||||
'required' => 'subject_is_blank',
|
||||
'isString' => 'subject_is_not_string'
|
||||
));
|
||||
$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;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('email', array(
|
||||
'required' => "email_is_blank",
|
||||
'isEmail' => "email_is_invalid"
|
||||
|
@@ -3,73 +3,27 @@
|
||||
use MailPoet\Models\Newsletter;
|
||||
|
||||
class NewsletterCest {
|
||||
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
'subject' => 'My First Newsletter',
|
||||
'body' => 'a verrryyyyy long body :)'
|
||||
'body' => 'a verrryyyyy long body :)'
|
||||
);
|
||||
|
||||
|
||||
$newsletter = Newsletter::create();
|
||||
$newsletter->hydrate($this->data);
|
||||
$newsletter->save();
|
||||
$this->saved = $newsletter->save();
|
||||
}
|
||||
|
||||
|
||||
function itCanBeCreated() {
|
||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
||||
->findOne();
|
||||
expect($newsletter->id)->notNull();
|
||||
expect($this->saved)->equals(true);
|
||||
}
|
||||
|
||||
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() {
|
||||
$newsletter = Newsletter::where('subject', $this->data['subject'])
|
||||
->findOne()
|
||||
->delete();
|
||||
$newsletter =
|
||||
Newsletter::where(
|
||||
'subject',
|
||||
$this->data['subject']
|
||||
)->findOne()->delete();
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class SettingCest {
|
||||
|
||||
function _before() {
|
||||
$this->before_time = time();
|
||||
$this->data = array(
|
||||
@@ -16,9 +15,7 @@ class SettingCest {
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
$setting = Setting::where('name', $this->data['name'])
|
||||
->findOne();
|
||||
expect($setting->id)->notNull();
|
||||
expect($this->result)->equals(true);
|
||||
}
|
||||
|
||||
function itHasToBeValid() {
|
||||
|
@@ -13,31 +13,35 @@ class SubscriberCest {
|
||||
|
||||
$this->subscriber = Subscriber::create();
|
||||
$this->subscriber->hydrate($this->data);
|
||||
$this->subscriber->save();
|
||||
$this->saved = $this->subscriber->save();
|
||||
}
|
||||
|
||||
function itCanBeCreated() {
|
||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||
->findOne();
|
||||
expect($subscriber->id)->notNull();
|
||||
expect($this->saved)->equals(true);
|
||||
}
|
||||
|
||||
function itHasAFirstName() {
|
||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||
$subscriber =
|
||||
Subscriber::where('email', $this->data['email'])
|
||||
->findOne();
|
||||
expect($subscriber->first_name)->equals($this->data['first_name']);
|
||||
expect($subscriber->first_name)
|
||||
->equals($this->data['first_name']);
|
||||
}
|
||||
|
||||
function itHasALastName() {
|
||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||
$subscriber =
|
||||
Subscriber::where('email', $this->data['email'])
|
||||
->findOne();
|
||||
expect($subscriber->last_name)->equals($this->data['last_name']);
|
||||
expect($subscriber->last_name)
|
||||
->equals($this->data['last_name']);
|
||||
}
|
||||
|
||||
function itHasAnEmail() {
|
||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||
$subscriber =
|
||||
Subscriber::where('email', $this->data['email'])
|
||||
->findOne();
|
||||
expect($subscriber->email)->equals($this->data['email']);
|
||||
expect($subscriber->email)
|
||||
->equals($this->data['email']);
|
||||
}
|
||||
|
||||
function emailMustBeUnique() {
|
||||
@@ -48,7 +52,8 @@ class SubscriberCest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
$subscriber = Subscriber::where('email', $this->data['email'])
|
||||
$subscriber =
|
||||
Subscriber::where('email', $this->data['email'])
|
||||
->findOne()
|
||||
->delete();
|
||||
}
|
||||
|
Reference in New Issue
Block a user