From 887b74b16f067508736c88d023f95098c46b1114 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 18 Sep 2018 12:17:49 -0300 Subject: [PATCH] fix Bulk edit API --- src/admin/tainacan-admin-i18n.php | 2 +- ...lass-tainacan-rest-bulkedit-controller.php | 10 +++---- tests/test-bulkedit.php | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index 017302080..4ec7dc551 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -302,7 +302,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_show_filters' => __( 'Show filters menu', 'tainacan' ), 'label_select_all_items' => __( 'Select all items', 'tainacan' ), 'label_select_all' => __( 'Select all', 'tainacan' ), - 'label_untrash_selected_items' => __( 'Remove from trash the selected items', 'tainacan' ), + 'label_untrash_selected_items' => __( 'Recover from trash', 'tainacan' ), 'label_value_not_informed' => __( 'Value not informed.', 'tainacan' ), 'label_description_not_informed' => __( 'Description not informed.', 'tainacan' ), diff --git a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php index eea7bde85..4a8bd23c5 100644 --- a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php +++ b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php @@ -183,12 +183,12 @@ class REST_Bulkedit_Controller extends REST_Controller { $args['items_ids'] = $body['items_ids']; } elseif ( isset($body['use_query']) && $body['use_query'] ) { - unset($request['paged']); - unset($request['offset']); - unset($request['perpage']); - $request['nopaging'] = 1; + unset($body['use_query']['paged']); + unset($body['use_query']['offset']); + unset($body['use_query']['perpage']); + $body['use_query']['nopaging'] = 1; - $query_args = $this->prepare_filters($request); + $query_args = $this->prepare_filters($body['use_query']); $collection_id = $request['collection_id']; diff --git a/tests/test-bulkedit.php b/tests/test-bulkedit.php index 3d7c3afd4..0e7da5a0b 100644 --- a/tests/test-bulkedit.php +++ b/tests/test-bulkedit.php @@ -1272,5 +1272,32 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { } + function test_create_delete_group() { + + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $ids = array_slice($this->items_ids, 2, 7); + + $bulk = new \Tainacan\Bulk_Edit([ + 'items_ids' => $ids, + ]); + + $bulk->trash_items(); + + $query = [ + 'status' => 'trash', + 'posts_per_page' => -1 + ]; + + $bulk = new \Tainacan\Bulk_Edit([ + 'query' => $query, + 'collection_id' => $this->collection->get_id() + ]); + + $this->assertEquals(7, $bulk->count_posts()); + + + } + } \ No newline at end of file