mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 04:47:08 +08:00

* refactor: json:api refactor iteration 1 * chore: delete dead code * fix: regressions * chore: move additions/changes to package * feat: AccessTokenResource * feat: allow dependency injection in resources * feat: `ApiResource` extender * feat: improve * feat: refactor tags extension * feat: refactor flags extension * fix: regressions * fix: drop bc layer * feat: refactor suspend extension * feat: refactor subscriptions extension * feat: refactor approval extension * feat: refactor sticky extension * feat: refactor nicknames extension * feat: refactor mentions extension * feat: refactor lock extension * feat: refactor likes extension * chore: merge conflicts * feat: refactor extension-manager extension * feat: context current endpoint helpers * chore: minor * feat: cleaner sortmap implementation * chore: drop old package * chore: not needed (auto scoping) * fix: actor only fields * refactor: simplify index endpoint * feat: eager loading * test: adapt * test: phpstan * test: adapt * fix: typing * fix: approving content * tet: adapt frontend tests * chore: typings * chore: review * fix: breaking change
92 lines
3.0 KiB
PHP
92 lines
3.0 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\Discussion\Discussion;
|
|
use Flarum\Post\Post;
|
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
|
use Flarum\Testing\integration\TestCase;
|
|
use Flarum\User\User;
|
|
|
|
class UseForumTest extends TestCase
|
|
{
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->extension('flarum-suspend');
|
|
|
|
$this->prepareDatabase([
|
|
User::class => [
|
|
['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'],
|
|
],
|
|
Discussion::class => [
|
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1],
|
|
],
|
|
Post::class => [
|
|
['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' => [
|
|
'type' => 'discussions',
|
|
'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' => [
|
|
'type' => 'posts',
|
|
'attributes' => [
|
|
'content' => '<t><p>Hello, world!</p></t>'
|
|
],
|
|
'relationships' => [
|
|
'discussion' => [
|
|
'data' => [
|
|
'type' => 'discussions',
|
|
'id' => 1,
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
}
|
|
}
|