-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mentions): implement test for post editing with content empty
- Loading branch information
1 parent
3655942
commit 2e3a516
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
extensions/mentions/tests/integration/api/EditPostTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |