Default fetch items return private items correctly

This commit is contained in:
Leo Germani 2018-02-16 15:24:05 -02:00
parent f173852c68
commit 853239c0cc
3 changed files with 68 additions and 6 deletions

View File

@ -221,10 +221,6 @@ class Items extends Repository {
$args = $this->parse_fetch_args($args);
$args = array_merge([
'post_status' => 'publish',
], $args);
$args['post_type'] = $cpt;
$wp_query = new \WP_Query($args);

View File

@ -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(){

View File

@ -0,0 +1,66 @@
<?php
namespace Tainacan\Tests;
/**
* Class TestCollections
*
* @package Test_Tainacan
*/
use Tainacan\Entities;
/**
* Test fetch methods to see if they return private objects (items, fiels, collections) correctly
*
* Private items should only be visible by logged users who have the rights
*
*/
class PrivateObjects extends TAINACAN_UnitTestCase {
/**
* @group privateObjects
*/
public function test_private_items () {
$collection = $this->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');
}
}