tainacan/tests/test-api-collections.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2017-11-27 14:32:03 +00:00
<?php
namespace Tainacan\Tests;
class TAINACAN_REST_Collections_Controller extends \WP_UnitTestCase {
2017-11-27 14:32:03 +00:00
public function test_create_and_fetch_collection_by_id(){
2017-11-27 14:32:03 +00:00
$collection_JSON = json_encode([
'name' => 'Teste',
'description' => 'Teste JSON',
2017-11-27 14:32:03 +00:00
]);
2017-11-29 19:11:30 +00:00
$collection = wp_remote_post(TAINACAN_TESTS_URL . '/wp-json/tainacan/v2/collections/', array(
'body' => $collection_JSON
));
2017-11-29 19:11:30 +00:00
$this->assertEquals(201, $collection['response']['code']);
$collection = json_decode(json_decode($collection['body'], true), true);
$id = $collection['id'];
2017-11-29 19:11:30 +00:00
$response = wp_remote_get(TAINACAN_TESTS_URL . '/wp-json/tainacan/v2/collections/'. $id);
2017-11-27 14:32:03 +00:00
$this->assertEquals(200, $response['response']['code']);
2017-11-27 14:32:03 +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 19:11:30 +00:00
$response = wp_remote_get(TAINACAN_TESTS_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
$one_collection = json_decode($data[0], true);
2017-11-27 14:32:03 +00:00
$this->assertEquals('Teste', $one_collection['name']);
2017-11-27 14:32:03 +00:00
}
}
?>