2018-05-14 19:32:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2019-01-02 05:17:09 +08:00
|
|
|
namespace Flarum\Tests\integration\api\Controller;
|
2018-05-14 19:32:19 +08:00
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
use Carbon\Carbon;
|
2018-05-14 19:32:19 +08:00
|
|
|
use Flarum\Api\Controller\ListDiscussionsController;
|
2019-01-31 04:15:27 +08:00
|
|
|
use Flarum\User\User;
|
2018-05-14 19:32:19 +08:00
|
|
|
|
2019-01-02 04:02:18 +08:00
|
|
|
class ListDiscussionsControllerTest extends ApiControllerTestCase
|
2018-05-14 19:32:19 +08:00
|
|
|
{
|
|
|
|
protected $controller = ListDiscussionsController::class;
|
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'discussions' => [
|
|
|
|
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1],
|
|
|
|
],
|
|
|
|
'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->normalUser(),
|
|
|
|
],
|
|
|
|
'groups' => [
|
|
|
|
$this->memberGroup(),
|
|
|
|
$this->guestGroup(),
|
|
|
|
],
|
|
|
|
'group_permission' => [
|
|
|
|
['permission' => 'viewDiscussions', 'group_id' => 2],
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-05-14 19:32:19 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shows_index_for_guest()
|
|
|
|
{
|
|
|
|
$response = $this->callWith();
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
$this->assertEquals(1, count($data['data']));
|
2018-05-14 19:32:19 +08:00
|
|
|
}
|
2018-10-30 06:01:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function can_search_for_author()
|
|
|
|
{
|
2019-01-31 04:15:27 +08:00
|
|
|
$user = User::find(2);
|
2018-10-30 06:01:25 +08:00
|
|
|
|
|
|
|
$response = $this->callWith([], [
|
|
|
|
'filter' => [
|
|
|
|
'q' => 'author:'.$user->username.' foo'
|
|
|
|
],
|
|
|
|
'include' => 'mostRelevantPost'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
2018-05-14 19:32:19 +08:00
|
|
|
}
|