mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 03:51:18 +00:00
Cleaned up some tests and moved some methods.
This commit is contained in:
@@ -1,304 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
* @coversDefaultClass \AccountController
|
||||
*/
|
||||
class AccountControllerTest 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 ::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
View::shouldReceive('make')->with('accounts.create')->once();
|
||||
|
||||
$this->action('GET', 'AccountController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'AccountController@delete', $account->id);
|
||||
$this->assertViewHas('account');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
/**
|
||||
* @covers ::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->once()->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'AccountController@destroy', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
$this->_accounts->shouldReceive('openingBalanceTransaction')->once()->andReturn(null);
|
||||
|
||||
// test if the view works:
|
||||
View::shouldReceive('make')->with('accounts.edit')->once()->andReturn(m::self())->shouldReceive('with')->with(
|
||||
'account', m::any()
|
||||
)
|
||||
->andReturn(m::self())->shouldReceive('with')->with('openingBalance', null)->andReturn(m::self());
|
||||
|
||||
$this->action('GET', 'AccountController@edit', $account->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
$collection = new Collection();
|
||||
$collection->add($account);
|
||||
|
||||
$list = [
|
||||
'personal' => [],
|
||||
'beneficiaries' => [],
|
||||
'initial' => [],
|
||||
'cash' => []
|
||||
];
|
||||
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
$this->action('GET', 'AccountController@index');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// some more mockery
|
||||
$paginator = \Paginator::make([], 0, 10);
|
||||
|
||||
$data = [
|
||||
'statistics' => [
|
||||
'period' => [
|
||||
'in' => 0,
|
||||
'out' => 0,
|
||||
'diff' => 0,
|
||||
't_in' => 0,
|
||||
't_out' => 0,
|
||||
't_diff' => 0
|
||||
],
|
||||
'categories' => [],
|
||||
'budgets' => [],
|
||||
'accounts' => []
|
||||
],
|
||||
'journals' => $paginator,
|
||||
];
|
||||
|
||||
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
|
||||
$this->action('GET', 'AccountController@show', $account->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store');
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
unset($account->name);
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store');
|
||||
$this->assertRedirectedToRoute('accounts.create');
|
||||
}
|
||||
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||
$this->action('POST', 'AccountController@store', ['create' => '1']);
|
||||
$this->assertRedirectedToRoute('accounts.create');
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($account);
|
||||
|
||||
$this->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.index');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->save();
|
||||
|
||||
unset($account->name);
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($account);
|
||||
|
||||
$this->action('POST', 'AccountController@update', $account->id);
|
||||
$this->assertRedirectedToRoute('accounts.edit', $account->id);
|
||||
|
||||
}
|
||||
}
|
||||
395
app/tests/controllers/AccountTest.php
Normal file
395
app/tests/controllers/AccountTest.php
Normal file
@@ -0,0 +1,395 @@
|
||||
<?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 controllers.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
* @coversDefaultClass \AccountController
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// whatever the account type of this account, searching for it using the
|
||||
// scope method should return one account:
|
||||
$accountTypeType = $account->accounttype->type;
|
||||
$this->assertCount(1, \Account::AccountTypeIn([$accountTypeType])->get());
|
||||
|
||||
// lame test
|
||||
$this->assertEquals('testing',\App::environment());
|
||||
|
||||
// count the number of accounts the account type has. Should be one:
|
||||
$accountType = $account->accounttype()->first();
|
||||
$this->assertCount(1,$accountType->accounts()->get());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::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 ::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// some prep work.
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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 ::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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 ::edit
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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 ::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
// two account types:
|
||||
$personalType = f::create('AccountType');
|
||||
$personalType->type = 'Default account';
|
||||
$personalType->save();
|
||||
$benType = f::create('AccountType');
|
||||
$benType->type = 'Beneficiary account';
|
||||
$benType->save();
|
||||
|
||||
// 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 ::show
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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 ::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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 ::store
|
||||
*/
|
||||
public function testStoreFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
/** @var \Account $account */
|
||||
$account = f::create('Account');
|
||||
|
||||
/** @var \AccountType $accountType */
|
||||
$accountType = f::create('AccountType');
|
||||
$accountType->type = 'Default account';
|
||||
$accountType->save();
|
||||
$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');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ Facade::define(
|
||||
[
|
||||
|
||||
'account_id' => 'factory|Account',
|
||||
'name' => 'string',
|
||||
'name' => 'word',
|
||||
'targetamount' => 'integer',
|
||||
'startdate' => function () {
|
||||
$start = new Carbon;
|
||||
|
||||
@@ -119,51 +119,51 @@ class ModelTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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
|
||||
|
||||
Reference in New Issue
Block a user