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