Fixed tests and added some more.

This commit is contained in:
James Cole 2014-07-08 21:35:14 +02:00
parent a7e103f62a
commit 138044fb41
3 changed files with 72 additions and 9 deletions

View File

@ -39,6 +39,16 @@ class HomeControllerTest extends TestCase
}
public function testIndexWithAccount() {
// mock Account
$account = $this->mock('Account');
$account->shouldReceive('setAttribute')->with('transactionList',[]);
// mock account repository
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('count')->andReturn(0);
$accounts->shouldReceive('getByIds')->andReturn([$account]);
// mock:
View::shouldReceive('share');
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
@ -46,21 +56,17 @@ class HomeControllerTest extends TestCase
->with('count', 0)
->andReturn(Mockery::self())
->shouldReceive('with')->once() // another 'with' parameter.
->with('accounts',[])
->with('accounts',[$account])
->andReturn(Mockery::self())
;
Auth::shouldReceive('check')->andReturn(true);
// mock Account
$account = $this->mock('Account');
// mock account repository
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('count')->andReturn(0);
$accounts->shouldReceive('getByIds')->andReturn([$account]);
// mock transaction journal
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('getByAccount')->with($account,10)->andReturn([]);
// mock preferences helper:
// mock preference:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn([1]);

View File

@ -0,0 +1,56 @@
<?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([]);
// mock view:
View::shouldReceive('share');
View::shouldReceive('make')->with('preferences.index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('accounts', [])->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('frontpageAccounts', $pref)->andReturn(\Mockery::self());
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($pref);
// 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();
}
public function testPostIndex() {
// mock
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('set')->with('frontpageAccounts', [1])->andReturn(true);
// call
$this->call('POST', '/preferences',['frontpageAccounts' => [1]]);
// test
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('preferences');
}
}

View File

@ -22,6 +22,7 @@
<directory suffix=".php">./app/helpers</directory>
<exclude>
<file>./app/controllers/BaseController.php</file>
<file>./app/controllers/MigrationController.php</file>
</exclude>
</whitelist>