test metadata api insert and suggest handler
This commit is contained in:
parent
46787350be
commit
ee95450891
|
@ -7,7 +7,7 @@ namespace Tainacan\Tests;
|
|||
*/
|
||||
class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
public function test_create_item_metadata_in_a_collection(){
|
||||
public function test_create_suggestion_item_metadata_in_a_collection(){
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
|
@ -27,7 +27,8 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'name' => 'teste_metadado',
|
||||
'description' => 'descricao',
|
||||
'collection' => $collection,
|
||||
'field_type' => $type
|
||||
'field_type' => $type,
|
||||
'accept_suggestion' => true
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -55,7 +56,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals(9 , $data['item']['id']);
|
||||
$this->assertEquals($item->get_id() , $data['item']['id']);
|
||||
$this->assertEquals('TestValues', $data['value']);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
|
@ -63,6 +64,35 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$this->assertEquals( 'TestValues', $data['value'] );
|
||||
|
||||
// Test Suggestion
|
||||
$new_user = $this->factory()->user->create(array( 'role' => 'subscriber' ));
|
||||
wp_set_current_user($new_user);
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValuesSuggestion',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'pending', $data['status'] );
|
||||
global $Tainacan_Logs;
|
||||
$query = $Tainacan_Logs->fetch(['post_status' => 'pending']);
|
||||
|
||||
$log = false;
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
$post = get_post();
|
||||
$log = $Tainacan_Logs->get_entity_by_post($post);
|
||||
}
|
||||
|
||||
$pending = $log->get_value();
|
||||
|
||||
$this->assertEquals('TestValuesSuggestion', $pending->value);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue