2018-05-14 19:32:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-28 08:16:50 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2018-05-14 19:32:19 +08:00
|
|
|
*/
|
|
|
|
|
2020-03-21 01:54:20 +08:00
|
|
|
namespace Flarum\Tests\integration\api\discussions;
|
2018-05-14 19:32:19 +08:00
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
use Carbon\Carbon;
|
2020-03-21 01:54:20 +08:00
|
|
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
|
|
|
use Flarum\Tests\integration\TestCase;
|
2018-05-14 19:32:19 +08:00
|
|
|
|
2020-03-21 01:54:20 +08:00
|
|
|
class DeletionTest extends TestCase
|
2018-05-14 19:32:19 +08:00
|
|
|
{
|
2020-03-21 01:54:20 +08:00
|
|
|
use RetrievesAuthorizedUsers;
|
2018-05-14 19:32:19 +08:00
|
|
|
|
2020-03-28 08:26:26 +08:00
|
|
|
protected function setUp(): void
|
2018-05-14 19:32:19 +08:00
|
|
|
{
|
2019-01-31 04:15:27 +08:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'discussions' => [
|
|
|
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
|
|
|
|
],
|
2019-10-31 07:27:00 +08:00
|
|
|
'posts' => [
|
|
|
|
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>'],
|
|
|
|
],
|
2019-01-31 04:15:27 +08:00
|
|
|
'users' => [
|
|
|
|
$this->normalUser(),
|
|
|
|
],
|
|
|
|
]);
|
2018-05-14 19:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function admin_can_delete()
|
|
|
|
{
|
2020-03-21 01:54:20 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('DELETE', '/api/discussions/1', [
|
|
|
|
'authenticatedAs' => 1,
|
|
|
|
'json' => [],
|
|
|
|
])
|
|
|
|
);
|
2018-05-14 19:32:19 +08:00
|
|
|
|
|
|
|
$this->assertEquals(204, $response->getStatusCode());
|
2019-10-31 07:27:00 +08:00
|
|
|
|
2020-03-21 01:54:20 +08:00
|
|
|
// Ensure both the database and the corresponding post are deleted
|
|
|
|
$this->assertNull($this->database()->table('discussions')->find(1), 'Discussion exists in the DB');
|
2019-10-31 07:27:00 +08:00
|
|
|
$this->assertNull($this->database()->table('posts')->find(1), 'Post exists in the DB');
|
|
|
|
}
|
2018-05-14 19:32:19 +08:00
|
|
|
}
|