1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Begin testing API (see #3)

This commit is contained in:
Toby Zerner
2015-01-19 20:46:14 +10:30
parent 49be8417a9
commit 2fcb1dc7c8
10 changed files with 3119 additions and 29 deletions

View File

@@ -0,0 +1,10 @@
<?php
namespace Codeception\Module;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class ApiHelper extends \Codeception\Module
{
}

View File

@@ -1,4 +1,4 @@
<?php //[STAMP] 62377ab49c890e65388dcf2e4aedfd9c
<?php //[STAMP] 35004e907fa829d784ccbf5cd2166fcf
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build

3
tests/api.suite.yml Normal file
View File

@@ -0,0 +1,3 @@
class_name: ApiTester
modules:
enabled: [Laravel4, REST, Asserts, ApiHelper]

3032
tests/api/ApiTester.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
<?php
use \ApiTester;
class DiscussionsResourceCest {
protected $endpoint = '/api/discussions';
public function getDiscussions(ApiTester $I)
{
$I->wantTo('get discussions via API');
$id = $I->haveRecord('discussions', ['title' => 'Game of Thrones', 'last_time' => date('c')]);
$id2 = $I->haveRecord('discussions', ['title' => 'Lord of the Rings', 'last_time' => date('c')]);
$I->sendGET($this->endpoint);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->expect('both items are in response');
$I->seeResponseContainsJson(['id' => (string) $id, 'title' => 'Game of Thrones']);
$I->seeResponseContainsJson(['id' => (string) $id2, 'title' => 'Lord of the Rings']);
$I->expect('both items are in root discussions array');
$I->seeResponseContainsJson(['discussions' => [['id' => (string) $id], ['id' => (string) $id2]]]);
}
public function createDiscussion(ApiTester $I)
{
$I->wantTo('create a discussion via API');
$I->haveHttpHeader('Authorization', 'Token 123456');
$I->sendPOST($this->endpoint, ['discussions' => ['title' => 'foo', 'content' => 'bar']]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['title' => 'foo']);
$I->seeResponseContainsJson(['type' => 'comment', 'contentHtml' => '<p>bar</p>']);
$id = $I->grabDataFromJsonResponse('discussions.id');
$I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']);
}
}

2
tests/api/_bootstrap.php Normal file
View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

@@ -1,4 +1,4 @@
<?php //[STAMP] 92e3a5639db903a93dbc0ada7934f9ca
<?php //[STAMP] 831f2f7900c1df5d29956ba25022e638
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build

View File

@@ -1,4 +1,4 @@
<?php //[STAMP] 4f61f396dfd2c13f154c1be4d8245c48
<?php //[STAMP] 5f044d831fb05d6a3185c10128c6729e
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build