Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Feb 7, 2025
1 parent f4b11b2 commit 82e48ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
32 changes: 25 additions & 7 deletions tests/Panel/Areas/AccountDialogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function testChangePassword(): void

$this->assertFormDialog($dialog);

$this->assertSame('Your current password', $props['fields']['currentPassword']['label']);
$this->assertSame('New password', $props['fields']['password']['label']);
$this->assertSame('Confirm the new password…', $props['fields']['passwordConfirmation']['label']);
$this->assertSame('Change', $props['submitButton']);
Expand All @@ -105,23 +106,39 @@ public function testChangePassword(): void
public function testChangePasswordOnSubmit(): void
{
$this->submit([
'password' => '12345678',
'passwordConfirmation' => '12345678'
'currentPassword' => '12345678',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefgh'
]);

$dialog = $this->dialog('account/changePassword');

$this->assertSame('user.changePassword', $dialog['event']);
$this->assertSame(200, $dialog['code']);

$this->assertTrue($this->app->user('test')->validatePassword(12345678));
$this->assertTrue($this->app->user('test')->validatePassword('abcdefgh'));
}

public function testChangePasswordOnSubmitWithInvalidCurrentPassword(): void
{
$this->submit([
'currentPassword' => '123456',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefgh'
]);

$dialog = $this->dialog('account/changePassword');

$this->assertSame(400, $dialog['code']);
$this->assertSame('Wrong password', $dialog['error']);
}

public function testChangePasswordOnSubmitWithInvalidPassword(): void
{
$this->submit([
'password' => '1234567',
'passwordConfirmation' => '1234567'
'currentPassword' => '12345678',
'password' => 'abcdef',
'passwordConfirmation' => 'abcdef'
]);

$dialog = $this->dialog('account/changePassword');
Expand All @@ -133,8 +150,9 @@ public function testChangePasswordOnSubmitWithInvalidPassword(): void
public function testChangePasswordOnSubmitWithInvalidConfirmation(): void
{
$this->submit([
'password' => '12345678',
'passwordConfirmation' => '1234567'
'currentPassword' => '12345678',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefg'
]);

$dialog = $this->dialog('account/changePassword');
Expand Down
8 changes: 5 additions & 3 deletions tests/Panel/Areas/AreaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kirby\Cms\App;
use Kirby\Cms\Blueprint;
use Kirby\Cms\User;
use Kirby\Filesystem\Dir;
use Kirby\Http\Response;
use Kirby\Panel\Panel;
Expand Down Expand Up @@ -82,9 +83,10 @@ public function install(): void
$this->app([
'users' => [
[
'id' => 'test',
'email' => 'test@getkirby.com',
'role' => 'admin',
'id' => 'test',
'email' => 'test@getkirby.com',
'role' => 'admin',
'password' => User::hashPassword('12345678')
]
]
]);
Expand Down
32 changes: 25 additions & 7 deletions tests/Panel/Areas/UsersDialogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function testChangePassword(): void

$this->assertFormDialog($dialog);

$this->assertSame('Your current password', $props['fields']['currentPassword']['label']);
$this->assertSame('New password', $props['fields']['password']['label']);
$this->assertSame('Confirm the new password…', $props['fields']['passwordConfirmation']['label']);
$this->assertSame('Change', $props['submitButton']);
Expand All @@ -168,23 +169,39 @@ public function testChangePassword(): void
public function testChangePasswordOnSubmit(): void
{
$this->submit([
'password' => '12345678',
'passwordConfirmation' => '12345678'
'currentPassword' => '12345678',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefgh'
]);

$dialog = $this->dialog('users/test/changePassword');

$this->assertSame('user.changePassword', $dialog['event']);
$this->assertSame(200, $dialog['code']);

$this->assertTrue($this->app->user('test')->validatePassword(12345678));
$this->assertTrue($this->app->user('test')->validatePassword('abcdefgh'));
}

public function testChangePasswordOnSubmitWithInvalidCurrentPassword(): void
{
$this->submit([
'currentPassword' => '123456',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefgh'
]);

$dialog = $this->dialog('users/test/changePassword');

$this->assertSame(400, $dialog['code']);
$this->assertSame('Wrong password', $dialog['error']);
}

public function testChangePasswordOnSubmitWithInvalidPassword(): void
{
$this->submit([
'password' => '1234567',
'passwordConfirmation' => '1234567'
'currentPassword' => '12345678',
'password' => 'abcdef',
'passwordConfirmation' => 'abcdef'
]);

$dialog = $this->dialog('users/test/changePassword');
Expand All @@ -196,8 +213,9 @@ public function testChangePasswordOnSubmitWithInvalidPassword(): void
public function testChangePasswordOnSubmitWithInvalidConfirmation(): void
{
$this->submit([
'password' => '12345678',
'passwordConfirmation' => '1234567'
'currentPassword' => '12345678',
'password' => 'abcdefgh',
'passwordConfirmation' => 'abcdefg'
]);

$dialog = $this->dialog('users/test/changePassword');
Expand Down

0 comments on commit 82e48ad

Please sign in to comment.