framework/tests/Api/Controller/ShowDiscussionControllerTest.php
Daniël Klabbers e226f81515
additional tests for api controllers (#1433)
* added CreatePostControllerTest

* added DeleteDiscussionControllerTest

* added ListDiscussionControllerTest

* added TokenControllerTest

* minor improvement to policy, no need for Carbon object there, added ShowDiscussionControllerTest

* added showDiscussionControllerTest but cant make Guests view the discussion created by a user

* viewing for guests tested, we might need factories
2018-05-16 09:25:48 +02:00

87 lines
2.0 KiB
PHP

<?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.
*/
namespace Flarum\Tests\Api\Controller;
use Flarum\Api\Controller\ShowDiscussionController;
use Flarum\Discussion\Discussion;
use Flarum\Tests\Test\Concerns\ManagesContent;
class ShowDiscussionControllerTest extends ApiControllerTestCase
{
use ManagesContent;
protected $controller = ShowDiscussionController::class;
/**
* @var Discussion
*/
protected $discussion;
protected function init()
{
$this->discussion = Discussion::start(__CLASS__, $this->getNormalUser());
}
/**
* @test
*/
public function author_can_see_discussion()
{
$this->discussion->save();
$this->actor = $this->getNormalUser();
$response = $this->callWith([], ['id' => $this->discussion->id]);
$this->assertEquals(200, $response->getStatusCode());
}
/**
* @test
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function guest_cannot_see_empty_discussion()
{
$this->discussion->save();
$response = $this->callWith([], ['id' => $this->discussion->id]);
$this->assertEquals(200, $response->getStatusCode());
}
/**
* @test
*/
public function guest_can_see_discussion()
{
$this->discussion->save();
$this->addPostByNormalUser();
$response = $this->callWith([], ['id' => $this->discussion->id]);
$this->assertEquals(200, $response->getStatusCode());
}
/**
* @test
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function guests_cannot_see_private_discussion()
{
$this->discussion->is_private = true;
$this->discussion->save();
$this->callWith([], ['id' => $this->discussion->id]);
}
}