Test endpoint 'collections'
This commit is contained in:
parent
9c0d1dd734
commit
d318bd0d42
|
@ -3,7 +3,8 @@
|
|||
"description": "Protótipo",
|
||||
"type": "wordpress-plugin",
|
||||
"require": {
|
||||
"respect/validation": "^1.1"
|
||||
"respect/validation": "^1.1",
|
||||
"guzzlehttp/guzzle": "^6.2@dev"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"config": {
|
||||
|
|
|
@ -4,8 +4,239 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "e0eb272f68b3132a64ef299d34cf9700",
|
||||
"content-hash": "06908e8219e421f4b636b0159525e648",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "6.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699",
|
||||
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/promises": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.4",
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": "^4.0 || ^5.0",
|
||||
"psr/log": "^1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"psr/log": "Required for using the Log middleware"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "6.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2017-06-22T18:50:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "e9cdab6ff93ff789b5b599326c727f51d10893a6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/e9cdab6ff93ff789b5b599326c727f51d10893a6",
|
||||
"reference": "e9cdab6ff93ff789b5b599326c727f51d10893a6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.36"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"time": "2017-10-06T12:25:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "d2537c86fa8b004c29e9b9f5e10028f0a29df101"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/d2537c86fa8b004c29e9b9f5e10028f0a29df101",
|
||||
"reference": "d2537c86fa8b004c29e9b9f5e10028f0a29df101",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2017-10-07T03:19:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "respect/validation",
|
||||
"version": "1.1.x-dev",
|
||||
|
@ -134,7 +365,9 @@
|
|||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": [],
|
||||
"stability-flags": {
|
||||
"guzzlehttp/guzzle": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Items_Controller extends WP_REST_Controller {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
const ENDPOINTS_DIR = __DIR__ . '/endpoints/';
|
||||
const ENDPOINTS_DIR = __DIR__ . '/endpoints/';
|
||||
|
||||
require_once(ENDPOINTS_DIR . 'class-tainacan-rest-collections-controller.php');
|
||||
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
|
||||
|
|
|
@ -11,7 +11,7 @@ class Collection extends Entity {
|
|||
|
||||
protected static $post_type = 'tainacan-collections';
|
||||
protected $repository = 'Tainacan_Collections';
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance of Collection
|
||||
* @param integer|\WP_Post optional $which Collection ID or a WP_Post object for existing collections. Leave empty to create a new collection.
|
||||
|
@ -19,11 +19,11 @@ class Collection extends Entity {
|
|||
function __construct($which = 0) {
|
||||
if (is_numeric($which) && $which > 0) {
|
||||
$post = get_post($which);
|
||||
|
||||
|
||||
if ($post instanceof \WP_Post) {
|
||||
$this->WP_Post = get_post($which);
|
||||
}
|
||||
|
||||
|
||||
} elseif ($which instanceof \WP_Post) {
|
||||
$this->WP_Post = $which;
|
||||
} else {
|
||||
|
@ -41,7 +41,9 @@ class Collection extends Entity {
|
|||
'name' => $this->get_name(),
|
||||
'description' => $this->get_description(),
|
||||
'items_per_page' => $this->get_itens_per_page(),
|
||||
]
|
||||
],
|
||||
JSON_NUMERIC_CHECK,
|
||||
JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
}
|
||||
/**
|
||||
|
@ -68,9 +70,9 @@ class Collection extends Entity {
|
|||
'parent_item_colon' => 'Item acima:',
|
||||
'menu_name' => $this->get_name()
|
||||
);
|
||||
|
||||
|
||||
$cpt_slug = $this->get_db_identifier();
|
||||
|
||||
|
||||
$args = array(
|
||||
'labels' => $cpt_labels,
|
||||
'hierarchical' => true,
|
||||
|
@ -91,10 +93,10 @@ class Collection extends Entity {
|
|||
],
|
||||
'capability_type' => 'post',
|
||||
);
|
||||
|
||||
if (post_type_exists($this->get_db_identifier()))
|
||||
|
||||
if (post_type_exists($this->get_db_identifier()))
|
||||
unregister_post_type($this->get_db_identifier());
|
||||
|
||||
|
||||
register_post_type($cpt_slug, $args);
|
||||
}*/
|
||||
|
||||
|
@ -159,7 +161,7 @@ class Collection extends Entity {
|
|||
function get_itens_per_page() {
|
||||
return $this->get_mapped_property('itens_per_page');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get collection DB identifier
|
||||
*
|
||||
|
@ -170,7 +172,7 @@ class Collection extends Entity {
|
|||
function get_db_identifier() {
|
||||
return $this->get_id() ? 'tnc_col_' . $this->get_id() : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get collection metadata.
|
||||
*
|
||||
|
@ -184,7 +186,7 @@ class Collection extends Entity {
|
|||
$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas();
|
||||
return $Tainacan_Metadatas->fetch($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the collection name
|
||||
*
|
||||
|
@ -198,7 +200,7 @@ class Collection extends Entity {
|
|||
/**
|
||||
* Set the collection slug
|
||||
*
|
||||
* If you dont set the collection slug, it will be set automatically based on the name and
|
||||
* If you dont set the collection slug, it will be set automatically based on the name and
|
||||
* following WordPress default behavior of creating slugs for posts.
|
||||
*
|
||||
* If you set the slug for an existing one, WordPress will append a number at the end of in order
|
||||
|
@ -250,4 +252,4 @@ class Collection extends Entity {
|
|||
function set_itens_per_page($value) {
|
||||
$this->set_mapped_property('itens_per_page', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
use \GuzzleHttp\Client;
|
||||
|
||||
class TAINACAN_REST_Collections_Controller extends \PHPUnit_Framework_TestCase {
|
||||
protected $client;
|
||||
|
||||
const URL = 'http://localhost/wordpress/';
|
||||
|
||||
protected function setUp(){
|
||||
$this->client = new Client([
|
||||
'base_uri' => self::URL,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_fetch_collection_by_id(){
|
||||
$id = 1;
|
||||
$response = $this->client->request('GET', 'wp-json/tainacan/v2/collections/'. $id);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
$data = json_decode(json_decode($response->getBody(), true));
|
||||
var_dump($data);
|
||||
$this->assertEquals('teste', $data->name);
|
||||
}
|
||||
|
||||
public function test_fetch_collections(){
|
||||
$response = $this->client->request('GET', 'wp-json/tainacan/v2/collections/');
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
$data = json_decode($response->getBody(), true);
|
||||
var_dump($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue