framework/extensions/nicknames/tests/integration/api/EditUserTest.php
Alexander Skvortsov 3c5229610f Prompt for nickname on registration (#4)
Allow users to set a nickname while registering, controlled by settings. Also, add a setting to hide the username input entirely and randomly generate the username.

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
2021-11-17 11:17:36 -05:00

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);
}
}