Router updates + unit tests + React
- added -f flag to run unit test command in order to fail fast - pass only id to "$endpoint->get($id)" in React forms instead of array - updated routers according to the ->get($id) change - refactored a bit the way form creation works - added unit tests for Segments router
This commit is contained in:
@@ -11,15 +11,12 @@ class Forms {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
|
||||
function get($id = false) {
|
||||
$form = Form::findOne($id);
|
||||
if($form === false) {
|
||||
wp_send_json(false);
|
||||
return false;
|
||||
} else {
|
||||
$form = $form->asArray();
|
||||
wp_send_json($form);
|
||||
return $form->asArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +44,11 @@ class Forms {
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json($listing_data);
|
||||
return $listing_data;
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Form::findArray();
|
||||
wp_send_json($collection);
|
||||
return Form::findArray();
|
||||
}
|
||||
|
||||
function create() {
|
||||
@@ -88,24 +84,16 @@ class Forms {
|
||||
)
|
||||
);
|
||||
|
||||
$form = Form::createOrUpdate($form_data);
|
||||
|
||||
if($form !== false && $form->id()) {
|
||||
wp_send_json(
|
||||
admin_url('admin.php?page=mailpoet-form-editor&id='.$form->id())
|
||||
);
|
||||
} else {
|
||||
wp_send_json(false);
|
||||
}
|
||||
return $this->save($form_data);
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$form = Form::createOrUpdate($data);
|
||||
|
||||
if($form !== false && $form->id()) {
|
||||
wp_send_json($form->id());
|
||||
return $form->id();
|
||||
} else {
|
||||
wp_send_json($form);
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,10 +107,10 @@ class Forms {
|
||||
// styles
|
||||
$css = new Util\Styles(FormRenderer::getStyles($data));
|
||||
|
||||
wp_send_json(array(
|
||||
return array(
|
||||
'html' => $html,
|
||||
'css' => $css->render()
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
function exportsEditor($id) {
|
||||
@@ -134,7 +122,7 @@ class Forms {
|
||||
$exports = Util\Export::getAll($form->asArray());
|
||||
}
|
||||
|
||||
wp_send_json($exports);
|
||||
return $exports;
|
||||
}
|
||||
|
||||
function saveEditor($data = array()) {
|
||||
@@ -146,7 +134,7 @@ class Forms {
|
||||
|
||||
if(empty($body) || empty($settings)) {
|
||||
// error
|
||||
wp_send_json(false);
|
||||
return false;
|
||||
} else {
|
||||
// check if the form is used as a widget
|
||||
$is_widget = false;
|
||||
@@ -195,10 +183,10 @@ class Forms {
|
||||
));
|
||||
|
||||
// response
|
||||
wp_send_json(array(
|
||||
return array(
|
||||
'result' => ($form !== false),
|
||||
'is_widget' => $is_widget
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
@@ -209,7 +197,7 @@ class Forms {
|
||||
$result = $form->restore();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function trash($id) {
|
||||
@@ -220,7 +208,7 @@ class Forms {
|
||||
$result = $form->trash();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
@@ -232,7 +220,7 @@ class Forms {
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function duplicate($id) {
|
||||
@@ -246,7 +234,7 @@ class Forms {
|
||||
$result = $form->duplicate($data)->asArray();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
@@ -255,6 +243,6 @@ class Forms {
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($bulk_action->apply());
|
||||
return $bulk_action->apply();
|
||||
}
|
||||
}
|
||||
|
@@ -9,14 +9,13 @@ class NewsletterTemplates {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id'])) ? (int) $data['id'] : 0;
|
||||
function get($id = false) {
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if($template === false) {
|
||||
wp_send_json(false);
|
||||
return false;
|
||||
} else {
|
||||
$template->body = json_decode($template->body);
|
||||
wp_send_json($template->asArray());
|
||||
return $template->asArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +25,15 @@ class NewsletterTemplates {
|
||||
$item['body'] = json_decode($item['body']);
|
||||
return $item;
|
||||
}, $collection);
|
||||
wp_send_json($collection);
|
||||
return $collection;
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$result = NewsletterTemplate::createOrUpdate($data);
|
||||
if($result !== true) {
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
} else {
|
||||
wp_send_json(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +44,6 @@ class NewsletterTemplates {
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -12,14 +12,12 @@ class Segments {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
|
||||
function get($id = false) {
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment === false) {
|
||||
wp_send_json(false);
|
||||
return false;
|
||||
} else {
|
||||
wp_send_json($segment->asArray());
|
||||
return $segment->asArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,12 +62,11 @@ class Segments {
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json($listing_data);
|
||||
return $listing_data;
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Segment::findArray();
|
||||
wp_send_json($collection);
|
||||
return Segment::findArray();
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
@@ -83,10 +80,10 @@ class Segments {
|
||||
} else {
|
||||
$result = true;
|
||||
}
|
||||
wp_send_json(array(
|
||||
return array(
|
||||
'result' => $result,
|
||||
'errors' => $errors
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
@@ -97,7 +94,7 @@ class Segments {
|
||||
$result = $segment->restore();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function trash($id) {
|
||||
@@ -108,7 +105,7 @@ class Segments {
|
||||
$result = $segment->trash();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
@@ -120,7 +117,7 @@ class Segments {
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function duplicate($id) {
|
||||
@@ -134,13 +131,13 @@ class Segments {
|
||||
$result = $segment->duplicate($data)->asArray();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function synchronize() {
|
||||
$result = WP::synchronizeUsers();
|
||||
|
||||
wp_send_json($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
@@ -149,6 +146,6 @@ class Segments {
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($bulk_action->apply());
|
||||
return $bulk_action->apply();
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,7 @@ class Subscribers {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int) $data['id'] : 0);
|
||||
|
||||
function get($id = false) {
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if($subscriber !== false && $subscriber->id() > 0) {
|
||||
$segments = $subscriber->segments()->findArray();
|
||||
|
Reference in New Issue
Block a user