remove `validate_metadata_order` #17

This commit is contained in:
vnmedeiros 2020-03-13 14:22:00 -03:00
parent a4ce5fb99c
commit 875b828eea
2 changed files with 18 additions and 47 deletions

View File

@ -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.

View File

@ -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());
}
}