2017-12-11 16:46:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
|
|
|
use Tainacan\Repositories;
|
|
|
|
|
|
|
|
class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
|
|
|
|
|
|
|
public function test_insert_metadata() {
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity('collection', '', true);
|
|
|
|
|
|
|
|
$item = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'item',
|
|
|
|
array(
|
2017-12-12 11:59:50 +00:00
|
|
|
'title' => 'No name',
|
2017-12-11 16:46:26 +00:00
|
|
|
'description' => 'No description',
|
2017-12-12 11:59:50 +00:00
|
|
|
'collection' => $collection
|
2017-12-11 16:46:26 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$field = $this->tainacan_field_factory->create_field('text', '', true);
|
|
|
|
|
|
|
|
$metadata = json_encode(
|
|
|
|
array(
|
2017-12-12 11:59:50 +00:00
|
|
|
'name' => 'Moeda',
|
2017-12-11 16:46:26 +00:00
|
|
|
'description' => 'Descreve campo moeda.',
|
2017-12-12 11:59:50 +00:00
|
|
|
'field_type' => $field->get_primitive_type(),
|
2017-12-11 16:46:26 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'POST',
|
|
|
|
$this->namespaced_route . '/metadata/collection/' . $collection->get_id()
|
|
|
|
);
|
|
|
|
$request->set_body($metadata);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$metadata_added = json_decode($response->get_data(), true);
|
|
|
|
|
|
|
|
$this->assertEquals('Moeda', $metadata_added['name']);
|
|
|
|
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
|
|
|
$meta_values = json_encode(
|
|
|
|
array(
|
|
|
|
'metadata_id' => $metadata_added['id'],
|
|
|
|
'values' => 'Valorado'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'POST',
|
|
|
|
$this->namespaced_route . '/metadata/item/' . $item->get_id()
|
|
|
|
);
|
|
|
|
$request->set_body($meta_values);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$metadata_updated = json_decode($response->get_data(), true);
|
|
|
|
|
|
|
|
$this->assertEquals($metadata_added['id'], $metadata_updated['id']);
|
|
|
|
|
|
|
|
$metav = get_post_meta($item->get_id(), $metadata_updated['id'], true);
|
|
|
|
|
|
|
|
$this->assertEquals('Valorado', $metav);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|