From eed70cdb62d72e328391b54d60ae3da0db271efb Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 Aug 2014 08:18:07 +0200 Subject: [PATCH] Finally fixed the tests. --- app/controllers/ChartController.php | 6 +- app/controllers/HomeController.php | 29 +++---- app/lib/Firefly/Helper/Controllers/Chart.php | 3 + app/tests/controllers/ChartControllerTest.php | 79 ++++++++++++++++++- 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php index f8b1a75cc5..eaddd83f3e 100644 --- a/app/controllers/ChartController.php +++ b/app/controllers/ChartController.php @@ -68,8 +68,7 @@ class ChartController extends BaseController // loop and get array data. $url = count($accounts) == 1 && is_array($accounts) - ? 'View more' - : + ? 'View more' : 'View more'; $data = [ 'chart_title' => count($accounts) == 1 ? $accounts[0]->name : 'All accounts', @@ -85,8 +84,9 @@ class ChartController extends BaseController return Response::json($data); } - public function homeAccountInfo(Account $account, $day, $month, $year) + public function homeAccountInfo($name, $day, $month, $year) { + $account = $this->_accounts->findByName($name); $date = Carbon::createFromDate($year, $month, $day); $result = $this->_chart->accountDailySummary($account, $date); diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 67dbc8ae2b..2919a7a1be 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -1,6 +1,5 @@ _accounts = $accounts; $this->_preferences = $preferences; $this->_journal = $journal; - $this->_tk = $toolkit; $this->_budgets = $budgets; View::share('menu', 'home'); } + /** + * @return \Illuminate\Http\RedirectResponse + */ + public function flush() + { + Cache::flush(); + + return Redirect::route('index'); + } + /** * @return $this|\Illuminate\View\View */ @@ -42,7 +48,8 @@ class HomeController extends BaseController { // count, maybe we need some introducing text to show: $count = $this->_accounts->count(); - list($start, $end) = $this->_tk->getDateRangeDates(); + $start = Session::get('start'); + $end = Session::get('end'); // get the preference for the home accounts to show: @@ -73,14 +80,4 @@ class HomeController extends BaseController // build the home screen: return View::make('index')->with('count', $count)->with('transactions', $transactions); } - - /** - * @return \Illuminate\Http\RedirectResponse - */ - public function flush() - { - Cache::flush(); - - return Redirect::route('index'); - } } \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.php index 2523979ae2..c08b4f9f2e 100644 --- a/app/lib/Firefly/Helper/Controllers/Chart.php +++ b/app/lib/Firefly/Helper/Controllers/Chart.php @@ -104,6 +104,9 @@ class Chart implements ChartInterface }] )->orderBy('name', 'ASC')->get(); + $limitInPeriod = 'Envelope for (empty)'; + $spentInPeriod = 'Spent in (empty)'; + foreach ($budgets as $budget) { $budget->count = 0; foreach ($budget->limits as $limit) { diff --git a/app/tests/controllers/ChartControllerTest.php b/app/tests/controllers/ChartControllerTest.php index f9ad9b7b7c..c641cc8a7c 100644 --- a/app/tests/controllers/ChartControllerTest.php +++ b/app/tests/controllers/ChartControllerTest.php @@ -1,9 +1,11 @@ _accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); + $this->_charts = $this->mock('Firefly\Helper\Controllers\ChartInterface'); // $this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface'); $this->_user = m::mock('User', 'Eloquent'); @@ -39,6 +43,8 @@ class ChartControllerTest extends TestCase Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); + $this->_charts->shouldReceive('categoryShowChart')->once()->andReturn([]); + $this->action('GET', 'ChartController@categoryShowChart', $category->id); $this->assertResponseOk(); @@ -47,16 +53,85 @@ class ChartControllerTest extends TestCase public function testHomeAccount() { $account = f::create('Account'); + $collection = new Collection(); + $collection->add($account); $this->session(['start' => new Carbon, 'end' => new Carbon, 'range' => '1M']); // for successful binding: Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); - $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(1); - $this->_accounts->shouldReceive('getByIds')->andReturn([$account]); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('bla@bla'); + $this->_user->shouldReceive('getAttribute')->with('id')->andReturn(1); + $this->_accounts->shouldReceive('getByIds')->andReturn($collection); + + $this->_charts->shouldReceive('account')->once()->andReturn([]); $this->action('GET', 'ChartController@homeAccount'); $this->assertResponseOk(); } + + public function testHomeAccountInfo() + { + $account = f::create('Account'); + $type = f::create('AccountType'); + $type->description = 'Default account'; + $type->save(); + $account->accounttype()->associate($type); + $account->save(); + // for successful binding: + Auth::shouldReceive('user')->andReturn($account->user()->first()); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('bla@bla'); + $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($account->user_id); + $this->_accounts->shouldReceive('findByName')->andReturn($account); + + $this->_charts->shouldReceive('accountDailySummary')->once()->andReturn(['rows' => [],'sum' => 0]); + + $this->call('GET', 'chart/home/info/' . $account->name . '/01/08/2014'); + $this->assertResponseOk(); + + } + + public function testHomeAccountWithAccount() + { + $account = f::create('Account'); + $this->session(['start' => new Carbon, 'end' => new Carbon, 'range' => '1M']); + + // for successful binding: + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('bla@bla'); + $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($account->user_id); + + $this->_charts->shouldReceive('account')->once()->andReturn([]); + + + $this->action('GET', 'ChartController@homeAccount', $account->id); + $this->assertResponseOk(); + } + + public function testHomeBudgets() + { + $date = new Carbon; + $this->session(['start' => $date]); + $this->_charts->shouldReceive('budgets')->once()->with($date)->andReturn([]); + + $this->action('GET', 'ChartController@homeBudgets'); + $this->assertResponseOk(); + } + + public function testHomeCategories() + { + $start = new Carbon; + $end = new Carbon; + + $this->_charts->shouldReceive('categories')->once()->with($start, $end)->andReturn([]); + + $this->session(['start' => $start, 'end' => $end]); + $this->action('GET', 'ChartController@homeCategories'); + $this->assertResponseOk(); + } + + } \ No newline at end of file