From dbed32b98ddb0c9fcdd5a04d9968edd357df8660 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sat, 14 Mar 2020 00:24:08 -0300 Subject: [PATCH] fix test instanceof Item_Metadata_Entity #17 --- ...-tainacan-rest-item-metadata-controller.php | 7 ++++++- .../class-tainacan-item-metadata-entity.php | 18 ++++++++---------- tests/test-compound-metadatum-types.php | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 445b32162..1cc1bdda8 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -183,7 +183,7 @@ class REST_Item_Metadata_Controller extends REST_Controller { $item_id = $request['item_id']; $metadatum_id = $request['metadatum_id']; $value = $body['values']; - $parent_meta_id = isset( $body['parent_meta_id'] ) && $parent_meta_id > 0 ? $body['parent_meta_id'] : null; + $parent_meta_id = isset( $body['parent_meta_id'] ) && $body['parent_meta_id'] > 0 ? $body['parent_meta_id'] : null; $item = $this->item_repository->fetch( $item_id ); $metadatum = $this->metadatum_repository->fetch( $metadatum_id ); @@ -279,6 +279,11 @@ class REST_Item_Metadata_Controller extends REST_Controller { ], 'description' => __('The value(s) of item metadata') ]; + $endpoint_args['parent_meta_id'] = [ + 'type' => 'array/string/object/integer', + 'items' => ['type' => 'array/string/object/integer'], + 'description' => __('The parent meta ID for group children item metadatas') + ]; } return $endpoint_args; diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index b708d9b83..d7b8c5f6c 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -30,11 +30,11 @@ class Item_Metadata_Entity extends Entity { * @param Metadatum $metadatum Metadatum Entity * @param int $meta_id ID for a specific meta row */ - function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) { - - $this->set_item($item); - $this->set_metadatum($metadatum); - + function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) { + + $this->set_item($item); + $this->set_metadatum($metadatum); + if (!is_null($meta_id) && is_int($meta_id)) { $this->set_meta_id($meta_id); } @@ -42,9 +42,7 @@ class Item_Metadata_Entity extends Entity { if (!is_null($parent_meta_id) && is_int($parent_meta_id)) { $this->set_parent_meta_id($parent_meta_id); } - - - } + } /** * Gets the string used before each value when concatenating multiple values @@ -214,7 +212,7 @@ class Item_Metadata_Entity extends Entity { $metadata = new Metadatum( $child['id'] ); $itemMetadata = new self( $this->get_item(), $metadata ); $child_primitive_type = $metadata->get_metadata_type_object()->get_primitive_type(); - if ( $itemMetadata instanceof ItemMetadataEntity && $child_primitive_type === 'term' ) { + if ( $itemMetadata instanceof Item_Metadata_Entity && $child_primitive_type === 'term' ) { $compounds[$child['id']] = $itemMetadata->_toArray(); } } @@ -223,7 +221,7 @@ class Item_Metadata_Entity extends Entity { if( is_array($value) ) { foreach ($value as $itemMetadata) { $child_primitive_type = $itemMetadata->get_metadatum()->get_metadata_type_object()->get_primitive_type(); - if ( $itemMetadata instanceof ItemMetadataEntity && $child_primitive_type !== 'term' ) { + if ( $itemMetadata instanceof Item_Metadata_Entity && $child_primitive_type !== 'term' ) { $compounds[$itemMetadata->get_metadatum()->get_id()] = $itemMetadata->_toArray(); } } diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index 554615278..675752fa4 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -429,8 +429,8 @@ 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[1]['id'], $order[3]['id']); + $this->assertEquals($metadata_order[2]['id'], $order[4]['id']); $order = [ ['id' => $metadatum1->get_id(), 'enabled' => true],