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 {
const URL = 'http://localhost/wordpress-test/';
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',
'itemsPerPage' => 10,
2017-11-27 14:32:03 +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
$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(){
$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
$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
}
}
?>