mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 23:53:42 +08:00
88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
|
<?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\Nicknames\Tests\integration;
|
||
|
|
||
|
use Flarum\Group\Group;
|
||
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||
|
use Flarum\Testing\integration\TestCase;
|
||
|
use Flarum\User\User;
|
||
|
|
||
|
class UpdateTest extends TestCase
|
||
|
{
|
||
|
use RetrievesAuthorizedUsers;
|
||
|
|
||
|
/**
|
||
|
* @inheritDoc
|
||
|
*/
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
|
||
|
$this->extension('flarum-nicknames');
|
||
|
$this->prepareDatabase([
|
||
|
'users' => [
|
||
|
$this->normalUser(),
|
||
|
],
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function user_cant_edit_own_nickname_if_not_allowed()
|
||
|
{
|
||
|
$this->database()->table('group_permission')->where('permission', 'user.editOwnNickname')->where('group_id', Group::MEMBER_ID)->delete();
|
||
|
|
||
|
$response = $this->send(
|
||
|
$this->request('PATCH', '/api/users/2', [
|
||
|
'authenticatedAs' => 2,
|
||
|
'json' => [
|
||
|
'data' => [
|
||
|
'attributes' => [
|
||
|
'nickname' => 'new nickname',
|
||
|
],
|
||
|
],
|
||
|
],
|
||
|
])
|
||
|
);
|
||
|
|
||
|
$this->assertEquals(403, $response->getStatusCode());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function user_can_edit_own_nickname_if_allowed()
|
||
|
{
|
||
|
$this->prepareDatabase([
|
||
|
'group_permission' => [
|
||
|
['permission' => 'user.editOwnNickname', 'group_id' => 2],
|
||
|
]
|
||
|
]);
|
||
|
|
||
|
$response = $this->send(
|
||
|
$this->request('PATCH', '/api/users/2', [
|
||
|
'authenticatedAs' => 2,
|
||
|
'json' => [
|
||
|
'data' => [
|
||
|
'attributes' => [
|
||
|
'nickname' => 'new nickname',
|
||
|
],
|
||
|
],
|
||
|
],
|
||
|
])
|
||
|
);
|
||
|
|
||
|
$this->assertEquals(200, $response->getStatusCode());
|
||
|
|
||
|
$this->assertEquals('new nickname', User::find(2)->nickname);
|
||
|
}
|
||
|
}
|