mirror of
https://github.com/flarum/core.git
synced 2025-08-01 14:10:37 +02:00
Convert more controller tests to request tests
This commit is contained in:
62
tests/integration/api/discussions/DeletionTest.php
Normal file
62
tests/integration/api/discussions/DeletionTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
|
||||
class DeletionTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->prepareDatabase([
|
||||
'discussions' => [
|
||||
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
|
||||
],
|
||||
'posts' => [
|
||||
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>'],
|
||||
],
|
||||
'users' => [
|
||||
$this->adminUser(),
|
||||
$this->normalUser(),
|
||||
],
|
||||
'groups' => [
|
||||
$this->adminGroup(),
|
||||
],
|
||||
'group_user' => [
|
||||
['user_id' => 1, 'group_id' => 1],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function admin_can_delete()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('DELETE', '/api/discussions/1', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
|
||||
// Ensure both the database and the corresponding post are deleted
|
||||
$this->assertNull($this->database()->table('discussions')->find(1), 'Discussion exists in the DB');
|
||||
$this->assertNull($this->database()->table('posts')->find(1), 'Post exists in the DB');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user