From 853239c0ccf4ba802a21efd0723500ba0715f615 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Fri, 16 Feb 2018 15:24:05 -0200 Subject: [PATCH] Default fetch items return private items correctly --- .../repositories/class-tainacan-items.php | 4 -- tests/test-api-items.php | 4 +- tests/test-private-objects.php | 66 +++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 tests/test-private-objects.php diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 4bcb88048..a8798cdea 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -220,10 +220,6 @@ class Items extends Repository { //TODO: get collection order and order by options $args = $this->parse_fetch_args($args); - - $args = array_merge([ - 'post_status' => 'publish', - ], $args); $args['post_type'] = $cpt; diff --git a/tests/test-api-items.php b/tests/test-api-items.php index 170f0b45c..8ed9d483b 100644 --- a/tests/test-api-items.php +++ b/tests/test-api-items.php @@ -76,8 +76,8 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase { $first_item = $data[0]; $second_item = $data[1]; - $this->assertEquals($item2->get_title(), $first_item['title']); - $this->assertEquals($item1->get_title(), $second_item['title']); + $this->assertEquals($item1->get_title(), $first_item['title']); + $this->assertEquals($item2->get_title(), $second_item['title']); } public function test_delete_or_trash_item_from_a_collection(){ diff --git a/tests/test-private-objects.php b/tests/test-private-objects.php new file mode 100644 index 000000000..c7910b8f6 --- /dev/null +++ b/tests/test-private-objects.php @@ -0,0 +1,66 @@ +tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'testePerm', + ), + true + ); + $privateItem = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'testPrivateItem', + 'collection' => $collection, + 'status' => 'private' + ), + true + ); + $item = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'testItem', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); + + global $Tainacan_Items; + + $items = $Tainacan_Items->fetch([], $collection); + + $this->assertEquals(2, $items->found_posts, 'admins should see all 2 items'); + + $new_contributor_user = $this->factory()->user->create(array( 'role' => 'contributor' )); + wp_set_current_user($new_contributor_user); + + $items = $Tainacan_Items->fetch([], $collection); + $this->assertEquals(1, $items->found_posts, 'contributors should not see private items'); + + } + +} \ No newline at end of file