2017-11-27 14:32:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
class TAINACAN_REST_Collections_Controller extends \WP_UnitTestCase {
|
|
|
|
const URL = 'http://localhost/wordpress-test/';
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
public function test_create_and_fetch_collection_by_id(){
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$collection_JSON = json_encode([
|
|
|
|
'name' => 'Teste',
|
|
|
|
'description' => 'Teste JSON',
|
|
|
|
'itemsPerPage' => 10,
|
2017-11-27 14:32:03 +00:00
|
|
|
]);
|
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$collection = wp_remote_post(self::URL . 'wp-json/tainacan/v2/collections/', array(
|
|
|
|
'body' => $collection_JSON
|
|
|
|
));
|
|
|
|
|
|
|
|
$collection = json_decode(json_decode($collection['body'], true), true);
|
|
|
|
|
|
|
|
$id = $collection['id'];
|
|
|
|
|
|
|
|
$response = wp_remote_get(self::URL . 'wp-json/tainacan/v2/collections/'. $id);
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$this->assertEquals(200, $response['response']['code']);
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$data = json_decode(json_decode($response['body'], true), true);
|
|
|
|
|
|
|
|
$this->assertEquals('Teste', $data['name']);
|
2017-11-27 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_fetch_collections(){
|
2017-11-29 13:45:30 +00:00
|
|
|
$response = wp_remote_get(self::URL . 'wp-json/tainacan/v2/collections/');
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['response']['code']);
|
|
|
|
|
|
|
|
$data = json_decode(json_decode($response['body'], true), true);
|
|
|
|
|
|
|
|
$this->assertContainsOnly('string', $data);
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$one_collection = json_decode($data[0], true);
|
2017-11-27 14:32:03 +00:00
|
|
|
|
2017-11-29 13:45:30 +00:00
|
|
|
$this->assertEquals('Teste', $one_collection['name']);
|
2017-11-27 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|