firefly-iii/app/tests/controllers/PreferencesControllerTest.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2014-07-08 14:35:14 -05:00
<?php
class PreferencesControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testIndex()
{
// mock preferences helper:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn([]);
2014-07-15 00:36:01 -05:00
$viewPref = $this->mock('Preference');
$viewPref->shouldReceive('getAttribute', 'data')->andReturn('1M');
2014-07-08 14:35:14 -05:00
// mock view:
View::shouldReceive('share');
View::shouldReceive('make')->with('preferences.index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('accounts', [])->andReturn(\Mockery::self())
2014-07-15 00:36:01 -05:00
->shouldReceive('with')->once()->with('viewRange', '1M')->andReturn(\Mockery::self())
2014-07-08 14:35:14 -05:00
->shouldReceive('with')->once()->with('frontpageAccounts', $pref)->andReturn(\Mockery::self());
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($pref);
2014-07-15 00:36:01 -05:00
$preferences->shouldReceive('get')->with('viewRange', '1M')->andReturn($viewPref);
2014-07-08 14:35:14 -05:00
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('accounts')->andReturn([]);
$accounts->shouldReceive('getDefault')->andReturn([]);
// call
$this->call('GET', '/preferences');
// test
$this->assertResponseOk();
}
2014-07-15 00:36:01 -05:00
public function testPostIndex()
{
2014-07-08 14:35:14 -05:00
// mock
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('set')->with('frontpageAccounts', [1])->andReturn(true);
2014-07-15 00:36:01 -05:00
$preferences->shouldReceive('set')->with('viewRange', '1M')->andReturn(true);
2014-07-08 14:35:14 -05:00
// call
2014-07-15 00:36:01 -05:00
$this->call('POST', '/preferences', ['frontpageAccounts' => [1], 'viewRange' => '1M']);
2014-07-08 14:35:14 -05:00
// test
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('preferences');
}
public function tearDown()
{
Mockery::close();
}
2014-07-08 14:35:14 -05:00
}