koel/tests/Integration/Models/UserTest.php

72 lines
1.9 KiB
PHP
Raw Normal View History

2017-12-09 22:39:34 +00:00
<?php
namespace Tests\Integration\Models;
use App\Models\User;
use Tests\TestCase;
class UserTest extends TestCase
{
2017-12-10 00:23:37 +00:00
/** @test */
public function user_preferences_can_be_set()
{
// Given a user
/** @var User $user */
$user = factory(User::class)->create();
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// When I see the user's preference
$user->setPreference('foo', 'bar');
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// Then I see the preference properly set
$this->assertArraySubset(['foo' => 'bar'], $user->preferences);
}
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
/** @test */
public function user_preferences_can_be_retrieved()
{
// Given a user with some preferences
/** @var User $user */
$user = factory(User::class)->create([
'preferences' => ['foo' => 'bar'],
]);
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// When I get a preference by its key
$value = $user->getPreference('foo');
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// Then I retrieve the preference value
$this->assertEquals('bar', $value);
}
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
/** @test */
public function user_preferences_can_be_deleted()
{
// Given a user with some preferences
/** @var User $user */
$user = factory(User::class)->create([
'preferences' => ['foo' => 'bar'],
]);
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// When I delete the preference by its key
$user->deletePreference('foo');
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// Then I see the preference gets deleted
$this->assertArrayNotHasKey('foo', $user->preferences);
}
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
/** @test */
public function sensitive_preferences_are_hidden()
{
// Given a user with sensitive preferences
/** @var User $user */
$user = factory(User::class)->create([
'preferences' => ['lastfm_session_key' => 'foo'],
]);
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// When I try to access the sensitive preferences
$value = $user->preferences['lastfm_session_key'];
2017-12-09 22:39:34 +00:00
2017-12-10 00:23:37 +00:00
// Then the sensitive preferences are replaced with "hidden"
$this->assertEquals('hidden', $value);
}
2017-12-09 22:39:34 +00:00
}