koel/tests/Feature/ProfileTest.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2016-05-30 05:50:59 +00:00
<?php
2017-02-14 06:53:02 +00:00
namespace Tests\Feature;
2016-05-30 05:50:59 +00:00
use App\Models\User;
use Illuminate\Support\Facades\Hash;
2024-01-09 18:34:40 +00:00
use Tests\TestCase;
2016-05-30 05:50:59 +00:00
2017-08-05 16:56:11 +00:00
class ProfileTest extends TestCase
2016-05-30 05:50:59 +00:00
{
public function testUpdateProfileRequiresCurrentPassword(): void
2016-05-30 05:50:59 +00:00
{
2022-07-27 08:49:33 +00:00
$this->putAs('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
2022-07-27 15:32:36 +00:00
])
->assertUnprocessable();
}
2018-08-22 19:46:36 +00:00
public function testUpdateProfileWithoutNewPassword(): void
{
2022-07-27 15:32:36 +00:00
/** @var User $user */
$user = User::factory()->create(['password' => Hash::make('secret')]);
2022-07-27 08:49:33 +00:00
$this->putAs('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
'current_password' => 'secret',
2022-07-27 15:32:36 +00:00
], $user);
2018-08-22 19:46:36 +00:00
2022-07-27 15:32:36 +00:00
$user->refresh();
2016-05-30 05:50:59 +00:00
2022-07-27 15:32:36 +00:00
self::assertSame('Foo', $user->name);
self::assertSame('bar@baz.com', $user->email);
self::assertTrue(Hash::check('secret', $user->password));
2016-05-30 05:50:59 +00:00
}
2018-08-22 19:46:36 +00:00
public function testUpdateProfileWithNewPassword(): void
2018-08-22 19:46:36 +00:00
{
2022-07-27 15:32:36 +00:00
/** @var User $user */
$user = User::factory()->create(['password' => Hash::make('secret')]);
$token = $this->putAs('api/me', [
2018-08-22 19:46:36 +00:00
'name' => 'Foo',
'email' => 'bar@baz.com',
'new_password' => 'new-secret',
'current_password' => 'secret',
2022-07-27 15:32:36 +00:00
], $user)
->headers
->get('Authorization');
$user->refresh();
2022-07-27 15:32:36 +00:00
self::assertNotNull($token);
self::assertSame('Foo', $user->name);
self::assertSame('bar@baz.com', $user->email);
self::assertTrue(Hash::check('new-secret', $user->password));
2018-08-22 19:46:36 +00:00
}
2016-05-30 05:50:59 +00:00
}