mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Covered the preferences controller.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php namespace FireflyIII\Http\Controllers;
|
<?php namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Auth;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
@@ -28,9 +28,9 @@ class PreferencesController extends Controller
|
|||||||
/**
|
/**
|
||||||
* @return $this|\Illuminate\View\View
|
* @return $this|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
||||||
$viewRange = Preferences::get('viewRange', '1M');
|
$viewRange = Preferences::get('viewRange', '1M');
|
||||||
$viewRangeValue = $viewRange->data;
|
$viewRangeValue = $viewRange->data;
|
||||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||||
|
84
tests/controllers/PreferencesControllerTest.php
Normal file
84
tests/controllers/PreferencesControllerTest.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PreferencesControllerTest
|
||||||
|
*/
|
||||||
|
class PreferencesControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
|
* This method is called before a test is executed.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called before the first test of this test class is run.
|
||||||
|
*
|
||||||
|
* @since Method available since Release 3.4.0
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
parent::setUpBeforeClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
|
* This method is called after a test is executed.
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
|
||||||
|
// mock:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
|
// fake!
|
||||||
|
$repository->shouldReceive('getAccounts')->with(['Default account', 'Asset account'])->andReturn(new Collection);
|
||||||
|
Preferences::shouldReceive('get')->once()->withArgs(['viewRange', '1M'])->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('get')->once()->withArgs(['budgetMaximum', 1000])->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('get')->once()->withArgs(['currencyPreference', 'EUR'])->andReturn($pref);
|
||||||
|
Amount::shouldReceive('format')->andReturn('xx');
|
||||||
|
Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection);
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
|
||||||
|
|
||||||
|
$this->call('GET', '/preferences');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostIndex()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'frontPageAccounts' => [1, 2, 3],
|
||||||
|
'_token' => 'replaceMe',
|
||||||
|
'viewRange' => '1M'
|
||||||
|
];
|
||||||
|
|
||||||
|
Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]);
|
||||||
|
Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']);
|
||||||
|
Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]);
|
||||||
|
|
||||||
|
|
||||||
|
$this->call('POST', '/preferences', $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user