mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
Convert more controller tests to feature tests
This commit is contained in:
committed by
Daniël Klabbers
parent
a6decb2350
commit
28e3ec4014
@@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
57
tests/integration/api/notifications/ListTest.php
Normal file
57
tests/integration/api/notifications/ListTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
@@ -7,14 +7,15 @@
|
|||||||
* LICENSE file that was distributed with this source code.
|
* 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;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class ListUsersControllerTest extends ApiControllerTestCase
|
class ListTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $controller = ListUsersController::class;
|
use RetrievesAuthorizedUsers;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,9 @@ class ListUsersControllerTest extends ApiControllerTestCase
|
|||||||
'group_user' => [
|
'group_user' => [
|
||||||
['user_id' => 1, 'group_id' => 1],
|
['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()
|
public function disallows_index_for_guest()
|
||||||
{
|
{
|
||||||
$response = $this->callWith();
|
$response = $this->send(
|
||||||
|
$this->request('GET', '/api/users')
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals(401, $response->getStatusCode());
|
$this->assertEquals(401, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
@@ -48,9 +54,10 @@ class ListUsersControllerTest extends ApiControllerTestCase
|
|||||||
*/
|
*/
|
||||||
public function shows_index_for_admin()
|
public function shows_index_for_admin()
|
||||||
{
|
{
|
||||||
$this->actor = User::find(1);
|
$response = $this->send(
|
||||||
|
$this->request('GET', '/api/users')
|
||||||
$response = $this->callWith();
|
->withHeader('Authorization', 'Token admintoken')
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
}
|
}
|
Reference in New Issue
Block a user