diff --git a/composer.json b/composer.json
index 246853070..7b0e765d7 100644
--- a/composer.json
+++ b/composer.json
@@ -112,6 +112,7 @@
"dflydev/fig-cookies": "^3.0",
"doctrine/dbal": "^3.6.2",
"dragonmantank/cron-expression": "^3.3",
+ "fakerphp/faker": "^1.9.1",
"franzl/whoops-middleware": "2.0",
"guzzlehttp/guzzle": "*",
"illuminate/bus": "^10.0",
diff --git a/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php b/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php
index 3f33097a6..bcf749887 100644
--- a/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php
+++ b/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php
@@ -10,19 +10,23 @@
namespace Flarum\Approval\Tests\integration;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\User\User;
trait InteractsWithUnapprovedContent
{
protected function prepareUnapprovedDatabaseContent()
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
$this->normalUser(),
['id' => 3, 'username' => 'acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'luceos', 'email' => 'luceos@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 4, 'first_post_id' => 1, 'comment_count' => 1, 'is_approved' => 1, 'is_private' => 0],
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 4, 'first_post_id' => 2, 'comment_count' => 1, 'is_approved' => 0, 'is_private' => 1],
['id' => 3, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 4, 'first_post_id' => 3, 'comment_count' => 1, 'is_approved' => 0, 'is_private' => 1],
@@ -31,7 +35,7 @@ trait InteractsWithUnapprovedContent
['id' => 6, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 4, 'first_post_id' => 6, 'comment_count' => 1, 'is_approved' => 0, 'is_private' => 1],
['id' => 7, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 4, 'first_post_id' => 7, 'comment_count' => 1, 'is_approved' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 4, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'is_approved' => 1, 'number' => 1],
['id' => 2, 'discussion_id' => 2, 'user_id' => 4, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'is_approved' => 1, 'number' => 1],
['id' => 3, 'discussion_id' => 3, 'user_id' => 4, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'is_approved' => 1, 'number' => 1],
@@ -45,7 +49,7 @@ trait InteractsWithUnapprovedContent
['id' => 10, 'discussion_id' => 7, 'user_id' => 4, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'is_approved' => 1, 'number' => 4],
['id' => 11, 'discussion_id' => 7, 'user_id' => 4, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 1, 'is_approved' => 0, 'number' => 5],
],
- 'groups' => [
+ Group::class => [
['id' => 4, 'name_singular' => 'Acme', 'name_plural' => 'Acme', 'is_hidden' => 0]
],
'group_user' => [
diff --git a/extensions/flags/tests/integration/api/flags/ListTest.php b/extensions/flags/tests/integration/api/flags/ListTest.php
index 7ab74e466..fb2c75171 100644
--- a/extensions/flags/tests/integration/api/flags/ListTest.php
+++ b/extensions/flags/tests/integration/api/flags/ListTest.php
@@ -9,9 +9,12 @@
namespace Flarum\Flags\Tests\integration\api\flags;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -28,7 +31,7 @@ class ListTest extends TestCase
$this->extension('flarum-flags');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
[
'id' => 3,
@@ -44,10 +47,10 @@ class ListTest extends TestCase
'group_permission' => [
['group_id' => Group::MODERATOR_ID, 'permission' => 'discussion.viewFlags'],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => '', 'user_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 3, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
diff --git a/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php b/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php
index 6a86e0f0e..7bd38b544 100644
--- a/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php
+++ b/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php
@@ -9,9 +9,13 @@
namespace Flarum\Flags\Tests\integration\api\flags;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListWithTagsTest extends TestCase
@@ -29,13 +33,13 @@ class ListWithTagsTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => [
+ Tag::class => [
['id' => 1, 'name' => 'Unrestricted', 'slug' => '1', 'position' => 0, 'parent_id' => null],
['id' => 2, 'name' => 'Mods can view discussions', 'slug' => '2', 'position' => 0, 'parent_id' => null, 'is_restricted' => true],
['id' => 3, 'name' => 'Mods can view flags', 'slug' => '3', 'position' => 0, 'parent_id' => null, 'is_restricted' => true],
['id' => 4, 'name' => 'Mods can view discussions and flags', 'slug' => '4', 'position' => 0, 'parent_id' => null, 'is_restricted' => true],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
[
'id' => 3,
@@ -55,7 +59,7 @@ class ListWithTagsTest extends TestCase
['group_id' => Group::MODERATOR_ID, 'permission' => 'tag4.viewDiscussions'],
['group_id' => Group::MODERATOR_ID, 'permission' => 'tag4.discussion.viewFlags'],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'no tags', 'user_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => 'has tags where mods can view discussions but not flags', 'user_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => 'has tags where mods can view flags but not discussions', 'user_id' => 1, 'comment_count' => 1],
@@ -68,7 +72,7 @@ class ListWithTagsTest extends TestCase
['discussion_id' => 4, 'tag_id' => 4],
['discussion_id' => 5, 'tag_id' => 1],
],
- 'posts' => [
+ Post::class => [
// From regular ListTest
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
diff --git a/extensions/likes/tests/integration/api/LikePostTest.php b/extensions/likes/tests/integration/api/LikePostTest.php
index 4bcbe49fa..1c60fa511 100644
--- a/extensions/likes/tests/integration/api/LikePostTest.php
+++ b/extensions/likes/tests/integration/api/LikePostTest.php
@@ -10,9 +10,13 @@
namespace Flarum\Likes\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Group\Group;
use Flarum\Post\CommentPost;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Psr\Http\Message\ResponseInterface;
class LikePostTest extends TestCase
@@ -26,21 +30,21 @@ class LikePostTest extends TestCase
$this->extension('flarum-likes');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
$this->normalUser(),
['id' => 3, 'username' => 'Acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'number' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
['id' => 3, 'number' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
['id' => 5, 'number' => 3, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'discussionRenamed', 'content' => 'something
'],
['id' => 6, 'number' => 4, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
],
- 'groups' => [
+ Group::class => [
['id' => 5, 'name_singular' => 'Acme', 'name_plural' => 'Acme', 'is_hidden' => 0],
['id' => 6, 'name_singular' => 'Acme1', 'name_plural' => 'Acme1', 'is_hidden' => 0]
],
diff --git a/extensions/likes/tests/integration/api/ListPostsTest.php b/extensions/likes/tests/integration/api/ListPostsTest.php
index 59a8f7a43..767de463c 100644
--- a/extensions/likes/tests/integration/api/ListPostsTest.php
+++ b/extensions/likes/tests/integration/api/ListPostsTest.php
@@ -10,10 +10,13 @@
namespace Flarum\Likes\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
use Flarum\Likes\Api\LoadLikesRelationship;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListPostsTest extends TestCase
@@ -30,13 +33,13 @@ class ListPostsTest extends TestCase
$this->extension('flarum-likes');
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 100, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 101, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 101, 'discussion_id' => 100, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'text
'],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 102, 'username' => 'user102', 'email' => '102@machine.local', 'is_email_confirmed' => 1],
['id' => 103, 'username' => 'user103', 'email' => '103@machine.local', 'is_email_confirmed' => 1],
diff --git a/extensions/mentions/tests/integration/api/GroupMentionsTest.php b/extensions/mentions/tests/integration/api/GroupMentionsTest.php
index f4c60b487..02f882fe1 100644
--- a/extensions/mentions/tests/integration/api/GroupMentionsTest.php
+++ b/extensions/mentions/tests/integration/api/GroupMentionsTest.php
@@ -10,8 +10,10 @@
namespace Flarum\Mentions\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
use Flarum\Post\CommentPost;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
@@ -30,14 +32,14 @@ class GroupMentionsTest extends TestCase
$this->extension('flarum-mentions');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 3, 'username' => 'potato', 'email' => 'potato@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'toby', 'email' => 'toby@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 3, 'first_post_id' => 4, 'comment_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 4, 'number' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => 'One of the @"Mods"#g4 will look at this
'],
['id' => 6, 'number' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '@"OldGroupName"#g100
'],
['id' => 7, 'number' => 4, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '@"OldGroupName"#g11
'],
@@ -53,7 +55,7 @@ class GroupMentionsTest extends TestCase
['group_id' => Group::MEMBER_ID, 'permission' => 'postWithoutThrottle'],
['group_id' => 9, 'permission' => 'mentionGroups'],
],
- 'groups' => [
+ Group::class => [
['id' => 9, 'name_singular' => 'HasPermissionToMentionGroups', 'name_plural' => 'test'],
['id' => 10, 'name_singular' => 'Hidden', 'name_plural' => 'Ninjas', 'icon' => 'fas fa-wrench', 'color' => '#000', 'is_hidden' => 1],
['id' => 11, 'name_singular' => 'Fresh Name', 'name_plural' => 'Fresh Name', 'color' => '#ccc', 'icon' => 'fas fa-users', 'is_hidden' => 0]
diff --git a/extensions/mentions/tests/integration/api/ListPostsTest.php b/extensions/mentions/tests/integration/api/ListPostsTest.php
index ab0964648..c70c1a638 100644
--- a/extensions/mentions/tests/integration/api/ListPostsTest.php
+++ b/extensions/mentions/tests/integration/api/ListPostsTest.php
@@ -10,9 +10,12 @@
namespace Flarum\Mentions\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Mentions\Api\LoadMentionedByRelationship;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListPostsTest extends TestCase
@@ -29,10 +32,10 @@ class ListPostsTest extends TestCase
$this->extension('flarum-mentions');
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'text
'],
['id' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'comment', 'content' => 'text
'],
['id' => 3, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'comment', 'content' => 'text
'],
@@ -43,7 +46,7 @@ class ListPostsTest extends TestCase
['post_id' => 3, 'mentions_user_id' => 1],
['post_id' => 4, 'mentions_user_id' => 2]
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
@@ -112,10 +115,10 @@ class ListPostsTest extends TestCase
protected function prepareMentionedByData(): void
{
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 100, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 101, 'comment_count' => 12],
],
- 'posts' => [
+ Post::class => [
['id' => 101, 'discussion_id' => 100, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'text
'],
['id' => 102, 'discussion_id' => 100, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'text
'],
['id' => 103, 'discussion_id' => 100, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'text
', 'is_private' => 1],
diff --git a/extensions/mentions/tests/integration/api/PostMentionsTest.php b/extensions/mentions/tests/integration/api/PostMentionsTest.php
index 25af7f255..3d0304c45 100644
--- a/extensions/mentions/tests/integration/api/PostMentionsTest.php
+++ b/extensions/mentions/tests/integration/api/PostMentionsTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Mentions\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Formatter\Formatter;
use Flarum\Post\CommentPost;
@@ -33,16 +34,16 @@ class PostMentionsTest extends TestCase
$this->extension('flarum-mentions');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 3, 'username' => 'potato', 'email' => 'potato@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'toby', 'email' => 'toby@machine.local', 'is_email_confirmed' => 1],
['id' => 5, 'username' => 'bad_user', 'email' => 'bad_user@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 3, 'first_post_id' => 4, 'comment_count' => 2],
['id' => 50, 'title' => __CLASS__, 'is_private' => true, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 3, 'first_post_id' => 4, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 4, 'number' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '@tobyuuu#5'],
['id' => 5, 'number' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 4, 'type' => 'comment', 'content' => '@potato#4'],
['id' => 6, 'number' => 4, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '@"i_am_a_deleted_user"#p7'],
diff --git a/extensions/mentions/tests/integration/api/TagMentionsTest.php b/extensions/mentions/tests/integration/api/TagMentionsTest.php
index f478a96d1..8bf30a007 100644
--- a/extensions/mentions/tests/integration/api/TagMentionsTest.php
+++ b/extensions/mentions/tests/integration/api/TagMentionsTest.php
@@ -10,10 +10,14 @@
namespace Flarum\Mentions\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
use Flarum\Post\CommentPost;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class TagMentionsTest extends TestCase
{
@@ -26,20 +30,20 @@ class TagMentionsTest extends TestCase
$this->extension('flarum-tags', 'flarum-mentions');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 3, 'username' => 'potato', 'email' => 'potato@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'toby', 'email' => 'toby@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 3, 'first_post_id' => 4, 'comment_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 4, 'number' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '#test_old_slug'],
['id' => 7, 'number' => 5, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 2021, 'type' => 'comment', 'content' => '#deleted_relation'],
['id' => 8, 'number' => 6, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 4, 'type' => 'comment', 'content' => '#i_am_a_deleted_tag'],
['id' => 10, 'number' => 11, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 4, 'type' => 'comment', 'content' => '#laravel'],
],
- 'tags' => [
+ Tag::class => [
['id' => 1, 'name' => 'Test', 'slug' => 'test', 'is_restricted' => 0],
['id' => 2, 'name' => 'Flarum', 'slug' => 'flarum', 'is_restricted' => 0],
['id' => 3, 'name' => 'Support', 'slug' => 'support', 'is_restricted' => 0],
diff --git a/extensions/mentions/tests/integration/api/UserMentionsTest.php b/extensions/mentions/tests/integration/api/UserMentionsTest.php
index 8d8708a81..6566c8f87 100644
--- a/extensions/mentions/tests/integration/api/UserMentionsTest.php
+++ b/extensions/mentions/tests/integration/api/UserMentionsTest.php
@@ -10,8 +10,10 @@
namespace Flarum\Mentions\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Post\CommentPost;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\DisplayName\DriverInterface;
@@ -31,16 +33,16 @@ class UserMentionsTest extends TestCase
$this->extension('flarum-mentions');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'potato', 'email' => 'potato@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'toby', 'email' => 'toby@machine.local', 'is_email_confirmed' => 1],
['id' => 5, 'username' => 'bad_user', 'email' => 'bad_user@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 3, 'first_post_id' => 4, 'comment_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 4, 'number' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'comment', 'content' => '@tobyuuu'],
['id' => 6, 'number' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 4, 'type' => 'comment', 'content' => '@"i_am_a_deleted_user"#2021'],
['id' => 10, 'number' => 11, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 5, 'type' => 'comment', 'content' => '@"Bad "#p6 User"#5'],
diff --git a/extensions/nicknames/tests/integration/api/EditUserTest.php b/extensions/nicknames/tests/integration/api/EditUserTest.php
index 113a9f34e..24222b740 100644
--- a/extensions/nicknames/tests/integration/api/EditUserTest.php
+++ b/extensions/nicknames/tests/integration/api/EditUserTest.php
@@ -27,7 +27,7 @@ class UpdateTest extends TestCase
$this->extension('flarum-nicknames');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php
index 35c25e858..536f77edc 100644
--- a/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php
+++ b/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Statistics\tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CanRequestCustomTimedStatisticsTest extends TestCase
{
@@ -36,18 +39,18 @@ class CanRequestCustomTimedStatisticsTest extends TestCase
protected function getDatabaseData(): array
{
return [
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->copy()],
['id' => 2, 'username' => 'normal', 'email' => 'normal@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->copy()->subDays(1)],
['id' => 3, 'username' => 'normal2', 'email' => 'normal2@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->copy()->subDays(2)],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 4, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(2), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()],
['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()->subDays(1)],
['id' => 3, 'discussion_id' => 3, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()->subDays(1)],
diff --git a/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php
index 3a7e01746..3b6967595 100644
--- a/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php
+++ b/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Statistics\tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CanRequestLifetimeStatisticsTest extends TestCase
{
@@ -36,17 +39,17 @@ class CanRequestLifetimeStatisticsTest extends TestCase
protected function getDatabaseData(): array
{
return [
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
['id' => 2, 'username' => 'normal', 'email' => 'normal@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->subDays(1)],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => $this->nowTime, 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => __CLASS__, 'created_at' => $this->nowTime->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => __CLASS__, 'created_at' => $this->nowTime->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 4, 'title' => __CLASS__, 'created_at' => $this->nowTime->subDays(2), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1],
['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1],
['id' => 3, 'discussion_id' => 3, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1],
@@ -75,9 +78,9 @@ class CanRequestLifetimeStatisticsTest extends TestCase
$this->assertEqualsCanonicalizing(
[
- 'users' => count($db['users']),
- 'discussions' => count($db['discussions']),
- 'posts' => count($db['posts']),
+ 'users' => count($db[User::class]),
+ 'discussions' => count($db[Discussion::class]),
+ 'posts' => count($db[Post::class]),
],
$body
);
diff --git a/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php
index 8dabfc6e7..4e82c84a6 100644
--- a/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php
+++ b/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Statistics\tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CanRequestTimedStatisticsTest extends TestCase
{
@@ -36,17 +39,17 @@ class CanRequestTimedStatisticsTest extends TestCase
protected function getDatabaseData(): array
{
return [
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->copy()],
['id' => 2, 'username' => 'normal', 'email' => 'normal@machine.local', 'is_email_confirmed' => 1, 'joined_at' => $this->nowTime->copy()->subDays(1)],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(1), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 4, 'title' => __CLASS__, 'created_at' => $this->nowTime->copy()->subDays(2), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()],
['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()->subDays(1)],
['id' => 3, 'discussion_id' => 3, 'user_id' => 1, 'type' => 'comment', 'content' => 'Text
', 'is_private' => 0, 'number' => 1, 'created_at' => $this->nowTime->copy()->subDays(1)],
diff --git a/extensions/sticky/tests/integration/api/ListDiscussionsTest.php b/extensions/sticky/tests/integration/api/ListDiscussionsTest.php
index 3f595acbb..5647c50f4 100644
--- a/extensions/sticky/tests/integration/api/ListDiscussionsTest.php
+++ b/extensions/sticky/tests/integration/api/ListDiscussionsTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Sticky\tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Tags\Tag;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListDiscussionsTest extends TestCase
@@ -25,12 +28,12 @@ class ListDiscussionsTest extends TestCase
$this->extension('flarum-tags', 'flarum-sticky');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
$this->normalUser(),
['id' => 3, 'username' => 'Muralf_', 'email' => 'muralf_@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => true, 'last_post_number' => 1],
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now()->addMinutes(2), 'last_posted_at' => Carbon::now()->addMinutes(5), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => false, 'last_post_number' => 1],
['id' => 3, 'title' => __CLASS__, 'created_at' => Carbon::now()->addMinutes(3), 'last_posted_at' => Carbon::now()->addMinute(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => true, 'last_post_number' => 1],
@@ -40,7 +43,7 @@ class ListDiscussionsTest extends TestCase
['discussion_id' => 1, 'user_id' => 3, 'last_read_post_number' => 1],
['discussion_id' => 3, 'user_id' => 3, 'last_read_post_number' => 1],
],
- 'tags' => [
+ Tag::class => [
['id' => 1, 'slug' => 'general', 'position' => 0, 'parent_id' => null]
],
'discussion_tag' => [
diff --git a/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php b/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php
index ea1aba479..540bcfb98 100644
--- a/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php
+++ b/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Subscriptions\tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Extend\ModelVisibility;
use Flarum\Group\Group;
use Flarum\Post\Post;
@@ -28,18 +29,18 @@ class ReplyNotificationTest extends TestCase
$this->extension('flarum-subscriptions');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1, 'preferences' => json_encode(['flarum-subscriptions.notify_for_all_posts' => true])],
['id' => 4, 'username' => 'acme2', 'email' => 'acme2@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'last_post_number' => 1, 'last_post_id' => 1],
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 2, 'comment_count' => 1, 'last_post_number' => 1, 'last_post_id' => 2],
['id' => 33, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 33, 'comment_count' => 6, 'last_post_number' => 6, 'last_post_id' => 38],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 1],
['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 1],
@@ -169,10 +170,10 @@ class ReplyNotificationTest extends TestCase
public function deleting_last_posts_then_posting_new_one_sends_reply_notification(array $postIds)
{
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 3, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 5, 'last_post_number' => 5, 'last_post_id' => 10],
],
- 'posts' => [
+ Post::class => [
['id' => 5, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 1],
['id' => 6, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 2],
['id' => 7, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 3],
diff --git a/extensions/suspend/tests/integration/api/UseForumTest.php b/extensions/suspend/tests/integration/api/UseForumTest.php
index 2ef69c5cc..3475c524e 100644
--- a/extensions/suspend/tests/integration/api/UseForumTest.php
+++ b/extensions/suspend/tests/integration/api/UseForumTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Suspend\Tests\integration\api;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class UseForumTest extends TestCase
{
@@ -24,14 +27,14 @@ class UseForumTest extends TestCase
$this->extension('flarum-suspend');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
['id' => 2, 'username' => 'SuspendedDonny', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->addDay(), 'suspend_reason' => 'acme', 'suspend_message' => 'acme'],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'number' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'discussion_id' => 1, 'content' => 'Hello, world!
'],
]
]);
diff --git a/extensions/suspend/tests/integration/api/users/ListUsersTest.php b/extensions/suspend/tests/integration/api/users/ListUsersTest.php
index f3a41d314..5b6a7340f 100644
--- a/extensions/suspend/tests/integration/api/users/ListUsersTest.php
+++ b/extensions/suspend/tests/integration/api/users/ListUsersTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Suspend\Tests\integration\api\users;
use Carbon\Carbon;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListUsersTest extends TestCase
@@ -25,7 +26,7 @@ class ListUsersTest extends TestCase
$this->extension('flarum-suspend');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
['id' => 2, 'username' => 'SuspendedDonny1', 'email' => 'acme1@machine.local', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->addDay(), 'suspend_reason' => 'acme', 'suspend_message' => 'acme'],
['id' => 3, 'username' => 'SuspendedDonny2', 'email' => 'acme2@machine.local', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->addDay(), 'suspend_reason' => 'acme', 'suspend_message' => 'acme'],
diff --git a/extensions/suspend/tests/integration/api/users/SuspendUserTest.php b/extensions/suspend/tests/integration/api/users/SuspendUserTest.php
index 3cf84a05a..d398ab497 100644
--- a/extensions/suspend/tests/integration/api/users/SuspendUserTest.php
+++ b/extensions/suspend/tests/integration/api/users/SuspendUserTest.php
@@ -10,8 +10,10 @@
namespace Flarum\Suspend\Tests\integration\api\users;
use Carbon\Carbon;
+use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Psr\Http\Message\ResponseInterface;
class SuspendUserTest extends TestCase
@@ -25,12 +27,12 @@ class SuspendUserTest extends TestCase
$this->extension('flarum-suspend');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
$this->normalUser(),
['id' => 3, 'username' => 'acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
],
- 'groups' => [
+ Group::class => [
['id' => 5, 'name_singular' => 'Acme', 'name_plural' => 'Acme', 'is_hidden' => 0]
],
'group_user' => [
diff --git a/extensions/tags/src/Tag.php b/extensions/tags/src/Tag.php
index f9b54f3ed..5d423e711 100644
--- a/extensions/tags/src/Tag.php
+++ b/extensions/tags/src/Tag.php
@@ -16,6 +16,7 @@ use Flarum\Group\Permission;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -51,6 +52,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
class Tag extends AbstractModel
{
use ScopeVisibilityTrait;
+ use HasFactory;
protected $table = 'tags';
diff --git a/extensions/tags/src/TagFactory.php b/extensions/tags/src/TagFactory.php
new file mode 100644
index 000000000..629fb4bb9
--- /dev/null
+++ b/extensions/tags/src/TagFactory.php
@@ -0,0 +1,39 @@
+ $this->faker->word,
+ 'slug' => $this->faker->slug,
+ 'description' => $this->faker->sentence,
+ 'color' => $this->faker->hexColor,
+ 'background_path' => null,
+ 'background_mode' => null,
+ 'position' => 0,
+ 'parent_id' => null,
+ 'default_sort' => null,
+ 'is_restricted' => false,
+ 'is_hidden' => false,
+ 'discussion_count' => 0,
+ 'last_posted_at' => null,
+ 'last_posted_discussion_id' => null,
+ 'last_posted_user_id' => null,
+ 'icon' => null,
+ 'created_at' => Carbon::now(),
+ ];
+ }
+}
diff --git a/extensions/tags/tests/integration/api/discussions/CreateTest.php b/extensions/tags/tests/integration/api/discussions/CreateTest.php
index d9384dfa8..ef7a0bd24 100644
--- a/extensions/tags/tests/integration/api/discussions/CreateTest.php
+++ b/extensions/tags/tests/integration/api/discussions/CreateTest.php
@@ -10,9 +10,11 @@
namespace Flarum\Tags\Tests\integration\api\discussions;
use Flarum\Group\Group;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CreateTest extends TestCase
{
@@ -29,8 +31,8 @@ class CreateTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
diff --git a/extensions/tags/tests/integration/api/discussions/ListTest.php b/extensions/tags/tests/integration/api/discussions/ListTest.php
index 4fe5eb221..42b544d79 100644
--- a/extensions/tags/tests/integration/api/discussions/ListTest.php
+++ b/extensions/tags/tests/integration/api/discussions/ListTest.php
@@ -9,9 +9,14 @@
namespace Flarum\Tags\Tests\integration\api\discussions;
+use Flarum\Discussion\Discussion;
+use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -29,8 +34,8 @@ class ListTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
[
'id' => 3,
@@ -40,7 +45,7 @@ class ListTest extends TestCase
'is_email_confirmed' => 1,
]
],
- 'groups' => [
+ Group::class => [
['id' => 100, 'name_singular' => 'acme', 'name_plural' => 'acme']
],
'group_user' => [
@@ -52,7 +57,7 @@ class ListTest extends TestCase
['group_id' => 100, 'permission' => 'tag11.viewForum'],
['group_id' => 100, 'permission' => 'tag13.viewForum'],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'no tags', 'user_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => 'open tags', 'user_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => 'open tag, restricted child tag', 'user_id' => 1, 'comment_count' => 1],
@@ -66,7 +71,7 @@ class ListTest extends TestCase
['id' => 11, 'title' => 'private, all closed', 'user_id' => 1, 'comment_count' => 1, 'is_private' => 1],
['id' => 12, 'title' => 'private, closed parent, open child tag', 'user_id' => 1, 'comment_count' => 1, 'is_private' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 3, 'discussion_id' => 3, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
diff --git a/extensions/tags/tests/integration/api/discussions/UpdateTest.php b/extensions/tags/tests/integration/api/discussions/UpdateTest.php
index 10533635d..a865b0d85 100644
--- a/extensions/tags/tests/integration/api/discussions/UpdateTest.php
+++ b/extensions/tags/tests/integration/api/discussions/UpdateTest.php
@@ -9,10 +9,15 @@
namespace Flarum\Tags\Tests\integration\api\discussions;
+use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class UpdateTest extends TestCase
{
@@ -29,8 +34,8 @@ class UpdateTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
@@ -40,10 +45,10 @@ class UpdateTest extends TestCase
['group_id' => Group::MEMBER_ID, 'permission' => 'tag11.viewForum'],
['group_id' => Group::MEMBER_ID, 'permission' => 'tag11.startDiscussion'],
],
- 'discussions' => [
- ['id' => 1, 'title' => 'Discussion with post', 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1],
+ Discussion::class => [
+ ['id' => 1, 'title' => 'Discussion with post', 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'created_at' => Carbon::now()->subDay()],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 2, 'type' => 'comment', 'content' => 'Text
'],
],
'discussion_tag' => [
@@ -241,7 +246,7 @@ class UpdateTest extends TestCase
])
);
- $this->assertEquals(403, $response->getStatusCode());
+ $this->assertEquals(403, $response->getStatusCode(), $response->getBody());
}
/**
diff --git a/extensions/tags/tests/integration/api/posts/ListTest.php b/extensions/tags/tests/integration/api/posts/ListTest.php
index efd331bf2..bc4032bb9 100644
--- a/extensions/tags/tests/integration/api/posts/ListTest.php
+++ b/extensions/tags/tests/integration/api/posts/ListTest.php
@@ -9,9 +9,14 @@
namespace Flarum\Tags\Tests\integration\api\posts;
+use Flarum\Discussion\Discussion;
+use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class ListTest extends TestCase
{
@@ -28,8 +33,8 @@ class ListTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
[
'id' => 3,
@@ -39,7 +44,7 @@ class ListTest extends TestCase
'is_email_confirmed' => 1,
]
],
- 'groups' => [
+ Group::class => [
['id' => 100, 'name_singular' => 'acme', 'name_plural' => 'acme']
],
'group_user' => [
@@ -48,10 +53,10 @@ class ListTest extends TestCase
'group_permission' => [
['group_id' => 100, 'permission' => 'tag5.viewForum'],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'no tags', 'user_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => '', 'number' => 1],
['id' => 2, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'discussionTagged', 'content' => '[[1,5],[5]]', 'number' => 2],
['id' => 3, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => '', 'number' => 3],
diff --git a/extensions/tags/tests/integration/api/tags/CreateTest.php b/extensions/tags/tests/integration/api/tags/CreateTest.php
index 39acb49a2..a31187dfc 100644
--- a/extensions/tags/tests/integration/api/tags/CreateTest.php
+++ b/extensions/tags/tests/integration/api/tags/CreateTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tags\Tests\integration\api\tags;
use Flarum\Tags\Tag;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class CreateTest extends TestCase
@@ -28,7 +29,7 @@ class CreateTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/extensions/tags/tests/integration/api/tags/ListTest.php b/extensions/tags/tests/integration/api/tags/ListTest.php
index cbe4c1f8f..d8e710d16 100644
--- a/extensions/tags/tests/integration/api/tags/ListTest.php
+++ b/extensions/tags/tests/integration/api/tags/ListTest.php
@@ -10,9 +10,11 @@
namespace Flarum\Tags\Tests\integration\api\tags;
use Flarum\Group\Group;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -30,8 +32,8 @@ class ListTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
diff --git a/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php b/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php
index d6ff6920e..5353b139e 100644
--- a/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php
+++ b/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php
@@ -9,6 +9,7 @@
namespace Flarum\Tags\Tests\integration\api\tags;
+use Flarum\Tags\Tag;
use Flarum\Testing\integration\TestCase;
use Illuminate\Support\Arr;
@@ -21,7 +22,7 @@ class ListWithFulltextSearchTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => [
+ Tag::class => [
['id' => 2, 'name' => 'Acme', 'slug' => 'acme'],
['id' => 3, 'name' => 'Test', 'slug' => 'test'],
['id' => 4, 'name' => 'Tag', 'slug' => 'tag'],
diff --git a/extensions/tags/tests/integration/api/tags/ShowTest.php b/extensions/tags/tests/integration/api/tags/ShowTest.php
index 043ce78bc..840bde027 100644
--- a/extensions/tags/tests/integration/api/tags/ShowTest.php
+++ b/extensions/tags/tests/integration/api/tags/ShowTest.php
@@ -10,9 +10,11 @@
namespace Flarum\Tags\Tests\integration\api\tags;
use Flarum\Group\Group;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ShowTest extends TestCase
@@ -30,8 +32,8 @@ class ShowTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
@@ -45,7 +47,7 @@ class ShowTest extends TestCase
public function can_show_tag_with_url_decoded_utf8_slug()
{
$this->prepareDatabase([
- 'tags' => [
+ Tag::class => [
['id' => 155, 'name' => '测试', 'slug' => '测试', 'position' => 0, 'parent_id' => null]
]
]);
@@ -67,7 +69,7 @@ class ShowTest extends TestCase
public function can_show_tag_with_url_encoded_utf8_slug()
{
$this->prepareDatabase([
- 'tags' => [
+ Tag::class => [
['id' => 155, 'name' => '测试', 'slug' => '测试', 'position' => 0, 'parent_id' => null]
]
]);
diff --git a/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php b/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php
index 7f52858be..bc66b08f2 100644
--- a/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php
+++ b/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Tags\Tests\integration\authorization;
use Flarum\Group\Group;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -30,8 +31,8 @@ class GlobalPolicyTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/extensions/tags/tests/integration/authorization/TagPolicyTest.php b/extensions/tags/tests/integration/authorization/TagPolicyTest.php
index 42076deb4..82de689f5 100644
--- a/extensions/tags/tests/integration/authorization/TagPolicyTest.php
+++ b/extensions/tags/tests/integration/authorization/TagPolicyTest.php
@@ -31,8 +31,8 @@ class TagPolicyTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
diff --git a/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php b/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php
index f47a5d2cf..4176a65f8 100644
--- a/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php
+++ b/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php
@@ -11,6 +11,8 @@ namespace Flarum\Tags\Tests\integration\api\discussions;
use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
+use Flarum\Post\Post;
+use Flarum\Tags\Tag;
use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -33,8 +35,8 @@ class DiscussionVisibilityTest extends TestCase
$this->extension('flarum-tags');
$this->prepareDatabase([
- 'tags' => $this->tags(),
- 'users' => [
+ Tag::class => $this->tags(),
+ User::class => [
$this->normalUser(),
],
'group_permission' => [
@@ -46,7 +48,7 @@ class DiscussionVisibilityTest extends TestCase
['group_id' => Group::MEMBER_ID, 'permission' => 'arbitraryAbility'],
['group_id' => Group::GUEST_ID, 'permission' => 'arbitraryAbility']
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'no tags', 'user_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => 'open tags', 'user_id' => 1, 'comment_count' => 1],
['id' => 3, 'title' => 'open tag, restricted child tag', 'user_id' => 1, 'comment_count' => 1],
@@ -55,7 +57,7 @@ class DiscussionVisibilityTest extends TestCase
['id' => 6, 'title' => 'closed parent, open child tag', 'user_id' => 1, 'comment_count' => 1],
['id' => 7, 'title' => 'one closed primary tag', 'user_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
['id' => 3, 'discussion_id' => 3, 'user_id' => 1, 'type' => 'comment', 'content' => ''],
diff --git a/framework/core/composer.json b/framework/core/composer.json
index 0bfd6b3b4..60619d9cd 100644
--- a/framework/core/composer.json
+++ b/framework/core/composer.json
@@ -41,6 +41,7 @@
"dflydev/fig-cookies": "^3.0",
"doctrine/dbal": "^3.6",
"dragonmantank/cron-expression": "*",
+ "fakerphp/faker": "^1.9.1",
"franzl/whoops-middleware": "2.0",
"guzzlehttp/guzzle": "^7.7",
"illuminate/bus": "^10.0",
diff --git a/framework/core/src/Api/ApiKey.php b/framework/core/src/Api/ApiKey.php
index 930081243..80a25d04a 100644
--- a/framework/core/src/Api/ApiKey.php
+++ b/framework/core/src/Api/ApiKey.php
@@ -12,6 +12,7 @@ namespace Flarum\Api;
use Carbon\Carbon;
use Flarum\Database\AbstractModel;
use Flarum\User\User;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
@@ -27,6 +28,8 @@ use Illuminate\Support\Str;
*/
class ApiKey extends AbstractModel
{
+ use HasFactory;
+
protected $casts = [
'id' => 'integer',
'user_id' => 'integer',
diff --git a/framework/core/src/Api/ApiKeyFactory.php b/framework/core/src/Api/ApiKeyFactory.php
new file mode 100644
index 000000000..c890ac9f1
--- /dev/null
+++ b/framework/core/src/Api/ApiKeyFactory.php
@@ -0,0 +1,28 @@
+ $this->faker->sha256,
+ 'allowed_ips' => null,
+ 'scopes' => null,
+ 'user_id' => null,
+ 'created_at' => Carbon::now(),
+ 'last_activity_at' => null,
+ ];
+ }
+}
diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php
index dfae3d6ac..99fef1674 100644
--- a/framework/core/src/Database/DatabaseServiceProvider.php
+++ b/framework/core/src/Database/DatabaseServiceProvider.php
@@ -9,17 +9,25 @@
namespace Flarum\Database;
+use Faker\Factory as FakerFactory;
+use Faker\Generator as FakerGenerator;
use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Container\Container as ContainerImplementation;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\ConnectionResolverInterface;
+use Illuminate\Database\Eloquent\Factories\Factory;
+use Illuminate\Support\Str;
class DatabaseServiceProvider extends AbstractServiceProvider
{
+ protected static array $fakers = [];
+
public function register(): void
{
+ $this->registerEloquentFactory();
+
$this->container->singleton(Manager::class, function (ContainerImplementation $container) {
$manager = new Manager($container);
@@ -63,11 +71,33 @@ class DatabaseServiceProvider extends AbstractServiceProvider
});
}
+ protected function registerEloquentFactory(): void
+ {
+ $this->app->singleton(FakerGenerator::class, function ($app, $parameters) {
+ $locale = $parameters['locale'] ?? 'en_US';
+
+ if (! isset(static::$fakers[$locale])) {
+ static::$fakers[$locale] = FakerFactory::create($locale);
+ }
+
+ static::$fakers[$locale]->unique(true);
+
+ return static::$fakers[$locale];
+ });
+ }
+
public function boot(Container $container): void
{
AbstractModel::setConnectionResolver($container->make(ConnectionResolverInterface::class));
AbstractModel::setEventDispatcher($container->make('events'));
+ Factory::guessFactoryNamesUsing(function (string $modelName) {
+ return $modelName.'Factory';
+ });
+ Factory::guessModelNamesUsing(function (Factory $factory) {
+ return Str::replaceLast('Factory', '', $factory::class);
+ });
+
foreach ($container->make('flarum.database.model_private_checkers') as $modelClass => $checkers) {
$modelClass::saving(function ($instance) use ($checkers) {
foreach ($checkers as $checker) {
diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php
index 22ba6985d..05a38ae65 100644
--- a/framework/core/src/Discussion/Discussion.php
+++ b/framework/core/src/Discussion/Discussion.php
@@ -24,6 +24,7 @@ use Flarum\Post\Post;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -60,6 +61,7 @@ class Discussion extends AbstractModel
{
use EventGeneratorTrait;
use ScopeVisibilityTrait;
+ use HasFactory;
/**
* An array of posts that have been modified during this request.
diff --git a/framework/core/src/Discussion/DiscussionFactory.php b/framework/core/src/Discussion/DiscussionFactory.php
new file mode 100644
index 000000000..ad602f2b4
--- /dev/null
+++ b/framework/core/src/Discussion/DiscussionFactory.php
@@ -0,0 +1,37 @@
+ $this->faker->sentence,
+ 'comment_count' => 1,
+ 'participant_count' => 1,
+ 'created_at' => Carbon::now(),
+ 'user_id' => User::factory(),
+ 'first_post_id' => null,
+ 'last_posted_at' => null,
+ 'last_posted_user_id' => null,
+ 'last_post_id' => null,
+ 'last_post_number' => null,
+ 'hidden_at' => null,
+ 'hidden_user_id' => null,
+ 'slug' => $this->faker->slug,
+ 'is_private' => 0
+ ];
+ }
+}
diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php
index 991323813..f4dc5574e 100644
--- a/framework/core/src/Group/Group.php
+++ b/framework/core/src/Group/Group.php
@@ -16,6 +16,7 @@ use Flarum\Group\Event\Created;
use Flarum\Group\Event\Deleted;
use Flarum\Group\Event\Renamed;
use Flarum\User\User;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -33,6 +34,7 @@ class Group extends AbstractModel
{
use EventGeneratorTrait;
use ScopeVisibilityTrait;
+ use HasFactory;
const ADMINISTRATOR_ID = 1;
const GUEST_ID = 2;
diff --git a/framework/core/src/Group/GroupFactory.php b/framework/core/src/Group/GroupFactory.php
new file mode 100644
index 000000000..0064e4333
--- /dev/null
+++ b/framework/core/src/Group/GroupFactory.php
@@ -0,0 +1,26 @@
+ $singular = $this->faker->word,
+ 'name_plural' => $singular.'(s)',
+ 'color' => $this->faker->hexColor,
+ 'icon' => null,
+ 'is_hidden' => false,
+ ];
+ }
+}
diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php
index 41f57c97d..a9b6db3c3 100644
--- a/framework/core/src/Http/AccessToken.php
+++ b/framework/core/src/Http/AccessToken.php
@@ -14,6 +14,7 @@ use Flarum\Database\AbstractModel;
use Flarum\Database\ScopeVisibilityTrait;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
@@ -34,6 +35,7 @@ use Psr\Http\Message\ServerRequestInterface;
class AccessToken extends AbstractModel
{
use ScopeVisibilityTrait;
+ use HasFactory;
protected $table = 'access_tokens';
@@ -71,6 +73,8 @@ class AccessToken extends AbstractModel
*/
private const LAST_ACTIVITY_UPDATE_DIFF = 90;
+ public ?array $uniqueKeys = ['token'];
+
/**
* Generate an access token for the specified user.
*/
diff --git a/framework/core/src/Http/AccessTokenFactory.php b/framework/core/src/Http/AccessTokenFactory.php
new file mode 100644
index 000000000..cad6b2b1a
--- /dev/null
+++ b/framework/core/src/Http/AccessTokenFactory.php
@@ -0,0 +1,32 @@
+ Str::random(40),
+ 'user_id' => User::factory(),
+ 'last_activity_at' => null,
+ 'type' => 'developer',
+ 'title' => $this->faker->sentence,
+ 'last_ip_address' => null,
+ 'last_user_agent' => null,
+ 'created_at' => Carbon::now(),
+ ];
+ }
+}
diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php
index 09ad65352..df52c78fc 100644
--- a/framework/core/src/Post/Post.php
+++ b/framework/core/src/Post/Post.php
@@ -17,6 +17,7 @@ use Flarum\Notification\Notification;
use Flarum\Post\Event\Deleted;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Expression;
use Staudenmeir\EloquentEagerLimit\HasEagerLimit;
@@ -45,6 +46,7 @@ class Post extends AbstractModel
use EventGeneratorTrait;
use ScopeVisibilityTrait;
use HasEagerLimit;
+ use HasFactory;
protected $table = 'posts';
diff --git a/framework/core/src/Post/PostFactory.php b/framework/core/src/Post/PostFactory.php
new file mode 100644
index 000000000..3ed282af2
--- /dev/null
+++ b/framework/core/src/Post/PostFactory.php
@@ -0,0 +1,36 @@
+ Discussion::factory(),
+ 'number' => null,
+ 'created_at' => Carbon::now(),
+ 'user_id' => User::factory(),
+ 'type' => CommentPost::$type,
+ 'content' => $this->faker->paragraph,
+ 'edited_at' => null,
+ 'edited_user_id' => null,
+ 'hidden_at' => null,
+ 'hidden_user_id' => null,
+ 'ip_address' => null,
+ 'is_private' => 0
+ ];
+ }
+}
diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php
index a891035a4..6ad65e2c0 100644
--- a/framework/core/src/User/User.php
+++ b/framework/core/src/User/User.php
@@ -35,6 +35,7 @@ use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;
@@ -72,6 +73,7 @@ class User extends AbstractModel
use EventGeneratorTrait;
use ScopeVisibilityTrait;
use HasEagerLimit;
+ use HasFactory;
protected $casts = [
'id' => 'integer',
diff --git a/framework/core/src/User/UserFactory.php b/framework/core/src/User/UserFactory.php
new file mode 100644
index 000000000..69fb5cda5
--- /dev/null
+++ b/framework/core/src/User/UserFactory.php
@@ -0,0 +1,33 @@
+ $this->faker->userName,
+ 'email' => $this->faker->safeEmail,
+ 'is_email_confirmed' => 1,
+ 'password' => $this->faker->password,
+ 'avatar_url' => $this->faker->imageUrl,
+ 'preferences' => [],
+ 'joined_at' => null,
+ 'last_seen_at' => null,
+ 'marked_all_as_read_at' => null,
+ 'read_notifications_at' => null,
+ 'discussion_count' => 0,
+ 'comment_count' => 0,
+ ];
+ }
+}
diff --git a/framework/core/tests/integration/admin/IndexTest.php b/framework/core/tests/integration/admin/IndexTest.php
index 2010f48b3..08234c7b3 100644
--- a/framework/core/tests/integration/admin/IndexTest.php
+++ b/framework/core/tests/integration/admin/IndexTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\admin;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class IndexTest extends TestCase
{
@@ -22,7 +23,7 @@ class IndexTest extends TestCase
protected function setUp(): void
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
]
]);
diff --git a/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php b/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php
index f2ddeef21..ce4096d3b 100644
--- a/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php
+++ b/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php
@@ -27,7 +27,7 @@ class AccessTokenLifecycleTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'access_tokens' => [
+ AccessToken::class => [
['token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
['token' => 'c', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
diff --git a/framework/core/tests/integration/api/access_tokens/CreateTest.php b/framework/core/tests/integration/api/access_tokens/CreateTest.php
index e87133966..07613e576 100644
--- a/framework/core/tests/integration/api/access_tokens/CreateTest.php
+++ b/framework/core/tests/integration/api/access_tokens/CreateTest.php
@@ -9,8 +9,10 @@
namespace Flarum\Tests\integration\api\access_tokens;
+use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CreateTest extends TestCase
{
@@ -24,12 +26,11 @@ class CreateTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'normal3', 'password' => '$2y$10$LO59tiT7uggl6Oe23o/O6.utnF6ipngYjvMvaxo1TciKqBttDNKim', 'email' => 'normal3@machine.local', 'is_email_confirmed' => 1]
],
- 'access_tokens' => [],
- 'groups' => [
+ Group::class => [
['id' => 10, 'name_plural' => 'Acme', 'name_singular' => 'Acme']
],
'group_user' => [
diff --git a/framework/core/tests/integration/api/access_tokens/DeleteTest.php b/framework/core/tests/integration/api/access_tokens/DeleteTest.php
index e2a9d1a25..bfc009eb2 100644
--- a/framework/core/tests/integration/api/access_tokens/DeleteTest.php
+++ b/framework/core/tests/integration/api/access_tokens/DeleteTest.php
@@ -10,12 +10,14 @@
namespace Flarum\Tests\integration\api\access_tokens;
use Carbon\Carbon;
+use Flarum\Group\Group;
use Flarum\Http\AccessToken;
use Flarum\Http\DeveloperAccessToken;
use Flarum\Http\RememberAccessToken;
use Flarum\Http\SessionAccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class DeleteTest extends TestCase
{
@@ -29,12 +31,12 @@ class DeleteTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'normal3', 'email' => 'normal3@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'normal4', 'email' => 'normal4@machine.local', 'is_email_confirmed' => 1],
],
- 'access_tokens' => [
+ AccessToken::class => [
['id' => 1, 'token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['id' => 2, 'token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
['id' => 3, 'token' => 'c', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
@@ -42,7 +44,7 @@ class DeleteTest extends TestCase
['id' => 5, 'token' => 'e', 'user_id' => 2, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['id' => 6, 'token' => 'f', 'user_id' => 3, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
],
- 'groups' => [
+ Group::class => [
['id' => 100, 'name_singular' => 'test', 'name_plural' => 'test']
],
'group_user' => [
diff --git a/framework/core/tests/integration/api/access_tokens/ListTest.php b/framework/core/tests/integration/api/access_tokens/ListTest.php
index 1e11766dd..cef14fc2b 100644
--- a/framework/core/tests/integration/api/access_tokens/ListTest.php
+++ b/framework/core/tests/integration/api/access_tokens/ListTest.php
@@ -10,9 +10,11 @@
namespace Flarum\Tests\integration\api\access_tokens;
use Carbon\Carbon;
+use Flarum\Group\Group;
use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -27,12 +29,12 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'normal3', 'email' => 'normal3@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'normal4', 'email' => 'normal4@machine.local', 'is_email_confirmed' => 1],
],
- 'access_tokens' => [
+ AccessToken::class => [
['id' => 1, 'token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['id' => 2, 'token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
['id' => 3, 'token' => 'c', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
@@ -40,7 +42,7 @@ class ListTest extends TestCase
['id' => 5, 'token' => 'e', 'user_id' => 2, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
['id' => 6, 'token' => 'f', 'user_id' => 3, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
],
- 'groups' => [
+ Group::class => [
['id' => 100, 'name_singular' => 'test', 'name_plural' => 'test']
],
'group_user' => [
diff --git a/framework/core/tests/integration/api/access_tokens/RemembererTest.php b/framework/core/tests/integration/api/access_tokens/RemembererTest.php
index 8d6a5b6be..1ff10e1f4 100644
--- a/framework/core/tests/integration/api/access_tokens/RemembererTest.php
+++ b/framework/core/tests/integration/api/access_tokens/RemembererTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Tests\integration\api\access_tokens;
use Carbon\Carbon;
+use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -25,7 +26,7 @@ class RemembererTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'access_tokens' => [
+ AccessToken::class => [
['token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
],
diff --git a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php
index 1e6986b94..544332bd1 100644
--- a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php
+++ b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php
@@ -13,6 +13,7 @@ use Carbon\Carbon;
use Flarum\Api\ApiKey;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class WithApiKeyTest extends TestCase
{
@@ -26,10 +27,10 @@ class WithApiKeyTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
- 'api_keys' => [
+ ApiKey::class => [
['key' => 'mastertoken', 'user_id' => null, 'created_at' => Carbon::now()->toDateTimeString()],
['key' => 'personaltoken', 'user_id' => 2, 'created_at' => Carbon::now()->toDateTimeString()],
]
diff --git a/framework/core/tests/integration/api/authentication/WithTokenTest.php b/framework/core/tests/integration/api/authentication/WithTokenTest.php
index aa16e8975..8ac9334cb 100644
--- a/framework/core/tests/integration/api/authentication/WithTokenTest.php
+++ b/framework/core/tests/integration/api/authentication/WithTokenTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\authentication;
use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class WithTokenTest extends TestCase
{
@@ -25,7 +26,7 @@ class WithTokenTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$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 d0a1180eb..461b6b6db 100644
--- a/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php
+++ b/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php
@@ -9,6 +9,8 @@
namespace Flarum\Tests\integration\api\csrf_protection;
+use Flarum\Api\ApiKey;
+use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -24,7 +26,7 @@ class RequireCsrfTokenTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'api_keys' => [
+ ApiKey::class => [
['user_id' => 1, 'key' => 'superadmin'],
]
]);
@@ -192,7 +194,7 @@ class RequireCsrfTokenTest extends TestCase
public function access_token_does_not_need_csrf_token()
{
$this->database()->table('access_tokens')->insert(
- ['token' => 'myaccesstoken', 'user_id' => 1, 'type' => 'developer']
+ AccessToken::factory()->raw(['token' => 'myaccesstoken', 'user_id' => 1, 'type' => 'developer'])
);
$response = $this->send(
diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php
index d306bc99b..999f67086 100644
--- a/framework/core/tests/integration/api/discussions/CreateTest.php
+++ b/framework/core/tests/integration/api/discussions/CreateTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\discussions;
use Flarum\Discussion\Discussion;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class CreateTest extends TestCase
@@ -26,7 +27,7 @@ class CreateTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/api/discussions/DeletionTest.php b/framework/core/tests/integration/api/discussions/DeletionTest.php
index 38a19694f..6f029a624 100644
--- a/framework/core/tests/integration/api/discussions/DeletionTest.php
+++ b/framework/core/tests/integration/api/discussions/DeletionTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class DeletionTest extends TestCase
{
@@ -25,13 +28,13 @@ class DeletionTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'foo bar
'],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
@@ -51,7 +54,7 @@ class DeletionTest extends TestCase
$this->assertEquals(204, $response->getStatusCode());
- // Ensure both the database and the corresponding post are deleted
+ // Ensure both the discussion and the corresponding post are deleted
$this->assertNull($this->database()->table('discussions')->find(1), 'Discussion exists in the DB');
$this->assertNull($this->database()->table('posts')->find(1), 'Post exists in the DB');
}
diff --git a/framework/core/tests/integration/api/discussions/ListTest.php b/framework/core/tests/integration/api/discussions/ListTest.php
index 170f9b05d..ac8d69963 100644
--- a/framework/core/tests/integration/api/discussions/ListTest.php
+++ b/framework/core/tests/integration/api/discussions/ListTest.php
@@ -10,6 +10,8 @@
namespace Flarum\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
@@ -27,19 +29,19 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
['id' => 2, 'title' => 'lightsail in title', 'created_at' => Carbon::createFromDate(1985, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(1985, 5, 21)->toDateTimeString(), 'user_id' => 2, 'comment_count' => 1],
['id' => 3, 'title' => 'not in title', 'created_at' => Carbon::createFromDate(1995, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(1995, 5, 21)->toDateTimeString(), 'user_id' => 2, 'comment_count' => 1],
['id' => 4, 'title' => 'hidden', 'created_at' => Carbon::createFromDate(2005, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(2005, 5, 21)->toDateTimeString(), 'hidden_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
'],
['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::createFromDate(1985, 5, 21)->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'not in text
'],
['id' => 3, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1995, 5, 21)->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'lightsail in text
'],
['id' => 4, 'discussion_id' => 4, 'created_at' => Carbon::createFromDate(2005, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'lightsail in text
'],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php
index 81694aefa..ae598cb78 100644
--- a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php
+++ b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php
@@ -10,6 +10,8 @@
namespace Flarum\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Illuminate\Support\Arr;
@@ -30,24 +32,24 @@ class ListWithFulltextSearchTest extends TestCase
// We need to insert these outside of a transaction, because FULLTEXT indexing,
// which is needed for search, doesn't happen in transactions.
// We clean it up explcitly at the end.
- $this->database()->table('discussions')->insert([
- ['id' => 1, 'title' => 'lightsail in title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 2, 'title' => 'lightsail in title too', 'created_at' => Carbon::createFromDate(2020, 01, 01)->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 3, 'title' => 'not in title either', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 4, 'title' => 'not in title or text', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 5, 'title' => 'తెలుగు', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 6, 'title' => '支持中文吗', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ]);
+ $this->database()->table('discussions')->insert($this->rowsThroughFactory(Discussion::class, [
+ ['id' => 1, 'title' => 'lightsail in title', 'user_id' => 1],
+ ['id' => 2, 'title' => 'lightsail in title too', 'created_at' => Carbon::createFromDate(2020, 01, 01)->toDateTimeString(), 'user_id' => 1],
+ ['id' => 3, 'title' => 'not in title either', 'user_id' => 1],
+ ['id' => 4, 'title' => 'not in title or text', 'user_id' => 1],
+ ['id' => 5, 'title' => 'తెలుగు', 'user_id' => 1],
+ ['id' => 6, 'title' => '支持中文吗', 'user_id' => 1],
+ ]));
- $this->database()->table('posts')->insert([
- ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'not in text
'],
- ['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'lightsail in text
'],
- ['id' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'another lightsail for discussion 2!
'],
- ['id' => 4, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'just one lightsail for discussion 3.
'],
- ['id' => 5, 'discussion_id' => 4, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'not in title or text
'],
- ['id' => 6, 'discussion_id' => 4, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'తెలుగు
'],
- ['id' => 7, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '支持中文吗
'],
- ]);
+ $this->database()->table('posts')->insert($this->rowsThroughFactory(Post::class, [
+ ['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'content' => 'not in text
'],
+ ['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'content' => 'lightsail in text
'],
+ ['id' => 3, 'discussion_id' => 2, 'user_id' => 1, 'content' => 'another lightsail for discussion 2!
'],
+ ['id' => 4, 'discussion_id' => 3, 'user_id' => 1, 'content' => 'just one lightsail for discussion 3.
'],
+ ['id' => 5, 'discussion_id' => 4, 'user_id' => 1, 'content' => 'not in title or text
'],
+ ['id' => 6, 'discussion_id' => 4, 'user_id' => 1, 'content' => 'తెలుగు
'],
+ ['id' => 7, 'discussion_id' => 2, 'user_id' => 1, 'content' => '支持中文吗
'],
+ ]));
// We need to call these again, since we rolled back the transaction started by `::app()`.
$this->database()->beginTransaction();
diff --git a/framework/core/tests/integration/api/discussions/ShowTest.php b/framework/core/tests/integration/api/discussions/ShowTest.php
index acdfccaac..6ee1550c7 100644
--- a/framework/core/tests/integration/api/discussions/ShowTest.php
+++ b/framework/core/tests/integration/api/discussions/ShowTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Tests\integration\api\discussions;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ShowTest extends TestCase
@@ -26,17 +29,17 @@ class ShowTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Empty discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
['id' => 2, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
['id' => 3, 'title' => 'Private discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 1],
['id' => 4, 'title' => 'Discussion with hidden post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 2, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'a normal reply - too-obscure
'],
['id' => 2, 'discussion_id' => 4, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'a hidden reply - too-obscure
', 'hidden_at' => Carbon::now()->toDateTimeString()],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/api/forum/ShowTest.php b/framework/core/tests/integration/api/forum/ShowTest.php
index e46e01a8e..4ad3979aa 100644
--- a/framework/core/tests/integration/api/forum/ShowTest.php
+++ b/framework/core/tests/integration/api/forum/ShowTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\api\forum;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ShowTest extends TestCase
@@ -25,7 +26,7 @@ class ShowTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/api/groups/CreateTest.php b/framework/core/tests/integration/api/groups/CreateTest.php
index f7924b5e6..c5aa13953 100644
--- a/framework/core/tests/integration/api/groups/CreateTest.php
+++ b/framework/core/tests/integration/api/groups/CreateTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\groups;
use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class CreateTest extends TestCase
@@ -26,7 +27,7 @@ class CreateTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/groups/ListTest.php b/framework/core/tests/integration/api/groups/ListTest.php
index b59af92d1..fcd55d6c7 100644
--- a/framework/core/tests/integration/api/groups/ListTest.php
+++ b/framework/core/tests/integration/api/groups/ListTest.php
@@ -9,6 +9,7 @@
namespace Flarum\Tests\integration\api\groups;
+use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Illuminate\Support\Arr;
@@ -25,7 +26,7 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'groups' => [
+ Group::class => [
$this->hiddenGroup(),
],
]);
diff --git a/framework/core/tests/integration/api/groups/ShowTest.php b/framework/core/tests/integration/api/groups/ShowTest.php
index 2a7585a8a..bac6d16d4 100644
--- a/framework/core/tests/integration/api/groups/ShowTest.php
+++ b/framework/core/tests/integration/api/groups/ShowTest.php
@@ -9,6 +9,7 @@
namespace Flarum\Tests\integration\api\groups;
+use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Illuminate\Support\Arr;
@@ -25,7 +26,7 @@ class ShowTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'groups' => [
+ Group::class => [
$this->hiddenGroup(),
],
]);
diff --git a/framework/core/tests/integration/api/notifications/DeleteTest.php b/framework/core/tests/integration/api/notifications/DeleteTest.php
index 4d4c2976b..27f257794 100644
--- a/framework/core/tests/integration/api/notifications/DeleteTest.php
+++ b/framework/core/tests/integration/api/notifications/DeleteTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Tests\integration\api\notifications;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
@@ -26,20 +27,20 @@ class DeleteTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Test Discussion', 'user_id' => 2, 'comment_count' => 1],
['id' => 2, 'title' => 'Test Discussion', 'user_id' => 2, 'comment_count' => 1],
['id' => 3, 'title' => 'Test Discussion', 'user_id' => 1, 'comment_count' => 1],
['id' => 4, 'title' => 'Test Discussion', 'user_id' => 1, 'comment_count' => 1],
],
'notifications' => [
- ['id' => 1, 'user_id' => 1, 'type' => 'discussionRenamed', 'subject_id' => 1, 'from_user_id' => 2, 'read_at' => Carbon::now()],
- ['id' => 2, 'user_id' => 1, 'type' => 'discussionRenamed', 'subject_id' => 2, 'from_user_id' => 2, 'read_at' => null],
- ['id' => 3, 'user_id' => 2, 'type' => 'discussionRenamed', 'subject_id' => 3, 'from_user_id' => 1, 'read_at' => Carbon::now()],
- ['id' => 4, 'user_id' => 2, 'type' => 'discussionRenamed', 'subject_id' => 4, 'from_user_id' => 1, 'read_at' => null],
+ ['id' => 1, 'user_id' => 1, 'type' => 'discussionRenamed', 'subject_id' => 1, 'from_user_id' => 2, 'read_at' => Carbon::now(), 'created_at' => Carbon::now()],
+ ['id' => 2, 'user_id' => 1, 'type' => 'discussionRenamed', 'subject_id' => 2, 'from_user_id' => 2, 'read_at' => null, 'created_at' => Carbon::now()],
+ ['id' => 3, 'user_id' => 2, 'type' => 'discussionRenamed', 'subject_id' => 3, 'from_user_id' => 1, 'read_at' => Carbon::now(), 'created_at' => Carbon::now()],
+ ['id' => 4, 'user_id' => 2, 'type' => 'discussionRenamed', 'subject_id' => 4, 'from_user_id' => 1, 'read_at' => null, 'created_at' => Carbon::now()],
],
]);
}
diff --git a/framework/core/tests/integration/api/notifications/ListTest.php b/framework/core/tests/integration/api/notifications/ListTest.php
index 4c94c3ce7..8b94feeeb 100644
--- a/framework/core/tests/integration/api/notifications/ListTest.php
+++ b/framework/core/tests/integration/api/notifications/ListTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\api\notifications;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class ListTest extends TestCase
{
@@ -24,7 +25,7 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/posts/CreateTest.php b/framework/core/tests/integration/api/posts/CreateTest.php
index 41b61276d..828c2eed7 100644
--- a/framework/core/tests/integration/api/posts/CreateTest.php
+++ b/framework/core/tests/integration/api/posts/CreateTest.php
@@ -10,9 +10,12 @@
namespace Flarum\Tests\integration\api\posts;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Group\Group;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class CreateTest extends TestCase
{
@@ -26,19 +29,19 @@ class CreateTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1],
// Discussion with deleted first post.
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::now()->subDay()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ''],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'restricted', 'email' => 'restricted@machine.local', 'is_email_confirmed' => 1],
],
- 'groups' => [
+ Group::class => [
['id' => 40, 'name_singular' => 'tess', 'name_plural' => 'tess'],
],
'group_user' => [
diff --git a/framework/core/tests/integration/api/posts/DeleteTest.php b/framework/core/tests/integration/api/posts/DeleteTest.php
index df347bc15..cf87ecd79 100644
--- a/framework/core/tests/integration/api/posts/DeleteTest.php
+++ b/framework/core/tests/integration/api/posts/DeleteTest.php
@@ -10,9 +10,12 @@
namespace Flarum\Tests\integration\api\posts;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Discussion\UserState;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class DeleteTest extends TestCase
{
@@ -26,14 +29,14 @@ class DeleteTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
['id' => 3, 'username' => 'acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
['id' => 4, 'username' => 'acme2', 'email' => 'acme2@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 3, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 5, 'last_post_number' => 5, 'last_post_id' => 10],
],
- 'posts' => [
+ Post::class => [
['id' => 5, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 1],
['id' => 6, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 2],
['id' => 7, 'discussion_id' => 3, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 3],
diff --git a/framework/core/tests/integration/api/posts/ListTest.php b/framework/core/tests/integration/api/posts/ListTest.php
index 8cc025999..7daf880e6 100644
--- a/framework/core/tests/integration/api/posts/ListTest.php
+++ b/framework/core/tests/integration/api/posts/ListTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Tests\integration\api\posts;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -23,18 +26,18 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 2],
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'number' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
['id' => 2, 'number' => 1, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
['id' => 3, 'number' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'comment', 'content' => 'something
'],
['id' => 4, 'number' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'comment', 'content' => 'something
'],
['id' => 5, 'number' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => 'something
'],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/posts/ShowTest.php b/framework/core/tests/integration/api/posts/ShowTest.php
index 632553af5..cf6d3b80d 100644
--- a/framework/core/tests/integration/api/posts/ShowTest.php
+++ b/framework/core/tests/integration/api/posts/ShowTest.php
@@ -10,8 +10,11 @@
namespace Flarum\Tests\integration\api\posts;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class ShowTest extends TestCase
{
@@ -25,14 +28,14 @@ class ShowTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'valid
'],
['id' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ' [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/api/settings/SetTest.php b/framework/core/tests/integration/api/settings/SetTest.php
index 03c6ca384..d8cbef337 100644
--- a/framework/core/tests/integration/api/settings/SetTest.php
+++ b/framework/core/tests/integration/api/settings/SetTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\api\settings;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class SetTest extends TestCase
{
@@ -24,7 +25,7 @@ class SetTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/users/DeleteTest.php b/framework/core/tests/integration/api/users/DeleteTest.php
index 4afe35051..099b5dd8c 100644
--- a/framework/core/tests/integration/api/users/DeleteTest.php
+++ b/framework/core/tests/integration/api/users/DeleteTest.php
@@ -22,7 +22,7 @@ class DeleteTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'ken', 'is_email_confirmed' => 1],
],
diff --git a/framework/core/tests/integration/api/users/GroupSearchTest.php b/framework/core/tests/integration/api/users/GroupSearchTest.php
index 803bd263d..d38c5b707 100644
--- a/framework/core/tests/integration/api/users/GroupSearchTest.php
+++ b/framework/core/tests/integration/api/users/GroupSearchTest.php
@@ -9,8 +9,10 @@
namespace Flarum\Tests\integration\api\users;
+use Flarum\Group\Group;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class GroupSearchTest extends TestCase
{
@@ -21,7 +23,7 @@ class GroupSearchTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
@@ -243,7 +245,7 @@ class GroupSearchTest extends TestCase
private function createMultipleUsersAndGroups()
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
[
'id' => 4,
'username' => 'normal4',
@@ -266,7 +268,7 @@ class GroupSearchTest extends TestCase
'is_email_confirmed' => 1,
],
],
- 'groups' => [
+ Group::class => [
[
'id' => 5,
'name_singular' => 'test1 user',
@@ -300,7 +302,7 @@ class GroupSearchTest extends TestCase
private function createHiddenUser()
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
[
'id' => 3,
'username' => 'normal2',
@@ -309,7 +311,7 @@ class GroupSearchTest extends TestCase
'is_email_confirmed' => 1,
],
],
- 'groups' => [
+ Group::class => [
[
'id' => 99,
'name_singular' => 'hidden user',
diff --git a/framework/core/tests/integration/api/users/ListTest.php b/framework/core/tests/integration/api/users/ListTest.php
index 4ff425c98..a16b73b7a 100644
--- a/framework/core/tests/integration/api/users/ListTest.php
+++ b/framework/core/tests/integration/api/users/ListTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\api\users;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Illuminate\Support\Arr;
class ListTest extends TestCase
@@ -25,7 +26,7 @@ class ListTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php b/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php
index d2b349511..b07ecebb6 100644
--- a/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php
+++ b/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php
@@ -13,6 +13,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\EmailToken;
use Flarum\User\PasswordToken;
+use Flarum\User\User;
class PasswordEmailTokensTest extends TestCase
{
@@ -23,7 +24,7 @@ class PasswordEmailTokensTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/users/SendActivationEmailTest.php b/framework/core/tests/integration/api/users/SendActivationEmailTest.php
index 1707251da..fe688fa1c 100644
--- a/framework/core/tests/integration/api/users/SendActivationEmailTest.php
+++ b/framework/core/tests/integration/api/users/SendActivationEmailTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\users;
use Carbon\Carbon;
use Flarum\Testing\integration\TestCase;
use Flarum\User\Throttler\EmailActivationThrottler;
+use Flarum\User\User;
class SendActivationEmailTest extends TestCase
{
@@ -20,7 +21,7 @@ class SendActivationEmailTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
[
'id' => 3,
'username' => 'normal2',
diff --git a/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php b/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php
index ac1f3bc0b..b86812585 100644
--- a/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php
+++ b/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\users;
use Carbon\Carbon;
use Flarum\Testing\integration\TestCase;
use Flarum\User\Throttler\PasswordResetThrottler;
+use Flarum\User\User;
class SendPasswordResetEmailTest extends TestCase
{
@@ -20,7 +21,7 @@ class SendPasswordResetEmailTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
[
'id' => 3,
'username' => 'normal2',
diff --git a/framework/core/tests/integration/api/users/ShowTest.php b/framework/core/tests/integration/api/users/ShowTest.php
index 48bb19e92..6050efc68 100644
--- a/framework/core/tests/integration/api/users/ShowTest.php
+++ b/framework/core/tests/integration/api/users/ShowTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\api\users;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class ShowTest extends TestCase
{
@@ -24,7 +25,7 @@ class ShowTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
diff --git a/framework/core/tests/integration/api/users/UpdateTest.php b/framework/core/tests/integration/api/users/UpdateTest.php
index 56290ac43..284fd4feb 100644
--- a/framework/core/tests/integration/api/users/UpdateTest.php
+++ b/framework/core/tests/integration/api/users/UpdateTest.php
@@ -27,7 +27,7 @@ class UpdateTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
[
'id' => 3,
diff --git a/framework/core/tests/integration/extenders/ApiControllerTest.php b/framework/core/tests/integration/extenders/ApiControllerTest.php
index 0bcb3cac9..6c79825b8 100644
--- a/framework/core/tests/integration/extenders/ApiControllerTest.php
+++ b/framework/core/tests/integration/extenders/ApiControllerTest.php
@@ -41,15 +41,15 @@ class ApiControllerTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
],
- 'discussions' => [
+ Discussion::class => [
['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],
['id' => 3, 'title' => 'Custom Discussion Title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => 'can i haz relationz?
'],
['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => 'can i haz relationz?
'],
['id' => 3, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'discussionRenamed', 'content' => 'can i haz relationz?
'],
@@ -306,7 +306,7 @@ class ApiControllerTest extends TestCase
->setSerializer(CustomPostSerializer::class, CustomApiControllerInvokableClass::class)
);
$this->prepareDatabase([
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'foo bar
'],
],
]);
diff --git a/framework/core/tests/integration/extenders/ApiSerializerTest.php b/framework/core/tests/integration/extenders/ApiSerializerTest.php
index 3e6138e21..fa48203ad 100644
--- a/framework/core/tests/integration/extenders/ApiSerializerTest.php
+++ b/framework/core/tests/integration/extenders/ApiSerializerTest.php
@@ -36,15 +36,15 @@ class ApiSerializerTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
],
- 'discussions' => [
+ Discussion::class => [
['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' => 2, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0],
['id' => 3, 'title' => 'Custom Discussion Title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => 'can i haz relationz?
'],
],
]);
diff --git a/framework/core/tests/integration/extenders/FrontendTitleTest.php b/framework/core/tests/integration/extenders/FrontendTitleTest.php
index c3410428b..92f9387d7 100644
--- a/framework/core/tests/integration/extenders/FrontendTitleTest.php
+++ b/framework/core/tests/integration/extenders/FrontendTitleTest.php
@@ -9,11 +9,14 @@
namespace Flarum\Tests\integration\extenders;
+use Flarum\Discussion\Discussion;
use Flarum\Extend\Frontend;
use Flarum\Frontend\Document;
use Flarum\Frontend\Driver\TitleDriverInterface;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
use Psr\Http\Message\ServerRequestInterface;
class FrontendTitleTest extends TestCase
@@ -23,13 +26,13 @@ class FrontendTitleTest extends TestCase
protected function setUp(): void
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Test Discussion', 'user_id' => 1, 'first_post_id' => 1]
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'user_id' => 2, 'type' => 'comment', 'content' => 'can i haz potat?
'],
],
]);
@@ -59,9 +62,9 @@ class FrontendTitleTest extends TestCase
{
$response = $this->send($this->request('GET', '/d/1'));
- preg_match('/\(?[^<]+)\<\/title\>/m', $response->getBody()->getContents(), $matches);
+ preg_match('/\(?[^<]+)\<\/title\>/m', $body = $response->getBody()->getContents(), $matches);
- $this->assertEquals($title, $matches['title']);
+ $this->assertEquals($title, $matches['title'] ?? null, $body);
}
}
diff --git a/framework/core/tests/integration/extenders/ModelTest.php b/framework/core/tests/integration/extenders/ModelTest.php
index af90dcfcf..a99aade13 100644
--- a/framework/core/tests/integration/extenders/ModelTest.php
+++ b/framework/core/tests/integration/extenders/ModelTest.php
@@ -33,7 +33,7 @@ class ModelTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
]);
@@ -42,10 +42,10 @@ class ModelTest extends TestCase
protected function prepPostsHierarchy()
{
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => 'can i haz relationz?
'],
],
]);
@@ -164,7 +164,7 @@ class ModelTest extends TestCase
);
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1]
]
]);
@@ -310,7 +310,7 @@ class ModelTest extends TestCase
$group2 = new Group;
$this->assertEquals(1, $group1->counter);
- $this->assertEquals(2, $group2->counter);
+ $this->assertEquals(3, $group2->counter);
}
/**
diff --git a/framework/core/tests/integration/extenders/ModelUrlTest.php b/framework/core/tests/integration/extenders/ModelUrlTest.php
index 9d41627c8..eb03e7773 100644
--- a/framework/core/tests/integration/extenders/ModelUrlTest.php
+++ b/framework/core/tests/integration/extenders/ModelUrlTest.php
@@ -33,7 +33,7 @@ class ModelUrlTest extends TestCase
$this->setting("slug_driver_$userClass", 'testDriver');
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/extenders/ModelVisibilityTest.php b/framework/core/tests/integration/extenders/ModelVisibilityTest.php
index db8d5b6e3..7ead3bcf6 100644
--- a/framework/core/tests/integration/extenders/ModelVisibilityTest.php
+++ b/framework/core/tests/integration/extenders/ModelVisibilityTest.php
@@ -32,16 +32,16 @@ class ModelVisibilityTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Empty discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
['id' => 2, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
['id' => 3, 'title' => 'Private discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 2, 'comment_count' => 1, 'is_private' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => 'a normal reply - too-obscure
'],
['id' => 2, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'private!
'],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/extenders/NotificationTest.php b/framework/core/tests/integration/extenders/NotificationTest.php
index b2603c49e..c77f1d769 100644
--- a/framework/core/tests/integration/extenders/NotificationTest.php
+++ b/framework/core/tests/integration/extenders/NotificationTest.php
@@ -144,7 +144,7 @@ class NotificationTest extends TestCase
);
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'hani']
],
diff --git a/framework/core/tests/integration/extenders/PolicyTest.php b/framework/core/tests/integration/extenders/PolicyTest.php
index 7466b182c..05b2c2a00 100644
--- a/framework/core/tests/integration/extenders/PolicyTest.php
+++ b/framework/core/tests/integration/extenders/PolicyTest.php
@@ -36,13 +36,13 @@ class PolicyTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Unrelated Discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'a normal reply - too-obscure
'],
]
]);
diff --git a/framework/core/tests/integration/extenders/SearchDriverTest.php b/framework/core/tests/integration/extenders/SearchDriverTest.php
index 802598da2..6d44df7e9 100644
--- a/framework/core/tests/integration/extenders/SearchDriverTest.php
+++ b/framework/core/tests/integration/extenders/SearchDriverTest.php
@@ -9,11 +9,11 @@
namespace Flarum\Tests\integration\extenders;
-use Carbon\Carbon;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Discussion\Search\Filter\UnreadFilter;
use Flarum\Extend;
+use Flarum\Post\Post;
use Flarum\Search\AbstractFulltextFilter;
use Flarum\Search\Database\DatabaseSearchDriver;
use Flarum\Search\Database\DatabaseSearchState;
@@ -37,13 +37,13 @@ class SearchDriverTest extends TestCase
// which is needed for search, doesn't happen in transactions.
// We clean it up explcitly at the end.
$this->database()->table('discussions')->insert([
- ['id' => 1, 'title' => 'DISCUSSION 1', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
- ['id' => 2, 'title' => 'DISCUSSION 2', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
+ Discussion::factory()->raw(['id' => 1, 'title' => 'DISCUSSION 1', 'user_id' => 1]),
+ Discussion::factory()->raw(['id' => 2, 'title' => 'DISCUSSION 2', 'user_id' => 1]),
]);
$this->database()->table('posts')->insert([
- ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'not in text
'],
- ['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'lightsail in text
'],
+ Post::factory()->raw(['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'content' => 'not in text
']),
+ Post::factory()->raw(['id' => 2, 'discussion_id' => 2, 'user_id' => 1, 'content' => 'lightsail in text
']),
]);
// We need to call these again, since we rolled back the transaction started by `::app()`.
diff --git a/framework/core/tests/integration/extenders/SearchIndexTest.php b/framework/core/tests/integration/extenders/SearchIndexTest.php
index 0ceccaa47..dba9874e0 100644
--- a/framework/core/tests/integration/extenders/SearchIndexTest.php
+++ b/framework/core/tests/integration/extenders/SearchIndexTest.php
@@ -13,6 +13,7 @@ use Carbon\Carbon;
use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Post\CommentPost;
+use Flarum\Post\Post;
use Flarum\Search\IndexerInterface;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -27,11 +28,11 @@ class SearchIndexTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'DISCUSSION 1', 'created_at' => Carbon::now()->subDays(1)->toDateTimeString(), 'hidden_at' => null, 'comment_count' => 1, 'user_id' => 1, 'first_post_id' => 1],
['id' => 2, 'title' => 'DISCUSSION 2', 'created_at' => Carbon::now()->subDays(2)->toDateTimeString(), 'hidden_at' => Carbon::now(), 'comment_count' => 1, 'user_id' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'number' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'content
', 'hidden_at' => null],
['id' => 2, 'number' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'content
', 'hidden_at' => Carbon::now()],
],
diff --git a/framework/core/tests/integration/extenders/SettingsTest.php b/framework/core/tests/integration/extenders/SettingsTest.php
index 42af179fe..ce6f2944e 100644
--- a/framework/core/tests/integration/extenders/SettingsTest.php
+++ b/framework/core/tests/integration/extenders/SettingsTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\extenders;
use Flarum\Extend;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class SettingsTest extends TestCase
{
@@ -25,7 +26,7 @@ class SettingsTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
]
]);
diff --git a/framework/core/tests/integration/extenders/ThrottleApiTest.php b/framework/core/tests/integration/extenders/ThrottleApiTest.php
index e827e5167..fa121a39a 100644
--- a/framework/core/tests/integration/extenders/ThrottleApiTest.php
+++ b/framework/core/tests/integration/extenders/ThrottleApiTest.php
@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\extenders;
use Flarum\Extend;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class ThrottleApiTest extends TestCase
{
@@ -25,7 +26,7 @@ class ThrottleApiTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/extenders/UserTest.php b/framework/core/tests/integration/extenders/UserTest.php
index 4727c5c42..18a2821d1 100644
--- a/framework/core/tests/integration/extenders/UserTest.php
+++ b/framework/core/tests/integration/extenders/UserTest.php
@@ -28,7 +28,7 @@ class UserTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/forum/DefaultRouteTest.php b/framework/core/tests/integration/forum/DefaultRouteTest.php
index 892cc7498..788058cef 100644
--- a/framework/core/tests/integration/forum/DefaultRouteTest.php
+++ b/framework/core/tests/integration/forum/DefaultRouteTest.php
@@ -10,8 +10,10 @@
namespace Flarum\Tests\integration\forum;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Foundation\AbstractServiceProvider;
+use Flarum\Post\Post;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Testing\integration\TestCase;
@@ -25,10 +27,10 @@ class DefaultRouteTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'foo bar', 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => 'foo bar
']
]
]);
diff --git a/framework/core/tests/integration/forum/GlobalLogoutTest.php b/framework/core/tests/integration/forum/GlobalLogoutTest.php
index be40570de..d4c84dbcc 100644
--- a/framework/core/tests/integration/forum/GlobalLogoutTest.php
+++ b/framework/core/tests/integration/forum/GlobalLogoutTest.php
@@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\EmailToken;
use Flarum\User\PasswordToken;
+use Flarum\User\User;
class GlobalLogoutTest extends TestCase
{
@@ -33,10 +34,10 @@ class GlobalLogoutTest extends TestCase
);
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
],
- 'access_tokens' => [
+ AccessToken::class => [
['id' => 1, 'token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['id' => 2, 'token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
['id' => 3, 'token' => 'c', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'developer'],
diff --git a/framework/core/tests/integration/forum/IndexTest.php b/framework/core/tests/integration/forum/IndexTest.php
index 06b454349..cd02d2935 100644
--- a/framework/core/tests/integration/forum/IndexTest.php
+++ b/framework/core/tests/integration/forum/IndexTest.php
@@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\forum;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class IndexTest extends TestCase
{
@@ -22,7 +23,7 @@ class IndexTest extends TestCase
protected function setUp(): void
{
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
]
]);
diff --git a/framework/core/tests/integration/forum/LoginTest.php b/framework/core/tests/integration/forum/LoginTest.php
index 826cda945..eef7239b3 100644
--- a/framework/core/tests/integration/forum/LoginTest.php
+++ b/framework/core/tests/integration/forum/LoginTest.php
@@ -13,6 +13,7 @@ use Flarum\Extend;
use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
+use Flarum\User\User;
class LoginTest extends TestCase
{
@@ -28,7 +29,7 @@ class LoginTest extends TestCase
);
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser()
]
]);
diff --git a/framework/core/tests/integration/notification/NotificationSyncerTest.php b/framework/core/tests/integration/notification/NotificationSyncerTest.php
index fd5a7c103..18cb6ff64 100644
--- a/framework/core/tests/integration/notification/NotificationSyncerTest.php
+++ b/framework/core/tests/integration/notification/NotificationSyncerTest.php
@@ -11,10 +11,12 @@ namespace Flarum\Tests\integration\notification;
use Carbon\Carbon;
use Flarum\Database\AbstractModel;
+use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Notification\Notification;
use Flarum\Notification\NotificationSyncer;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
@@ -28,16 +30,16 @@ class NotificationSyncerTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
['id' => 3, 'username' => 'Receiver', 'email' => 'receiver@machine.local', 'is_email_confirmed' => 1],
],
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Public discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 2, 'is_private' => 0, 'last_post_number' => 2],
['id' => 2, 'title' => 'Private discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 3, 'comment_count' => 2, 'is_private' => 1, 'last_post_number' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '', 'is_private' => 0],
['id' => 2, 'discussion_id' => 1, 'number' => 2, 'created_at' => Carbon::parse('2021-11-01 13:00:03')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '', 'is_private' => 1],
diff --git a/framework/core/tests/integration/policy/DiscussionPolicyTest.php b/framework/core/tests/integration/policy/DiscussionPolicyTest.php
index b01a68087..a1950975f 100644
--- a/framework/core/tests/integration/policy/DiscussionPolicyTest.php
+++ b/framework/core/tests/integration/policy/DiscussionPolicyTest.php
@@ -14,6 +14,7 @@ use Flarum\Bus\Dispatcher;
use Flarum\Discussion\Discussion;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\Post\Command\PostReply;
+use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
@@ -31,16 +32,16 @@ class DiscussionPolicyTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Editable discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 2, 'is_private' => 0, 'last_post_number' => 1, 'participant_count' => 1],
['id' => 2, 'title' => 'Editable discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 2, 'comment_count' => 2, 'is_private' => 0, 'last_post_number' => 2, 'participant_count' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 2, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:03')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ''],
['id' => 3, 'discussion_id' => 2, 'number' => 2, 'created_at' => Carbon::parse('2021-11-01 13:00:03')->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => ''],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/policy/PostPolicyTest.php b/framework/core/tests/integration/policy/PostPolicyTest.php
index 046cbf39e..b5e185b90 100644
--- a/framework/core/tests/integration/policy/PostPolicyTest.php
+++ b/framework/core/tests/integration/policy/PostPolicyTest.php
@@ -10,6 +10,7 @@
namespace Flarum\Tests\integration\policy;
use Carbon\Carbon;
+use Flarum\Discussion\Discussion;
use Flarum\Post\Post;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
@@ -27,14 +28,14 @@ class PostPolicyTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'discussions' => [
+ Discussion::class => [
['id' => 1, 'title' => 'Editable discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 2, 'is_private' => 0, 'last_post_number' => 2],
],
- 'posts' => [
+ Post::class => [
['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ''],
['id' => 2, 'discussion_id' => 1, 'number' => 2, 'created_at' => Carbon::parse('2021-11-01 13:00:03')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => ''],
],
- 'users' => [
+ User::class => [
$this->normalUser(),
]
]);
diff --git a/framework/core/tests/integration/slugger/SlugDriverTest.php b/framework/core/tests/integration/slugger/SlugDriverTest.php
index b83d6a076..b8bd7d39e 100644
--- a/framework/core/tests/integration/slugger/SlugDriverTest.php
+++ b/framework/core/tests/integration/slugger/SlugDriverTest.php
@@ -25,10 +25,10 @@ class SlugDriverTest extends TestCase
parent::setUp();
$this->prepareDatabase([
- 'users' => [
+ User::class => [
$this->normalUser(),
],
- 'discussions' => [
+ Discussion::class => [
['id' => 20, 'title' => 'Empty discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
['id' => 21, 'title' => 'తెలుగు', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
['id' => 22, 'title' => '支持中文吗', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0],
diff --git a/php-packages/testing/src/integration/TestCase.php b/php-packages/testing/src/integration/TestCase.php
index 8cd464034..68f2d4764 100644
--- a/php-packages/testing/src/integration/TestCase.php
+++ b/php-packages/testing/src/integration/TestCase.php
@@ -9,15 +9,18 @@
namespace Flarum\Testing\integration;
+use Flarum\Database\AbstractModel;
use Flarum\Extend\ExtenderInterface;
use Flarum\Testing\integration\Setup\Bootstrapper;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Database\ConnectionInterface;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Laminas\Diactoros\ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
+use RuntimeException;
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
@@ -175,9 +178,12 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
return $this->database;
}
- protected $databaseContent = [];
+ protected array $databaseContent = [];
- protected function prepareDatabase(array $tableData)
+ /**
+ * @var array, array[]>
+ */
+ protected function prepareDatabase(array $tableData): void
{
$this->databaseContent = array_merge_recursive(
$this->databaseContent,
@@ -185,25 +191,44 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
);
}
- protected function populateDatabase()
+ protected function populateDatabase(): void
{
// We temporarily disable foreign key checks to simplify this process.
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
+ $databaseContent = [];
+
+ foreach ($this->databaseContent as $tableOrModelClass => $_rows) {
+ if (class_exists($tableOrModelClass) && method_exists($tableOrModelClass, 'factory')) {
+ /** @var AbstractModel $instance */
+ $instance = (new $tableOrModelClass);
+
+ $databaseContent[$instance->getTable()] = [
+ 'rows' => $this->rowsThroughFactory($tableOrModelClass, $_rows),
+ 'unique' => $instance->uniqueKeys ?? null,
+ ];
+ } else {
+ $databaseContent[$tableOrModelClass] = [
+ 'rows' => $_rows,
+ 'unique' => null,
+ ];
+ }
+ }
+
// Then, insert all rows required for this test case.
- foreach ($this->databaseContent as $table => $rows) {
- foreach ($rows as $row) {
+ foreach ($databaseContent as $table => $data) {
+ foreach ($data['rows'] as $row) {
+ $unique = $row;
+
if ($table === 'settings') {
- $this->database()->table($table)->updateOrInsert(
- ['key' => $row['key']],
- $row
- );
- } else {
- $this->database()->table($table)->updateOrInsert(
- isset($row['id']) ? ['id' => $row['id']] : $row,
- $row
- );
+ $unique = Arr::only($row, ['key']);
+ } elseif (isset($row['id'])) {
+ $unique = Arr::only($row, ['id']);
+ } elseif ($data['unique']) {
+ $unique = Arr::only($row, $data['unique']);
}
+
+ $this->database()->table($table)->updateOrInsert($unique, $row);
}
}
@@ -211,6 +236,27 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
$this->database()->getSchemaBuilder()->enableForeignKeyConstraints();
}
+ protected function throughFactory(string $modelClass, array $attributes): array
+ {
+ if (! method_exists($modelClass, 'factory')) {
+ throw new RuntimeException("$modelClass must use the HasFactory trait and have a Factory class.");
+ }
+
+ /** @var \Illuminate\Database\Eloquent\Factories\Factory $factory */
+ $factory = $modelClass::factory();
+
+ return array_map(function (mixed $value) {
+ return is_array($value) ? json_encode($value) : $value;
+ }, $factory->raw($attributes));
+ }
+
+ protected function rowsThroughFactory(string $modelClass, array $rows): array
+ {
+ return array_map(function (array $row) use ($modelClass) {
+ return $this->throughFactory($modelClass, $row);
+ }, $rows);
+ }
+
/**
* Send a full HTTP request through Flarum's middleware stack.
*/