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