mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Tests for budget controller.
This commit is contained in:
@@ -22,7 +22,6 @@ class AccountControllerTest extends TestCase
|
||||
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
// $this->app->instance('User', $this->_user);
|
||||
|
||||
}
|
||||
|
||||
@@ -92,12 +91,6 @@ class AccountControllerTest extends TestCase
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$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('openingBalanceTransaction')->once()->andReturn(null);
|
||||
|
||||
$this->action('GET', 'AccountController@edit', $account->id);
|
||||
@@ -155,15 +148,6 @@ class AccountControllerTest extends TestCase
|
||||
];
|
||||
|
||||
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
|
||||
|
||||
//$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);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
@@ -175,13 +159,6 @@ class AccountControllerTest extends TestCase
|
||||
$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()
|
||||
{
|
||||
@@ -192,6 +169,14 @@ class AccountControllerTest extends TestCase
|
||||
$this->assertRedirectedToRoute('accounts.create');
|
||||
}
|
||||
|
||||
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 testUpdate()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
@@ -201,10 +186,11 @@ class AccountControllerTest extends TestCase
|
||||
$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->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
@@ -215,96 +201,8 @@ class AccountControllerTest extends TestCase
|
||||
$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);
|
||||
$this->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.edit', $account->id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 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();
|
||||
//// }
|
||||
////
|
||||
|
||||
|
||||
}
|
266
app/tests/controllers/BudgetControllerTest.php
Normal file
266
app/tests/controllers/BudgetControllerTest.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Mockery as m;
|
||||
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
|
||||
|
||||
class BudgetControllerTest extends TestCase {
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
protected $_budgets;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_budgets = $this->mock('Firefly\Helper\Controllers\BudgetInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->action('GET', 'BudgetController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@delete', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.change');
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyByDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.change');
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', [$budget->id,'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.change');
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(false);
|
||||
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@edit', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByBudget()
|
||||
{
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@indexByBudget');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByDate()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
$this->_budgets->shouldReceive('organizeByDate')->with($collection)->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@indexByDate');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
$this->_budgets->shouldReceive('organizeRepetitions')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@show', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowNoEnvelope()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
$this->_budgets->shouldReceive('outsideRepetitions')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id,'noenvelope' => 'true']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowWithRep()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// $this->_budgets->shouldReceive('show')->once()->andReturn([]);
|
||||
$arr = [0 => ['limitrepetition' => null, 'limit' => null,'date' => '']];
|
||||
$this->_budgets->shouldReceive('organizeRepetition')->once()->andReturn($arr);
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, 'rep' => '1']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store');
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
}
|
||||
public function testStoreFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store',['from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->id);
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store',['from'=>'budget']);
|
||||
$this->assertRedirectedToRoute('budgets.create');
|
||||
}
|
||||
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'budget','create' => '1']);
|
||||
$this->assertRedirectedToRoute('budgets.create',['from' => 'budget']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id,'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.edit', $budget->id);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user