mirror of
https://github.com/flarum/framework.git
synced 2025-02-14 15:42:53 +08:00
87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?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\Suspend\Tests\integration\api;
|
|
|
|
use Carbon\Carbon;
|
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
|
use Flarum\Testing\integration\TestCase;
|
|
|
|
class UseForumTest extends TestCase
|
|
{
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->extension('flarum-suspend');
|
|
|
|
$this->prepareDatabase([
|
|
'users' => [
|
|
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1],
|
|
['id' => 2, 'username' => 'SuspendedDonny', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->addDay(), 'suspend_reason' => 'acme', 'suspend_message' => 'acme'],
|
|
],
|
|
'discussions' => [
|
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
|
|
],
|
|
'posts' => [
|
|
['id' => 1, 'number' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'discussion_id' => 1, 'content' => '<t><p>Hello, world!</p></t>'],
|
|
]
|
|
]);
|
|
}
|
|
|
|
/** @test */
|
|
public function suspended_user_cannot_create_discussions()
|
|
{
|
|
$response = $this->send(
|
|
$this->request('POST', '/api/discussions', [
|
|
'authenticatedAs' => 2,
|
|
'json' => [
|
|
'data' => [
|
|
'attributes' => [
|
|
'title' => 'Test post',
|
|
'content' => '<t><p>Hello, world!</p></t>'
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
}
|
|
|
|
/** @test */
|
|
public function suspended_user_cannot_reply_to_discussions()
|
|
{
|
|
$response = $this->send(
|
|
$this->request('POST', '/api/posts', [
|
|
'authenticatedAs' => 2,
|
|
'json' => [
|
|
'data' => [
|
|
'attributes' => [
|
|
'content' => '<t><p>Hello, world!</p></t>'
|
|
],
|
|
'relationships' => [
|
|
'discussion' => [
|
|
'data' => [
|
|
'type' => 'discussions',
|
|
'id' => 1,
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
}
|
|
}
|