koel/tests/Feature/ProfileTest.php

63 lines
1.7 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\Http\Response;
use Illuminate\Support\Facades\Hash;
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
{
/** @var User */
private $user;
2018-08-22 19:46:36 +00:00
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-22 19:46:36 +00:00
{
parent::setUp();
2021-07-26 21:21:36 +00:00
// @phpstan-ignore-next-line
$this->user = User::factory()->create(['password' => Hash::make('secret')]);
2018-08-22 19:46:36 +00:00
}
public function testUpdateProfileRequiresCurrentPassword(): void
2016-05-30 05:50:59 +00:00
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
], $this->user)
->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
}
2018-08-22 19:46:36 +00:00
public function testUpdateProfileWithoutNewPassword(): void
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
'current_password' => 'secret',
], $this->user);
2018-08-22 19:46:36 +00:00
$this->user->refresh();
2016-05-30 05:50:59 +00:00
self::assertSame('Foo', $this->user->name);
self::assertSame('bar@baz.com', $this->user->email);
self::assertTrue(Hash::check('secret', $this->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
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
'new_password' => 'new-secret',
'current_password' => 'secret',
], $this->user)
->assertJsonStructure(['token']);
2018-08-22 19:46:36 +00:00
$this->user->refresh();
self::assertSame('Foo', $this->user->name);
self::assertSame('bar@baz.com', $this->user->email);
self::assertTrue(Hash::check('new-secret', $this->user->password));
2018-08-22 19:46:36 +00:00
}
2016-05-30 05:50:59 +00:00
}