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 @@ +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 */