From 9120e556ebb4c223608e1e9d3a5d88d69ae22545 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 14 Sep 2019 13:09:56 +0200 Subject: [PATCH] Convert more controller tests to feature tests --- .../ListTest.php} | 26 ++++++++++++------- .../ListTest.php} | 23 ++++++++++------ 2 files changed, 31 insertions(+), 18 deletions(-) rename framework/core/tests/integration/api/{Controller/ListNotificationsControllerTest.php => notifications/ListTest.php} (51%) rename framework/core/tests/integration/api/{Controller/ListUsersControllerTest.php => users/ListTest.php} (61%) diff --git a/framework/core/tests/integration/api/Controller/ListNotificationsControllerTest.php b/framework/core/tests/integration/api/notifications/ListTest.php similarity index 51% rename from framework/core/tests/integration/api/Controller/ListNotificationsControllerTest.php rename to framework/core/tests/integration/api/notifications/ListTest.php index 0e1135825..00261a676 100644 --- a/framework/core/tests/integration/api/Controller/ListNotificationsControllerTest.php +++ b/framework/core/tests/integration/api/notifications/ListTest.php @@ -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()); } diff --git a/framework/core/tests/integration/api/Controller/ListUsersControllerTest.php b/framework/core/tests/integration/api/users/ListTest.php similarity index 61% rename from framework/core/tests/integration/api/Controller/ListUsersControllerTest.php rename to framework/core/tests/integration/api/users/ListTest.php index b57e8c4d9..1cd91db7a 100644 --- a/framework/core/tests/integration/api/Controller/ListUsersControllerTest.php +++ b/framework/core/tests/integration/api/users/ListTest.php @@ -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()); }