wantTo('get discussions via API'); $discussions = Factory::times(2)->create('Flarum\Core\Discussions\Discussion'); $I->sendGET($this->endpoint); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->expect('there are two discussions in the response'); $I->assertEquals(2, count($I->grabDataFromJsonResponse('discussions'))); $I->expect('they are the discussions we created'); $I->seeResponseContainsJson(['id' => (string) $discussions[0]->id, 'title' => $discussions[0]->title]); $I->seeResponseContainsJson(['id' => (string) $discussions[1]->id, 'title' => $discussions[1]->title]); } public function showDiscussion(ApiTester $I) { $I->wantTo('show a single discussion via API'); $discussion = Factory::create('Flarum\Core\Discussions\Discussion'); $I->sendGET($this->endpoint.'/'.$discussion->id); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['discussions' => ['id' => (string) $discussion->id, 'title' => $discussion->title]]); } 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' => '
bar
']); $id = $I->grabDataFromJsonResponse('discussions.id'); $I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']); } public function updateDiscussion(ApiTester $I) { $I->wantTo('update a discussion via API'); $I->haveHttpHeader('Authorization', 'Token 123456'); $discussion = Factory::create('Flarum\Core\Discussions\Discussion'); $I->sendPUT($this->endpoint.'/'.$discussion->id, ['discussions' => ['title' => 'foo']]); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['title' => 'foo']); $id = $I->grabDataFromJsonResponse('discussions.id'); $I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']); } public function deleteDiscussion(ApiTester $I) { $I->wantTo('delete a discussion via API'); $I->haveHttpHeader('Authorization', 'Token 123456'); $discussion = Factory::create('Flarum\Core\Discussions\Discussion'); $I->sendDELETE($this->endpoint.'/'.$discussion->id); $I->seeResponseCodeIs(204); $I->seeResponseEquals(''); $I->dontSeeRecord('discussions', ['id' => $discussion->id]); } }