0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-04-30 15:30:11 +00:00
kevinpapst_kimai2/tests/Controller/Security/PasswordResetControllerTest.php
2024-02-07 23:47:25 +01:00

80 lines
2.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Controller\Security;
use App\Tests\Controller\ControllerBaseTest;
/**
* @group integration
*/
class PasswordResetControllerTest extends ControllerBaseTest
{
private function testResetActionWithDeactivatedFeature(string $route, string $method = 'GET')
{
$client = self::createClient();
$this->setSystemConfiguration('user.password_reset', false);
$this->request($client, $route, $method);
$this->assertRouteNotFound($client);
}
public function testResetRequestWithDeactivatedFeature(): void
{
$this->testResetActionWithDeactivatedFeature('/resetting/request');
}
public function testSendEmailRequestWithDeactivatedFeature(): void
{
$this->testResetActionWithDeactivatedFeature('/resetting/send-email', 'POST');
}
public function testCheckEmailWithDeactivatedFeature(): void
{
$this->testResetActionWithDeactivatedFeature('/resetting/check-email');
}
public function testResetWithDeactivatedFeature(): void
{
$this->testResetActionWithDeactivatedFeature('/resetting/reset/1234567890');
}
public function testResetRequestPageIsRendered(): void
{
$client = self::createClient();
$this->setSystemConfiguration('user.password_reset', true);
$this->request($client, '/resetting/request');
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$content = $response->getContent();
$this->assertStringContainsString('<title>Kimai Time Tracking</title>', $content);
$this->assertStringContainsString('Reset your password', $content);
$this->assertStringContainsString('<form class="card-body security-password-reset" action="/en/resetting/send-email" method="post" autocomplete="off">', $content);
$this->assertStringContainsString('<input type="text"', $content);
$this->assertStringContainsString('id="username" name="username" required="required"', $content);
$this->assertStringContainsString('Reset your password', $content);
$form = $client->getCrawler()->filter('form')->form();
$client->submit($form, [
'username' => 'john_user',
]);
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email?username=john_user'));
$client->followRedirect();
$this->assertTrue($client->getResponse()->isSuccessful());
$user = $this->loadUserFromDatabase('john_user');
$token = $user->getConfirmationToken();
$this->request($client, '/resetting/reset/' . $token);
$this->assertTrue($client->getResponse()->isSuccessful());
}
}