mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
Convert more controller tests to request tests
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
<?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\Controller;
|
||||
|
||||
use Flarum\Api\Controller\CreateDiscussionController;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateDiscussionControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
protected $controller = CreateDiscussionController::class;
|
||||
|
||||
protected $data = [
|
||||
'title' => 'test - too-obscure',
|
||||
'content' => 'predetermined content for automated testing - too-obscure'
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->prepareDatabase([
|
||||
'discussions' => [],
|
||||
'posts' => [],
|
||||
'users' => [
|
||||
$this->adminUser(),
|
||||
],
|
||||
'groups' => [
|
||||
$this->adminGroup(),
|
||||
],
|
||||
'group_user' => [
|
||||
['user_id' => 1, 'group_id' => 1],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function can_create_discussion()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$response = $this->callWith($this->data);
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
/** @var Discussion $discussion */
|
||||
$discussion = Discussion::where('title', $this->data['title'])->firstOrFail();
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
$this->assertEquals($this->data['title'], $discussion->title);
|
||||
$this->assertEquals($this->data['title'], Arr::get($data, 'data.attributes.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function cannot_create_discussion_without_content()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$data = Arr::except($this->data, 'content');
|
||||
$response = $this->callWith($data);
|
||||
|
||||
$this->assertEquals(422, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function cannot_create_discussion_without_title()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$data = Arr::except($this->data, 'title');
|
||||
$response = $this->callWith($data);
|
||||
|
||||
$this->assertEquals(422, $response->getStatusCode());
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
<?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\Controller;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Api\Controller\DeleteDiscussionController;
|
||||
use Flarum\User\User;
|
||||
|
||||
class DeleteDiscussionControllerTest extends ApiControllerTestCase
|
||||
{
|
||||
protected $controller = DeleteDiscussionController::class;
|
||||
|
||||
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()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$response = $this->callWith([], ['id' => 1]);
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function deleting_discussions_deletes_their_posts()
|
||||
{
|
||||
$this->actor = User::find(1);
|
||||
|
||||
$this->callWith([], ['id' => 1]);
|
||||
|
||||
$this->assertNull($this->database()->table('posts')->find(1), 'Post exists in the DB');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user