firefly-iii/tests/controllers/PreferencesControllerTest.php

121 lines
4.3 KiB
PHP
Raw Normal View History

2015-04-21 10:19:14 -05:00
<?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();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\PreferencesController::index
*/
2015-04-21 10:19:14 -05:00
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);
2015-06-11 14:19:40 -05:00
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($pref);
2015-04-21 10:19:14 -05:00
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
2015-04-21 10:19:14 -05:00
Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
2015-06-03 14:15:52 -05:00
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
// language preference:
2015-05-18 10:57:44 -05:00
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
2015-04-21 10:19:14 -05:00
$this->call('GET', '/preferences');
$this->assertResponseOk();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
2015-04-21 10:19:14 -05:00
public function testPostIndex()
{
2015-05-05 00:51:02 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
2015-04-21 10:19:14 -05:00
$this->be($user);
$data = [
'frontPageAccounts' => [1, 2, 3],
'_token' => 'replaceMe',
2015-05-15 16:02:42 -05:00
'viewRange' => '1M',
2015-05-18 10:57:44 -05:00
'language' => 'en',
2015-04-21 10:19:14 -05:00
];
2015-05-15 16:24:55 -05:00
// language preference:
2015-05-18 10:57:44 -05:00
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
2015-05-15 16:24:55 -05:00
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
2015-04-21 10:19:14 -05:00
Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]);
Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']);
Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]);
2015-05-15 16:24:55 -05:00
Preferences::shouldReceive('set')->once()->withArgs(['language', 'en']);
2015-06-02 10:58:30 -05:00
Preferences::shouldReceive('mark')->once()->andReturn(true);
2015-04-21 10:19:14 -05:00
// language preference:
2015-05-18 10:57:44 -05:00
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
2015-06-03 14:15:52 -05:00
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
2015-04-21 10:19:14 -05:00
$this->call('POST', '/preferences', $data);
$this->assertResponseStatus(302);
}
}