Files
firefly-iii/tests/acceptance/Controllers/Auth/ConfirmationControllerTest.php

122 lines
4.6 KiB
PHP
Raw Normal View History

2016-11-19 20:30:30 +01:00
<?php
2016-12-06 09:16:36 +01:00
/**
* ConfirmationControllerTest.php
* Copyright (C) 2016 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.
*/
2016-11-19 20:30:30 +01:00
namespace Auth;
2016-11-20 11:43:19 +01:00
2016-12-09 07:20:48 +01:00
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
use FireflyIII\Support\Facades\FireflyConfig;
use FireflyIII\Support\Facades\Preferences;
2016-11-19 20:30:30 +01:00
use TestCase;
/**
2016-12-07 19:53:41 +01:00
* Generated by PHPUnit_SkeletonGenerator on 2016-12-07 at 18:50:31.
2016-11-19 20:30:30 +01:00
*/
class ConfirmationControllerTest extends TestCase
{
2016-11-20 07:24:18 +01:00
2016-11-19 20:30:30 +01:00
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
2016-11-20 08:30:25 +01:00
parent::setUp();
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\Auth\ConfirmationController::confirmationError
2016-11-26 08:55:26 +01:00
* Implement testConfirmationError().
2016-11-19 20:30:30 +01:00
*/
public function testConfirmationError()
{
2016-12-09 07:20:48 +01:00
// need a user that is not activated. And site must require activated users.
2016-12-09 15:17:57 +01:00
$trueConfig = new Configuration;
$trueConfig->data = true;
$falsePreference = new Preference;
$falsePreference->data = false;
2016-12-09 07:20:48 +01:00
2016-12-09 15:17:57 +01:00
Preferences::shouldReceive('get')->withArgs(['user_confirmed', false])->andReturn($falsePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);
2016-12-09 07:20:48 +01:00
FireflyConfig::shouldReceive('get')->withArgs(['must_confirm_account', false])->once()->andReturn($trueConfig);
2016-12-09 15:17:57 +01:00
$this->be($this->user());
2016-12-09 07:20:48 +01:00
$this->call('GET', route('confirmation_error'));
$this->assertResponseStatus(200);
$this->see('has been sent to the address you used during your registration');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\Auth\ConfirmationController::doConfirmation
2016-11-26 08:55:26 +01:00
* Implement testDoConfirmation().
2016-11-19 20:30:30 +01:00
*/
public function testDoConfirmation()
{
2016-12-09 15:17:57 +01:00
$codePreference = new Preference;
$codePreference->data = 'abcde';
$timePreference = new Preference;
$timePreference->data = 0;
$falsePreference = new Preference;
$falsePreference->data = false;
Preferences::shouldReceive('get')->withArgs(['user_confirmed_code'])->andReturn($codePreference);
Preferences::shouldReceive('get')->withArgs(['user_confirmed_last_mail', 0])->andReturn($timePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);
Preferences::shouldReceive('get')->withArgs(['user_confirmed', false])->andReturn($falsePreference);
$this->be($this->user());
$this->call('GET', route('do_confirm_account', ['abcde']));
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('home');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\Auth\ConfirmationController::resendConfirmation
2016-11-26 08:55:26 +01:00
* Implement testResendConfirmation().
2016-11-19 20:30:30 +01:00
*/
public function testResendConfirmation()
{
2016-12-09 15:17:57 +01:00
$trueConfig = new Configuration;
$trueConfig->data = true;
$codePreference = new Preference;
$codePreference->data = 'abcde';
$timePreference = new Preference;
$timePreference->data = 0;
$falsePreference = new Preference;
$falsePreference->data = false;
Preferences::shouldReceive('get')->withArgs(['user_confirmed_last_mail', 0])->andReturn($timePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);
FireflyConfig::shouldReceive('get')->withArgs(['must_confirm_account', false])->once()->andReturn($trueConfig);
Preferences::shouldReceive('get')->withArgs(['user_confirmed', false])->andReturn($falsePreference);
// from event handler:
Preferences::shouldReceive('setForUser')->withAnyArgs()->once();
$this->be($this->user());
$this->call('GET', route('resend_confirmation'));
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
2016-11-20 11:43:19 +01:00
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
2016-11-19 20:30:30 +01:00
}