From 75a64ebed1d381406fc61221dfb7bd3cd3499c99 Mon Sep 17 00:00:00 2001 From: weryques Date: Thu, 7 Dec 2017 10:00:35 -0200 Subject: [PATCH] Test fetch items from a collection --- tests/test-api-items.php | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test-api-items.php diff --git a/tests/test-api-items.php b/tests/test-api-items.php new file mode 100644 index 000000000..446e5e6fb --- /dev/null +++ b/tests/test-api-items.php @@ -0,0 +1,55 @@ +tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'Agile', + 'description' => 'Agile methods' + ), + true + ); + + $item1 = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'Lean Startup', + 'description' => 'Um processo ágio de criação de novos negócios.', + 'collection' => $collection + ), + true + ); + + $item2 = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'SCRUM', + 'description' => 'Um framework ágio para gerenciamento de tarefas.', + 'collection' => $collection + ), + true + ); + + $request = new \WP_REST_Request('GET', $this->namespaced_route . '/items/collection/' . $collection->get_id()); + $response = $this->server->dispatch($request); + + $this->assertEquals(201, $response->get_status()); + + $data = json_decode($response->get_data(), true); + + $this->assertContainsOnly('string', $data); + + $first_item = json_decode($data[0], true); + $second_item = json_decode($data[1], true); + + $this->assertEquals($item2->get_title(), $first_item['title']); + $this->assertEquals($item1->get_title(), $second_item['title']); +} + +} + +?> \ No newline at end of file