firefly-iii/app/tests/controllers/ChartControllerTest.php

138 lines
4.6 KiB
PHP
Raw Normal View History

<?php
use Carbon\Carbon;
2014-08-09 01:18:07 -05:00
use Illuminate\Database\Eloquent\Collection;
use League\FactoryMuffin\Facade as f;
2014-08-28 00:53:54 -05:00
use Mockery as m;
2014-08-09 01:18:07 -05:00
/**
* Class ChartControllerTest
2014-08-10 11:22:42 -05:00
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
*/
class ChartControllerTest extends TestCase
{
protected $_user;
// protected $_repository;
protected $_accounts;
2014-08-09 01:18:07 -05:00
protected $_charts;
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
2014-08-09 01:18:07 -05:00
$this->_charts = $this->mock('Firefly\Helper\Controllers\ChartInterface');
// $this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface');
$this->_user = m::mock('User', 'Eloquent');
}
public function tearDown()
{
Mockery::close();
}
public function testCategoryShowChart()
{
$this->session(['start' => new Carbon, 'end' => new Carbon, 'range' => '1M']);
$category = f::create('Category');
// for successful binding:
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
2014-08-09 01:18:07 -05:00
$this->_charts->shouldReceive('categoryShowChart')->once()->andReturn([]);
$this->action('GET', 'ChartController@categoryShowChart', $category->id);
$this->assertResponseOk();
}
public function testHomeAccount()
{
$account = f::create('Account');
2014-08-09 01:18:07 -05:00
$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);
2014-08-09 01:18:07 -05:00
$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();
}
2014-08-09 01:18:07 -05:00
public function testHomeAccountInfo()
{
$account = f::create('Account');
$accountType = \AccountType::whereType('Default account')->first();
$account->accounttype()->associate($accountType);
2014-08-09 01:18:07 -05:00
$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);
2014-08-10 04:30:14 -05:00
$this->_charts->shouldReceive('accountDailySummary')->once()->andReturn(['rows' => [], 'sum' => 0]);
2014-08-09 01:18:07 -05:00
$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();
}
}