mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Removed ALL tests. Yes, I know.
This commit is contained in:
parent
6423feff3a
commit
fcc184cd2a
@ -1,388 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class AccountTest
|
||||
*
|
||||
* Test EVERYTHING related to accounts. Models, views, and controllers.
|
||||
*
|
||||
* This class does not cover the /lib/ map, it is for a later date.
|
||||
*
|
||||
* As far as I am concerned, this class is complete! Yay!
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*
|
||||
*/
|
||||
class AccountTest extends TestCase
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
protected $_accounts;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Account
|
||||
* @covers \AccountType
|
||||
*/
|
||||
public function testAccountModel()
|
||||
{
|
||||
// create account and user:
|
||||
$account = f::create('Account');
|
||||
$user = f::create('User');
|
||||
$user->accounts()->save($account);
|
||||
|
||||
// new account? balance should be 0.00
|
||||
$this->assertEquals(0.0, $account->balance());
|
||||
|
||||
// create and link two transactions / piggybanks:
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$transaction = f::create('Transaction');
|
||||
$transaction->account()->associate($account);
|
||||
$transaction->save();
|
||||
|
||||
$piggy = f::create('Piggybank');
|
||||
$piggy->account()->associate($account);
|
||||
$piggy->save();
|
||||
|
||||
}
|
||||
// test related models
|
||||
$this->assertCount(2, $account->transactions()->get());
|
||||
$this->assertCount(2, $account->piggybanks()->get());
|
||||
|
||||
// predict should always be null:
|
||||
$this->assertNull($account->predict(new Carbon));
|
||||
|
||||
// user should equal test user:
|
||||
$this->assertEquals($user->id, $account->user()->first()->id);
|
||||
|
||||
$this->assertEquals('testing', \App::environment());
|
||||
|
||||
// whatever the account type of this account, searching for it using the
|
||||
// scope method should return one account:
|
||||
$accountType = $account->accounttype()->first();
|
||||
$accounts = $accountType->accounts()->count();
|
||||
$this->assertCount($accounts, \Account::AccountTypeIn([$accountType->type])->get());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// test the view:
|
||||
View::shouldReceive('make')->once()->with('accounts.create')->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('title', 'Create account');
|
||||
|
||||
// call and final test:
|
||||
$this->action('GET', 'AccountController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// some prep work.
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding with the account to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->once()->with('accounts.delete')->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('account', m::any())->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('title', 'Delete account "' . $account->name . '"');
|
||||
|
||||
// call and final test:
|
||||
$this->action('GET', 'AccountController@delete', $account->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
|
||||
// for successful binding with the account to destroy:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test if the repository receives an argument:
|
||||
$this->_repository->shouldReceive('destroy')->once();
|
||||
|
||||
// post it:
|
||||
$this->action('POST', 'AccountController@destroy', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::edit
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding with the account to edit:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test if the repository works:
|
||||
$this->_accounts->shouldReceive('openingBalanceTransaction')->once()->with(m::any())->andReturn(null);
|
||||
|
||||
// test if the view works:
|
||||
View::shouldReceive('make')->once()->with('accounts.edit')->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('account', m::any())->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('openingBalance', null)->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('title', 'Edit account "' . $account->name . '"');
|
||||
|
||||
$this->action('GET', 'AccountController@edit', $account->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
// two account types:
|
||||
$personalType = \AccountType::whereType('Default account')->first();
|
||||
$benType = \AccountType::whereType('Beneficiary account')->first();
|
||||
|
||||
// create two accounts:
|
||||
/** @var \Account $account */
|
||||
$personal = f::create('Account');
|
||||
$personal->accountType()->associate($personalType);
|
||||
$personal->save();
|
||||
$ben = f::create('Account');
|
||||
$ben->accountType()->associate($benType);
|
||||
$ben->save();
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$collection = new Collection();
|
||||
$collection->add($personal);
|
||||
$collection->add($ben);
|
||||
|
||||
$list = [
|
||||
'personal' => [$personal],
|
||||
'beneficiaries' => [$ben],
|
||||
];
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
|
||||
// test view:
|
||||
View::shouldReceive('make')->once()->with('accounts.index')->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('accounts', $list)->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('title', 'All your accounts');
|
||||
|
||||
$this->action('GET', 'AccountController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::show
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding with the account to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test view:
|
||||
View::shouldReceive('make')->once()->with('accounts.show')->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('account', m::any())->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('show', [])->andReturn(m::self())
|
||||
->shouldReceive('with')->once()->with('title', 'Details for account "' . $account->name . '"');
|
||||
|
||||
$this->_accounts->shouldReceive('show')->once()->andReturn([]);
|
||||
|
||||
|
||||
$this->action('GET', 'AccountController@show', $account->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store');
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStoreFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
unset($account->name);
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store');
|
||||
$this->assertRedirectedToRoute('accounts.create');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store', ['create' => '1']);
|
||||
$this->assertRedirectedToRoute('accounts.create');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding with the account to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test
|
||||
$this->_repository->shouldReceive('update')->andReturn($account);
|
||||
|
||||
$this->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AccountController::update
|
||||
*/
|
||||
public function testUpdateFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
unset($account->name);
|
||||
|
||||
// for successful binding with the account to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// test
|
||||
$this->_repository->shouldReceive('update')->andReturn($account);
|
||||
|
||||
$this->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.edit', $account->id);
|
||||
$this->assertSessionHas('error');
|
||||
|
||||
}
|
||||
}
|
@ -1,460 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class BudgetTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class BudgetTest 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Budget
|
||||
*
|
||||
*/
|
||||
public function testBudgetModel()
|
||||
{
|
||||
// create budget:
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// create some transaction journals:
|
||||
$t1 = f::create('TransactionJournal');
|
||||
$t2 = f::create('TransactionJournal');
|
||||
|
||||
$budget->transactionjournals()->save($t1);
|
||||
$budget->transactionjournals()->save($t2);
|
||||
|
||||
$this->assertCount(2, $budget->transactionjournals()->get());
|
||||
$this->assertEquals($budget->id, $t1->budgets()->first()->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// test config:
|
||||
$periods = [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
];
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.create')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('periods', $periods)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Create a new budget')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.delete')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Delete budget "' . $budget->name . '"')->once();
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@delete', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// fire the event:
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
|
||||
// fire the repository:
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// fire and test:
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::destroy
|
||||
*/
|
||||
public function testDestroyFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// fire the event:
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
|
||||
// fire the repository:
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// fire and test:
|
||||
$this->action('POST', 'BudgetController@destroy', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::edit
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.edit')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Edit budget "' . $budget->name . '"')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@edit', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::indexByBudget
|
||||
*/
|
||||
public function testIndexByBudget()
|
||||
{
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.indexByBudget')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budgets', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('today', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'All your budgets grouped by budget')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@indexByBudget');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::indexByDate
|
||||
*/
|
||||
public function testIndexByDate()
|
||||
{
|
||||
$collection = new Collection();
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.indexByDate')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budgets', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'All your budgets grouped by date')->once();
|
||||
|
||||
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
$this->_budgets->shouldReceive('organizeByDate')->with($collection)->andReturn([]);
|
||||
|
||||
$this->action('GET', 'BudgetController@indexByDate');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::show
|
||||
*/
|
||||
public function testShowDefault()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('organizeRepetitions')->with(m::any(), false)->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 4)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', $budget->name)->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::show
|
||||
*/
|
||||
public function testShowOutsideEnvelope()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('outsideRepetitions')->with(m::any())->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 2)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', $budget->name . ', transactions outside an envelope')->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, null, 'noenvelope' => 'true']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::show
|
||||
*/
|
||||
public function testShowWithRepetition()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$limit = f::create('Limit');
|
||||
$repetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($repetition);
|
||||
$budget->limits()->save($limit);
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('organizeRepetition')->with(m::any())->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 1)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title',
|
||||
$budget->name . ', ' . $repetition->periodShow() . ', ' .
|
||||
mf($limit->amount, false))->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, $repetition->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store');
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::store
|
||||
*/
|
||||
public function testStoreComingFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::store
|
||||
*/
|
||||
public function testStoreFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->once()->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
$this->action('POST', 'BudgetController@store', ['name' => null]);
|
||||
$this->assertRedirectedToRoute('budgets.create');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::store
|
||||
*/
|
||||
public function testStoreWithRecreation()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->once()->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store', ['name' => $budget->name, 'create' => '1']);
|
||||
$this->assertRedirectedTo('http://localhost/budgets/create?');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
// fire in the hole!
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::update
|
||||
*/
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id]);
|
||||
$this->assertRedirectedToRoute('budgets.edit', $budget->id);
|
||||
$this->assertSessionHas('error');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \BudgetController::update
|
||||
*/
|
||||
public function testUpdateFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
// fire in the hole!
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
}
|
||||
}
|
@ -1,220 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class CategoryTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class CategoryTest extends TestCase
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
protected $_category;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('categories.create')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Create a new category')->once();
|
||||
|
||||
$this->action('GET', 'CategoryController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
|
||||
$category = f::create('Category');
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('categories.delete')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Delete category "' . $category->name . '"')->once();
|
||||
|
||||
// for successful binding with the category to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'CategoryController@delete', $category->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
|
||||
// for successful binding with the category to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// fire the repository:
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// fire and test:
|
||||
$this->action('POST', 'CategoryController@destroy', $category->id);
|
||||
$this->assertRedirectedToRoute('categories.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::edit
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
|
||||
// for successful binding with the category to edit:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('categories.edit')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Edit category "' . $category->name . '"')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'CategoryController@edit', $category->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
$collection = new Collection();
|
||||
$collection->add($category);
|
||||
|
||||
$this->_repository->shouldReceive('get')->with()->once()->andReturn($collection);
|
||||
|
||||
View::shouldReceive('make')->with('categories.index')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('categories', $collection)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'All your categories')->once();
|
||||
|
||||
|
||||
|
||||
$this->action('GET', 'CategoryController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CategoryController::show
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
|
||||
// for successful binding with the category to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
|
||||
$this->_category->shouldReceive('journalsInRange')->once()->andReturn([]);
|
||||
$this->action('GET', 'CategoryController@show', $category->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
$this->_repository->shouldReceive('store')->andReturn($category);
|
||||
$this->action('POST', 'CategoryController@store');
|
||||
$this->assertRedirectedToRoute('categories.index');
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
unset($category->name);
|
||||
$this->_repository->shouldReceive('store')->andReturn($category);
|
||||
$this->action('POST', 'CategoryController@store');
|
||||
$this->assertRedirectedToRoute('categories.create');
|
||||
}
|
||||
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
$this->_repository->shouldReceive('store')->andReturn($category);
|
||||
$this->action('POST', 'CategoryController@store', ['create' => '1']);
|
||||
$this->assertRedirectedToRoute('categories.create');
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$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);
|
||||
$this->_repository->shouldReceive('update')->andReturn($category);
|
||||
|
||||
$this->action('POST', 'CategoryController@update', $category->id);
|
||||
$this->assertRedirectedToRoute('categories.index');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
unset($category->name);
|
||||
// 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);
|
||||
$this->_repository->shouldReceive('update')->andReturn($category);
|
||||
|
||||
$this->action('POST', 'CategoryController@update', [$category->id]);
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChartControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class ChartControllerTest extends TestCase
|
||||
{
|
||||
protected $_user;
|
||||
// protected $_repository;
|
||||
protected $_accounts;
|
||||
protected $_charts;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$this->_charts->shouldReceive('categoryShowChart')->once()->andReturn([]);
|
||||
|
||||
|
||||
$this->action('GET', 'ChartController@categoryShowChart', $category->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
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('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');
|
||||
$accountType = \AccountType::whereType('Default account')->first();
|
||||
$account->accounttype()->associate($accountType);
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon as Carbon;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class HomeControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class HomeControllerTest extends TestCase
|
||||
{
|
||||
protected $_accounts;
|
||||
protected $_repository;
|
||||
protected $_preferences;
|
||||
protected $_journals;
|
||||
protected $_reminders;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$this->_journals = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$this->_reminders = $this->mock('Firefly\Storage\Reminder\ReminderRepositoryInterface');
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testFlush()
|
||||
{
|
||||
$this->action('GET', 'HomeController@flush');
|
||||
$this->assertRedirectedToRoute('index');
|
||||
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
// mock preference:
|
||||
$preference = $this->mock('Preference');
|
||||
$preference->shouldReceive('getAttribute')->with('data')->andReturn([]);
|
||||
|
||||
Event::shouldReceive('fire')->with('limits.check');
|
||||
Event::shouldReceive('fire')->with('piggybanks.check');
|
||||
Event::shouldReceive('fire')->with('recurring.check');
|
||||
|
||||
$this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]);
|
||||
|
||||
// mock accounts:
|
||||
$this->_repository->shouldReceive('count')->once()->andReturn(0);
|
||||
$this->_repository->shouldReceive('getActiveDefault')->once()->andReturn([]);
|
||||
|
||||
// mock preferences:
|
||||
$this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
|
||||
|
||||
$this->action('GET', 'HomeController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexWithAccount()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
$start = new Carbon;
|
||||
$end = new Carbon;
|
||||
$this->session(['start' => $start, 'end' => $end]);
|
||||
|
||||
|
||||
// mock preference:
|
||||
$preference = $this->mock('Preference');
|
||||
$preference->shouldReceive('getAttribute')->with('data')->andReturn([$account->id]);
|
||||
|
||||
Event::shouldReceive('fire')->with('limits.check');
|
||||
Event::shouldReceive('fire')->with('piggybanks.check');
|
||||
Event::shouldReceive('fire')->with('recurring.check');
|
||||
|
||||
$this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]);
|
||||
|
||||
|
||||
// mock accounts:
|
||||
$this->_repository->shouldReceive('count')->once()->andReturn(0);
|
||||
$this->_repository->shouldReceive('getByIds')->with([$account->id])->once()->andReturn([$account]);
|
||||
|
||||
// mock preferences:
|
||||
$this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
|
||||
|
||||
// mock journals:
|
||||
$this->_journals->shouldReceive('getByAccountInDateRange')->once()->with($account, 10, $start, $end)->andReturn(
|
||||
[1, 2]
|
||||
);
|
||||
|
||||
$this->action('GET', 'HomeController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexWithAccounts()
|
||||
{
|
||||
$accountOne = f::create('Account');
|
||||
$accountTwo = f::create('Account');
|
||||
$accounThree = f::create('Account');
|
||||
$set = [$accountOne, $accountTwo, $accounThree];
|
||||
$ids = [$accountOne->id, $accountTwo->id, $accounThree->id];
|
||||
$start = new Carbon;
|
||||
$end = new Carbon;
|
||||
$this->session(['start' => $start, 'end' => $end]);
|
||||
|
||||
|
||||
// mock preference:
|
||||
$preference = $this->mock('Preference');
|
||||
$preference->shouldReceive('getAttribute')->with('data')->andReturn($ids);
|
||||
|
||||
Event::shouldReceive('fire')->with('limits.check');
|
||||
Event::shouldReceive('fire')->with('piggybanks.check');
|
||||
Event::shouldReceive('fire')->with('recurring.check');
|
||||
|
||||
$this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]);
|
||||
|
||||
|
||||
// mock accounts:
|
||||
$this->_repository->shouldReceive('count')->once()->andReturn(0);
|
||||
$this->_repository->shouldReceive('getByIds')->with($ids)->once()->andReturn(
|
||||
$set
|
||||
);
|
||||
|
||||
// mock preferences:
|
||||
$this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference);
|
||||
|
||||
// mock journals:
|
||||
$this->_journals->shouldReceive('getByAccountInDateRange')->andReturn([1, 2]);
|
||||
|
||||
$this->action('GET', 'HomeController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
|
||||
/**
|
||||
* Class JsonControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class JsonControllerTest extends TestCase
|
||||
{
|
||||
protected $_accounts;
|
||||
protected $_categories;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testBeneficiaries()
|
||||
{
|
||||
$beneficiary = f::create('Account');
|
||||
|
||||
$this->_accounts->shouldReceive('getBeneficiaries')->once()->andReturn([$beneficiary]);
|
||||
$this->action('GET', 'JsonController@beneficiaries');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCategories()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
$this->_categories->shouldReceive('get')->once()->andReturn([$category]);
|
||||
$this->action('GET', 'JsonController@categories');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
}
|
@ -1,245 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class LimitControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class LimitControllerTest extends TestCase
|
||||
{
|
||||
|
||||
protected $_budgets;
|
||||
protected $_limits;
|
||||
protected $_user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_limits = $this->mock('Firefly\Storage\Limit\LimitRepositoryInterface');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
$this->action('GET', 'LimitController@create');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'LimitController@delete', $limit->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_limits->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'LimitController@destroy', $limit->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testDestroyFails()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_limits->shouldReceive('destroy')->once()->andReturn(false);
|
||||
|
||||
$this->action('POST', 'LimitController@destroy', $limit->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testDestroyRedirect()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_limits->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'LimitController@destroy', [$limit->id, 'from' => 'date']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'LimitController@edit', $limit->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
$this->_limits->shouldReceive('store')->once()->andReturn($limit);
|
||||
$this->action('POST', 'LimitController@store');
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$limit = f::create('Limit');
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->save();
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
unset($limit->startdate);
|
||||
unset($limit->component_id);
|
||||
|
||||
|
||||
$this->_limits->shouldReceive('store')->once()->andReturn($limit);
|
||||
$this->action('POST', 'LimitController@store', $budget->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRedirect()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$limit = f::create('Limit');
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->save();
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
$this->_limits->shouldReceive('store')->once()->andReturn($limit);
|
||||
$this->action('POST', 'LimitController@store', [$budget->id, 'from' => 'date']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_limits->shouldReceive('update')->once()->andReturn($limit);
|
||||
|
||||
|
||||
$this->action(
|
||||
'POST', 'LimitController@update',
|
||||
[$limit->id,
|
||||
'date' => '02-02-2012',
|
||||
'period' => 'monthly',
|
||||
'repeats' => 0,
|
||||
'amount' => '0.01'
|
||||
|
||||
]
|
||||
);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
unset($limit->amount);
|
||||
$this->_limits->shouldReceive('update')->once()->andReturn($limit);
|
||||
|
||||
|
||||
$this->action(
|
||||
'POST', 'LimitController@update',
|
||||
$limit->id
|
||||
);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdateRedirect()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$limitrepetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($limitrepetition);
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($limit->budget()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_limits->shouldReceive('update')->once()->andReturn($limit);
|
||||
|
||||
|
||||
$this->action(
|
||||
'POST', 'LimitController@update',
|
||||
[$limit->id,
|
||||
'date' => '02-02-2012',
|
||||
'period' => 'monthly',
|
||||
'repeats' => 0,
|
||||
'amount' => '0.01',
|
||||
'from' => 'date'
|
||||
|
||||
]
|
||||
);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,440 +0,0 @@
|
||||
<?php
|
||||
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
|
||||
/**
|
||||
* Class PiggybankControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class PiggybankControllerTest extends TestCase
|
||||
{
|
||||
protected $_accounts;
|
||||
protected $_piggybanks;
|
||||
protected $_user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_piggybanks = $this->mock('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testAddMoneyGET()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(1);
|
||||
|
||||
$this->action('GET', 'PiggybankController@addMoney', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testCreatePiggybank()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
$this->action('GET', 'PiggybankController@createPiggybank');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testCreateRepeated()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
$this->action('GET', 'PiggybankController@createRepeated');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('GET', 'PiggybankController@delete', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
$this->_piggybanks->shouldReceive('destroy')->andReturn(true);
|
||||
Event::shouldReceive('fire')->with('piggybanks.destroy', [$piggyBank]);
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@destroy', $piggyBank->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('GET', 'PiggybankController@edit', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testEditRepeated()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->repeats = 1;
|
||||
$piggyBank->save();
|
||||
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'PiggybankController@edit', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$aOne = f::create('Account');
|
||||
$aTwo = f::create('Account');
|
||||
|
||||
$one = f::create('Piggybank');
|
||||
$one->account()->associate($aOne);
|
||||
$two = f::create('Piggybank');
|
||||
$two->account()->associate($aOne);
|
||||
$three = f::create('Piggybank');
|
||||
$three->account()->associate($aTwo);
|
||||
$this->_piggybanks->shouldReceive('get')->andReturn([$one, $two, $three]);
|
||||
$this->_piggybanks->shouldReceive('countRepeating')->andReturn(0);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(0);
|
||||
$this->_piggybanks->shouldReceive('countNonrepeating')->andReturn(0);
|
||||
Event::shouldReceive('fire')->with('piggybanks.change');
|
||||
|
||||
|
||||
$this->action('GET', 'PiggybankController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testModifyMoneyAddPOST()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'add'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire'); //->with('piggybanks.modifyAmountAdd', [$piggyBank, 10.0]);
|
||||
$this->_piggybanks->shouldReceive('modifyAmount')->once();
|
||||
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->once()->andReturn(200);
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyAddPOSTFails()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'add'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($piggyBank->account()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire')->with('piggybanks.modifyAmountAdd', [$piggyBank, -10.0]);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->once()->andReturn(5);
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function testModifyMoneyPOSTException()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'yomoma'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($piggyBank->account()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyRemovePOST()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(11);
|
||||
$this->_piggybanks->shouldReceive('modifyAmount')->once();
|
||||
|
||||
$input = [
|
||||
$rep->piggybank()->first()->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'remove'
|
||||
];
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyRemovePOSTFails()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->currentAmount = 5;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
|
||||
$input = [
|
||||
$rep->piggybank()->first()->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'remove'
|
||||
];
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function testRemoveMoneyGET()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(1)->once();
|
||||
|
||||
$this->action('GET', 'PiggybankController@removeMoney', $piggybank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->save();
|
||||
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggybank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->andReturn('some@email');
|
||||
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
|
||||
// repos:
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount');
|
||||
|
||||
$this->action('GET', 'PiggybankController@show', $piggybank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStoreRepeated()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
$piggy->repeats = 1;
|
||||
$piggy->save();
|
||||
Event::shouldReceive('fire')->with('piggybanks.store', [$piggy])->once();
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storeRepeated');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRepeatedFails()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
unset($piggy->id);
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storeRepeated');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
|
||||
$this->_piggybanks->shouldReceive('update')->andReturn($piggyBank);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire')->with('piggybanks.update', [$piggyBank]);
|
||||
|
||||
$this->action('POST', 'PiggybankController@update', $piggyBank->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
unset($piggyBank->name);
|
||||
|
||||
$this->_piggybanks->shouldReceive('update')->andReturn($piggyBank);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire')->with('piggybanks.change');
|
||||
|
||||
$this->action('POST', 'PiggybankController@update', $piggyBank->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function teststorePiggybank()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
$piggy->repeats = 0;
|
||||
$piggy->save();
|
||||
Event::shouldReceive('fire')->with('piggybanks.store', [$piggy])->once();
|
||||
|
||||
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storePiggybank');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function teststorePiggybankFails()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
unset($piggy->id);
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storePiggybank');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class PreferencesControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class PreferencesControllerTest extends TestCase
|
||||
{
|
||||
|
||||
protected $_user;
|
||||
protected $_helper;
|
||||
protected $_accounts;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_helper = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$viewRange = $this->mock('Preference');
|
||||
$viewRange->shouldReceive('getAttribute')->with('data')->andReturn('1M');
|
||||
|
||||
$this->_accounts->shouldReceive('getDefault')->andReturn([]);
|
||||
$this->_helper->shouldReceive('get')->with('viewRange', '1M')->andReturn($viewRange);
|
||||
$this->_helper->shouldReceive('get')->with('frontpageAccounts', [])->andReturn([]);
|
||||
|
||||
|
||||
$this->action('GET', 'PreferencesController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostIndex()
|
||||
{
|
||||
$this->_helper->shouldReceive('set')->with('frontpageAccounts', [1]);
|
||||
$this->_helper->shouldReceive('set')->with('viewRange', '1M');
|
||||
$this->action('POST', 'PreferencesController@postIndex', ['frontpageAccounts' => [1], 'viewRange' => '1M']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class ProfileControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class ProfileControllerTest extends TestCase
|
||||
{
|
||||
protected $_user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
|
||||
public function testChangePassword()
|
||||
{
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'ProfileController@changePassword');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'ProfileController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostChangePasswordDifferentNew()
|
||||
{
|
||||
$user = f::create('User');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email);
|
||||
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password);
|
||||
|
||||
$this->action(
|
||||
'POST', 'ProfileController@postChangePassword',
|
||||
['old' => 'sander', 'new1' => 'sander1', 'new2' => 'sander2']
|
||||
);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostChangePasswordOK()
|
||||
{
|
||||
$user = f::create('User');
|
||||
$user->password = 'sander';
|
||||
$user->save();
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email);
|
||||
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password);
|
||||
|
||||
$this->action(
|
||||
'POST', 'ProfileController@postChangePassword',
|
||||
['old' => 'sander', 'new1' => 'sander2', 'new2' => 'sander2']
|
||||
);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
|
||||
public function testPostChangePasswordNoCurrent()
|
||||
{
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn('Blablabla');
|
||||
|
||||
$this->action('POST', 'ProfileController@postChangePassword', ['old' => '']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostChangePasswordNoMatchNew()
|
||||
{
|
||||
$user = f::create('User');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email);
|
||||
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password);
|
||||
|
||||
$this->action(
|
||||
'POST', 'ProfileController@postChangePassword', ['old' => 'sander', 'new1' => 'sander', 'new2' => 'sander']
|
||||
);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostChangePasswordSame()
|
||||
{
|
||||
$user = f::create('User');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email);
|
||||
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password);
|
||||
|
||||
$this->action('POST', 'ProfileController@postChangePassword', ['old' => 'sander']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class RecurringControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class RecurringControllerTest extends TestCase
|
||||
{
|
||||
protected $_user;
|
||||
protected $_repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_repository = $this->mock(
|
||||
'Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->action('GET', 'RecurringController@create');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('GET', 'RecurringController@delete', $recurringTransaction->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
Event::shouldReceive('fire')->with('recurring.destroy',m::any());
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
$this->_repository->shouldReceive('destroy')->andReturn(true);
|
||||
|
||||
$this->action('POST', 'RecurringController@destroy', $recurringTransaction->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testDestroyFails()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Event::shouldReceive('fire')->with('recurring.destroy',m::any());
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
$this->_repository->shouldReceive('destroy')->andReturn(false);
|
||||
|
||||
$this->action('POST', 'RecurringController@destroy', $recurringTransaction->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'RecurringController@edit', $recurringTransaction->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
|
||||
$this->_repository->shouldReceive('get')->andReturn([]);
|
||||
|
||||
$this->action('GET', 'RecurringController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('GET', 'RecurringController@show', $recurringTransaction->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
Event::shouldReceive('fire')->with('recurring.store',m::any());
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
|
||||
$this->action('POST', 'RecurringController@store');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRedirect()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
Event::shouldReceive('fire')->with('recurring.store',m::any());
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
|
||||
$this->action('POST', 'RecurringController@store', ['create' => '1']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
unset($recurringTransaction->active);
|
||||
unset($recurringTransaction->automatch);
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
|
||||
$this->action('POST', 'RecurringController@store', ['create' => '1']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$recurringTransaction = f::create('RecurringTransaction');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
Event::shouldReceive('fire')->with('recurring.update',m::any());
|
||||
|
||||
$this->_repository->shouldReceive('update')->andReturn($recurringTransaction);
|
||||
|
||||
|
||||
$this->action('POST', 'RecurringController@update', $recurringTransaction->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class ReportControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class ReportControllerTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$this->action('GET', 'ReportController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class SearchControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class SearchControllerTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$this->action('GET', 'SearchController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
}
|
@ -1,312 +0,0 @@
|
||||
<?php
|
||||
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class TransactionControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class TransactionControllerTest extends TestCase
|
||||
{
|
||||
protected $_user;
|
||||
protected $_repository;
|
||||
|
||||
protected $_accounts;
|
||||
protected $_budgets;
|
||||
protected $_piggies;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_repository = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_piggies = $this->mock('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testCreateDeposit()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
$this->_piggies->shouldReceive('get')->andReturn([]);
|
||||
|
||||
$this->action('GET', 'TransactionController@create', ['what' => 'deposit']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCreateTransfer()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
$this->_piggies->shouldReceive('get')->andReturn([]);
|
||||
$this->action('GET', 'TransactionController@create', ['what' => 'transfer']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCreateWithdrawal()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
$this->_piggies->shouldReceive('get')->andReturn([]);
|
||||
$this->action('GET', 'TransactionController@create', ['what' => 'withdrawal']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'TransactionController@delete', $journal->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('POST', 'TransactionController@destroy', $journal->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
$type->type = 'Withdrawal';
|
||||
$type->save();
|
||||
$journal->transactiontype()->associate($type);
|
||||
$journal->save();
|
||||
|
||||
$category = f::create('Category');
|
||||
$journal->categories()->save($category);
|
||||
|
||||
$budget = f::create('Budget');
|
||||
$journal->budgets()->save($budget);
|
||||
|
||||
$one = f::create('Transaction');
|
||||
$two = f::create('Transaction');
|
||||
$one->transactionjournal()->associate($journal);
|
||||
$two->transactionjournal()->associate($journal);
|
||||
$one->save();
|
||||
$two->save();
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_piggies->shouldReceive('get')->once()->andReturn([]);
|
||||
|
||||
$this->action('GET', 'TransactionController@edit', $journal->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testEditDeposit()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
$type->type = 'Deposit';
|
||||
$type->save();
|
||||
$journal->transactiontype()->associate($type);
|
||||
$journal->save();
|
||||
|
||||
$category = f::create('Category');
|
||||
$journal->categories()->save($category);
|
||||
|
||||
$budget = f::create('Budget');
|
||||
$journal->budgets()->save($budget);
|
||||
|
||||
$one = f::create('Transaction');
|
||||
$two = f::create('Transaction');
|
||||
$one->transactionjournal()->associate($journal);
|
||||
$two->transactionjournal()->associate($journal);
|
||||
$one->save();
|
||||
$two->save();
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
|
||||
$this->_piggies->shouldReceive('get')->once()->andReturn([]);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'TransactionController@edit', $journal->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testEditTransfer()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
$type->type = 'Transfer';
|
||||
$type->save();
|
||||
$journal->transactiontype()->associate($type);
|
||||
$journal->save();
|
||||
|
||||
$category = f::create('Category');
|
||||
$journal->categories()->save($category);
|
||||
|
||||
$budget = f::create('Budget');
|
||||
$journal->budgets()->save($budget);
|
||||
|
||||
$one = f::create('Transaction');
|
||||
$two = f::create('Transaction');
|
||||
$one->transactionjournal()->associate($journal);
|
||||
$two->transactionjournal()->associate($journal);
|
||||
$one->save();
|
||||
$two->save();
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
|
||||
$this->_piggies->shouldReceive('get')->once()->andReturn([]);
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'TransactionController@edit', $journal->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
$type->type = 'Withdrawal';
|
||||
$type->save();
|
||||
$journal->transactiontype()->associate($type);
|
||||
$journal->save();
|
||||
|
||||
$one = f::create('Transaction');
|
||||
$two = f::create('Transaction');
|
||||
$one->transactionjournal()->associate($journal);
|
||||
$two->transactionjournal()->associate($journal);
|
||||
$one->save();
|
||||
$two->save();
|
||||
|
||||
// make a paginator
|
||||
$paginator = Paginator::make([$journal], 1, 1);
|
||||
|
||||
|
||||
$this->_repository->shouldReceive('paginate')->with(25)->andReturn($paginator);
|
||||
$this->_repository->shouldReceive('get')->andReturn([]);
|
||||
$this->action('GET', 'TransactionController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'TransactionController@show', $journal->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($journal);
|
||||
|
||||
$this->action('POST', 'TransactionController@store', ['what' => 'deposit']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
unset($journal->description);
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($journal);
|
||||
|
||||
$this->action('POST', 'TransactionController@store', ['what' => 'deposit', 'create' => '1']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRedirect()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($journal);
|
||||
|
||||
$this->action('POST', 'TransactionController@store', ['what' => 'deposit', 'create' => '1']);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->_repository->shouldReceive('update')->andReturn($journal);
|
||||
|
||||
$this->action('POST', 'TransactionController@update', $journal->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testUpdateFailed()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($journal->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$journal->description = null;
|
||||
|
||||
$this->_repository->shouldReceive('update')->andReturn($journal);
|
||||
|
||||
$this->action('POST', 'TransactionController@update', $journal->id);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
|
||||
/**
|
||||
* Class UserControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class UserControllerTest extends TestCase
|
||||
{
|
||||
protected $_user;
|
||||
protected $_users;
|
||||
protected $_email;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
$this->_users = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$this->_email = $this->mock('Firefly\Helper\Email\EmailHelperInterface');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->action('GET', 'UserController@login');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testLogout()
|
||||
{
|
||||
$this->action('GET', 'UserController@logout');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testPostLogin()
|
||||
{
|
||||
$input = [
|
||||
'email' => 'bla@bla',
|
||||
'password' => 'something',
|
||||
];
|
||||
|
||||
Auth::shouldReceive('attempt')->with($input, false)->andReturn(true);
|
||||
|
||||
$this->action('POST', 'UserController@postLogin', $input);
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testPostLoginFails()
|
||||
{
|
||||
|
||||
$this->action('POST', 'UserController@postLogin');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRegister()
|
||||
{
|
||||
Config::set('auth.allow_register', true);
|
||||
$user = f::create('User');
|
||||
$this->_users->shouldReceive('register')->andReturn($user);
|
||||
$this->_email->shouldReceive('sendPasswordMail')->with($user);
|
||||
$this->action('POST', 'UserController@postRegister');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRegisterFails()
|
||||
{
|
||||
Config::set('auth.allow_register', true);
|
||||
$this->_users->shouldReceive('register')->andReturn(false);
|
||||
$this->action('POST', 'UserController@postRegister');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRegisterNotAllowed()
|
||||
{
|
||||
Config::set('auth.allow_register', false);
|
||||
$this->action('POST', 'UserController@postRegister');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRegisterVerify()
|
||||
{
|
||||
Config::set('auth.allow_register', true);
|
||||
Config::set('auth.verify_mail', true);
|
||||
$user = f::create('User');
|
||||
$this->_users->shouldReceive('register')->andReturn($user);
|
||||
$this->_email->shouldReceive('sendVerificationMail')->with($user);
|
||||
$this->action('POST', 'UserController@postRegister');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRemindme()
|
||||
{
|
||||
$user = f::create('User');
|
||||
Config::set('auth.verify_reset', true);
|
||||
$this->_users->shouldReceive('findByEmail')->andReturn($user);
|
||||
$this->_email->shouldReceive('sendResetVerification');
|
||||
$this->action('POST', 'UserController@postRemindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRemindmeNoVerify()
|
||||
{
|
||||
$user = f::create('User');
|
||||
Config::set('auth.verify_reset', false);
|
||||
$this->_users->shouldReceive('findByEmail')->andReturn($user);
|
||||
$this->_email->shouldReceive('sendPasswordMail');
|
||||
$this->action('POST', 'UserController@postRemindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRemindmeFails()
|
||||
{
|
||||
Config::set('auth.verify_reset', true);
|
||||
$this->_users->shouldReceive('findByEmail')->andReturn(false);
|
||||
$this->action('POST', 'UserController@postRemindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testRegister()
|
||||
{
|
||||
$this->action('GET', 'UserController@register');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testRegisterNotAllowed()
|
||||
{
|
||||
Config::set('auth.allow_register', false);
|
||||
$this->action('GET', 'UserController@register');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testRemindme()
|
||||
{
|
||||
$this->action('GET', 'UserController@remindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$user = f::create('User');
|
||||
|
||||
$this->_users->shouldReceive('findByReset')->andReturn($user);
|
||||
$this->_email->shouldReceive('sendPasswordMail');
|
||||
$this->action('GET', 'UserController@reset');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testResetNoUser()
|
||||
{
|
||||
$this->_users->shouldReceive('findByReset')->andReturn(false);
|
||||
$this->action('GET', 'UserController@reset');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Account',
|
||||
[
|
||||
'user_id' => 'factory|User',
|
||||
'account_type_id' => 'factory|AccountType',
|
||||
'name' => 'word',
|
||||
'active' => 'boolean'
|
||||
]
|
||||
);
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'AccountType',
|
||||
[
|
||||
'type' => 'unique:word',
|
||||
'editable' => 1
|
||||
]
|
||||
);
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Budget',
|
||||
[
|
||||
'name' => 'word',
|
||||
'user_id' => 'factory|User',
|
||||
'class' => 'Budget'
|
||||
]
|
||||
);
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Category',
|
||||
[
|
||||
'name' => 'word',
|
||||
'user_id' => 'factory|User',
|
||||
'class' => 'Category'
|
||||
]
|
||||
);
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Component',
|
||||
[
|
||||
'name' => 'word',
|
||||
'user_id' => 'factory|User',
|
||||
'class' => 'Component'
|
||||
]
|
||||
);
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Limit',
|
||||
[
|
||||
|
||||
'component_id' => 'factory|Budget',
|
||||
'startdate' => function () {
|
||||
$start = new Carbon;
|
||||
$start->startOfMonth();
|
||||
|
||||
return $start;
|
||||
},
|
||||
'amount' => 100,
|
||||
'repeats' => 'boolean',
|
||||
'repeat_freq' => function () {
|
||||
$frequencies = ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'];
|
||||
|
||||
return $frequencies[rand(0, 5)];
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
);
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'LimitRepetition',
|
||||
[
|
||||
|
||||
'limit_id' => 'factory|Limit',
|
||||
'startdate' => function () {
|
||||
$start = new Carbon;
|
||||
$start->startOfMonth();
|
||||
|
||||
return $start;
|
||||
|
||||
},
|
||||
'enddate' => function () {
|
||||
$end = new Carbon;
|
||||
$end->endOfMonth();
|
||||
|
||||
return $end;
|
||||
|
||||
},
|
||||
'amount' => 100
|
||||
|
||||
|
||||
]
|
||||
);
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Piggybank',
|
||||
[
|
||||
|
||||
'account_id' => 'factory|Account',
|
||||
'name' => 'word',
|
||||
'targetamount' => 'integer',
|
||||
'startdate' => function () {
|
||||
$start = new Carbon;
|
||||
$start->startOfMonth();
|
||||
|
||||
return $start;
|
||||
},
|
||||
'targetdate' => function () {
|
||||
$end = new Carbon;
|
||||
$end->endOfMonth();
|
||||
|
||||
return $end;
|
||||
},
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_times' => 0,
|
||||
'rep_every' => 0,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'order' => 1,
|
||||
]
|
||||
);
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'PiggybankEvent',
|
||||
[
|
||||
|
||||
'piggybank_id' => 'factory|Piggybank',
|
||||
'date' => new Carbon,
|
||||
'amount' => 10
|
||||
|
||||
]
|
||||
);
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'PiggybankRepetition',
|
||||
[
|
||||
|
||||
|
||||
'piggybank_id' => 'factory|Piggybank',
|
||||
'startdate' => function () {
|
||||
$start = new Carbon;
|
||||
$start->startOfMonth();
|
||||
|
||||
return $start;
|
||||
},
|
||||
'targetdate' => function () {
|
||||
$end = new Carbon;
|
||||
$end->endOfMonth();
|
||||
|
||||
return $end;
|
||||
},
|
||||
'currentamount' => 200
|
||||
]
|
||||
);
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Preference',
|
||||
[
|
||||
|
||||
'user_id' => 'factory|User',
|
||||
'name' => 'word',
|
||||
'data' => 'word'
|
||||
]
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
// TODO better factory.
|
||||
|
||||
Facade::define(
|
||||
'RecurringTransaction',
|
||||
[
|
||||
|
||||
'user_id' => 'factory|User',
|
||||
'name' => 'string',
|
||||
'match' => 'string',
|
||||
'amount_max' => 100,
|
||||
'amount_min' => 50,
|
||||
'date' => new Carbon,
|
||||
'active' => 'boolean',
|
||||
'automatch' => 'boolean',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 'boolean',
|
||||
|
||||
]
|
||||
);
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'Transaction',
|
||||
[
|
||||
'account_id' => 'factory|Account',
|
||||
'piggybank_id' => null,
|
||||
'transaction_journal_id' => 'factory|TransactionJournal',
|
||||
'description' => 'string',
|
||||
'amount' => 'integer:5',
|
||||
]
|
||||
);
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'TransactionCurrency',
|
||||
[
|
||||
'code' => 'EUR'
|
||||
]
|
||||
);
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'TransactionJournal',
|
||||
[
|
||||
'transaction_type_id' => 'factory|TransactionType',
|
||||
'transaction_currency_id' => 'factory|TransactionCurrency',
|
||||
'description' => 'word',
|
||||
'completed' => 'boolean',
|
||||
'user_id' => 'factory|User',
|
||||
'date' => new Carbon
|
||||
]
|
||||
);
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'TransactionType',
|
||||
[
|
||||
'type' => function () {
|
||||
$types = ['Withdrawal', 'Deposit', 'Transfer', 'Opening balance'];
|
||||
|
||||
return $types[rand(0, 3)];
|
||||
}
|
||||
]
|
||||
);
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade;
|
||||
|
||||
Facade::define(
|
||||
'User',
|
||||
[
|
||||
'email' => 'safeEmail',
|
||||
'password' => function () {
|
||||
return \Str::random(60);
|
||||
},
|
||||
'reset' => function () {
|
||||
return \Str::random(32);
|
||||
},
|
||||
'remember_token' => null,
|
||||
'migrated' => 'boolean'
|
||||
]
|
||||
);
|
@ -1,417 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
|
||||
/**
|
||||
* Class ModelTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
*/
|
||||
class ModelTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testAccount()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
$user = f::create('User');
|
||||
$type = f::create('AccountType');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$account->user()->associate($user);
|
||||
$account->accounttype()->associate($type);
|
||||
$account->piggybanks()->save($piggybank);
|
||||
|
||||
|
||||
$this->assertEquals($account->predict(new Carbon), null);
|
||||
$this->assertEquals($account->balance(new Carbon), null);
|
||||
$this->assertEquals($account->user_id, $user->id);
|
||||
$this->assertEquals($piggybank->account_id, $account->id);
|
||||
$this->assertEquals($account->account_type_id, $type->id);
|
||||
|
||||
}
|
||||
|
||||
public function testAccountType()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
$type = f::create('AccountType');
|
||||
$type->accounts()->save($account);
|
||||
|
||||
$this->assertEquals($account->account_type_id, $type->id);
|
||||
}
|
||||
|
||||
public function testBudget()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$limit = f::create('Limit');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$budget->limits()->save($limit);
|
||||
$budget->transactionjournals()->save($journal);
|
||||
|
||||
$this->assertEquals($limit->component_id, $budget->id);
|
||||
$this->assertEquals($journal->budgets()->first()->id, $budget->id);
|
||||
}
|
||||
|
||||
public function testCategory()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$category->transactionjournals()->save($journal);
|
||||
|
||||
$this->assertEquals($journal->categories()->first()->id, $category->id);
|
||||
}
|
||||
|
||||
public function testComponent()
|
||||
{
|
||||
$component = f::create('Component');
|
||||
$limit = f::create('Limit');
|
||||
$component->limits()->save($limit);
|
||||
$component->save();
|
||||
|
||||
$transaction = f::create('Transaction');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$user = f::create('User');
|
||||
|
||||
|
||||
$component->transactions()->save($transaction);
|
||||
$component->transactionjournals()->save($journal);
|
||||
$component->user()->associate($user);
|
||||
|
||||
$this->assertEquals($transaction->components()->first()->id, $component->id);
|
||||
$this->assertEquals($journal->components()->first()->id, $component->id);
|
||||
$this->assertEquals($limit->component()->first()->id, $component->id);
|
||||
$this->assertEquals($component->user_id, $user->id);
|
||||
|
||||
}
|
||||
|
||||
public function testLimit()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$budget = f::create('Budget');
|
||||
$rep = f::create('LimitRepetition');
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->limitrepetitions()->save($rep);
|
||||
$rep->save();
|
||||
$limit->save();
|
||||
|
||||
$this->assertEquals($rep->limit_id, $limit->id);
|
||||
$this->assertEquals($limit->component_id, $budget->id);
|
||||
|
||||
// create repetition:
|
||||
$start = new Carbon;
|
||||
$list = ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'];
|
||||
foreach ($list as $entry) {
|
||||
$limit->repeat_freq = $entry;
|
||||
$limit->createRepetition($start);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @expectedException \Firefly\Exception\FireflyException
|
||||
// */
|
||||
// public function testLimitrepetition()
|
||||
// {
|
||||
// $limit = f::create('Limit');
|
||||
// $rep = f::create('LimitRepetition');
|
||||
// $budget = f::create('Budget');
|
||||
// $journal = f::create('TransactionJournal');
|
||||
// $one = f::create('Transaction');
|
||||
// $two = f::create('Transaction');
|
||||
// $one->amount = 300;
|
||||
// $two->amount = -300;
|
||||
//
|
||||
// $rep->limit()->associate($limit);
|
||||
// $limit->budget()->associate($budget);
|
||||
// $journal->transactions()->save($one);
|
||||
// $journal->transactions()->save($two);
|
||||
// $journal->budgets()->save($budget);
|
||||
//
|
||||
// $this->assertEquals(($rep->amount - 300), $rep->left());
|
||||
//
|
||||
// // repeat frequency (not present) for periodOrder
|
||||
// $testDate = new Carbon;
|
||||
// $testDate->startOfMonth();
|
||||
// $rep->repeat_freq = null;
|
||||
//
|
||||
// // this test will FAIL because nowadays the $rep has a random thing.
|
||||
// // TODO
|
||||
//
|
||||
//
|
||||
// //$this->assertEquals($testDate->format('Ymd') . '-3', $rep->periodOrder());
|
||||
//
|
||||
// // repeat frequency (present) for periodOrder
|
||||
// $list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily'];
|
||||
// foreach ($list as $index => $entry) {
|
||||
// $rep->repeat_freq = $entry;
|
||||
// $this->assertEquals($testDate->format('Ymd') . '-' . $index, $rep->periodOrder());
|
||||
// }
|
||||
//
|
||||
// // repeat freq (invalid) for periodOrder
|
||||
// $rep->repeat_freq = 'bad';
|
||||
// $rep->periodOrder();
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* @expectedException \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function testLimitrepetitionContinued()
|
||||
{
|
||||
$limit = f::create('Limit');
|
||||
$rep = f::create('LimitRepetition');
|
||||
$budget = f::create('Budget');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$one = f::create('Transaction');
|
||||
$two = f::create('Transaction');
|
||||
$one->amount = 300;
|
||||
$two->amount = -300;
|
||||
|
||||
$rep->limit()->associate($limit);
|
||||
$limit->budget()->associate($budget);
|
||||
$journal->transactions()->save($one);
|
||||
$journal->transactions()->save($two);
|
||||
$journal->budgets()->save($budget);
|
||||
|
||||
// repeat frequency (not present) for periodShow
|
||||
$testDate = new Carbon;
|
||||
$testDate->startOfMonth();
|
||||
$rep->repeat_freq = null;
|
||||
// TODO cannot test this with the new factories.
|
||||
// $this->assertEquals($testDate->format('F Y'), $rep->periodShow());
|
||||
|
||||
// repeat frequency (present) for periodOrder
|
||||
$list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily'];
|
||||
foreach ($list as $entry) {
|
||||
$rep->repeat_freq = $entry;
|
||||
$this->assertGreaterThan(0, strlen($rep->periodShow()));
|
||||
}
|
||||
|
||||
// repeat freq (invalid) for periodOrder
|
||||
$rep->repeat_freq = 'bad';
|
||||
$rep->periodShow();
|
||||
}
|
||||
|
||||
public function testPiggybank()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
$account = f::create('Account');
|
||||
$piggy->account()->associate($account);
|
||||
$this->assertEquals($account->id, $piggy->account_id);
|
||||
|
||||
$repetition = f::create('PiggybankRepetition');
|
||||
$repetition->piggybank()->associate($piggy);
|
||||
$repetition->save();
|
||||
$list = ['day', 'week', 'month', 'year'];
|
||||
|
||||
// with a start date, so next reminder is built from a loop:
|
||||
foreach ($list as $reminder) {
|
||||
$piggy->reminder = $reminder;
|
||||
$repetition->save();
|
||||
$piggy->nextReminderDate();
|
||||
}
|
||||
// set the reminder period to be invalid, should return NULL
|
||||
$piggy->reminder = 'invalid';
|
||||
$piggy->save();
|
||||
$this->assertNull($piggy->nextReminderDate());
|
||||
|
||||
// set the start date to zero, give a valid $reminder, retry:
|
||||
$repetition->startdate = null;
|
||||
$piggy->reminder = 'month';
|
||||
$repetition->save();
|
||||
foreach ($list as $reminder) {
|
||||
$piggy->reminder = $reminder;
|
||||
$repetition->save();
|
||||
$piggy->nextReminderDate();
|
||||
}
|
||||
// set the reminder to be invalid again:
|
||||
$piggy->reminder = 'invalid';
|
||||
$piggy->save();
|
||||
$piggy->nextReminderDate();
|
||||
|
||||
// set it to be NULL
|
||||
$piggy->reminder = null;
|
||||
$piggy->save();
|
||||
$piggy->nextReminderDate();
|
||||
|
||||
|
||||
// remove the repetition, retry:
|
||||
$piggy->reminder = 'month';
|
||||
$piggy->save();
|
||||
$repetition->delete();
|
||||
$piggy->nextReminderDate();
|
||||
|
||||
$event = f::create('PiggybankEvent');
|
||||
$event->piggybank()->associate($piggy);
|
||||
$event->save();
|
||||
$this->assertEquals($piggy->piggybankevents()->first()->id, $event->id);
|
||||
|
||||
$this->assertNull($piggy->repetitionForDate(new Carbon('2012-02-02')));
|
||||
|
||||
$transaction = f::create('Transaction');
|
||||
$transaction->piggybank()->associate($piggy);
|
||||
$transaction->save();
|
||||
$this->assertEquals($transaction->piggybank_id, $piggy->id);
|
||||
$this->assertEquals($piggy->transactions()->first()->id, $transaction->id);
|
||||
|
||||
$repetition->pct();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testPreference()
|
||||
{
|
||||
$pref = f::create('Preference');
|
||||
$user = f::create('User');
|
||||
$pref->user()->associate($user);
|
||||
$this->assertEquals($pref->user_id, $user->id);
|
||||
$pref->data = 'Hello';
|
||||
$this->assertEquals($pref->data, 'Hello');
|
||||
}
|
||||
|
||||
public function testRecurringtransaction()
|
||||
{
|
||||
$rec = f::create('RecurringTransaction');
|
||||
$user = f::create('User');
|
||||
$rec->user()->associate($user);
|
||||
$this->assertEquals($rec->user_id, $user->id);
|
||||
|
||||
$list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily'];
|
||||
foreach ($list as $entry) {
|
||||
$start = clone $rec->date;
|
||||
$rec->repeat_freq = $entry;
|
||||
$end = $rec->next();
|
||||
$this->assertTrue($end > $start);
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransaction()
|
||||
{
|
||||
$transaction = f::create('Transaction');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$component = f::create('Component');
|
||||
$budget = f::create('Budget');
|
||||
$category = f::create('Category');
|
||||
$account = f::create('Account');
|
||||
$piggy = f::create('Piggybank');
|
||||
|
||||
$transaction->transactionJournal()->associate($journal);
|
||||
$this->assertEquals($transaction->transaction_journal_id, $journal->id);
|
||||
$transaction->components()->save($component);
|
||||
$this->assertEquals($transaction->components()->first()->id, $component->id);
|
||||
$transaction->budgets()->save($budget);
|
||||
$this->assertEquals($transaction->budgets()->first()->id, $budget->id);
|
||||
$transaction->categories()->save($category);
|
||||
$this->assertEquals($transaction->categories()->first()->id, $category->id);
|
||||
$transaction->account()->associate($account);
|
||||
$this->assertEquals($transaction->account_id, $account->id);
|
||||
$transaction->piggybank()->associate($piggy);
|
||||
$this->assertEquals($transaction->piggybank_id, $piggy->id);
|
||||
}
|
||||
|
||||
public function testTransactionCurrency()
|
||||
{
|
||||
$cur = f::create('TransactionCurrency');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$cur->transactionjournals()->save($journal);
|
||||
$journal->save();
|
||||
$cur->save();
|
||||
$this->assertEquals($cur->id, $journal->transaction_currency_id);
|
||||
}
|
||||
|
||||
public function testTransactionJournal()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
$user = f::create('User');
|
||||
$cur = f::create('TransactionCurrency');
|
||||
$transaction = f::create('Transaction');
|
||||
$component = f::create('Component');
|
||||
$budget = f::create('Budget');
|
||||
$category = f::create('Category');
|
||||
|
||||
$journal->transactionType()->associate($type);
|
||||
$this->assertEquals($type->id, $journal->transaction_type_id);
|
||||
|
||||
$journal->user()->associate($user);
|
||||
$this->assertEquals($user->id, $journal->user_id);
|
||||
|
||||
$journal->transactionCurrency()->associate($cur);
|
||||
$this->assertEquals($cur->id, $journal->transaction_currency_id);
|
||||
|
||||
$journal->transactions()->save($transaction);
|
||||
$this->assertEquals($journal->transactions()->first()->id, $transaction->id);
|
||||
|
||||
$journal->components()->save($component);
|
||||
$this->assertEquals($journal->components()->first()->id, $component->id);
|
||||
|
||||
$journal->budgets()->save($budget);
|
||||
$this->assertEquals($journal->budgets()->first()->id, $budget->id);
|
||||
|
||||
$journal->categories()->save($category);
|
||||
$this->assertEquals($journal->categories()->first()->id, $category->id);
|
||||
}
|
||||
|
||||
public function testTransactionType()
|
||||
{
|
||||
$journal = f::create('TransactionJournal');
|
||||
$type = f::create('TransactionType');
|
||||
|
||||
$type->transactionjournals()->save($journal);
|
||||
$this->assertEquals($type->transactionJournals()->first()->id, $journal->id);
|
||||
|
||||
}
|
||||
|
||||
public function testUser()
|
||||
{
|
||||
$user = f::create('User');
|
||||
|
||||
$account = f::create('Account');
|
||||
$bud = f::create('Budget');
|
||||
$cat = f::create('Category');
|
||||
$comp = f::create('Component');
|
||||
$pref = f::create('Preference');
|
||||
$rec = f::create('RecurringTransaction');
|
||||
$journal = f::create('TransactionJournal');
|
||||
$piggy = f::create('Piggybank');
|
||||
|
||||
$user->accounts()->save($account);
|
||||
$this->assertEquals($account->id, $user->accounts()->first()->id);
|
||||
|
||||
$user->components()->save($comp);
|
||||
$this->assertEquals($comp->id, $user->components()->first()->id);
|
||||
|
||||
$user->budgets()->save($bud);
|
||||
$this->assertEquals($bud->id, $user->budgets()->first()->id);
|
||||
|
||||
$user->categories()->save($cat);
|
||||
$this->assertEquals($cat->id, $user->categories()->first()->id);
|
||||
|
||||
$user->preferences()->save($pref);
|
||||
$this->assertEquals($pref->id, $user->preferences()->first()->id);
|
||||
|
||||
$user->recurringtransactions()->save($rec);
|
||||
$this->assertEquals($rec->id, $user->recurringtransactions()->first()->id);
|
||||
|
||||
$user->transactionjournals()->save($journal);
|
||||
$this->assertEquals($journal->id, $user->transactionjournals()->first()->id);
|
||||
|
||||
$piggy->account()->associate($account);
|
||||
$piggy->save();
|
||||
$this->assertCount(1, $user->piggybanks()->get());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user