2019-01-02 04:02:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2020-02-05 05:11:08 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2019-01-02 04:02:18 +08:00
|
|
|
*/
|
|
|
|
|
2019-09-14 19:09:56 +08:00
|
|
|
namespace Flarum\Tests\integration\api\users;
|
2019-01-02 04:02:18 +08:00
|
|
|
|
2019-09-15 03:23:30 +08:00
|
|
|
use Flarum\Group\Permission;
|
2019-09-14 19:09:56 +08:00
|
|
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
|
|
|
use Flarum\Tests\integration\TestCase;
|
2019-01-02 04:02:18 +08:00
|
|
|
|
2019-09-14 19:09:56 +08:00
|
|
|
class ListTest extends TestCase
|
2019-01-02 04:02:18 +08:00
|
|
|
{
|
2019-09-14 19:09:56 +08:00
|
|
|
use RetrievesAuthorizedUsers;
|
2019-01-02 04:02:18 +08:00
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'users' => [
|
|
|
|
$this->adminUser(),
|
|
|
|
],
|
|
|
|
'groups' => [
|
|
|
|
$this->adminGroup(),
|
2019-09-15 03:23:30 +08:00
|
|
|
$this->guestGroup(),
|
2019-01-31 04:15:27 +08:00
|
|
|
],
|
2019-09-15 03:23:30 +08:00
|
|
|
'group_permission' => [],
|
2019-01-31 04:15:27 +08:00
|
|
|
'group_user' => [
|
|
|
|
['user_id' => 1, 'group_id' => 1],
|
|
|
|
],
|
2019-09-14 19:09:56 +08:00
|
|
|
'access_tokens' => [
|
|
|
|
['token' => 'admintoken', 'user_id' => 1],
|
|
|
|
],
|
2019-01-31 04:15:27 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-01-02 04:02:18 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function disallows_index_for_guest()
|
|
|
|
{
|
2019-09-14 19:09:56 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('GET', '/api/users')
|
|
|
|
);
|
2019-07-30 06:09:10 +08:00
|
|
|
|
2019-09-15 02:33:23 +08:00
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
2019-01-02 04:02:18 +08:00
|
|
|
}
|
|
|
|
|
2019-09-15 03:23:30 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shows_index_for_guest_when_they_have_permission()
|
|
|
|
{
|
|
|
|
Permission::unguarded(function () {
|
|
|
|
Permission::create([
|
|
|
|
'permission' => 'viewUserList',
|
|
|
|
'group_id' => 2,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$response = $this->send(
|
|
|
|
$this->request('GET', '/api/users')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2019-01-02 04:02:18 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shows_index_for_admin()
|
|
|
|
{
|
2019-09-14 19:09:56 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('GET', '/api/users')
|
|
|
|
->withHeader('Authorization', 'Token admintoken')
|
|
|
|
);
|
2019-01-02 04:02:18 +08:00
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
}
|