mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
2c46888db5
New stuff: - Signup + email confirmation. - Updated authentication strategy with remember cookies. closes #5 - New search system with some example gambits! This is cool - check out the source. Fulltext drivers will be implemented as decorators overriding the EloquentPostRepository’s findByContent method. - Lay down the foundation for bootstrapping the Ember app. - Update Web layer’s asset manager to properly publish CSS/JS files. - Console commands to run installation migrations and seeds. Refactoring: - New structure: move models, repositories, commands, and events into their own namespaces, rather than grouping by entity. - All events are classes. - Use L5 middleware and command bus implementations. - Clearer use of repositories and the Active Record pattern. Repositories are used only for retrieval of ActiveRecord objects, and then save/delete operations are called directly on those ActiveRecords. This way, we don’t over-abstract at the cost of Eloquent magic, but testing is still easy. - Refactor of Web layer so that it uses the Actions routing architecture. - “Actor” concept instead of depending on Laravel’s Auth. - General cleanup!
99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
|
|
|
use Laracasts\TestDummy\Factory;
|
|
|
|
class DiscussionsResourceCest
|
|
{
|
|
protected $endpoint = '/api/discussions';
|
|
|
|
public function getDiscussions(ApiTester $I)
|
|
{
|
|
$I->wantTo('get discussions via API');
|
|
|
|
$discussions = Factory::times(2)->create('Flarum\Core\Models\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('the discussions exist');
|
|
$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\Models\Discussion');
|
|
|
|
$I->sendGET($this->endpoint.'/'.$discussion->id);
|
|
$I->seeResponseCodeIs(200);
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->expect('the discussion in the response exists');
|
|
$I->seeResponseContainsJson(['discussions' => ['id' => (string) $discussion->id, 'title' => $discussion->title]]);
|
|
}
|
|
|
|
public function createDiscussion(ApiTester $I)
|
|
{
|
|
$I->wantTo('create a discussion via API');
|
|
|
|
$I->amAuthenticated();
|
|
|
|
$I->sendPOST($this->endpoint, ['discussions' => ['title' => 'foo', 'content' => 'bar']]);
|
|
$I->seeResponseCodeIs(200);
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->expect('the discussion is included in the response');
|
|
$I->seeResponseContainsJson(['title' => 'foo']);
|
|
|
|
$I->expect('posts are included in the response');
|
|
$I->seeResponseContainsJson(['type' => 'comment', 'contentHtml' => '<p>bar</p>']);
|
|
|
|
$I->expect('the discussion was created in the database');
|
|
$id = $I->grabDataFromJsonResponse('discussions.id');
|
|
$I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']);
|
|
}
|
|
|
|
public function updateDiscussion(ApiTester $I)
|
|
{
|
|
$I->wantTo('update a discussion via API');
|
|
|
|
$user = $I->amAuthenticated();
|
|
|
|
$discussion = Factory::create('Flarum\Core\Models\Discussion', ['start_user_id' => $user->id]);
|
|
|
|
$I->sendPUT($this->endpoint.'/'.$discussion->id, ['discussions' => ['title' => 'foo']]);
|
|
$I->seeResponseCodeIs(200);
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->expect('the discussion title was updated');
|
|
$I->seeResponseContainsJson(['title' => 'foo']);
|
|
|
|
$I->expect('the discussion was updated in the database');
|
|
$id = $I->grabDataFromJsonResponse('discussions.id');
|
|
$I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']);
|
|
}
|
|
|
|
public function deleteDiscussion(ApiTester $I)
|
|
{
|
|
$I->wantTo('delete a discussion via API');
|
|
|
|
$user = $I->amAuthenticated();
|
|
$user->groups()->attach(4); // Make the user a moderator
|
|
|
|
$discussion = Factory::create('Flarum\Core\Models\Discussion', ['start_user_id' => $user->id]);
|
|
|
|
$I->sendDELETE($this->endpoint.'/'.$discussion->id);
|
|
$I->seeResponseCodeIs(204);
|
|
$I->seeResponseEquals('');
|
|
|
|
$I->expect('the discussion was deleted in the database');
|
|
$I->dontSeeRecord('discussions', ['id' => $discussion->id]);
|
|
}
|
|
}
|