diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 298b14d8f5..7df980e19f 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -1,6 +1,6 @@ accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']); + $accounts = $repository->getAccounts(['Default account', 'Asset account']); $viewRange = Preferences::get('viewRange', '1M'); $viewRangeValue = $viewRange->data; $frontPage = Preferences::get('frontPageAccounts', []); diff --git a/tests/controllers/PreferencesControllerTest.php b/tests/controllers/PreferencesControllerTest.php new file mode 100644 index 0000000000..02f61910d6 --- /dev/null +++ b/tests/controllers/PreferencesControllerTest.php @@ -0,0 +1,84 @@ +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); + } +} \ No newline at end of file