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