diff --git a/extensions/mentions/composer.json b/extensions/mentions/composer.json
index 946c7c9f7b..9182a9fa5d 100644
--- a/extensions/mentions/composer.json
+++ b/extensions/mentions/composer.json
@@ -78,6 +78,8 @@
"require-dev": {
"flarum/core": "*@dev",
"flarum/tags": "*@dev",
+ "flarum/approval": "*@dev",
+ "flarum/flags": "*@dev",
"flarum/testing": "^2.0"
},
"repositories": [
diff --git a/extensions/mentions/tests/integration/api/NotificationsTest.php b/extensions/mentions/tests/integration/api/NotificationsTest.php
new file mode 100644
index 0000000000..95f17b5e23
--- /dev/null
+++ b/extensions/mentions/tests/integration/api/NotificationsTest.php
@@ -0,0 +1,102 @@
+extension('flarum-mentions');
+
+ $this->prepareDatabase([
+ User::class => [
+ $this->normalUser(),
+ ['id' => 3, 'username' => 'acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
+ ],
+ 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' => 2, 'last_post_id' => 2],
+ ],
+ 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' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 3, 'type' => 'comment', 'content' => 'foo bar
', 'number' => 2],
+ ],
+ 'group_user' => [
+ ['group_id' => Group::MEMBER_ID, 'user_id' => 2],
+ ],
+ ]);
+ }
+
+ #[Test]
+ public function approving_reply_sends_mention_notification()
+ {
+ $this->extensions = ['flarum-flags', 'flarum-approval', 'flarum-mentions'];
+
+ $this->app();
+
+ $this->database()
+ ->table('group_permission')
+ ->where('group_id', Group::MEMBER_ID)
+ ->where('permission', 'discussion.replyWithoutApproval')
+ ->delete();
+
+ /** @var User $mainUser */
+ $mainUser = User::query()->find(3);
+
+ $this->assertEquals(0, $mainUser->getUnreadNotificationCount());
+
+ $response = $this->send(
+ $this->request('POST', '/api/posts', [
+ 'authenticatedAs' => 2,
+ 'json' => [
+ 'data' => [
+ 'attributes' => [
+ 'content' => '@"mainUser"#p2',
+ ],
+ 'relationships' => [
+ 'discussion' => ['data' => ['id' => 1]],
+ ],
+ ]
+ ]
+ ])
+ );
+
+ $this->assertEquals(0, $mainUser->getUnreadNotificationCount());
+
+ $json = json_decode($response->getBody()->getContents(), true);
+
+ $this->send(
+ $this->request('PATCH', '/api/posts/'.$json['data']['id'], [
+ 'authenticatedAs' => 1,
+ 'json' => [
+ 'data' => [
+ 'attributes' => [
+ 'isApproved' => 1,
+ ]
+ ]
+ ]
+ ])
+ );
+
+ $this->assertEquals(1, $mainUser->getUnreadNotificationCount());
+ }
+}