framework/tests/integration/extenders/UserTest.php
Alexander Skvortsov b0822df759
Use drivers for display names, add display name extender (#2174)
* Deprecate GetDisplayName event

* Add interface for display name driver

* Add username driver as default

* Add code to register supported drivers / used driver as singletons

* Configured User class to use new driver-based system for display names

* Add extender for adding display name driver

* Add integration test for user display name driver

* Add frontend UI for selecting display name driver
2020-05-19 18:45:56 -04:00

70 lines
1.5 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\Tests\integration\extenders;
use Flarum\Extend;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\DisplayName\DriverInterface;
use Flarum\User\User;
class UserTest extends TestCase
{
use RetrievesAuthorizedUsers;
protected function prepDb()
{
$this->prepareDatabase([
'users' => [
$this->adminUser(),
], 'settings' => [
['key' => 'display_name_driver', 'value' => 'custom'],
],
]);
}
/**
* @test
*/
public function username_display_name_driver_used_by_default()
{
$this->prepDb();
$user = User::find(1);
$this->assertEquals('admin', $user->displayName);
}
/**
* @test
*/
public function can_use_custom_display_name_driver()
{
$this->extend(
(new Extend\User)
->displayNameDriver('custom', CustomDisplayNameDriver::class)
);
$this->prepDb();
$user = User::find(1);
$this->assertEquals('admin@machine.local$$$suffix', $user->displayName);
}
}
class CustomDisplayNameDriver implements DriverInterface
{
public function displayName(User $user): string
{
return $user->email.'$$$suffix';
}
}