diff --git a/src/admin/components/other/event-diff/event-split.vue b/src/admin/components/other/event-diff/event-split.vue index ac1eb8357..9fa4b1bbb 100644 --- a/src/admin/components/other/event-diff/event-split.vue +++ b/src/admin/components/other/event-diff/event-split.vue @@ -33,7 +33,7 @@

- {{ o.title }} {{ o.mime_type }} + {{ o.title }} {{ o.mime_type }}
{{ o.description }}

@@ -99,7 +99,7 @@

- {{ d.title }} {{ d.mime_type }} + {{ d.title }} {{ d.mime_type }}
{{ d.description }}

diff --git a/src/admin/components/other/event-diff/event-unified.vue b/src/admin/components/other/event-diff/event-unified.vue index 7c0e8bc20..fd5bb453e 100644 --- a/src/admin/components/other/event-diff/event-unified.vue +++ b/src/admin/components/other/event-diff/event-unified.vue @@ -35,7 +35,7 @@

- {{ o.title }} {{ o.mime_type }} + {{ o.title }} {{ o.mime_type }}
{{ o.description }}

@@ -96,7 +96,7 @@

- {{ d.title }} {{ d.mime_type }} + {{ d.title }} {{ d.mime_type }}
{{ d.description }}

diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index 89f1e7fff..a9c97350b 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -189,7 +189,10 @@ class Entity { } } - $this->set_validated($is_valid); + if($is_valid){ + $this->set_as_valid(); + } + return $is_valid; } diff --git a/src/classes/entities/class-tainacan-field.php b/src/classes/entities/class-tainacan-field.php index 16d151631..945eb5028 100644 --- a/src/classes/entities/class-tainacan-field.php +++ b/src/classes/entities/class-tainacan-field.php @@ -432,11 +432,15 @@ class Field extends Entity { $is_valid = $fto->validate_options($this); } - if (true === $is_valid) - return true; + if (true === $is_valid) { + $this->set_as_valid(); + + return true; + } - if (!is_array($is_valid)) - throw new \Exception("Return of validate_options field type method should be an Array in case of error"); + if (!is_array($is_valid)) { + throw new \Exception( "Return of validate_options field type method should be an Array in case of error" ); + } $this->add_error('field_type_options', $is_valid); diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index b61e1eb11..e3bd384fb 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -205,11 +205,14 @@ class Filter extends Entity { $is_valid = $fto->validate_options( $this ); } - if (true === $is_valid) - return true; + if (true === $is_valid) { + $this->set_as_valid(); + return true; + } - if (!is_array($is_valid)) - throw new \Exception("Return of validate_options field type method should be an Array in case of error"); + if (!is_array($is_valid)) { + throw new \Exception( "Return of validate_options field type method should be an Array in case of error" ); + } foreach ($is_valid as $field => $message) { $this->add_error($field, $message); diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index 21240d241..f62a90b69 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -388,6 +388,10 @@ class Item extends Entity { } } + if($is_valid){ + $this->set_as_valid(); + } + return $is_valid; } diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 1eb323d7d..cf7f66241 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -221,6 +221,7 @@ class Term extends Entity { return false; } + $this->set_as_valid(); return true; } diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index b785852dc..03360d848 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -262,10 +262,22 @@ class Collections extends Repository { */ public function delete( $args ) { if ( ! empty( $args[1] ) && $args[1] === true ) { - return new Entities\Collection( wp_delete_post( $args[0], $args[1] ) ); + $deleted = new Entities\Collection( wp_delete_post( $args[0], $args[1] ) ); + + if($deleted) { + do_action( 'tainacan-deleted', $deleted, $is_update = false, $is_delete_permanently = true ); + } + + return $deleted; } - return new Entities\Collection( wp_trash_post( $args[0] ) ); + $trashed = new Entities\Collection( wp_trash_post( $args[0] ) ); + + if($trashed) { + do_action( 'tainacan-trashed', $trashed, $is_update = false, $is_delete_permanently = false ); + } + + return $trashed; } /** diff --git a/src/classes/repositories/class-tainacan-fields.php b/src/classes/repositories/class-tainacan-fields.php index 3b12d9778..5c339c4e1 100644 --- a/src/classes/repositories/class-tainacan-fields.php +++ b/src/classes/repositories/class-tainacan-fields.php @@ -430,8 +430,6 @@ class Fields extends Repository { * @see \Tainacan\Repositories\Repository::insert() */ public function insert($field){ - $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); - $this->pre_update_category_field($field); $new_field = parent::insert($field); @@ -452,7 +450,14 @@ class Fields extends Repository { public function delete($field_id){ $this->delete_category_field($field_id); - return new Entities\Field( wp_trash_post( $field_id ) ); + + $deleted = new Entities\Field( wp_trash_post( $field_id ) ); + + if($deleted) { + do_action( 'tainacan-deleted', $deleted, $is_update = false, $is_delete_permanently = true ); + } + + return $deleted; } /** diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php index 7c022bd81..f1937a592 100644 --- a/src/classes/repositories/class-tainacan-filters.php +++ b/src/classes/repositories/class-tainacan-filters.php @@ -186,10 +186,24 @@ class Filters extends Repository { */ public function delete($args){ if(!empty($args[1]) && $args[1] === true){ - return new Entities\Filter(wp_delete_post($args[0], $args[1])); + + $deleted = new Entities\Filter(wp_delete_post($args[0], $args[1])); + + if($deleted){ + do_action('tainacan-deleted', $deleted, $is_update = false, $is_delete_permanently = true); + } + + return $deleted; } - return new Entities\Filter(wp_trash_post($args[0])); + + $trashed = new Entities\Filter(wp_trash_post($args[0])); + + if($trashed){ + do_action('tainacan-trashed', $trashed, $is_update = false, $is_delete_permanently = false); + } + + return $trashed; } public function update($object, $new_values = null){ diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 3426c1893..5b03d9e74 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -13,18 +13,15 @@ class Items extends Repository { private static $instance = null; - public static function get_instance() - { - if(!isset(self::$instance)) - { + public static function get_instance() { + if(!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } - protected function __construct() - { + protected function __construct() { parent::__construct(); add_filter( 'posts_where', array(&$this, 'title_in_posts_where'), 10, 2 ); add_filter( 'posts_where', array(&$this, 'content_in_posts_where'), 10, 2 ); @@ -167,108 +164,7 @@ class Items extends Repository { } public function insert( $item ) { - - $is_update = false; - $diffs = []; - if ( $item->get_id() ) { - - $old = $item->get_repository()->fetch( $item->get_id() ); - - if($old->get_status() === 'auto-draft') { - $is_update = false; - } else { - $is_update = true; - } - - $diffs = $this->diff($old, $item); - } - - $map = $this->get_map(); - - // get collection to determine post type - $collection = $item->get_collection(); - - if ( !$collection ) { - return false; - } - - $cpt = $collection->get_db_identifier(); - - // iterate through the native post properties - foreach ( $map as $prop => $mapped ) { - if ( $mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi' && $mapped['map'] != 'terms' ) { - $item->WP_Post->{$mapped['map']} = $item->get_mapped_property( $prop ); - } - } - - // save post and get its ID - $item->WP_Post->post_type = $cpt; - //$item->WP_Post->post_status = 'publish'; - - $id = wp_insert_post( $item->WP_Post ); - $item->WP_Post = get_post( $id ); - - // Now run through properties stored as postmeta - foreach ( $map as $prop => $mapped ) { - if ( $mapped['map'] == 'meta' ) { - update_post_meta( $id, $prop, wp_slash( $item->get_mapped_property( $prop ) ) ); - } elseif ( $mapped['map'] == 'meta_multi' ) { - $values = $item->get_mapped_property( $prop ); - - delete_post_meta( $id, $prop ); - - if ( is_array( $values ) ) { - foreach ( $values as $value ) { - add_post_meta( $id, $prop, wp_slash( $value ) ); - } - } - } - } - - if ( method_exists( $item, 'get_featured_img_id' ) ) { - if ( ! get_post_thumbnail_id( $item->WP_Post->ID ) ) { - // was added a thumbnail - - $settled = set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) ); - - if ( $settled ) { - - $thumbnail_url = get_the_post_thumbnail_url( $item->WP_Post->ID ); - - $diffs['featured_image'] = [ - 'new' => $thumbnail_url, - 'old' => '', - 'diff_with_index' => 0, - ]; - - } - - } else { - - // was update a thumbnail - - $old_thumbnail = get_the_post_thumbnail_url( $item->WP_Post->ID ); - - $settled = set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) ); - - if ( $settled ) { - - $thumbnail_url = get_the_post_thumbnail_url( $item->WP_Post->ID ); - - $diffs['featured_image'] = [ - 'new' => $thumbnail_url, - 'old' => $old_thumbnail, - 'diff_with_index' => 0, - ]; - } - } - } - - do_action( 'tainacan-insert', $item, $diffs, $is_update ); - do_action( 'tainacan-insert-Item', $item ); - - // return a brand new object - return new Entities\Item( $item->WP_Post ); + return parent::insert($item); } /** @@ -395,10 +291,23 @@ class Items extends Repository { */ public function delete( $args ) { if ( ! empty( $args[1] ) && $args[1] === true ) { - return new Entities\Item( wp_delete_post( $args[0], $args[1] ) ); + + $deleted = new Entities\Item( wp_delete_post( $args[0], $args[1] ) ); + + if($deleted) { + do_action( 'tainacan-deleted', $deleted, $is_update = false, $is_delete_permanently = true ); + } + + return $deleted; } - return new Entities\Item( wp_trash_post( $args[0] ) ); + $trashed = new Entities\Item( wp_trash_post( $args[0] ) ); + + if($trashed) { + do_action( 'tainacan-trashed', $trashed, $is_update = false, $is_delete_permanently = false ); + } + + return $trashed; } /** diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index 851a9ad93..4dab76789 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -28,10 +28,12 @@ class Logs extends Repository { protected function __construct() { parent::__construct(); - add_action( 'tainacan-insert', array( $this, 'insert_log' ), 10, 3 ); + add_action( 'tainacan-insert', array( $this, 'insert_log' ), 10, 4 ); + add_action( 'tainacan-deleted', array( $this, 'insert_log'), 10, 4 ); + add_action( 'tainacan-trashed', array( $this, 'insert_log'), 10, 4 ); - add_action( 'add_attachment', array( $this, 'prepare_attachment_log_before_insert' ), 10, 3 ); -// add_action( 'attachment_updated', array( $this, 'prepare_attachment_log_before_insert' ), 10, 3); + add_action( 'add_attachment', array( $this, 'prepare_attachment_log_before_insert' ), 10 ); + add_action( 'attachment_updated', array( $this, 'prepare_attachment_log_before_insert' ), 10, 3); } public function get_map() { @@ -263,6 +265,8 @@ class Logs extends Repository { } } + } else { + // TODO: Save a log when a attachment is updated } } @@ -270,16 +274,16 @@ class Logs extends Repository { * Insert a log when a new entity is inserted * * @param Entity $new_value - * @param Entity $old_value - * + * @param array $diffs * @param null $is_update * * @return Entities\Log new created log */ - public function insert_log( $new_value, $diffs, $is_update = null ) { + public function insert_log( $new_value, $diffs = [], $is_update = null, $is_delete_permanently = null ) { $msn = ""; $description = ""; + // TODO: Continue with is_delete_permanently if ( is_object( $new_value ) ) { // do not log a log if ( ( method_exists( $new_value, 'get_post_type' ) && $new_value->get_post_type() === 'tainacan-log' ) || $new_value->get_status() === 'auto-draft' ) { diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index 895bc70c4..8b0367f07 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -108,6 +108,19 @@ abstract class Repository { $obj->WP_Post->post_status = 'publish'; } + if( $obj instanceof Entities\Item ){ + // get collection to determine post type + $collection = $obj->get_collection(); + + if ( !$collection ) { + return false; + } + + $post_t = $collection->get_db_identifier(); + + $obj->WP_Post->post_type = $post_t; + } + // TODO verificar se salvou mesmo $id = wp_insert_post( $obj->WP_Post ); diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index 426fb2d5a..80171043d 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -193,22 +193,26 @@ class Taxonomies extends Repository { return $unregistered; } - $deleted = wp_delete_post($taxonomy_id, true); + $deleted = new Entities\Taxonomy(wp_delete_post($taxonomy_id, true)); if(!$deleted){ return $deleted; } - return new Entities\Taxonomy($deleted); + do_action('tainacan-deleted', $deleted, $is_update = false, $is_delete_permanently = true); + + return $deleted; } - $trashed = wp_trash_post($taxonomy_id); + $trashed = new Entities\Taxonomy(wp_trash_post($taxonomy_id)); if(!$trashed){ return $trashed; } - return new Entities\Taxonomy($trashed); + do_action('tainacan-trashed', $trashed, $diffs = [], $is_update = false, $is_delete_permanently = false ); + + return $trashed; } diff --git a/src/classes/repositories/class-tainacan-terms.php b/src/classes/repositories/class-tainacan-terms.php index 270ffd4ae..fbf1d1571 100644 --- a/src/classes/repositories/class-tainacan-terms.php +++ b/src/classes/repositories/class-tainacan-terms.php @@ -225,7 +225,15 @@ class Terms extends Repository { } public function delete($args){ - return wp_delete_term($args[0], $args[1]); + $deleted = wp_delete_term($args[0], $args[1]); + + if($deleted) { + $deleted_term_tainacan = new Entities\Term($args[0], $args[1]); + + do_action( 'tainacan-deleted', $deleted_term_tainacan, $is_update = false, $is_delete_permanently = true ); + } + + return $deleted; } public function register_post_type() { } diff --git a/src/exposers/types/class-tainacan-html.php b/src/exposers/types/class-tainacan-html.php index b1bd35bed..cd66c9ac2 100644 --- a/src/exposers/types/class-tainacan-html.php +++ b/src/exposers/types/class-tainacan-html.php @@ -52,7 +52,7 @@ class Html extends Type { $html .= ''.htmlspecialchars($value).''; } } - if(count($data > 0)) $html = ''.implode('', $heads).''.$html.''; + if(count($data) > 0) $html = ''.implode('', $heads).''.$html.''; return $html; } } \ No newline at end of file diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index 7bf2fe748..fe6cee47a 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -406,7 +406,13 @@ abstract class Importer { // inserted the id on processed item with its index as array index $this->processed_items[ $index ] = $item->get_id(); - $Tainacan_Items->update( $item ); + if($item->validate()) { + $Tainacan_Items->update( $item ); + } else { + $this->add_log( 'error', 'Item ' . $index . ': ' ); // TODO add the $item->get_errors() array + return false; + } + return $item; } else { $this->add_log( 'error', 'Collection not set'); diff --git a/tests/factories/class-tainacan-entity-factory.php b/tests/factories/class-tainacan-entity-factory.php index ef31b781e..c55484112 100644 --- a/tests/factories/class-tainacan-entity-factory.php +++ b/tests/factories/class-tainacan-entity-factory.php @@ -26,6 +26,8 @@ class Entity_Factory { * @param array $args * @param bool $is_validated_and_in_db * + * @param bool $publish + * * @return mixed * @throws \ErrorException */ diff --git a/tests/test-api-exposers.php b/tests/test-api-exposers.php index c5b770bea..6d6a25f19 100644 --- a/tests/test-api-exposers.php +++ b/tests/test-api-exposers.php @@ -70,7 +70,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'values' => 'TestValues_exposers', ]); - $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() ); + $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/' . $this->field->get_id() ); $request->set_body($item__metadata_json); $response = $this->server->dispatch($request); @@ -79,13 +79,13 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $data = $response->get_data(); - $this->assertEquals($item->get_id(), $data['item']['id']); + $this->assertEquals($this->item->get_id(), $data['item']['id']); $this->assertEquals('TestValues_exposers', $data['value']); $item_exposer_json = json_encode([ 'exposer-map' => 'Value', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->field->get_id() ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -93,7 +93,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $this->assertEquals('TestValues_exposers', $data['teste_Expose']); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -116,7 +116,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'values' => 'TestValues_exposers', ]); - $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() ); + $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/' . $this->field->get_id() ); $request->set_body($item__metadata_json); $response = $this->server->dispatch($request); @@ -125,14 +125,14 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $data = $response->get_data(); - $this->assertEquals($item->get_id(), $data['item']['id']); + $this->assertEquals($this->item->get_id(), $data['item']['id']); $this->assertEquals('TestValues_exposers', $data['value']); $item_exposer_json = json_encode([ 'exposer-type' => 'Xml', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->field->get_id() ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -143,7 +143,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $item_exposer_json = json_encode([ 'exposer-map' => 'Dublin Core', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->field->get_id() ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -154,7 +154,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'exposer-type' => 'Xml', 'exposer-map' => 'Dublin Core', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -181,7 +181,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $item_exposer_json = json_encode([ 'exposer-type' => 'OAI-PMH', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -205,7 +205,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'exposer-type' => 'Html', 'exposer-map' => 'Value' ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -254,7 +254,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'values' => 'TestValues_exposers', ]); - $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() ); + $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/' . $this->field->get_id() ); $request->set_body($item__metadata_json); $response = $this->server->dispatch($request); @@ -264,7 +264,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $item_exposer_json = json_encode([ 'exposer-type' => 'Csv', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' ); + $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); @@ -300,7 +300,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'values' => 'TestValues_exposers', ]); - $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() ); + $request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/' . $this->field->get_id() ); $request->set_body($item__metadata_json); $response = $this->server->dispatch($request); @@ -309,7 +309,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { $data = $response->get_data(); - $this->assertEquals($item->get_id(), $data['item']['id']); + $this->assertEquals($this->item->get_id(), $data['item']['id']); $this->assertEquals('TestValues_exposers', $data['value']); $item2 = $this->tainacan_entity_factory->create_entity( @@ -317,7 +317,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { array( 'title' => 'item_teste_Expose2', 'description' => 'adasdasdsa2', - 'collection' => $collection + 'collection' => $this->collection ), true, true @@ -328,7 +328,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { array( 'title' => 'item_teste_Expose3', 'description' => 'adasdasdsa3', - 'collection' => $collection + 'collection' => $this->collection ), true, true @@ -338,7 +338,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { 'exposer-map' => 'Value', ]); - $request = new \WP_REST_Request('GET', $this->namespace . '/items/' . $item->get_id() ); + $request = new \WP_REST_Request('GET', $this->namespace . '/items/' . $this->item->get_id() ); $request->set_body($item_exposer_json); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status());