mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 00:03:37 +08:00
101 lines
2.8 KiB
PHP
101 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\Tests\integration\api\posts;
|
|
|
|
use Carbon\Carbon;
|
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
|
use Flarum\Testing\integration\TestCase;
|
|
|
|
class CreateTest extends TestCase
|
|
{
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->prepareDatabase([
|
|
'discussions' => [
|
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
|
|
],
|
|
'users' => [
|
|
$this->normalUser(),
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function can_create_reply()
|
|
{
|
|
$response = $this->send(
|
|
$this->request('POST', '/api/posts', [
|
|
'authenticatedAs' => 2,
|
|
'json' => [
|
|
'data' => [
|
|
'attributes' => [
|
|
'content' => 'reply with predetermined content for automated testing - too-obscure',
|
|
],
|
|
'relationships' => [
|
|
'discussion' => ['data' => ['id' => 1]],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$this->assertEquals(201, $response->getStatusCode());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function limited_by_throttler()
|
|
{
|
|
$this->send(
|
|
$this->request('POST', '/api/posts', [
|
|
'authenticatedAs' => 2,
|
|
'json' => [
|
|
'data' => [
|
|
'attributes' => [
|
|
'content' => 'reply with predetermined content for automated testing - too-obscure',
|
|
],
|
|
'relationships' => [
|
|
'discussion' => ['data' => ['id' => 1]],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$response = $this->send(
|
|
$this->request('POST', '/api/posts', [
|
|
'authenticatedAs' => 2,
|
|
'json' => [
|
|
'data' => [
|
|
'attributes' => [
|
|
'content' => 'Second reply with predetermined content for automated testing - too-obscure',
|
|
],
|
|
'relationships' => [
|
|
'discussion' => ['data' => ['id' => 1]],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
);
|
|
|
|
$this->assertEquals(429, $response->getStatusCode());
|
|
}
|
|
}
|