2017-02-12 05:00:11 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PreferencesControllerTest.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;
|
|
|
|
|
2017-03-05 11:15:38 -06:00
|
|
|
use FireflyIII\Models\AccountType;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use PragmaRX\Google2FA\Contracts\Google2FA;
|
2017-02-12 05:00:11 -06:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2017-03-05 11:15:38 -06:00
|
|
|
/**
|
|
|
|
* Class PreferencesControllerTest
|
|
|
|
*
|
|
|
|
* @package Tests\Feature\Controllers
|
|
|
|
*/
|
2017-02-12 05:00:11 -06:00
|
|
|
class PreferencesControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
|
2017-02-12 05:21:44 -06:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\PreferencesController::code
|
|
|
|
*/
|
|
|
|
public function testCode()
|
|
|
|
{
|
2017-03-05 11:15:38 -06:00
|
|
|
// mock stuff
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$google = $this->mock(Google2FA::class);
|
|
|
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
|
|
|
$google->shouldReceive('generateSecretKey')->andReturn('secret');
|
|
|
|
$google->shouldReceive('getQRCodeInline')->andReturn('long-data-url');
|
2017-02-12 05:21:44 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('preferences.code'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\PreferencesController::deleteCode
|
|
|
|
*/
|
|
|
|
public function testDeleteCode()
|
|
|
|
{
|
2017-03-05 11:15:38 -06:00
|
|
|
// mock stuff
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
2017-02-12 05:21:44 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('preferences.delete-code'));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
$response->assertSessionHas('info');
|
2017-02-12 05:32:13 -06:00
|
|
|
$response->assertRedirect(route('preferences.index'));
|
2017-02-12 05:21:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\PreferencesController::index
|
2017-02-17 13:14:38 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\PreferencesController::__construct
|
2017-02-12 05:21:44 -06:00
|
|
|
*/
|
|
|
|
public function testIndex()
|
|
|
|
{
|
2017-03-05 11:15:38 -06:00
|
|
|
// mock stuff
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
|
|
|
|
|
2017-02-12 05:21:44 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('preferences.index'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
|
|
|
|
*/
|
|
|
|
public function testPostIndex()
|
|
|
|
{
|
2017-03-05 11:15:38 -06:00
|
|
|
// mock stuff
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
2017-02-12 05:21:44 -06:00
|
|
|
$data = [
|
|
|
|
'fiscalYearStart' => '2016-01-01',
|
|
|
|
'frontPageAccounts' => [],
|
|
|
|
'viewRange' => '1M',
|
|
|
|
'customFiscalYear' => 0,
|
|
|
|
'showDepositsFrontpage' => 0,
|
|
|
|
'transactionPageSize' => 100,
|
|
|
|
'twoFactorAuthEnabled' => 0,
|
|
|
|
'language' => 'en_US',
|
|
|
|
'tj' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('preferences.update'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
2017-02-12 05:32:13 -06:00
|
|
|
$response->assertRedirect(route('preferences.index'));
|
2017-02-12 05:21:44 -06:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:33:32 -06:00
|
|
|
}
|