changing return of insert term repository for consistency
This commit is contained in:
parent
2f23fd9d35
commit
65e2819ecc
|
@ -105,9 +105,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
||||||
$this->prepare_item_for_database($to_prepare);
|
$this->prepare_item_for_database($to_prepare);
|
||||||
|
|
||||||
if($this->term->validate()){
|
if($this->term->validate()){
|
||||||
$term_id = $this->terms_repository->insert($this->term);
|
$term_inserted = $this->terms_repository->insert($this->term);
|
||||||
|
|
||||||
$term_inserted = $this->terms_repository->fetch($term_id, $taxonomy);
|
|
||||||
|
|
||||||
return new WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200);
|
return new WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,6 +53,9 @@ class Term extends Entity {
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
function get_id() {
|
function get_id() {
|
||||||
|
return $this->get_term_id();
|
||||||
|
}
|
||||||
|
function get_term_id() {
|
||||||
return $this->get_mapped_property('term_id');
|
return $this->get_mapped_property('term_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Terms extends Repository {
|
||||||
'title' => __('Parent', 'tainacan'),
|
'title' => __('Parent', 'tainacan'),
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'description'=> __('The parent of the term', 'tainacan'),
|
'description'=> __('The parent of the term', 'tainacan'),
|
||||||
|
'default' => 0,
|
||||||
'validation' => ''
|
'validation' => ''
|
||||||
],
|
],
|
||||||
'description' => [
|
'description' => [
|
||||||
|
@ -86,9 +87,9 @@ class Terms extends Repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
// save post and get its ID
|
// save post and get its ID
|
||||||
$term_inserted = wp_insert_term( $term->WP_Term->name, $term->WP_Term->taxonomy, [
|
$term_inserted = wp_insert_term( $term->get_name(), $term->get_taxonomy(), [
|
||||||
'parent' => ( isset( $term->WP_Term->parent ) ) ? $term->WP_Term->parent : 0,
|
'parent' => $term->get_parent(),
|
||||||
'description' => ( isset( $term->WP_Term->description ) ) ? $term->WP_Term->description : '',
|
'description' => $term->get_description(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Now run through properties stored as postmeta
|
// Now run through properties stored as postmeta
|
||||||
|
@ -100,8 +101,8 @@ class Terms extends Repository {
|
||||||
|
|
||||||
do_action('tainacan-insert', $term);
|
do_action('tainacan-insert', $term);
|
||||||
do_action('tainacan-insert-Term', $term);
|
do_action('tainacan-insert-Term', $term);
|
||||||
|
//var_dump($term);
|
||||||
return $term_inserted['term_id'];
|
return new Entities\Term($term_inserted['term_id'], $term->get_taxonomy());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,7 +162,7 @@ class Terms extends Repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($object, $tax_name = null){
|
public function update($object, $tax_name = null){
|
||||||
return new Entities\Term($this->insert($object), $tax_name);
|
return $this->insert($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($args){
|
public function delete($args){
|
||||||
|
|
|
@ -283,8 +283,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
wp_set_post_terms($itemA1->get_id(), $termA, $taxonomyA->get_db_identifier());
|
wp_set_post_terms($itemA1->get_id(), $termA->get_term_id(), $taxonomyA->get_db_identifier());
|
||||||
wp_set_post_terms($itemA2->get_id(), $termA, $taxonomyA->get_db_identifier());
|
wp_set_post_terms($itemA2->get_id(), $termA->get_term_id(), $taxonomyA->get_db_identifier());
|
||||||
|
|
||||||
$tax_query_request_collections = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
|
$tax_query_request_collections = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
|
||||||
$tax_query_request_collections->set_query_params($tax_query);
|
$tax_query_request_collections->set_query_params($tax_query);
|
||||||
|
|
|
@ -61,7 +61,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new \WP_REST_Request('DELETE', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term);
|
$request = new \WP_REST_Request('DELETE', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term->get_term_id());
|
||||||
|
|
||||||
$response = $this->server->dispatch($request);
|
$response = $this->server->dispatch($request);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
||||||
|
|
||||||
$this->assertTrue($data);
|
$this->assertTrue($data);
|
||||||
|
|
||||||
$term = get_term($term);
|
$term = get_term($term->get_term_id());
|
||||||
|
|
||||||
$this->assertNull($term);
|
$this->assertNull($term);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request = new \WP_REST_Request(
|
$request = new \WP_REST_Request(
|
||||||
'PATCH', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term
|
'PATCH', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term->get_term_id()
|
||||||
);
|
);
|
||||||
|
|
||||||
$request->set_body($new_attributes);
|
$request->set_body($new_attributes);
|
||||||
|
@ -169,7 +169,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
||||||
#### FETCH A TERM ####
|
#### FETCH A TERM ####
|
||||||
|
|
||||||
$request = new \WP_REST_Request(
|
$request = new \WP_REST_Request(
|
||||||
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term2
|
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term2->get_term_id()
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $this->server->dispatch($request);
|
$response = $this->server->dispatch($request);
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
//retorna um objeto da classe Tainacan_Term
|
//retorna um objeto da classe Tainacan_Term
|
||||||
$test = $Tainacan_Terms->fetch($term, $taxonomy_test);
|
$test = $Tainacan_Terms->fetch($term->get_term_id(), $taxonomy_test);
|
||||||
$this->assertEquals( $test->get_name(), 'Rock' );
|
$this->assertEquals( $test->get_name(), 'Rock' );
|
||||||
$this->assertEquals( $test->get_user(), 56 );
|
$this->assertEquals( $test->get_user(), 56 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue