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('getCurrencyCode')->andReturn('X'); Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection); Amount::shouldReceive('getDefaultCurrency')->andReturn($currency); $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $this->call('GET', '/preferences'); $this->assertResponseOk(); } /** * @covers FireflyIII\Http\Controllers\PreferencesController::postIndex */ public function testPostIndex() { $user = FactoryMuffin::create('FireflyIII\User'); $this->be($user); $data = [ 'frontPageAccounts' => [1, 2, 3], '_token' => 'replaceMe', 'viewRange' => '1M', 'language' => 'en', ]; // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]); Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']); Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]); Preferences::shouldReceive('set')->once()->withArgs(['language', 'en']); Preferences::shouldReceive('mark')->once()->andReturn(true); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); $this->call('POST', '/preferences', $data); $this->assertResponseStatus(302); } }