mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 19:47:48 +00:00
Create deposits, transfers and withdrawals. Also tests!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use \League\FactoryMuffin\Facade\FactoryMuffin;
|
||||
use League\FactoryMuffin\Facade\FactoryMuffin;
|
||||
|
||||
class TransactionControllerTest extends TestCase
|
||||
{
|
||||
@@ -51,6 +51,63 @@ class TransactionControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCreateDeposit()
|
||||
{
|
||||
|
||||
$set = [0 => '(no budget)'];
|
||||
View::shouldReceive('share');
|
||||
View::shouldReceive('make')->with('transactions.deposit')->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once()
|
||||
->with('accounts', [])
|
||||
->andReturn(Mockery::self())
|
||||
->shouldReceive('with')->once()
|
||||
->with('budgets', $set)->andReturn(Mockery::self());
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('getAsSelectList')->andReturn($set);
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/transactions/add/deposit');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCreateTransfer()
|
||||
{
|
||||
|
||||
$set = [0 => '(no budget)'];
|
||||
View::shouldReceive('share');
|
||||
View::shouldReceive('make')->with('transactions.transfer')->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once()
|
||||
->with('accounts', [])
|
||||
->andReturn(Mockery::self())
|
||||
->shouldReceive('with')->once()
|
||||
->with('budgets', $set)->andReturn(Mockery::self());
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('getAsSelectList')->andReturn($set);
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/transactions/add/transfer');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
public function testPostCreateWithdrawal()
|
||||
{
|
||||
// create objects.
|
||||
@@ -90,7 +147,130 @@ class TransactionControllerTest extends TestCase
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
|
||||
|
||||
// $tj->shouldReceive('createSimpleJournal')->with($account, $beneficiary, $data['description'], $data['amount'], new \Carbon\Carbon($data['date']))->once()->andReturn($journal);
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/withdrawal', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
public function testPostCreateDeposit()
|
||||
{
|
||||
// create objects.
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$beneficiary = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'beneficiary' => $beneficiary->name,
|
||||
'category' => $category->name,
|
||||
'account_id' => $account->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('createOrFindBeneficiary')->with($beneficiary->name)->andReturn($beneficiary);
|
||||
$accounts->shouldReceive('find')->andReturn($account);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/deposit', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
public function testPostCreateTransfer()
|
||||
{
|
||||
// create objects.
|
||||
$from = FactoryMuffin::create('Account');
|
||||
$to = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'category' => $category->name,
|
||||
'account_from_id' => $from->id,
|
||||
'account_to_id' => $to->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
|
||||
$accounts->shouldReceive('find')->with($to->id)->andReturn($to);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/transfer', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
public function testPostCreateWithdrawalEmptyBeneficiary()
|
||||
{
|
||||
// create objects.
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$beneficiary = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'beneficiary' => '',
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'account_id' => $account->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
|
||||
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
|
||||
$accounts->shouldReceive('find')->andReturn($account);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock budget repository
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
|
||||
$budgets->shouldReceive('find')->andReturn($budget);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/withdrawal', $data);
|
||||
@@ -98,6 +278,194 @@ class TransactionControllerTest extends TestCase
|
||||
// test
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
public function testPostCreateDepositEmptyBeneficiary()
|
||||
{
|
||||
// create objects.
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$beneficiary = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'beneficiary' => '',
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'account_id' => $account->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
|
||||
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
|
||||
$accounts->shouldReceive('find')->andReturn($account);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock budget repository
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
|
||||
$budgets->shouldReceive('find')->andReturn($budget);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/deposit', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Firefly\Exception\FireflyException;
|
||||
*/
|
||||
public function testPostCreateWithdrawalException()
|
||||
{
|
||||
// create objects.
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$beneficiary = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'beneficiary' => '',
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'account_id' => $account->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
|
||||
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
|
||||
$accounts->shouldReceive('find')->andReturn($account);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock budget repository
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
|
||||
$budgets->shouldReceive('find')->andReturn($budget);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/withdrawal', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('transactions.withdrawal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Firefly\Exception\FireflyException;
|
||||
*/
|
||||
public function testPostCreateDepositException()
|
||||
{
|
||||
// create objects.
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$beneficiary = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'beneficiary' => '',
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'account_id' => $account->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
|
||||
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
|
||||
$accounts->shouldReceive('find')->andReturn($account);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock budget repository
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
|
||||
$budgets->shouldReceive('find')->andReturn($budget);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/deposit', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('transactions.deposit');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Firefly\Exception\FireflyException;
|
||||
*/
|
||||
public function testPostCreateTransferException()
|
||||
{
|
||||
// create objects.
|
||||
$from = FactoryMuffin::create('Account');
|
||||
$category = FactoryMuffin::create('Category');
|
||||
|
||||
|
||||
// data to send:
|
||||
$data = [
|
||||
'category' => $category->name,
|
||||
'account_from_id' => $from->id,
|
||||
'account_to_id' => $from->id,
|
||||
'description' => 'Bla',
|
||||
'amount' => 1.2,
|
||||
'date' => '2012-01-01'
|
||||
];
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
|
||||
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
|
||||
|
||||
// mock category repository
|
||||
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
|
||||
|
||||
// mock transaction journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
|
||||
|
||||
// call
|
||||
$this->call('POST', '/transactions/add/transfer', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('transactions.transfer');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
|
Reference in New Issue
Block a user