mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Finally fixed the tests.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use 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 TestCase
|
||||
protected $_user;
|
||||
// protected $_repository;
|
||||
protected $_accounts;
|
||||
protected $_charts;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -19,6 +22,7 @@ class ChartControllerTest extends TestCase
|
||||
Artisan::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 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user