From 1b98526e89910c7c8799f81ec5c5814f6386c0b7 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 20 May 2020 00:18:00 +0200 Subject: [PATCH] Tests: Rely on admin user, groups, permissions from test setup script --- .../integration/RetrievesAuthorizedUsers.php | 44 ------------------- .../api/authentication/WithApiKeyTest.php | 1 - .../csrf_protection/RequireCsrfTokenTest.php | 12 ----- .../api/discussions/CreateTest.php | 24 ---------- .../api/discussions/DeletionTest.php | 7 --- .../integration/api/discussions/ListTest.php | 7 --- .../integration/api/discussions/ShowTest.php | 11 ----- .../tests/integration/api/forum/ShowTest.php | 11 +---- .../integration/api/groups/CreateTest.php | 7 --- .../tests/integration/api/groups/ListTest.php | 16 +++---- .../integration/api/posts/CreateTest.php | 9 ---- .../integration/api/users/CreateTest.php | 10 ----- .../tests/integration/api/users/ListTest.php | 19 -------- .../tests/integration/api/users/ShowTest.php | 10 ----- .../integration/api/users/UpdateTest.php | 13 ------ .../extenders/ApiControllerTest.php | 5 --- .../extenders/ApiSerializerTest.php | 1 - .../tests/integration/extenders/EventTest.php | 9 ---- .../tests/integration/extenders/MailTest.php | 21 --------- .../tests/integration/extenders/ModelTest.php | 6 --- .../integration/extenders/ModelUrlTest.php | 1 - .../extenders/ModelVisibilityTest.php | 11 ----- .../integration/extenders/PolicyTest.php | 1 - .../integration/extenders/SettingsTest.php | 1 - .../integration/extenders/ThrottleApiTest.php | 9 ---- .../tests/integration/extenders/UserTest.php | 7 --- framework/core/tests/integration/setup.php | 4 +- 27 files changed, 8 insertions(+), 269 deletions(-) diff --git a/framework/core/tests/integration/RetrievesAuthorizedUsers.php b/framework/core/tests/integration/RetrievesAuthorizedUsers.php index df2f80e87..a4bd58a98 100644 --- a/framework/core/tests/integration/RetrievesAuthorizedUsers.php +++ b/framework/core/tests/integration/RetrievesAuthorizedUsers.php @@ -11,50 +11,6 @@ namespace Flarum\Tests\integration; trait RetrievesAuthorizedUsers { - protected function adminGroup(): array - { - return [ - 'id' => 1, - 'name_singular' => 'Admin', - 'name_plural' => 'Admins', - 'color' => '#B72A2A', - 'icon' => 'fas fa-wrench', - ]; - } - - protected function guestGroup(): array - { - return [ - 'id' => 2, - 'name_singular' => 'Guest', - 'name_plural' => 'Guests', - 'color' => null, - 'icon' => null, - ]; - } - - protected function memberGroup(): array - { - return [ - 'id' => 3, - 'name_singular' => 'Member', - 'name_plural' => 'Members', - 'color' => null, - 'icon' => null, - ]; - } - - protected function adminUser(): array - { - return [ - 'id' => 1, - 'username' => 'admin', - 'password' => '$2y$10$HMOAe.XaQjOimA778VmFue1OCt7tj5j0wk5vfoL/CMSJq2BQlfBV2', // BCrypt hash for "password" - 'email' => 'admin@machine.local', - 'is_email_confirmed' => 1, - ]; - } - protected function normalUser(): array { return [ diff --git a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php index 2b5f82ba9..2518d4238 100644 --- a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php +++ b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php @@ -25,7 +25,6 @@ class WithApiKeyTest extends TestCase $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], ]); diff --git a/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php b/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php index b6540eb66..965aeeef9 100644 --- a/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php +++ b/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php @@ -21,18 +21,6 @@ class RequireCsrfTokenTest extends TestCase parent::setUp(); $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - ], - 'groups' => [ - $this->adminGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], - 'group_permission' => [ - ['permission' => 'viewUserList', 'group_id' => 3], - ], 'api_keys' => [ ['user_id' => 1, 'key' => 'superadmin'], ], diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php index 816b1590f..e24969937 100644 --- a/framework/core/tests/integration/api/discussions/CreateTest.php +++ b/framework/core/tests/integration/api/discussions/CreateTest.php @@ -18,30 +18,6 @@ class CreateTest extends TestCase { use RetrievesAuthorizedUsers; - protected function setUp(): void - { - parent::setUp(); - - $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - $this->normalUser(), - ], - 'groups' => [ - $this->adminGroup(), - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 3], - ['permission' => 'startDiscussion', 'group_id' => 3], - ] - ]); - } - /** * @test */ diff --git a/framework/core/tests/integration/api/discussions/DeletionTest.php b/framework/core/tests/integration/api/discussions/DeletionTest.php index aa948d046..ea825fd9b 100644 --- a/framework/core/tests/integration/api/discussions/DeletionTest.php +++ b/framework/core/tests/integration/api/discussions/DeletionTest.php @@ -29,15 +29,8 @@ class DeletionTest extends TestCase ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '

foo bar

'], ], 'users' => [ - $this->adminUser(), $this->normalUser(), ], - 'groups' => [ - $this->adminGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], ]); } diff --git a/framework/core/tests/integration/api/discussions/ListTest.php b/framework/core/tests/integration/api/discussions/ListTest.php index 3e56c4150..b47bbe127 100644 --- a/framework/core/tests/integration/api/discussions/ListTest.php +++ b/framework/core/tests/integration/api/discussions/ListTest.php @@ -30,13 +30,6 @@ class ListTest extends TestCase ], 'users' => [ $this->normalUser(), - ], - 'groups' => [ - $this->memberGroup(), - $this->guestGroup(), - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 2], ] ]); } diff --git a/framework/core/tests/integration/api/discussions/ShowTest.php b/framework/core/tests/integration/api/discussions/ShowTest.php index b4300a34a..79d036c16 100644 --- a/framework/core/tests/integration/api/discussions/ShowTest.php +++ b/framework/core/tests/integration/api/discussions/ShowTest.php @@ -37,17 +37,6 @@ class ShowTest extends TestCase ], 'users' => [ $this->normalUser(), - ], - 'groups' => [ - $this->guestGroup(), - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 2], - ['permission' => 'viewDiscussions', 'group_id' => 3], ] ]); } diff --git a/framework/core/tests/integration/api/forum/ShowTest.php b/framework/core/tests/integration/api/forum/ShowTest.php index 965473678..7ff520712 100644 --- a/framework/core/tests/integration/api/forum/ShowTest.php +++ b/framework/core/tests/integration/api/forum/ShowTest.php @@ -23,17 +23,8 @@ class ShowTest extends TestCase $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), - ], - 'groups' => [ - $this->adminGroup(), - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ['user_id' => 2, 'group_id' => 3], - ], + ] ]); } diff --git a/framework/core/tests/integration/api/groups/CreateTest.php b/framework/core/tests/integration/api/groups/CreateTest.php index 360e7f3b3..ba4b43303 100644 --- a/framework/core/tests/integration/api/groups/CreateTest.php +++ b/framework/core/tests/integration/api/groups/CreateTest.php @@ -24,15 +24,8 @@ class CreateTest extends TestCase $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], - 'groups' => [ - $this->adminGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], ]); } diff --git a/framework/core/tests/integration/api/groups/ListTest.php b/framework/core/tests/integration/api/groups/ListTest.php index 13f476b1f..9cef5476f 100644 --- a/framework/core/tests/integration/api/groups/ListTest.php +++ b/framework/core/tests/integration/api/groups/ListTest.php @@ -22,16 +22,8 @@ class ListTest extends TestCase parent::setUp(); $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - $this->normalUser(), - ], 'groups' => [ - $this->adminGroup(), - $this->hiddenGroup() - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], + $this->hiddenGroup(), ], ]); } @@ -48,7 +40,8 @@ class ListTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getBody()->getContents(), true); - $this->assertEquals(['1'], Arr::pluck($data['data'], 'id')); + // The four default groups created by the installer + $this->assertEquals(['1', '2', '3', '4'], Arr::pluck($data['data'], 'id')); } /** @@ -65,7 +58,8 @@ class ListTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getBody()->getContents(), true); - $this->assertEquals(['1', '10'], Arr::pluck($data['data'], 'id')); + // The four default groups created by the installer and our hidden group + $this->assertEquals(['1', '2', '3', '4', '10'], Arr::pluck($data['data'], 'id')); } protected function hiddenGroup(): array diff --git a/framework/core/tests/integration/api/posts/CreateTest.php b/framework/core/tests/integration/api/posts/CreateTest.php index f9efe2d32..cc023677c 100644 --- a/framework/core/tests/integration/api/posts/CreateTest.php +++ b/framework/core/tests/integration/api/posts/CreateTest.php @@ -27,15 +27,6 @@ class CreateTest extends TestCase ], 'users' => [ $this->normalUser(), - ], - 'groups' => [ - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 3], ] ]); } diff --git a/framework/core/tests/integration/api/users/CreateTest.php b/framework/core/tests/integration/api/users/CreateTest.php index 65e821ab7..6e1d6d023 100644 --- a/framework/core/tests/integration/api/users/CreateTest.php +++ b/framework/core/tests/integration/api/users/CreateTest.php @@ -23,16 +23,6 @@ class CreateTest extends TestCase parent::setUp(); $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - $this->normalUser(), - ], - 'groups' => [ - $this->adminGroup() - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], 'settings' => [ ['key' => 'mail_driver', 'value' => 'log'], ], diff --git a/framework/core/tests/integration/api/users/ListTest.php b/framework/core/tests/integration/api/users/ListTest.php index 152ea18f6..ab9dac7a5 100644 --- a/framework/core/tests/integration/api/users/ListTest.php +++ b/framework/core/tests/integration/api/users/ListTest.php @@ -9,7 +9,6 @@ namespace Flarum\Tests\integration\api\users; -use Flarum\Group\Permission; use Flarum\Tests\integration\RetrievesAuthorizedUsers; use Flarum\Tests\integration\TestCase; @@ -17,24 +16,6 @@ class ListTest extends TestCase { use RetrievesAuthorizedUsers; - protected function setUp(): void - { - parent::setUp(); - - $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - ], - 'groups' => [ - $this->adminGroup(), - $this->guestGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], - ]); - } - /** * @test */ diff --git a/framework/core/tests/integration/api/users/ShowTest.php b/framework/core/tests/integration/api/users/ShowTest.php index 3ee210203..3fb0e7bd2 100644 --- a/framework/core/tests/integration/api/users/ShowTest.php +++ b/framework/core/tests/integration/api/users/ShowTest.php @@ -22,18 +22,8 @@ class ShowTest extends TestCase $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], - 'groups' => [ - $this->adminGroup() - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], - 'settings' => [ - ['key' => 'mail_driver', 'value' => 'log'], - ], ]); } diff --git a/framework/core/tests/integration/api/users/UpdateTest.php b/framework/core/tests/integration/api/users/UpdateTest.php index e143e6565..be6b397dd 100644 --- a/framework/core/tests/integration/api/users/UpdateTest.php +++ b/framework/core/tests/integration/api/users/UpdateTest.php @@ -22,20 +22,7 @@ class UpdateTest extends TestCase $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), - ], - 'groups' => [ - $this->adminGroup(), - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewUserList', 'group_id' => 3], - ['permission' => 'viewDiscussions', 'group_id' => 3] ] ]); } diff --git a/framework/core/tests/integration/extenders/ApiControllerTest.php b/framework/core/tests/integration/extenders/ApiControllerTest.php index 5d8784cd7..7b3e21d8f 100644 --- a/framework/core/tests/integration/extenders/ApiControllerTest.php +++ b/framework/core/tests/integration/extenders/ApiControllerTest.php @@ -35,13 +35,8 @@ class ApiControllerTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser() ], - 'groups' => [ - $this->adminGroup(), - $this->memberGroup() - ], 'discussions' => [ ['id' => 1, 'title' => 'Custom Discussion Title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0], ['id' => 2, 'title' => 'Custom Discussion Title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 3, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0], diff --git a/framework/core/tests/integration/extenders/ApiSerializerTest.php b/framework/core/tests/integration/extenders/ApiSerializerTest.php index 2bee2bafd..8e3e32236 100644 --- a/framework/core/tests/integration/extenders/ApiSerializerTest.php +++ b/framework/core/tests/integration/extenders/ApiSerializerTest.php @@ -31,7 +31,6 @@ class ApiSerializerTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser() ], 'discussions' => [ diff --git a/framework/core/tests/integration/extenders/EventTest.php b/framework/core/tests/integration/extenders/EventTest.php index de32cd1ee..0aab2ce06 100644 --- a/framework/core/tests/integration/extenders/EventTest.php +++ b/framework/core/tests/integration/extenders/EventTest.php @@ -24,15 +24,6 @@ class EventTest extends TestCase protected function buildGroup() { - $this->prepareDatabase([ - 'groups' => [ - $this->adminGroup(), - ], - 'users' => [ - $this->adminUser(), - ], - ]); - $bus = $this->app()->getContainer()->make(Dispatcher::class); return $bus->dispatch( diff --git a/framework/core/tests/integration/extenders/MailTest.php b/framework/core/tests/integration/extenders/MailTest.php index 7a8a1dc52..a62773b3f 100644 --- a/framework/core/tests/integration/extenders/MailTest.php +++ b/framework/core/tests/integration/extenders/MailTest.php @@ -23,28 +23,11 @@ class MailTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() - { - $this->prepareDatabase([ - 'users' => [ - $this->adminUser(), - ], - 'groups' => [ - $this->adminGroup(), - ], - 'group_user' => [ - ['user_id' => 1, 'group_id' => 1], - ], - ]); - } - /** * @test */ public function drivers_are_unchanged_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/mail/settings', [ 'authenticatedAs' => 1, @@ -76,8 +59,6 @@ class MailTest extends TestCase ->driver('custom', CustomDriver::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/mail/settings', [ 'authenticatedAs' => 1, @@ -100,8 +81,6 @@ class MailTest extends TestCase ->driver('smtp', CustomDriver::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/mail/settings', [ 'authenticatedAs' => 1, diff --git a/framework/core/tests/integration/extenders/ModelTest.php b/framework/core/tests/integration/extenders/ModelTest.php index 5034bf9e1..9d01dc1fb 100644 --- a/framework/core/tests/integration/extenders/ModelTest.php +++ b/framework/core/tests/integration/extenders/ModelTest.php @@ -29,7 +29,6 @@ class ModelTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], ]); @@ -245,11 +244,6 @@ class ModelTest extends TestCase ); $this->prepDB(); - $this->prepareDatabase([ - 'groups' => [ - $this->adminGroup() - ] - ]); $group = Group::find(1); diff --git a/framework/core/tests/integration/extenders/ModelUrlTest.php b/framework/core/tests/integration/extenders/ModelUrlTest.php index e5eea08ad..44abd1ef6 100644 --- a/framework/core/tests/integration/extenders/ModelUrlTest.php +++ b/framework/core/tests/integration/extenders/ModelUrlTest.php @@ -26,7 +26,6 @@ class ModelUrlTest extends TestCase $userClass = User::class; $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], 'settings' => [ diff --git a/framework/core/tests/integration/extenders/ModelVisibilityTest.php b/framework/core/tests/integration/extenders/ModelVisibilityTest.php index 0121e6e8a..69ff0820b 100644 --- a/framework/core/tests/integration/extenders/ModelVisibilityTest.php +++ b/framework/core/tests/integration/extenders/ModelVisibilityTest.php @@ -37,17 +37,6 @@ class ModelVisibilityTest extends TestCase ], 'users' => [ $this->normalUser(), - ], - 'groups' => [ - $this->guestGroup(), - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 2], - ['permission' => 'viewDiscussions', 'group_id' => 3], ] ]); } diff --git a/framework/core/tests/integration/extenders/PolicyTest.php b/framework/core/tests/integration/extenders/PolicyTest.php index d45c2cdc5..b2f0420b8 100644 --- a/framework/core/tests/integration/extenders/PolicyTest.php +++ b/framework/core/tests/integration/extenders/PolicyTest.php @@ -32,7 +32,6 @@ class PolicyTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], 'discussions' => [ diff --git a/framework/core/tests/integration/extenders/SettingsTest.php b/framework/core/tests/integration/extenders/SettingsTest.php index 6a8f0b142..77c41d70e 100644 --- a/framework/core/tests/integration/extenders/SettingsTest.php +++ b/framework/core/tests/integration/extenders/SettingsTest.php @@ -21,7 +21,6 @@ class SettingsTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser() ], 'settings' => [ diff --git a/framework/core/tests/integration/extenders/ThrottleApiTest.php b/framework/core/tests/integration/extenders/ThrottleApiTest.php index 79400cf40..33a4853e7 100644 --- a/framework/core/tests/integration/extenders/ThrottleApiTest.php +++ b/framework/core/tests/integration/extenders/ThrottleApiTest.php @@ -22,15 +22,6 @@ class ThrottleApiTest extends TestCase $this->prepareDatabase([ 'users' => [ $this->normalUser(), - ], - 'groups' => [ - $this->memberGroup(), - ], - 'group_user' => [ - ['user_id' => 2, 'group_id' => 3], - ], - 'group_permission' => [ - ['permission' => 'viewDiscussions', 'group_id' => 3], ] ]); } diff --git a/framework/core/tests/integration/extenders/UserTest.php b/framework/core/tests/integration/extenders/UserTest.php index a4108509a..473805185 100644 --- a/framework/core/tests/integration/extenders/UserTest.php +++ b/framework/core/tests/integration/extenders/UserTest.php @@ -24,17 +24,10 @@ class UserTest extends TestCase { $this->prepareDatabase([ 'users' => [ - $this->adminUser(), $this->normalUser(), ], - 'group_permission' => [ - ['permission' => 'viewUserList', 'group_id' => 3] - ], 'settings' => [ ['key' => 'display_name_driver', 'value' => 'custom'], - ], - 'group_permission' => [ - ['permission' => 'viewUserList', 'group_id' => 3], ] ]); } diff --git a/framework/core/tests/integration/setup.php b/framework/core/tests/integration/setup.php index 2a18ca4a6..95739eaac 100644 --- a/framework/core/tests/integration/setup.php +++ b/framework/core/tests/integration/setup.php @@ -56,8 +56,8 @@ $pipeline = $installation ) ->adminUser(new AdminUser( 'admin', - 'secret', - 'admin@flarum.email' + 'password', + 'admin@machine.local' )) ->settings(['mail_driver' => 'log']) ->build();