mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Finally fixed the tests.
This commit is contained in:
parent
ebb28df607
commit
eed70cdb62
@ -68,8 +68,7 @@ class ChartController extends BaseController
|
|||||||
// loop and get array data.
|
// loop and get array data.
|
||||||
|
|
||||||
$url = count($accounts) == 1 && is_array($accounts)
|
$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>';
|
'<a href="' . route('accounts.index') . '">View more</a>';
|
||||||
$data = [
|
$data = [
|
||||||
'chart_title' => count($accounts) == 1 ? $accounts[0]->name : 'All accounts',
|
'chart_title' => count($accounts) == 1 ? $accounts[0]->name : 'All accounts',
|
||||||
@ -85,8 +84,9 @@ class ChartController extends BaseController
|
|||||||
return Response::json($data);
|
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);
|
$date = Carbon::createFromDate($year, $month, $day);
|
||||||
$result = $this->_chart->accountDailySummary($account, $date);
|
$result = $this->_chart->accountDailySummary($account, $date);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||||
use Firefly\Helper\Toolkit\ToolkitInterface as Toolkit;
|
|
||||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||||
@ -14,27 +13,34 @@ class HomeController extends BaseController
|
|||||||
protected $_preferences;
|
protected $_preferences;
|
||||||
protected $_journal;
|
protected $_journal;
|
||||||
protected $_budgets;
|
protected $_budgets;
|
||||||
protected $_tk;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ARI $accounts
|
* @param ARI $accounts
|
||||||
* @param PHI $preferences
|
* @param PHI $preferences
|
||||||
* @param TJRI $journal
|
* @param TJRI $journal
|
||||||
* @param Toolkit $toolkit
|
|
||||||
* @param BRI $budgets
|
* @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->_accounts = $accounts;
|
||||||
$this->_preferences = $preferences;
|
$this->_preferences = $preferences;
|
||||||
$this->_journal = $journal;
|
$this->_journal = $journal;
|
||||||
$this->_tk = $toolkit;
|
|
||||||
$this->_budgets = $budgets;
|
$this->_budgets = $budgets;
|
||||||
View::share('menu', 'home');
|
View::share('menu', 'home');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function flush()
|
||||||
|
{
|
||||||
|
Cache::flush();
|
||||||
|
|
||||||
|
return Redirect::route('index');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this|\Illuminate\View\View
|
* @return $this|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
@ -42,7 +48,8 @@ class HomeController extends BaseController
|
|||||||
{
|
{
|
||||||
// count, maybe we need some introducing text to show:
|
// count, maybe we need some introducing text to show:
|
||||||
$count = $this->_accounts->count();
|
$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:
|
// get the preference for the home accounts to show:
|
||||||
@ -73,14 +80,4 @@ class HomeController extends BaseController
|
|||||||
// build the home screen:
|
// build the home screen:
|
||||||
return View::make('index')->with('count', $count)->with('transactions', $transactions);
|
return View::make('index')->with('count', $count)->with('transactions', $transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function flush()
|
|
||||||
{
|
|
||||||
Cache::flush();
|
|
||||||
|
|
||||||
return Redirect::route('index');
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -104,6 +104,9 @@ class Chart implements ChartInterface
|
|||||||
}]
|
}]
|
||||||
)->orderBy('name', 'ASC')->get();
|
)->orderBy('name', 'ASC')->get();
|
||||||
|
|
||||||
|
$limitInPeriod = 'Envelope for (empty)';
|
||||||
|
$spentInPeriod = 'Spent in (empty)';
|
||||||
|
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
$budget->count = 0;
|
$budget->count = 0;
|
||||||
foreach ($budget->limits as $limit) {
|
foreach ($budget->limits as $limit) {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
|
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ChartControllerTest
|
* Class ChartControllerTest
|
||||||
*/
|
*/
|
||||||
@ -12,6 +14,7 @@ class ChartControllerTest extends TestCase
|
|||||||
protected $_user;
|
protected $_user;
|
||||||
// protected $_repository;
|
// protected $_repository;
|
||||||
protected $_accounts;
|
protected $_accounts;
|
||||||
|
protected $_charts;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
@ -19,6 +22,7 @@ class ChartControllerTest extends TestCase
|
|||||||
Artisan::call('migrate');
|
Artisan::call('migrate');
|
||||||
Artisan::call('db:seed');
|
Artisan::call('db:seed');
|
||||||
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
$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->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface');
|
||||||
$this->_user = m::mock('User', 'Eloquent');
|
$this->_user = m::mock('User', 'Eloquent');
|
||||||
|
|
||||||
@ -39,6 +43,8 @@ class ChartControllerTest extends TestCase
|
|||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
$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->action('GET', 'ChartController@categoryShowChart', $category->id);
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
@ -47,16 +53,85 @@ class ChartControllerTest extends TestCase
|
|||||||
public function testHomeAccount()
|
public function testHomeAccount()
|
||||||
{
|
{
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->add($account);
|
||||||
$this->session(['start' => new Carbon, 'end' => new Carbon, 'range' => '1M']);
|
$this->session(['start' => new Carbon, 'end' => new Carbon, 'range' => '1M']);
|
||||||
|
|
||||||
// for successful binding:
|
// for successful binding:
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(1);
|
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('bla@bla');
|
||||||
$this->_accounts->shouldReceive('getByIds')->andReturn([$account]);
|
$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->action('GET', 'ChartController@homeAccount');
|
||||||
$this->assertResponseOk();
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user