mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Expanded test coverage.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* ForgotPasswordControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Auth;
|
||||
|
||||
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ForgotPasswordControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::sendResetLinkEmail
|
||||
*/
|
||||
public function testSendResetLinkEmail()
|
||||
{
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->andReturn(false);
|
||||
$data = [
|
||||
'email' => 'thegrumpydictator@gmail.com',
|
||||
];
|
||||
|
||||
$response = $this->post(route('password.email'), $data);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::sendResetLinkEmail
|
||||
*/
|
||||
public function testSendResetLinkEmailDemo()
|
||||
{
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->andReturn(true);
|
||||
$data = [
|
||||
'email' => 'thegrumpydictator@gmail.com',
|
||||
];
|
||||
|
||||
$response = $this->post(route('password.email'), $data);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
}
|
@@ -7,12 +7,13 @@
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Auth;
|
||||
|
||||
|
||||
use FireflyIII\Models\Preference;
|
||||
use PragmaRX\Google2FA\Contracts\Google2FA;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -30,17 +31,53 @@ class TwoFactorControllerTest extends TestCase
|
||||
{
|
||||
$this->be($this->user());
|
||||
|
||||
$falsePreference = new Preference;
|
||||
$falsePreference->data = true;
|
||||
$truePref = new Preference;
|
||||
$truePref->data = true;
|
||||
$secretPreference = new Preference;
|
||||
$secretPreference->data = 'BlablaSeecret';
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::index
|
||||
*/
|
||||
public function testIndexNo2FA()
|
||||
{
|
||||
$this->be($this->user());
|
||||
|
||||
$falsePreference = new Preference;
|
||||
$falsePreference->data = false;
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once();
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::index
|
||||
* @expectedExceptionMessage Your two factor authentication secret is empty
|
||||
*/
|
||||
public function testIndexNoSecret()
|
||||
{
|
||||
$this->be($this->user());
|
||||
|
||||
$truePref = new Preference;
|
||||
$truePref->data = true;
|
||||
$secretPreference = new Preference;
|
||||
$secretPreference->data = '';
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::lostTwoFactor
|
||||
*/
|
||||
@@ -59,4 +96,18 @@ class TwoFactorControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::postIndex
|
||||
*/
|
||||
public function testPostIndex()
|
||||
{
|
||||
$data = ['code' => '123456'];
|
||||
$google = $this->mock(Google2FA::class);
|
||||
$google->shouldReceive('verifyKey')->andReturn(true)->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('two-factor.post'), $data);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user