tainacan/tests/test-api-terms.php

75 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Tainacan\Tests;
class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
public function test_create_term(){
$taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => '1genero',
'description' => 'tipos de musica',
'allow_insert' => 'yes',
'status' => 'publish'
),
true
);
$request = new \WP_REST_Request(
2018-01-15 19:47:27 +00:00
'POST', $this->namespace . '/terms/taxonomy/' . $taxonomy->get_id()
);
$term = json_encode([
'name' => 'Termo teste',
'user' => get_current_user_id()
]);
$request->set_body($term);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals('Termo teste', $data['name']);
$this->assertEquals($taxonomy->get_db_identifier(), $data['taxonomy']);
}
2018-01-15 19:47:27 +00:00
public function test_delete(){
$taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => '1genero',
'description' => 'tipos de musica',
'allow_insert' => 'yes',
'status' => 'publish'
),
true
);
$term = $this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $taxonomy->get_db_identifier(),
'name' => 'Rock',
'user' => get_current_user_id(),
),
true
);
$request = new \WP_REST_Request('DELETE', $this->namespace . '/terms/' . $term . '/taxonomy/' . $taxonomy->get_id());
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertTrue($data);
$term = get_term($term);
$this->assertNull($term);
}
}
?>