1
0
mirror of https://github.com/flarum/core.git synced 2025-08-05 07:57:46 +02:00

Convert more controller tests to feature tests

This commit is contained in:
Franz Liedke
2019-09-14 13:09:56 +02:00
committed by Daniël Klabbers
parent a6decb2350
commit 28e3ec4014
3 changed files with 72 additions and 59 deletions

View File

@@ -1,51 +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\ListNotificationsController;
use Flarum\User\User;
class ListNotificationsControllerTest extends ApiControllerTestCase
{
protected $controller = ListNotificationsController::class;
public function setUp()
{
parent::setUp();
$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
]);
}
/**
* @test
*/
public function disallows_index_for_guest()
{
$response = $this->callWith();
$this->assertEquals(401, $response->getStatusCode());
}
/**
* @test
*/
public function show_index_for_user()
{
$this->actor = User::find(2);
$response = $this->callWith();
$this->assertEquals(200, $response->getStatusCode());
}
}

View File

@@ -0,0 +1,57 @@
<?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\notifications;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
class ListTest extends TestCase
{
use RetrievesAuthorizedUsers;
public function setUp()
{
parent::setUp();
$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
'access_tokens' => [
['token' => 'normaltoken', 'user_id' => 2],
],
]);
}
/**
* @test
*/
public function disallows_index_for_guest()
{
$response = $this->send(
$this->request('GET', '/api/notifications')
);
$this->assertEquals(401, $response->getStatusCode());
}
/**
* @test
*/
public function shows_index_for_user()
{
$response = $this->send(
$this->request('GET', '/api/notifications')
->withHeader('Authorization', 'Token normaltoken')
);
$this->assertEquals(200, $response->getStatusCode());
}
}

View File

@@ -7,14 +7,15 @@
* LICENSE 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()
{
@@ -30,6 +31,9 @@ class ListUsersControllerTest extends ApiControllerTestCase
'group_user' => [
['user_id' => 1, 'group_id' => 1],
],
'access_tokens' => [
['token' => 'admintoken', 'user_id' => 1],
],
]);
}
@@ -38,7 +42,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());
}
@@ -48,9 +54,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());
}