2019-01-02 04:02:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-28 08:16:50 +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
|
|
|
*/
|
|
|
|
|
2020-03-27 19:22:22 +08:00
|
|
|
namespace Flarum\Tests\integration\api\groups;
|
2019-01-02 04:02:18 +08:00
|
|
|
|
2020-04-21 23:49:53 +08:00
|
|
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
2020-03-27 19:22:22 +08:00
|
|
|
use Flarum\Tests\integration\TestCase;
|
2020-04-21 23:49:53 +08:00
|
|
|
use Illuminate\Support\Arr;
|
2019-01-02 04:02:18 +08:00
|
|
|
|
2020-03-27 19:22:22 +08:00
|
|
|
class ListTest extends TestCase
|
2019-01-02 04:02:18 +08:00
|
|
|
{
|
2020-04-21 23:49:53 +08:00
|
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
|
2020-05-02 21:35:18 +08:00
|
|
|
protected function setUp(): void
|
2020-04-21 23:49:53 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'users' => [
|
|
|
|
$this->adminUser(),
|
|
|
|
$this->normalUser(),
|
|
|
|
],
|
|
|
|
'groups' => [
|
|
|
|
$this->adminGroup(),
|
|
|
|
$this->hiddenGroup()
|
|
|
|
],
|
|
|
|
'group_user' => [
|
|
|
|
['user_id' => 1, 'group_id' => 1],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-01-02 04:02:18 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-04-21 23:49:53 +08:00
|
|
|
public function shows_limited_index_for_guest()
|
2019-01-02 04:02:18 +08:00
|
|
|
{
|
2020-03-27 19:22:22 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('GET', '/api/groups')
|
|
|
|
);
|
2019-01-02 04:02:18 +08:00
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
|
|
|
2020-04-21 23:49:53 +08:00
|
|
|
$this->assertEquals(['1'], Arr::pluck($data['data'], 'id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shows_index_for_admin()
|
|
|
|
{
|
|
|
|
$response = $this->send(
|
|
|
|
$this->request('GET', '/api/groups', [
|
|
|
|
'authenticatedAs' => 1,
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
|
|
|
|
|
|
$this->assertEquals(['1', '10'], Arr::pluck($data['data'], 'id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function hiddenGroup(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 10,
|
|
|
|
'name_singular' => 'Hidden',
|
|
|
|
'name_plural' => 'Ninjas',
|
|
|
|
'color' => null,
|
|
|
|
'icon' => 'fas fa-wrench',
|
|
|
|
'is_hidden' => 1
|
|
|
|
];
|
2019-01-02 04:02:18 +08:00
|
|
|
}
|
|
|
|
}
|