always get fresh related collection #339

This commit is contained in:
leogermani 2019-11-29 17:27:47 -03:00
parent de7391a3a4
commit fbd6e105ce
4 changed files with 107 additions and 80 deletions

View File

@ -27,8 +27,6 @@ trait Entity_Collection_Relation {
* @return Entities\Collection|NULL Return Collection or null on errors
*/
public function get_collection() {
if (isset($this->collection) && $this->collection instanceof Entities\Collection)
return $this->collection;
if (is_numeric($this->get_collection_id())) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();

View File

@ -12,8 +12,6 @@ trait Entity_Collections_Relation {
}
public function get_collections() {
if (isset($this->collections))
return $this->collections;
if (is_array($this->get_collections_ids()) && !empty($this->get_collections_ids())) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();

View File

@ -415,4 +415,38 @@ class Items extends TAINACAN_UnitTestCase {
}
function test_update_collection() {
$ItemRepo = \Tainacan\Repositories\Items::get_instance();
$ColRepo = \Tainacan\Repositories\Collections::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste1',
'description' => 'adasdasdsa',
'status' => 'publish'
),
true
);
$item = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'testeItem',
'collection' => $collection,
'status' => 'publish'
),
true
);
$collection->set_status('private');
$collection->validate();
$collection = $ColRepo->insert($collection);
$this->assertEquals('private', $item->get_collection()->get_status());
}
}

View File

@ -255,9 +255,6 @@ class Permissions extends TAINACAN_UnitTestCase {
$collection->validate();
$collection = $ColRepo->insert($collection);
// refresh item
$item = new \Tainacan\Entities\Item($item->get_id());
$this->assertFalse($item->can_read());