From a7e103f62af84febe62c658f9cd191f4aed899cb Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Tue, 8 Jul 2014 15:31:59 +0200 Subject: [PATCH] This will fail. --- app/tests/controllers/ChartControllerTest.php | 8 ++-- app/tests/controllers/HomeControllerTest.php | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/tests/controllers/ChartControllerTest.php b/app/tests/controllers/ChartControllerTest.php index 1932694509..47afa74fbb 100644 --- a/app/tests/controllers/ChartControllerTest.php +++ b/app/tests/controllers/ChartControllerTest.php @@ -13,7 +13,7 @@ class ChartControllerTest extends TestCase { // mock preference: $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute','data')->andReturn('week'); + $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); // mock preferences helper: $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); @@ -69,7 +69,7 @@ class ChartControllerTest extends TestCase // mock preference: $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute','data')->andReturn('week'); + $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); // mock preferences helper: $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); @@ -79,7 +79,7 @@ class ChartControllerTest extends TestCase $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); $toolkit->shouldReceive('getDateRange')->andReturn(null); - // mock account repository: + // mock account repository: $accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); $accounts->shouldReceive('find')->with(1)->andReturn($account); @@ -111,7 +111,7 @@ class ChartControllerTest extends TestCase // mock preference: $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute','data')->andReturn('week'); + $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); // mock preferences helper: $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); diff --git a/app/tests/controllers/HomeControllerTest.php b/app/tests/controllers/HomeControllerTest.php index c05d72771d..d66f660c1e 100644 --- a/app/tests/controllers/HomeControllerTest.php +++ b/app/tests/controllers/HomeControllerTest.php @@ -38,6 +38,44 @@ class HomeControllerTest extends TestCase $this->assertResponseOk(); } + public function testIndexWithAccount() { + // mock: + View::shouldReceive('share'); + View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self()) + ->shouldReceive('with')->once() // Pass a 'with' parameter + ->with('count', 0) + ->andReturn(Mockery::self()) + ->shouldReceive('with')->once() // another 'with' parameter. + ->with('accounts',[]) + ->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 preferences helper: + // mock preference: + $pref = $this->mock('Preference'); + $pref->shouldReceive('getAttribute', 'data')->andReturn([1]); + + + $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); + $preferences->shouldReceive('get')->with('frontpageAccounts',[])->andReturn($pref)->once(); + $preferences->shouldReceive('get')->with('viewRange', 'week')->once()->andReturn('week'); + + // call + $this->call('GET', '/'); + + // test + $this->assertResponseOk(); + } + public function tearDown() { Mockery::close();