From 6d1c8b3e832d3f9d5a07e7cd8e99eb12f3e54b6d Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 17:44:13 +0200
Subject: [PATCH 01/11] test(core): implement test for creating discussion
 without content

---
 .../api/discussions/CreateTest.php            | 92 +++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php
index d306bc99b5..f04a454b49 100644
--- a/framework/core/tests/integration/api/discussions/CreateTest.php
+++ b/framework/core/tests/integration/api/discussions/CreateTest.php
@@ -10,6 +10,7 @@
 namespace Flarum\Tests\integration\api\discussions;
 
 use Flarum\Discussion\Discussion;
+use Flarum\Extend;
 use Flarum\Testing\integration\RetrievesAuthorizedUsers;
 use Flarum\Testing\integration\TestCase;
 use Illuminate\Support\Arr;
@@ -68,6 +69,97 @@ public function cannot_create_discussion_without_content()
         ], json_decode($body, true));
     }
 
+    /**
+     * @test
+     */
+    public function cannot_create_discussion_without_content_property()
+    {
+        $this->extend(
+            (new Extend\Formatter)
+                ->unparse(function ($context, string $content) {
+                    return $content;
+                }),
+            (new Extend\Event())
+                ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
+                    $event->post->content;
+                })
+        );
+
+        $response = $this->send(
+            $this->request('POST', '/api/discussions', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'title' => 'Test post',
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_create_discussion_with_content_set_to_null()
+    {
+        $this->extend(
+            (new Extend\Formatter)
+                ->unparse(function ($context, string $content) {
+                    return $content;
+                }),
+            (new Extend\Event())
+                ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
+                    $event->post->content;
+                })
+        );
+
+        $response = $this->send(
+            $this->request('POST', '/api/discussions', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'title' => 'Test post',
+                            'content' => null,
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
     /**
      * @test
      */

From 46da02b299aa2928c21ff104bc72435e9c82f9d0 Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 17:57:09 +0200
Subject: [PATCH 02/11] fix(core): handle `null` case in XML parser

---
 framework/core/src/Formatter/Formatter.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php
index f47daae694..b93072eddf 100644
--- a/framework/core/src/Formatter/Formatter.php
+++ b/framework/core/src/Formatter/Formatter.php
@@ -139,7 +139,7 @@ public function unparse($xml, $context = null)
             $xml = $callback($context, $xml);
         }
 
-        return Unparser::unparse($xml);
+        return $xml !== null ? Unparser::unparse($xml) : null;
     }
 
     /**

From 2d598e5deed63f826b7cf78207c0f712ccbea5f8 Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:00:37 +0200
Subject: [PATCH 03/11] fix(mentions): change/remove typings in unparser

---
 extensions/mentions/src/Formatter/UnparsePostMentions.php | 4 ++--
 extensions/mentions/src/Formatter/UnparseTagMentions.php  | 4 ++--
 extensions/mentions/src/Formatter/UnparseUserMentions.php | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/extensions/mentions/src/Formatter/UnparsePostMentions.php b/extensions/mentions/src/Formatter/UnparsePostMentions.php
index f223dd638f..78a692bfd5 100644
--- a/extensions/mentions/src/Formatter/UnparsePostMentions.php
+++ b/extensions/mentions/src/Formatter/UnparsePostMentions.php
@@ -30,9 +30,9 @@ public function __construct(TranslatorInterface $translator)
      *
      * @param string $xml
      * @param mixed $context
-     * @return string $xml to be unparsed
+     * @return mixed $xml to be unparsed
      */
-    public function __invoke($context, string $xml)
+    public function __invoke($context, $xml)
     {
         $xml = $this->updatePostMentionTags($context, $xml);
         $xml = $this->unparsePostMentionTags($xml);
diff --git a/extensions/mentions/src/Formatter/UnparseTagMentions.php b/extensions/mentions/src/Formatter/UnparseTagMentions.php
index b2cae82f2f..a0075cb310 100644
--- a/extensions/mentions/src/Formatter/UnparseTagMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseTagMentions.php
@@ -20,9 +20,9 @@ class UnparseTagMentions
      *
      * @param string $xml
      * @param mixed $context
-     * @return string $xml to be unparsed
+     * @return mixed $xml to be unparsed
      */
-    public function __invoke($context, string $xml)
+    public function __invoke($context, $xml)
     {
         $xml = $this->updateTagMentionTags($context, $xml);
         $xml = $this->unparseTagMentionTags($xml);
diff --git a/extensions/mentions/src/Formatter/UnparseUserMentions.php b/extensions/mentions/src/Formatter/UnparseUserMentions.php
index b150d2f7ba..6ca5bb3dfd 100644
--- a/extensions/mentions/src/Formatter/UnparseUserMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseUserMentions.php
@@ -31,9 +31,9 @@ public function __construct(TranslatorInterface $translator)
      *
      * @param string $xml
      * @param mixed $context
-     * @return string $xml to be unparsed
+     * @return mixed $xml to be unparsed
      */
-    public function __invoke($context, string $xml)
+    public function __invoke($context, $xml)
     {
         $xml = $this->updateUserMentionTags($context, $xml);
         $xml = $this->unparseUserMentionTags($xml);

From 20c292c60566ae35e773fe67ed6e4ad88f9d6a3a Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:00:59 +0200
Subject: [PATCH 04/11] fix(mentions): return early if xml null

---
 extensions/mentions/src/Formatter/UnparsePostMentions.php | 4 ++++
 extensions/mentions/src/Formatter/UnparseTagMentions.php  | 4 ++++
 extensions/mentions/src/Formatter/UnparseUserMentions.php | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/extensions/mentions/src/Formatter/UnparsePostMentions.php b/extensions/mentions/src/Formatter/UnparsePostMentions.php
index 78a692bfd5..e7866deab4 100644
--- a/extensions/mentions/src/Formatter/UnparsePostMentions.php
+++ b/extensions/mentions/src/Formatter/UnparsePostMentions.php
@@ -34,6 +34,10 @@ public function __construct(TranslatorInterface $translator)
      */
     public function __invoke($context, $xml)
     {
+        if ($xml === null) {
+            return $xml;
+        }
+
         $xml = $this->updatePostMentionTags($context, $xml);
         $xml = $this->unparsePostMentionTags($xml);
 
diff --git a/extensions/mentions/src/Formatter/UnparseTagMentions.php b/extensions/mentions/src/Formatter/UnparseTagMentions.php
index a0075cb310..c4d98debaf 100644
--- a/extensions/mentions/src/Formatter/UnparseTagMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseTagMentions.php
@@ -24,6 +24,10 @@ class UnparseTagMentions
      */
     public function __invoke($context, $xml)
     {
+        if ($xml === null) {
+            return $xml;
+        }
+
         $xml = $this->updateTagMentionTags($context, $xml);
         $xml = $this->unparseTagMentionTags($xml);
 
diff --git a/extensions/mentions/src/Formatter/UnparseUserMentions.php b/extensions/mentions/src/Formatter/UnparseUserMentions.php
index 6ca5bb3dfd..cdba49b76a 100644
--- a/extensions/mentions/src/Formatter/UnparseUserMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseUserMentions.php
@@ -35,6 +35,10 @@ public function __construct(TranslatorInterface $translator)
      */
     public function __invoke($context, $xml)
     {
+        if ($xml === null) {
+            return $xml;
+        }
+
         $xml = $this->updateUserMentionTags($context, $xml);
         $xml = $this->unparseUserMentionTags($xml);
 

From 35d2be1cdf3e90fef9d788dfbd6c0795ced7617c Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:22:41 +0200
Subject: [PATCH 05/11] chore: fix PHPStan

---
 extensions/mentions/src/Formatter/UnparsePostMentions.php | 2 +-
 extensions/mentions/src/Formatter/UnparseTagMentions.php  | 2 +-
 extensions/mentions/src/Formatter/UnparseUserMentions.php | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/extensions/mentions/src/Formatter/UnparsePostMentions.php b/extensions/mentions/src/Formatter/UnparsePostMentions.php
index e7866deab4..3cfbfa0558 100644
--- a/extensions/mentions/src/Formatter/UnparsePostMentions.php
+++ b/extensions/mentions/src/Formatter/UnparsePostMentions.php
@@ -28,7 +28,7 @@ public function __construct(TranslatorInterface $translator)
     /**
      * Configure rendering for user mentions.
      *
-     * @param string $xml
+     * @param string|null $xml
      * @param mixed $context
      * @return mixed $xml to be unparsed
      */
diff --git a/extensions/mentions/src/Formatter/UnparseTagMentions.php b/extensions/mentions/src/Formatter/UnparseTagMentions.php
index c4d98debaf..ff3ccf8342 100644
--- a/extensions/mentions/src/Formatter/UnparseTagMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseTagMentions.php
@@ -18,7 +18,7 @@ class UnparseTagMentions
     /**
      * Configure rendering for user mentions.
      *
-     * @param string $xml
+     * @param string|null $xml
      * @param mixed $context
      * @return mixed $xml to be unparsed
      */
diff --git a/extensions/mentions/src/Formatter/UnparseUserMentions.php b/extensions/mentions/src/Formatter/UnparseUserMentions.php
index cdba49b76a..f42c7bac39 100644
--- a/extensions/mentions/src/Formatter/UnparseUserMentions.php
+++ b/extensions/mentions/src/Formatter/UnparseUserMentions.php
@@ -29,7 +29,7 @@ public function __construct(TranslatorInterface $translator)
     /**
      * Configure rendering for user mentions.
      *
-     * @param string $xml
+     * @param string|null $xml
      * @param mixed $context
      * @return mixed $xml to be unparsed
      */

From 4c89945f69ecf90747d76d6b72954a047acba0de Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:27:19 +0200
Subject: [PATCH 06/11] chore: move tests to mentions

---
 .../integration/api/CreateDiscussionTest.php  | 104 ++++++++++++++++++
 .../api/discussions/CreateTest.php            |  91 ---------------
 2 files changed, 104 insertions(+), 91 deletions(-)
 create mode 100644 extensions/mentions/tests/integration/api/CreateDiscussionTest.php

diff --git a/extensions/mentions/tests/integration/api/CreateDiscussionTest.php b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
new file mode 100644
index 0000000000..703de08c0f
--- /dev/null
+++ b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
@@ -0,0 +1,104 @@
+<?php
+
+/*
+ * This file is part of Flarum.
+ *
+ * For detailed copyright and license information, please view the
+ * LICENSE file that was distributed with this source code.
+ */
+
+namespace Flarum\Mentions\Tests\integration\api;
+
+use Flarum\Discussion\Discussion;
+use Flarum\Extend;
+use Flarum\Testing\integration\TestCase;
+use Illuminate\Support\Arr;
+
+class CreateDiscussionTest extends TestCase
+{
+    /**
+     * @inheritDoc
+     */
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->extension('flarum-mentions');
+
+        $this->extend(
+            (new Extend\Event())
+            ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
+                $event->post->content;
+            })
+        );
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_create_discussion_without_content_property()
+    {
+        $response = $this->send(
+            $this->request('POST', '/api/discussions', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'title' => 'Test post',
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_create_discussion_with_content_set_to_null()
+    {
+        $response = $this->send(
+            $this->request('POST', '/api/discussions', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'title' => 'Test post',
+                            'content' => null,
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+}
diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php
index f04a454b49..ac5141570b 100644
--- a/framework/core/tests/integration/api/discussions/CreateTest.php
+++ b/framework/core/tests/integration/api/discussions/CreateTest.php
@@ -69,97 +69,6 @@ public function cannot_create_discussion_without_content()
         ], json_decode($body, true));
     }
 
-    /**
-     * @test
-     */
-    public function cannot_create_discussion_without_content_property()
-    {
-        $this->extend(
-            (new Extend\Formatter)
-                ->unparse(function ($context, string $content) {
-                    return $content;
-                }),
-            (new Extend\Event())
-                ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
-                    $event->post->content;
-                })
-        );
-
-        $response = $this->send(
-            $this->request('POST', '/api/discussions', [
-                'authenticatedAs' => 1,
-                'json' => [
-                    'data' => [
-                        'attributes' => [
-                            'title' => 'Test post',
-                        ],
-                    ],
-                ],
-            ])
-        );
-
-        $this->assertEquals(422, $response->getStatusCode());
-
-        $body = (string) $response->getBody();
-        $this->assertJson($body);
-        $this->assertEquals([
-            'errors' => [
-                [
-                    'status' => '422',
-                    'code' => 'validation_error',
-                    'detail' => 'The content field is required.',
-                    'source' => ['pointer' => '/data/attributes/content'],
-                ],
-            ],
-        ], json_decode($body, true));
-    }
-
-    /**
-     * @test
-     */
-    public function cannot_create_discussion_with_content_set_to_null()
-    {
-        $this->extend(
-            (new Extend\Formatter)
-                ->unparse(function ($context, string $content) {
-                    return $content;
-                }),
-            (new Extend\Event())
-                ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
-                    $event->post->content;
-                })
-        );
-
-        $response = $this->send(
-            $this->request('POST', '/api/discussions', [
-                'authenticatedAs' => 1,
-                'json' => [
-                    'data' => [
-                        'attributes' => [
-                            'title' => 'Test post',
-                            'content' => null,
-                        ],
-                    ],
-                ],
-            ])
-        );
-
-        $this->assertEquals(422, $response->getStatusCode());
-
-        $body = (string) $response->getBody();
-        $this->assertJson($body);
-        $this->assertEquals([
-            'errors' => [
-                [
-                    'status' => '422',
-                    'code' => 'validation_error',
-                    'detail' => 'The content field is required.',
-                    'source' => ['pointer' => '/data/attributes/content'],
-                ],
-            ],
-        ], json_decode($body, true));
-    }
-
     /**
      * @test
      */

From 96ecb46088f8ec68888862703642bcd2968a36a5 Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:27:52 +0200
Subject: [PATCH 07/11] chore: remove unused import

---
 framework/core/tests/integration/api/discussions/CreateTest.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php
index ac5141570b..d306bc99b5 100644
--- a/framework/core/tests/integration/api/discussions/CreateTest.php
+++ b/framework/core/tests/integration/api/discussions/CreateTest.php
@@ -10,7 +10,6 @@
 namespace Flarum\Tests\integration\api\discussions;
 
 use Flarum\Discussion\Discussion;
-use Flarum\Extend;
 use Flarum\Testing\integration\RetrievesAuthorizedUsers;
 use Flarum\Testing\integration\TestCase;
 use Illuminate\Support\Arr;

From 3655942f873b30fddbea3764343fe502777d4791 Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:29:02 +0200
Subject: [PATCH 08/11] chore: remove unused imports

---
 .../mentions/tests/integration/api/CreateDiscussionTest.php     | 2 --
 1 file changed, 2 deletions(-)

diff --git a/extensions/mentions/tests/integration/api/CreateDiscussionTest.php b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
index 703de08c0f..bdb78c74ff 100644
--- a/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
+++ b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
@@ -9,10 +9,8 @@
 
 namespace Flarum\Mentions\Tests\integration\api;
 
-use Flarum\Discussion\Discussion;
 use Flarum\Extend;
 use Flarum\Testing\integration\TestCase;
-use Illuminate\Support\Arr;
 
 class CreateDiscussionTest extends TestCase
 {

From 2e3a516ec5cd42501dee5331154e4595b4fe431f Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Mon, 7 Oct 2024 18:50:02 +0200
Subject: [PATCH 09/11] test(mentions): implement test for post editing with
 content empty

---
 .../tests/integration/api/EditPostTest.php    | 142 ++++++++++++++++++
 1 file changed, 142 insertions(+)
 create mode 100644 extensions/mentions/tests/integration/api/EditPostTest.php

diff --git a/extensions/mentions/tests/integration/api/EditPostTest.php b/extensions/mentions/tests/integration/api/EditPostTest.php
new file mode 100644
index 0000000000..eb00c61240
--- /dev/null
+++ b/extensions/mentions/tests/integration/api/EditPostTest.php
@@ -0,0 +1,142 @@
+<?php
+
+/*
+ * This file is part of Flarum.
+ *
+ * For detailed copyright and license information, please view the
+ * LICENSE file that was distributed with this source code.
+ */
+
+namespace Flarum\Mentions\Tests\integration\api;
+
+use Flarum\Extend;
+use Flarum\Testing\integration\TestCase;
+
+class EditPostTest extends TestCase
+{
+    /**
+     * @inheritDoc
+     */
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->extension('flarum-mentions');
+
+        $this->prepareDatabase([
+            'discussions' => [
+                ['id' => 1, 'title' => '', 'user_id' => 1, 'comment_count' => 1],
+            ],
+            'posts' => [
+                ['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p></p></t>'],
+            ]
+        ]);
+
+        $this->extend(
+            (new Extend\Event())
+            ->listen(\Flarum\Post\Event\Saving::class, function ($event) {
+                $event->post->content;
+            })
+        );
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_update_post_with_empty_string()
+    {
+        $response = $this->send(
+            $this->request('PATCH', '/api/posts/1', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'content' => '',
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_update_post_without_content_property()
+    {
+        $response = $this->send(
+            $this->request('PATCH', '/api/posts/1', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
+    /**
+     * @test
+     */
+    public function cannot_update_post_with_content_set_to_null()
+    {
+        $response = $this->send(
+            $this->request('PATCH', '/api/posts/1', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'content' => null,
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+}

From 20d9099abc49cfef2e26efe7607902ee1e17b66d Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Tue, 8 Oct 2024 07:13:59 +0200
Subject: [PATCH 10/11] test(mentions): change post edit tests

---
 .../tests/integration/api/EditPostTest.php    | 40 ++-----------------
 1 file changed, 4 insertions(+), 36 deletions(-)

diff --git a/extensions/mentions/tests/integration/api/EditPostTest.php b/extensions/mentions/tests/integration/api/EditPostTest.php
index eb00c61240..52b48a1f74 100644
--- a/extensions/mentions/tests/integration/api/EditPostTest.php
+++ b/extensions/mentions/tests/integration/api/EditPostTest.php
@@ -25,10 +25,10 @@ protected function setUp(): void
 
         $this->prepareDatabase([
             'discussions' => [
-                ['id' => 1, 'title' => '', 'user_id' => 1, 'comment_count' => 1],
+                ['id' => 1, 'title' => 'Discussion with post', 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
             ],
             'posts' => [
-                ['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p></p></t>'],
+                ['id' => 1, 'discussion_id' => 1, 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>Text</p></t>'],
             ]
         ]);
 
@@ -77,39 +77,7 @@ public function cannot_update_post_with_empty_string()
     /**
      * @test
      */
-    public function cannot_update_post_without_content_property()
-    {
-        $response = $this->send(
-            $this->request('PATCH', '/api/posts/1', [
-                'authenticatedAs' => 1,
-                'json' => [
-                    'data' => [
-                        'attributes' => [],
-                    ],
-                ],
-            ])
-        );
-
-        $this->assertEquals(422, $response->getStatusCode());
-
-        $body = (string) $response->getBody();
-        $this->assertJson($body);
-        $this->assertEquals([
-            'errors' => [
-                [
-                    'status' => '422',
-                    'code' => 'validation_error',
-                    'detail' => 'The content field is required.',
-                    'source' => ['pointer' => '/data/attributes/content'],
-                ],
-            ],
-        ], json_decode($body, true));
-    }
-
-    /**
-     * @test
-     */
-    public function cannot_update_post_with_content_set_to_null()
+    public function cannot_update_post_with_invalid_content_type()
     {
         $response = $this->send(
             $this->request('PATCH', '/api/posts/1', [
@@ -117,7 +85,7 @@ public function cannot_update_post_with_content_set_to_null()
                 'json' => [
                     'data' => [
                         'attributes' => [
-                            'content' => null,
+                            'content' => [],
                         ],
                     ],
                 ],

From aa0d529f7e5e1992dee3936253b09684f8032829 Mon Sep 17 00:00:00 2001
From: Davide Iadeluca <davide.iadeluca@glowingblue.com>
Date: Tue, 8 Oct 2024 07:15:24 +0200
Subject: [PATCH 11/11] test(mentions): add test for creating discussion with
 empty string

---
 .../integration/api/CreateDiscussionTest.php  | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/extensions/mentions/tests/integration/api/CreateDiscussionTest.php b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
index bdb78c74ff..6c93a34e49 100644
--- a/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
+++ b/extensions/mentions/tests/integration/api/CreateDiscussionTest.php
@@ -31,6 +31,41 @@ protected function setUp(): void
         );
     }
 
+    /**
+     * @test
+     */
+    public function cannot_create_discussion_with_empty_string()
+    {
+        $response = $this->send(
+            $this->request('POST', '/api/discussions', [
+                'authenticatedAs' => 1,
+                'json' => [
+                    'data' => [
+                        'attributes' => [
+                            'title' => 'Test post',
+                            'content' => '',
+                        ],
+                    ],
+                ],
+            ])
+        );
+
+        $this->assertEquals(422, $response->getStatusCode());
+
+        $body = (string) $response->getBody();
+        $this->assertJson($body);
+        $this->assertEquals([
+            'errors' => [
+                [
+                    'status' => '422',
+                    'code' => 'validation_error',
+                    'detail' => 'The content field is required.',
+                    'source' => ['pointer' => '/data/attributes/content'],
+                ],
+            ],
+        ], json_decode($body, true));
+    }
+
     /**
      * @test
      */