- Model returns validation errors upon save (Closes #122)
- Fixed acceptance test for Newsletters (Closes #126)
This commit is contained in:
@ -16,15 +16,15 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
parent::save();
|
parent::save();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Sudzy\ValidationException $e) {
|
} catch (\Sudzy\ValidationException $e) {
|
||||||
return false;
|
return array_unique($e->getValidationErrors());
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
return false;
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setTimestamp() {
|
private function setTimestamp() {
|
||||||
if ($this->created_at === null) {
|
if ($this->created_at === null) {
|
||||||
$this->created_at = date("Y-m-d H:i:s");
|
$this->created_at = date('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,7 @@ class Subscriber extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subscriber->hydrate($data);
|
$subscriber->hydrate($data);
|
||||||
$saved = $subscriber->save();
|
return $subscriber->save();
|
||||||
|
|
||||||
if($saved === false) {
|
|
||||||
return $subscriber->getValidationErrors();
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,8 @@ class Newsletters {
|
|||||||
function save($args) {
|
function save($args) {
|
||||||
$model = Newsletter::create();
|
$model = Newsletter::create();
|
||||||
$model->hydrate($args);
|
$model->hydrate($args);
|
||||||
$saved = $model->save();
|
$result = $model->save();
|
||||||
|
wp_send_json($result);
|
||||||
if(!$saved) {
|
|
||||||
wp_send_json($model->getValidationErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($args) {
|
function update($args) {
|
||||||
|
@ -25,13 +25,8 @@ class Segments {
|
|||||||
function save($args) {
|
function save($args) {
|
||||||
$model = Segment::create();
|
$model = Segment::create();
|
||||||
$model->hydrate($args);
|
$model->hydrate($args);
|
||||||
$saved = $model->save();
|
$result = $model->save();
|
||||||
|
wp_send_json($result);
|
||||||
if(!$saved) {
|
|
||||||
wp_send_json($model->getValidationErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($args) {
|
function update($args) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Router;
|
namespace MailPoet\Router;
|
||||||
use \MailPoet\Models\Subscriber;
|
|
||||||
use \MailPoet\Listing;
|
use MailPoet\Listing;
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ class Subscribers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
$id = (isset($data['id']) ? (int) $data['id'] : 0);
|
||||||
|
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if($subscriber === false) {
|
if($subscriber === false) {
|
||||||
@ -35,12 +36,7 @@ class Subscribers {
|
|||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$result = Subscriber::createOrUpdate($data);
|
$result = Subscriber::createOrUpdate($data);
|
||||||
|
wp_send_json($result);
|
||||||
if($result !== true) {
|
|
||||||
wp_send_json($result);
|
|
||||||
} else {
|
|
||||||
wp_send_json(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($data) {
|
function update($data) {
|
||||||
|
@ -17,7 +17,7 @@ class NewslettersPageCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function iCanAddNewsletterFromListingPage(AcceptanceTester $I) {
|
function iCanAddNewsletterFromListingPage(AcceptanceTester $I) {
|
||||||
$I->see('No newsletters found');
|
$I->waitForElement('.no-items', $this->waitTime);
|
||||||
$I->click('New', '#newsletters');
|
$I->click('New', '#newsletters');
|
||||||
$I->fillField('Subject', 'first newsletter');
|
$I->fillField('Subject', 'first newsletter');
|
||||||
$I->fillField('Body', 'some body');
|
$I->fillField('Body', 'some body');
|
||||||
|
@ -23,7 +23,7 @@ class SegmentCest {
|
|||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->saved)->equals(true);
|
expect($this->saved)->equals(true);
|
||||||
$empty_model = Segment::create();
|
$empty_model = Segment::create();
|
||||||
expect($empty_model->save())->equals(false);
|
expect($empty_model->save())->notEquals(true);
|
||||||
$validations = $empty_model->getValidationErrors();
|
$validations = $empty_model->getValidationErrors();
|
||||||
expect(count($validations))->equals(2);
|
expect(count($validations))->equals(2);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class SettingCest {
|
|||||||
function itHasToBeValid() {
|
function itHasToBeValid() {
|
||||||
expect($this->result)->equals(true);
|
expect($this->result)->equals(true);
|
||||||
$empty_model = Setting::create();
|
$empty_model = Setting::create();
|
||||||
expect($empty_model->save())->equals(false);
|
expect($empty_model->save())->notEquals(true);
|
||||||
$validations = $empty_model->getValidationErrors();
|
$validations = $empty_model->getValidationErrors();
|
||||||
expect(count($validations))->equals(4);
|
expect(count($validations))->equals(4);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class SubscriberCest {
|
|||||||
$conflict_subscriber = Subscriber::create();
|
$conflict_subscriber = Subscriber::create();
|
||||||
$conflict_subscriber->hydrate($this->data);
|
$conflict_subscriber->hydrate($this->data);
|
||||||
$saved = $conflict_subscriber->save();
|
$saved = $conflict_subscriber->save();
|
||||||
expect($saved)->equals(false);
|
expect($saved)->notEquals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itHasAStatus() {
|
function itHasAStatus() {
|
||||||
|
Reference in New Issue
Block a user