fix set_value() passing an Term Entity #250
This commit is contained in:
parent
5bab9ed48f
commit
46df1f9588
|
@ -175,7 +175,10 @@ class Item_Metadata extends Repository {
|
||||||
// $success = wp_set_object_terms( $item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() );
|
// $success = wp_set_object_terms( $item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() );
|
||||||
|
|
||||||
$insert = [];
|
$insert = [];
|
||||||
foreach ( (array) $new_terms as $new_term ) {
|
if ( !is_array($new_terms) ) {
|
||||||
|
$new_terms = [ $new_terms ];
|
||||||
|
}
|
||||||
|
foreach ( $new_terms as $new_term ) {
|
||||||
if ( \is_object($new_term) && $new_term instanceof Entities\Term ) {
|
if ( \is_object($new_term) && $new_term instanceof Entities\Term ) {
|
||||||
$exists = $new_term->WP_Term;
|
$exists = $new_term->WP_Term;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -477,6 +477,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertEquals(201, $response->get_status());
|
$this->assertEquals(201, $response->get_status());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group duplicate
|
||||||
|
*/
|
||||||
function test_duplicate() {
|
function test_duplicate() {
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
|
@ -523,6 +526,16 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$taxonomy2 = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'taxonomy',
|
||||||
|
array(
|
||||||
|
'name' => 'taxonomy_public2',
|
||||||
|
'description' => 'taxonomy_public2',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
$tax_meta = $this->tainacan_entity_factory->create_entity(
|
$tax_meta = $this->tainacan_entity_factory->create_entity(
|
||||||
'metadatum',
|
'metadatum',
|
||||||
array(
|
array(
|
||||||
|
@ -539,6 +552,22 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$tax_meta_single = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'metadatum',
|
||||||
|
array(
|
||||||
|
'name' => 'metadata-public-single',
|
||||||
|
'status' => 'publish',
|
||||||
|
'collection' => $collection,
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
|
||||||
|
'metadata_type_options' => [
|
||||||
|
'allow_new_terms' => 'yes',
|
||||||
|
'taxonomy_id' => $taxonomy2->get_id()
|
||||||
|
],
|
||||||
|
'multiple' => 'no'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
$item1 = $this->tainacan_entity_factory->create_entity(
|
$item1 = $this->tainacan_entity_factory->create_entity(
|
||||||
'item',
|
'item',
|
||||||
array(
|
array(
|
||||||
|
@ -567,6 +596,11 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
|
||||||
$newMeta->validate();
|
$newMeta->validate();
|
||||||
$itemMetaRepo->insert($newMeta);
|
$itemMetaRepo->insert($newMeta);
|
||||||
|
|
||||||
|
$newMeta = new \Tainacan\Entities\Item_Metadata_Entity($item1, $tax_meta_single);
|
||||||
|
$newMeta->set_value('test term');
|
||||||
|
$newMeta->validate();
|
||||||
|
$itemMetaRepo->insert($newMeta);
|
||||||
|
|
||||||
$request = new \WP_REST_Request('POST', $this->namespace . '/collection/' . $collection->get_id() . '/items/' . $item1->get_id() . '/duplicate');
|
$request = new \WP_REST_Request('POST', $this->namespace . '/collection/' . $collection->get_id() . '/items/' . $item1->get_id() . '/duplicate');
|
||||||
|
|
||||||
$response = $this->server->dispatch($request);
|
$response = $this->server->dispatch($request);
|
||||||
|
|
Loading…
Reference in New Issue