2017-12-09 22:39:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Models;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class UserTest extends TestCase
|
|
|
|
{
|
2020-09-06 18:21:39 +00:00
|
|
|
public function testSetUserPreferences(): void
|
2018-09-04 06:25:24 +00:00
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
$user->setPreference('foo', 'bar');
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertSame('bar', $user->preferences['foo']);
|
2018-09-04 06:25:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
public function testGetUserPreferences(): void
|
2018-09-04 06:25:24 +00:00
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = factory(User::class)->create([
|
|
|
|
'preferences' => ['foo' => 'bar'],
|
|
|
|
]);
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertEquals('bar', $user->getPreference('foo'));
|
2018-09-04 06:25:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
public function testDeleteUserPreferences(): void
|
2018-09-04 06:25:24 +00:00
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = factory(User::class)->create([
|
|
|
|
'preferences' => ['foo' => 'bar'],
|
|
|
|
]);
|
|
|
|
$user->deletePreference('foo');
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertArrayNotHasKey('foo', $user->preferences);
|
2018-09-04 06:25:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
public function testSensitivePreferencesAreHidden(): void
|
2017-12-10 00:23:37 +00:00
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = factory(User::class)->create([
|
|
|
|
'preferences' => ['lastfm_session_key' => 'foo'],
|
|
|
|
]);
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertEquals('hidden', $user->preferences['lastfm_session_key']);
|
2017-12-10 00:23:37 +00:00
|
|
|
}
|
2017-12-09 22:39:34 +00:00
|
|
|
}
|