mirror of
https://github.com/flarum/core.git
synced 2025-08-09 09:57:06 +02:00
Upgrade to L5 + huge refactor + more. closes #2
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!
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
<?php
|
||||
use \ApiTester;
|
||||
|
||||
use Laracasts\TestDummy\Factory;
|
||||
|
||||
class DiscussionsResourceCest {
|
||||
|
||||
class DiscussionsResourceCest
|
||||
{
|
||||
protected $endpoint = '/api/discussions';
|
||||
|
||||
public function getDiscussions(ApiTester $I)
|
||||
{
|
||||
$I->wantTo('get discussions via API');
|
||||
|
||||
$discussions = Factory::times(2)->create('Flarum\Core\Discussions\Discussion');
|
||||
$discussions = Factory::times(2)->create('Flarum\Core\Models\Discussion');
|
||||
|
||||
$I->sendGET($this->endpoint);
|
||||
$I->seeResponseCodeIs(200);
|
||||
@@ -20,7 +19,7 @@ class DiscussionsResourceCest {
|
||||
$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->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]);
|
||||
}
|
||||
@@ -29,12 +28,13 @@ class DiscussionsResourceCest {
|
||||
{
|
||||
$I->wantTo('show a single discussion via API');
|
||||
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion');
|
||||
$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]]);
|
||||
}
|
||||
|
||||
@@ -47,11 +47,14 @@ class DiscussionsResourceCest {
|
||||
$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>']);
|
||||
|
||||
// @todo check for post in response
|
||||
|
||||
$I->expect('the discussion was created in the database');
|
||||
$id = $I->grabDataFromJsonResponse('discussions.id');
|
||||
$I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']);
|
||||
}
|
||||
@@ -62,13 +65,16 @@ class DiscussionsResourceCest {
|
||||
|
||||
$user = $I->amAuthenticated();
|
||||
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion', ['start_user_id' => $user->id]);
|
||||
$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']);
|
||||
}
|
||||
@@ -78,14 +84,15 @@ class DiscussionsResourceCest {
|
||||
$I->wantTo('delete a discussion via API');
|
||||
|
||||
$user = $I->amAuthenticated();
|
||||
$user->groups()->attach(4);
|
||||
$user->groups()->attach(4); // Make the user a moderator
|
||||
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion', ['start_user_id' => $user->id]);
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user