Convert more controller tests to feature tests

This commit is contained in:
Franz Liedke 2019-09-14 13:09:56 +02:00
parent cad6ab1e6e
commit 9120e556eb
2 changed files with 31 additions and 18 deletions

View File

@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/
namespace Flarum\Tests\integration\api\Controller;
namespace Flarum\Tests\integration\api\notifications;
use Flarum\Api\Controller\ListNotificationsController;
use Flarum\User\User;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
class ListNotificationsControllerTest extends ApiControllerTestCase
class ListTest extends TestCase
{
protected $controller = ListNotificationsController::class;
use RetrievesAuthorizedUsers;
public function setUp()
{
@ -26,6 +26,9 @@ class ListNotificationsControllerTest extends ApiControllerTestCase
'users' => [
$this->normalUser(),
],
'access_tokens' => [
['token' => 'normaltoken', 'user_id' => 2],
],
]);
}
@ -34,7 +37,9 @@ class ListNotificationsControllerTest extends ApiControllerTestCase
*/
public function disallows_index_for_guest()
{
$response = $this->callWith();
$response = $this->send(
$this->request('GET', '/api/notifications')
);
$this->assertEquals(401, $response->getStatusCode());
}
@ -42,11 +47,12 @@ class ListNotificationsControllerTest extends ApiControllerTestCase
/**
* @test
*/
public function show_index_for_user()
public function shows_index_for_user()
{
$this->actor = User::find(2);
$response = $this->callWith();
$response = $this->send(
$this->request('GET', '/api/notifications')
->withHeader('Authorization', 'Token normaltoken')
);
$this->assertEquals(200, $response->getStatusCode());
}

View File

@ -9,14 +9,15 @@
* file that was distributed with this source code.
*/
namespace Flarum\Tests\integration\api\Controller;
namespace Flarum\Tests\integration\api\users;
use Flarum\Api\Controller\ListUsersController;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
class ListUsersControllerTest extends ApiControllerTestCase
class ListTest extends TestCase
{
protected $controller = ListUsersController::class;
use RetrievesAuthorizedUsers;
public function setUp()
{
@ -32,6 +33,9 @@ class ListUsersControllerTest extends ApiControllerTestCase
'group_user' => [
['user_id' => 1, 'group_id' => 1],
],
'access_tokens' => [
['token' => 'admintoken', 'user_id' => 1],
],
]);
}
@ -40,7 +44,9 @@ class ListUsersControllerTest extends ApiControllerTestCase
*/
public function disallows_index_for_guest()
{
$response = $this->callWith();
$response = $this->send(
$this->request('GET', '/api/users')
);
$this->assertEquals(401, $response->getStatusCode());
}
@ -50,9 +56,10 @@ class ListUsersControllerTest extends ApiControllerTestCase
*/
public function shows_index_for_admin()
{
$this->actor = User::find(1);
$response = $this->callWith();
$response = $this->send(
$this->request('GET', '/api/users')
->withHeader('Authorization', 'Token admintoken')
);
$this->assertEquals(200, $response->getStatusCode());
}