mirror of
https://github.com/flarum/framework.git
synced 2024-11-30 13:36:10 +08:00
Merge branch 'master' of github.com:flarum/core
This commit is contained in:
commit
a46c9b0c1d
|
@ -53,6 +53,10 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
return $routes;
|
||||
});
|
||||
|
||||
$this->app->afterResolving('flarum.forum.routes', function (RouteCollection $routes) {
|
||||
$this->setDefaultRoute($routes);
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.forum.middleware', function (Application $app) {
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
|
@ -181,7 +185,16 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
$this->app->make('events')->fire(
|
||||
new ConfigureForumRoutes($routes, $factory)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the default route.
|
||||
*
|
||||
* @param RouteCollection $routes
|
||||
*/
|
||||
protected function setDefaultRoute(RouteCollection $routes)
|
||||
{
|
||||
$factory = $this->app->make(RouteHandlerFactory::class);
|
||||
$defaultRoute = $this->app->make('flarum.settings')->get('default_route');
|
||||
|
||||
if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) {
|
||||
|
|
|
@ -17,6 +17,7 @@ use Flarum\Api\Client;
|
|||
use Flarum\Api\Controller\CreateGroupController;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\Guest;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Str;
|
||||
|
@ -57,7 +58,6 @@ class AuthenticateWithApiKeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function cannot_authorize_without_key()
|
||||
{
|
||||
|
@ -65,6 +65,8 @@ class AuthenticateWithApiKeyTest extends TestCase
|
|||
$api = $this->app()->getContainer()->make(Client::class);
|
||||
$api->setErrorHandler(null);
|
||||
|
||||
$this->expectException(PermissionDeniedException::class);
|
||||
|
||||
$api->send(CreateGroupController::class, new Guest);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ use Flarum\Api\Controller\CreateDiscussionController;
|
|||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
|
@ -65,8 +66,6 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
* @expectedExceptionMessage The given data was invalid.
|
||||
*/
|
||||
public function cannot_create_discussion_without_content()
|
||||
{
|
||||
|
@ -74,13 +73,14 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
|||
|
||||
$data = Arr::except($this->data, 'content');
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->expectExceptionMessage('The given data was invalid.');
|
||||
|
||||
$this->callWith($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
* @expectedExceptionMessage The given data was invalid.
|
||||
*/
|
||||
public function cannot_create_discussion_without_title()
|
||||
{
|
||||
|
@ -88,6 +88,9 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase
|
|||
|
||||
$data = Arr::except($this->data, 'title');
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->expectExceptionMessage('The given data was invalid.');
|
||||
|
||||
$this->callWith($data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,11 @@ namespace Flarum\Tests\integration\api\Controller;
|
|||
|
||||
use Flarum\Api\Controller\CreateGroupController;
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateGroupControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
|
@ -48,13 +50,14 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
* @expectedExceptionMessage The given data was invalid.
|
||||
*/
|
||||
public function admin_cannot_create_group_without_data()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->expectExceptionMessage('The given data was invalid.');
|
||||
|
||||
$this->callWith();
|
||||
}
|
||||
|
||||
|
@ -81,12 +84,13 @@ class CreateGroupControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function unauthorized_user_cannot_create_group()
|
||||
{
|
||||
$this->actor = User::find(2);
|
||||
|
||||
$this->expectException(PermissionDeniedException::class);
|
||||
|
||||
$this->callWith($this->data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ namespace Flarum\Tests\integration\api\Controller;
|
|||
|
||||
use Flarum\Api\Controller\CreateUserController;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateUserControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
|
@ -48,11 +50,12 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
* @expectedExceptionMessage The given data was invalid.
|
||||
*/
|
||||
public function cannot_create_user_without_data()
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->expectExceptionMessage('The given data was invalid.');
|
||||
|
||||
$this->callWith();
|
||||
}
|
||||
|
||||
|
@ -96,7 +99,6 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function disabling_sign_up_prevents_user_creation()
|
||||
{
|
||||
|
@ -104,6 +106,8 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
|||
$settings = app(SettingsRepositoryInterface::class);
|
||||
$settings->set('allow_sign_up', false);
|
||||
|
||||
$this->expectException(PermissionDeniedException::class);
|
||||
|
||||
try {
|
||||
$this->callWith($this->data);
|
||||
} finally {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Flarum\Tests\integration\api\Controller;
|
||||
|
||||
use Flarum\Api\Controller\ListNotificationsController;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ListNotificationsControllerTest extends ApiControllerTestCase
|
||||
|
@ -31,10 +32,11 @@ class ListNotificationsControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function disallows_index_for_guest()
|
||||
{
|
||||
$this->expectException(PermissionDeniedException::class);
|
||||
|
||||
$this->callWith();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Flarum\Tests\integration\api\Controller;
|
||||
|
||||
use Flarum\Api\Controller\ListUsersController;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ListUsersControllerTest extends ApiControllerTestCase
|
||||
|
@ -37,10 +38,11 @@ class ListUsersControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function disallows_index_for_guest()
|
||||
{
|
||||
$this->expectException(PermissionDeniedException::class);
|
||||
|
||||
$this->callWith();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ use Carbon\Carbon;
|
|||
use Flarum\Api\Controller\ShowDiscussionController;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ShowDiscussionControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
|
@ -69,10 +70,11 @@ class ShowDiscussionControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function guest_cannot_see_empty_discussion()
|
||||
{
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
|
||||
$response = $this->callWith([], ['id' => 1]);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
@ -90,10 +92,11 @@ class ShowDiscussionControllerTest extends ApiControllerTestCase
|
|||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function guests_cannot_see_private_discussion()
|
||||
{
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
|
||||
$this->callWith([], ['id' => 3]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user