2014-07-05 12:44:26 -05:00
|
|
|
<?php
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
use Carbon\Carbon;
|
2014-07-27 13:29:58 -05:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2014-08-02 05:12:03 -05:00
|
|
|
use Mockery as m;
|
|
|
|
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
/**
|
|
|
|
* Class AccountControllerTest
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class AccountControllerTest extends TestCase
|
|
|
|
{
|
2014-07-27 13:29:58 -05:00
|
|
|
protected $_repository;
|
|
|
|
protected $_user;
|
|
|
|
protected $_accounts;
|
2014-08-02 05:12:03 -05:00
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-07-08 07:04:02 -05:00
|
|
|
Artisan::call('migrate');
|
|
|
|
Artisan::call('db:seed');
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
|
|
|
$this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->_user = m::mock('User', 'Eloquent');
|
|
|
|
// $this->app->instance('User', $this->_user);
|
2014-07-27 13:29:58 -05:00
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function tearDown()
|
2014-07-08 01:07:15 -05:00
|
|
|
{
|
2014-07-27 13:29:58 -05:00
|
|
|
Mockery::close();
|
|
|
|
}
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
$this->action('GET', 'AccountController@create');
|
|
|
|
$this->assertResponseOk();
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
}
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testDelete()
|
|
|
|
{
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
$account = f::create('Account');
|
2014-08-02 05:12:03 -05:00
|
|
|
|
|
|
|
// for successful binding:
|
2014-07-27 13:29:58 -05:00
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->action('GET', 'AccountController@delete', $account->id);
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testDestroy()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
2014-08-02 05:12:03 -05:00
|
|
|
|
|
|
|
// for successful binding:
|
2014-07-27 13:29:58 -05:00
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
2014-08-02 05:12:03 -05:00
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->action('POST', 'AccountController@destroy', $account->id);
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->assertRedirectedToRoute('accounts.index');
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
}
|
2014-07-06 14:07:52 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testDestroyFails()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
2014-08-02 05:12:03 -05:00
|
|
|
|
|
|
|
// for successful binding:
|
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
$this->_repository->shouldReceive('destroy')->once()->andReturn(false);
|
|
|
|
|
|
|
|
$this->action('POST', 'AccountController@destroy', $account->id);
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->assertRedirectedToRoute('accounts.index');
|
|
|
|
$this->assertSessionHas('error');
|
|
|
|
}
|
2014-07-08 07:04:02 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testEdit()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
2014-07-06 14:07:52 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
// for successful binding.
|
2014-07-27 13:29:58 -05:00
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
|
|
|
|
|
|
|
|
|
|
|
// Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
// Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
// $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
// $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->_accounts->shouldReceive('openingBalanceTransaction')->once()->andReturn(null);
|
2014-07-06 14:07:52 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->action('GET', 'AccountController@edit', $account->id);
|
2014-07-06 14:07:52 -05:00
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testIndex()
|
2014-07-05 12:44:26 -05:00
|
|
|
{
|
2014-07-27 13:29:58 -05:00
|
|
|
$account = f::create('Account');
|
|
|
|
$collection = new Collection();
|
|
|
|
$collection->add($account);
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
$list = [
|
|
|
|
'personal' => [],
|
|
|
|
'beneficiaries' => [],
|
|
|
|
'initial' => [],
|
|
|
|
'cash' => []
|
|
|
|
];
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
$this->_repository->shouldReceive('get')->with()->once()->andReturn($collection);
|
|
|
|
$this->_accounts->shouldReceive('index')->with($collection)->once()->andReturn($list);
|
|
|
|
$this->action('GET', 'AccountController@index');
|
2014-07-05 12:44:26 -05:00
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
2014-07-06 08:18:11 -05:00
|
|
|
|
|
|
|
public function testShow()
|
|
|
|
{
|
2014-07-27 13:29:58 -05:00
|
|
|
$account = f::create('Account');
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
// for successful binding.
|
2014-07-27 13:29:58 -05:00
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
|
2014-08-02 05:12:03 -05:00
|
|
|
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
|
|
|
|
|
|
|
// some more mockery
|
|
|
|
$paginator = \Paginator::make([], 0, 10);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'statistics' => [
|
|
|
|
'period' => [
|
|
|
|
'in' => 0,
|
|
|
|
'out' => 0,
|
|
|
|
'diff' => 0,
|
|
|
|
't_in' => 0,
|
|
|
|
't_out' => 0,
|
|
|
|
't_diff' => 0
|
|
|
|
],
|
|
|
|
'categories' => [],
|
|
|
|
'budgets' => [],
|
|
|
|
'accounts' => []
|
|
|
|
],
|
|
|
|
'journals' => $paginator,
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
|
2014-07-06 14:07:52 -05:00
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
//$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
|
|
|
|
|
|
|
// Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
// Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
// $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
// $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
|
|
|
|
// $this->_accounts->shouldReceive('paginate')->with($account,40)->once()->andReturn();
|
|
|
|
|
|
|
|
$this->action('GET', 'AccountController@show', $account->id);
|
2014-07-06 14:07:52 -05:00
|
|
|
$this->assertResponseOk();
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2014-07-08 01:07:15 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
public function testStore()
|
|
|
|
{
|
2014-08-02 05:12:03 -05:00
|
|
|
$account = f::create('Account');
|
|
|
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
|
|
|
$this->action('POST', 'AccountController@store');
|
|
|
|
$this->assertRedirectedToRoute('accounts.index');
|
|
|
|
}
|
|
|
|
public function testStoreRecreate()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
|
|
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
|
|
|
$this->action('POST', 'AccountController@store',['create' => '1']);
|
|
|
|
$this->assertRedirectedToRoute('accounts.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStoreFails()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
|
|
|
unset($account->id);
|
|
|
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
|
|
|
$this->action('POST', 'AccountController@store');
|
|
|
|
$this->assertRedirectedToRoute('accounts.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
|
|
|
// for successful binding.
|
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
$this->_repository->shouldReceive('update')->andReturn($account);
|
|
|
|
|
|
|
|
$this->action('POST', 'AccountController@update',$account->id);
|
|
|
|
$this->assertRedirectedToRoute('accounts.index');
|
|
|
|
|
|
|
|
}
|
|
|
|
public function testUpdateFails()
|
|
|
|
{
|
|
|
|
$account = f::create('Account');
|
|
|
|
unset($account->name);
|
|
|
|
// for successful binding.
|
|
|
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
|
|
|
Auth::shouldReceive('check')->andReturn(true);
|
|
|
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
|
|
|
$this->_repository->shouldReceive('update')->andReturn($account);
|
|
|
|
|
|
|
|
$this->action('POST', 'AccountController@update',$account->id);
|
|
|
|
$this->assertRedirectedToRoute('accounts.edit',$account->id);
|
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
}
|
|
|
|
|
2014-07-08 01:07:15 -05:00
|
|
|
|
2014-07-27 13:29:58 -05:00
|
|
|
//
|
|
|
|
// public function testIndex()
|
|
|
|
// {
|
|
|
|
//// // mock account type(s):
|
|
|
|
//// $personal = $this->mock('AccountType');
|
|
|
|
//// $personal->shouldReceive('getAttribute', 'description')->andReturn('Default account');
|
|
|
|
////
|
|
|
|
//// $bene = $this->mock('AccountType');
|
|
|
|
//// $bene->shouldReceive('getAttribute', 'description')->andReturn('Beneficiary account');
|
|
|
|
////
|
|
|
|
//// $initial = $this->mock('AccountType');
|
|
|
|
//// $initial->shouldReceive('getAttribute', 'description')->andReturn('Initial balance account');
|
|
|
|
////
|
|
|
|
//// $cash = $this->mock('AccountType');
|
|
|
|
//// $cash->shouldReceive('getAttribute', 'description')->andReturn('Cash account');
|
|
|
|
////
|
|
|
|
////
|
|
|
|
//// // mock account(s)
|
|
|
|
//// $one = $this->mock('Account');
|
|
|
|
//// $one->shouldReceive('getAttribute')->andReturn($personal);
|
|
|
|
////
|
|
|
|
//// $two = $this->mock('Account');
|
|
|
|
//// $two->shouldReceive('getAttribute')->andReturn($bene);
|
|
|
|
////
|
|
|
|
//// $three = $this->mock('Account');
|
|
|
|
//// $three->shouldReceive('getAttribute')->andReturn($initial);
|
|
|
|
////
|
|
|
|
//// $four = $this->mock('Account');
|
|
|
|
//// $four->shouldReceive('getAttribute')->andReturn($cash);
|
|
|
|
//// $c = new \Illuminate\Database\Eloquent\Collection([$one, $two, $three, $four]);
|
|
|
|
////
|
|
|
|
//// // mock account repository:
|
|
|
|
//// $accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
|
|
|
//// $accounts->shouldReceive('get')->andReturn($c);
|
|
|
|
////
|
|
|
|
////
|
|
|
|
//// $list = [
|
|
|
|
//// 'personal' => [$one],
|
|
|
|
//// 'beneficiaries' => [$two],
|
|
|
|
//// 'initial' => [$three],
|
|
|
|
//// 'cash' => [$four]
|
|
|
|
//// ];
|
|
|
|
////
|
|
|
|
//// // mock:
|
|
|
|
//// View::shouldReceive('share');
|
|
|
|
//// View::shouldReceive('make')->with('accounts.index')->once()->andReturn(\Mockery::self())
|
|
|
|
//// ->shouldReceive('with')->once()->with('accounts', $list)->andReturn(\Mockery::self())
|
|
|
|
//// ->shouldReceive('with')->once()->with('total', 4)->andReturn(\Mockery::self());
|
|
|
|
////
|
|
|
|
//
|
|
|
|
// // call
|
|
|
|
// $this->call('GET', '/accounts');
|
|
|
|
//
|
|
|
|
// // test
|
|
|
|
// $this->assertResponseOk();
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
////
|
|
|
|
//// public function testCreate()
|
|
|
|
//// {
|
|
|
|
//// // mock:
|
|
|
|
//// View::shouldReceive('share');
|
|
|
|
//// View::shouldReceive('make')->with('accounts.create');
|
|
|
|
////
|
|
|
|
//// // call
|
|
|
|
//// $this->call('GET', '/accounts/create');
|
|
|
|
////
|
|
|
|
//// // test
|
|
|
|
//// $this->assertResponseOk();
|
|
|
|
//// }
|
|
|
|
////
|
|
|
|
//// public function testShow()
|
|
|
|
//// {
|
|
|
|
//// // mock account repository:
|
|
|
|
//// $accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
|
|
|
//// $accounts->shouldReceive('get')->with(1)->andReturn([]);
|
|
|
|
////
|
|
|
|
//// // call
|
|
|
|
//// $this->call('GET', '/accounts/1');
|
|
|
|
////
|
|
|
|
//// // test
|
|
|
|
//// $this->assertResponseOk();
|
|
|
|
//// }
|
|
|
|
////
|
|
|
|
|
2014-08-02 05:12:03 -05:00
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|