Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Finally fixed the tests.
James Coleeed70cdb62d7
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.phpindex 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)- ? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>'- :+ ? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>' :'<a href="' . route('accounts.index') . '">View more</a>';$data = ['chart_title' => count($accounts) == 1 ? $accounts[0]->name : 'All accounts',@@ -85,8 +84,9 @@ class ChartController extends BaseControllerreturn 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.phpindex 67dbc8ae2b..2919a7a1be 100644--- a/app/controllers/HomeController.php+++ b/app/controllers/HomeController.php@@ -1,6 +1,5 @@<?phpuse Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;-use Firefly\Helper\Toolkit\ToolkitInterface as Toolkit;use Firefly\Storage\Account\AccountRepositoryInterface as ARI;use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;@@ -14,27 +13,34 @@ class HomeController extends BaseControllerprotected $_preferences;protected $_journal;protected $_budgets;- protected $_tk;/*** @param ARI $accounts* @param PHI $preferences* @param TJRI $journal- * @param Toolkit $toolkit* @param BRI $budgets*/- public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets)+ public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, BRI $budgets){$this->_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 filediff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.phpindex 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.phpindex f9ad9b7b7c..c641cc8a7c 100644--- a/app/tests/controllers/ChartControllerTest.php+++ b/app/tests/controllers/ChartControllerTest.php@@ -1,9 +1,11 @@<?phpuse Carbon\Carbon;+use Illuminate\Database\Eloquent\Collection;use Mockery as m;use Zizaco\FactoryMuff\Facade\FactoryMuff as f;+/*** Class ChartControllerTest*/@@ -12,6 +14,7 @@ class ChartControllerTest extends TestCaseprotected $_user;// protected $_repository;protected $_accounts;+ protected $_charts;public function setUp(){@@ -19,6 +22,7 @@ class ChartControllerTest extends TestCaseArtisan::call('migrate');Artisan::call('db:seed');$this->_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 TestCaseAuth::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 TestCasepublic 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