From 875b828eea1e4b30b66c97d651be4957aef29a1d Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 13 Mar 2020 14:22:00 -0300 Subject: [PATCH] remove `validate_metadata_order` #17 --- .../entities/class-tainacan-collection.php | 30 +--------------- tests/test-compound-metadatum-types.php | 35 +++++++++---------- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index dfde5f5b0..0848a34c8 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -746,38 +746,10 @@ class Collection extends Entity { return true; } - return $this->validate_metadata_order() && parent::validate(); + return parent::validate(); } - /** - * Validate metadata order collection - * - * @return bool - */ - function validate_metadata_order() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $metadata_order = $this->get_metadata_order(); - if( empty($metadata_order) ) { - return true; - } - - $parent = 0; - for($pos = 0; $pos < sizeof($metadata_order); $pos++ ) { - $metadatum_id = $metadata_order[$pos]['id']; - $metadatum = $Tainacan_Metadata->fetch( $metadatum_id ); - if ($metadatum->get_parent() != 0) { - if ($parent != $metadatum->get_parent()) { - $this->add_error('metadata_order', __('collection metadata order is invalid', 'tainacan')); - return false; - } - } else { - $parent = $metadatum_id; - } - } - return true; - } - /** * Checks if an user have permission on any of the collections capabilities * defined in Tainacan\Roles class. diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index 46fa44910..554615278 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -415,8 +415,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $order = [ ['id' => $metadatum->get_id(), 'enabled' => true], - ['id' => $metadatum_child1->get_id(), 'enabled' => true], - ['id' => $metadatum_child2->get_id(), 'enabled' => true], + //['id' => $metadatum_child1->get_id(), 'enabled' => true], + //['id' => $metadatum_child2->get_id(), 'enabled' => true], ['id' => $metadatum1->get_id(), 'enabled' => true], ['id' => $metadatum2->get_id(), 'enabled' => true] ]; @@ -427,8 +427,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $metadata_order = $Tainacan_Collections->fetch( $collection->get_id(), 'OBJECT' )->get_metadata_order(); $this->assertEquals($metadata_order[0]['id'], $order[0]['id']); - $this->assertEquals($metadata_order[1]['id'], $order[1]['id']); - $this->assertEquals($metadata_order[2]['id'], $order[2]['id']); + //$this->assertEquals($metadata_order[1]['id'], $order[1]['id']); + //$this->assertEquals($metadata_order[2]['id'], $order[2]['id']); $this->assertEquals($metadata_order[3]['id'], $order[3]['id']); $this->assertEquals($metadata_order[4]['id'], $order[4]['id']); @@ -436,8 +436,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { ['id' => $metadatum1->get_id(), 'enabled' => true], ['id' => $metadatum2->get_id(), 'enabled' => true], ['id' => $metadatum->get_id(), 'enabled' => true], - ['id' => $metadatum_child1->get_id(), 'enabled' => true], - ['id' => $metadatum_child2->get_id(), 'enabled' => true] + //['id' => $metadatum_child1->get_id(), 'enabled' => true], + //['id' => $metadatum_child2->get_id(), 'enabled' => true] ]; $collection->set_metadata_order($order); @@ -448,19 +448,18 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertEquals($metadata_order[0]['id'], $order[0]['id']); $this->assertEquals($metadata_order[1]['id'], $order[1]['id']); $this->assertEquals($metadata_order[2]['id'], $order[2]['id']); - $this->assertEquals($metadata_order[3]['id'], $order[3]['id']); - $this->assertEquals($metadata_order[4]['id'], $order[4]['id']); + //$this->assertEquals($metadata_order[3]['id'], $order[3]['id']); + //$this->assertEquals($metadata_order[4]['id'], $order[4]['id']); + // $order = [ + // ['id' => $metadatum1->get_id(), 'enabled' => true], + // ['id' => $metadatum->get_id(), 'enabled' => true], + // ['id' => $metadatum2->get_id(), 'enabled' => true], + // //['id' => $metadatum_child1->get_id(), 'enabled' => true], + // //['id' => $metadatum_child2->get_id(), 'enabled' => true] + // ]; - $order = [ - ['id' => $metadatum1->get_id(), 'enabled' => true], - ['id' => $metadatum->get_id(), 'enabled' => true], - ['id' => $metadatum2->get_id(), 'enabled' => true], - ['id' => $metadatum_child1->get_id(), 'enabled' => true], - ['id' => $metadatum_child2->get_id(), 'enabled' => true] - ]; - - $collection->set_metadata_order($order); - $this->assertFalse($collection->validate()); + // $collection->set_metadata_order($order); + // $this->assertFalse($collection->validate()); } } \ No newline at end of file