mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-03 20:55:05 +00:00
Fixed tests and added some more.
This commit is contained in:
@@ -39,6 +39,16 @@ class HomeControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testIndexWithAccount() {
|
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:
|
// mock:
|
||||||
View::shouldReceive('share');
|
View::shouldReceive('share');
|
||||||
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
|
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
|
||||||
@@ -46,21 +56,17 @@ class HomeControllerTest extends TestCase
|
|||||||
->with('count', 0)
|
->with('count', 0)
|
||||||
->andReturn(Mockery::self())
|
->andReturn(Mockery::self())
|
||||||
->shouldReceive('with')->once() // another 'with' parameter.
|
->shouldReceive('with')->once() // another 'with' parameter.
|
||||||
->with('accounts',[])
|
->with('accounts',[$account])
|
||||||
->andReturn(Mockery::self())
|
->andReturn(Mockery::self())
|
||||||
;
|
;
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
|
||||||
|
|
||||||
// mock Account
|
|
||||||
$account = $this->mock('Account');
|
|
||||||
|
|
||||||
// mock account repository
|
|
||||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
// mock transaction journal
|
||||||
$accounts->shouldReceive('count')->andReturn(0);
|
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||||
$accounts->shouldReceive('getByIds')->andReturn([$account]);
|
$tj->shouldReceive('getByAccount')->with($account,10)->andReturn([]);
|
||||||
|
|
||||||
// mock preferences helper:
|
// mock preferences helper:
|
||||||
// mock preference:
|
|
||||||
$pref = $this->mock('Preference');
|
$pref = $this->mock('Preference');
|
||||||
$pref->shouldReceive('getAttribute', 'data')->andReturn([1]);
|
$pref->shouldReceive('getAttribute', 'data')->andReturn([1]);
|
||||||
|
|
||||||
|
|||||||
56
app/tests/controllers/PreferencesControllerTest.php
Normal file
56
app/tests/controllers/PreferencesControllerTest.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
<directory suffix=".php">./app/helpers</directory>
|
<directory suffix=".php">./app/helpers</directory>
|
||||||
<exclude>
|
<exclude>
|
||||||
<file>./app/controllers/BaseController.php</file>
|
<file>./app/controllers/BaseController.php</file>
|
||||||
|
<file>./app/controllers/MigrationController.php</file>
|
||||||
</exclude>
|
</exclude>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user