-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35d2be1
commit 4c89945
Showing
2 changed files
with
104 additions
and
91 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
extensions/mentions/tests/integration/api/CreateDiscussionTest.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,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)); | ||
} | ||
} |
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