mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
First tests for transaction controller.
This commit is contained in:
parent
15b023d116
commit
ee5afaa6bc
@ -39,6 +39,8 @@ class TransactionController extends BaseController
|
|||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @return array|\Illuminate\Http\JsonResponse
|
* @return array|\Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function alreadyRelated(TransactionJournal $journal)
|
public function alreadyRelated(TransactionJournal $journal)
|
||||||
@ -130,8 +132,10 @@ class TransactionController extends BaseController
|
|||||||
{
|
{
|
||||||
$type = $transactionJournal->transactionType->type;
|
$type = $transactionJournal->transactionType->type;
|
||||||
$return = 'withdrawal';
|
$return = 'withdrawal';
|
||||||
$this->_repository->destroy($transactionJournal);
|
|
||||||
|
|
||||||
|
Session::flash('success', 'Transaction "' . e($transactionJournal->description) . '" destroyed.');
|
||||||
|
|
||||||
|
$this->_repository->destroy($transactionJournal);
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'Deposit':
|
case 'Deposit':
|
||||||
@ -149,6 +153,8 @@ class TransactionController extends BaseController
|
|||||||
* TODO this needs cleaning up and thinking over.
|
* TODO this needs cleaning up and thinking over.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function doRelate()
|
public function doRelate()
|
||||||
{
|
{
|
||||||
@ -259,6 +265,8 @@ class TransactionController extends BaseController
|
|||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return \Illuminate\View\View
|
* @return \Illuminate\View\View
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function relate(TransactionJournal $journal)
|
public function relate(TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
@ -282,6 +290,8 @@ class TransactionController extends BaseController
|
|||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function relatedSearch(TransactionJournal $journal)
|
public function relatedSearch(TransactionJournal $journal)
|
||||||
@ -385,6 +395,7 @@ class TransactionController extends BaseController
|
|||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@ -420,39 +431,24 @@ class TransactionController extends BaseController
|
|||||||
$data = Input::except('_token');
|
$data = Input::except('_token');
|
||||||
$data['currency'] = 'EUR';
|
$data['currency'] = 'EUR';
|
||||||
$data['what'] = strtolower($journal->transactionType->type);
|
$data['what'] = strtolower($journal->transactionType->type);
|
||||||
|
|
||||||
// always validate:
|
|
||||||
$messages = $this->_repository->validate($data);
|
$messages = $this->_repository->validate($data);
|
||||||
|
|
||||||
// flash messages:
|
|
||||||
Session::flash('warnings', $messages['warnings']);
|
Session::flash('warnings', $messages['warnings']);
|
||||||
Session::flash('successes', $messages['successes']);
|
Session::flash('successes', $messages['successes']);
|
||||||
Session::flash('errors', $messages['errors']);
|
Session::flash('errors', $messages['errors']);
|
||||||
if ($messages['errors']->count() > 0) {
|
if ($messages['errors']->count() > 0) {
|
||||||
Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first());
|
Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return to update screen:
|
|
||||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||||
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update
|
|
||||||
$this->_repository->update($journal, $data);
|
$this->_repository->update($journal, $data);
|
||||||
Session::flash('success', 'Transaction "' . e($data['description']) . '" updated.');
|
Session::flash('success', 'Transaction "' . e($data['description']) . '" updated.');
|
||||||
|
|
||||||
Event::fire('transactionJournal.update', [$journal]); // new and used.
|
Event::fire('transactionJournal.update', [$journal]); // new and used.
|
||||||
|
|
||||||
/*
|
|
||||||
* Also trigger on both transactions.
|
|
||||||
*/
|
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($journal->transactions()->get() as $transaction) {
|
foreach ($journal->transactions()->get() as $transaction) {
|
||||||
Event::fire('transaction.update', [$transaction]);
|
Event::fire('transaction.update', [$transaction]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// go back to list
|
|
||||||
if ($data['post_submit_action'] == 'update') {
|
if ($data['post_submit_action'] == 'update') {
|
||||||
return Redirect::route('transactions.index', $data['what']);
|
return Redirect::route('transactions.index', $data['what']);
|
||||||
}
|
}
|
||||||
|
@ -102,13 +102,15 @@ class TestContentSeeder extends Seeder
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PiggyBankEvent::create(['piggy_bank_id' => 1, 'date' => $startDate->format('Y-m-d'), 'amount' => 100]);
|
PiggyBankEvent::create(['piggy_bank_id' => 1, 'date' => $startDate->format('Y-m-d'), 'amount' => 100]);
|
||||||
PiggyBankRepetition::create(
|
PiggyBankRepetition::create(
|
||||||
[
|
[
|
||||||
'piggy_bank_id' => $piggy->id,
|
'piggy_bank_id' => $piggy->id,
|
||||||
'startdate' => Carbon::now()->format('Y-m-d'),
|
'startdate' => Carbon::now()->format('Y-m-d'),
|
||||||
'targetdate' => null,
|
'targetdate' => null,
|
||||||
'currentamount' => 0
|
'currentamount' => 100
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -337,10 +339,35 @@ class TestContentSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create some big expenses, move some money around.
|
// create some big expenses, move some money around.
|
||||||
$this->createTransaction($savings, $checking, 1259, $transfer, 'Money for new PC', $end->format('Y-m') . '-11', $dollar);
|
$one = $this->createTransaction($savings, $checking, 1259, $transfer, 'Money for new PC', $end->format('Y-m') . '-11', $dollar);
|
||||||
$this->createTransaction($checking, $store, 1259, $withdrawal, 'New PC', $end->format('Y-m') . '-12', $euro);
|
$two = $this->createTransaction($checking, $store, 1259, $withdrawal, 'New PC', $end->format('Y-m') . '-12', $euro);
|
||||||
|
|
||||||
// create two budgets
|
// create a group for these two:
|
||||||
|
$group = TransactionGroup::create(
|
||||||
|
[
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'relation' => 'balance'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$group->transactionjournals()->save($one);
|
||||||
|
$group->transactionjournals()->save($two);
|
||||||
|
|
||||||
|
|
||||||
|
// piggy bank event
|
||||||
|
// add money to this piggy bank
|
||||||
|
// create a piggy bank event to match:
|
||||||
|
$intoPiggy = $this->createTransaction(
|
||||||
|
$checking, $savings, 100, $transfer, 'Money for piggy',
|
||||||
|
Carbon::now()->addDay()->format('Y-m-d'), $euro, $groceriesBudget, $house
|
||||||
|
);
|
||||||
|
$event = PiggyBankEvent::create(
|
||||||
|
[
|
||||||
|
'piggy_bank_id' => $piggy->id,
|
||||||
|
'transaction_journal_id' => $intoPiggy->id,
|
||||||
|
'date' => Carbon::now()->addDay()->format('Y-m-d'),
|
||||||
|
'amount' => 100
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// create two categories
|
// create two categories
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) }}
|
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) }}
|
||||||
{{Form::open(['class' => 'form-horizontal','url' => route('transactions.store',$what)])}}
|
{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('transactions.store',$what)])}}
|
||||||
{{Form::hidden('reminder',Input::get('reminder_id'))}}
|
{{Form::hidden('reminder',Input::get('reminder_id'))}}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }}
|
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }}
|
||||||
{{Form::open(['class' => 'form-horizontal','url' => route('transactions.destroy',$journal->id)])}}
|
{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('transactions.destroy',$journal->id)])}}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }}
|
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }}
|
||||||
{{Form::open(['class' => 'form-horizontal','url' => route('transactions.update',$journal->id)])}}
|
{{Form::open(['class' => 'form-horizontal','id' => 'update','url' => route('transactions.update',$journal->id)])}}
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
127
tests/functional/TransactionControllerCest.php
Normal file
127
tests/functional/TransactionControllerCest.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TransactionControllerCest
|
||||||
|
*/
|
||||||
|
class TransactionControllerCest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param FunctionalTester $I
|
||||||
|
*/
|
||||||
|
public function _after(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FunctionalTester $I
|
||||||
|
*/
|
||||||
|
public function _before(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->amLoggedAs(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('create a transaction');
|
||||||
|
$I->amOnPage('/transactions/create/withdrawal?account_id=1');
|
||||||
|
$I->see('Add a new withdrawal');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('delete a transaction');
|
||||||
|
$I->amOnPage('/transaction/delete/3');
|
||||||
|
$I->see('Delete withdrawal "Huur Portaal for January 2014"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroyWithdrawal(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('destroy a withdrawal');
|
||||||
|
$I->amOnPage('/transaction/delete/3');
|
||||||
|
$I->submitForm('#destroy', []);
|
||||||
|
$I->see('Transaction "Huur Portaal for January 2014" destroyed.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroyDeposit(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('destroy a deposit');
|
||||||
|
$I->amOnPage('/transaction/delete/32');
|
||||||
|
$I->submitForm('#destroy', []);
|
||||||
|
$I->see('Transaction "Salary" destroyed.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroyTransfer(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('destroy a transfer');
|
||||||
|
$I->amOnPage('/transaction/delete/406');
|
||||||
|
$I->submitForm('#destroy', []);
|
||||||
|
$I->see('Transaction "Money for new PC" destroyed.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('edit a transaction');
|
||||||
|
$I->amOnPage('/transaction/edit/408');
|
||||||
|
$I->see('Edit transfer "Money for piggy"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('see all withdrawals');
|
||||||
|
$I->amOnPage('/transactions/withdrawal');
|
||||||
|
$I->see('Expenses');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function indexExpenses(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('see all expenses');
|
||||||
|
$I->amOnPage('/transactions/deposit');
|
||||||
|
$I->see('Revenue, income and deposits');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function indexTransfers(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('see all transfers');
|
||||||
|
$I->amOnPage('/transactions/transfers');
|
||||||
|
$I->see('Transfers');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('see a transaction');
|
||||||
|
$I->amOnPage('/transaction/show/406');
|
||||||
|
$I->see('Transfer "Money for new PC"');
|
||||||
|
$I->see('1.259');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('store a transaction');
|
||||||
|
$I->amOnPage('/transactions/create/withdrawal');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(FunctionalTester $I)
|
||||||
|
{
|
||||||
|
$I->wantTo('update a transaction');
|
||||||
|
$I->amOnPage('/transaction/edit/3');
|
||||||
|
$I->see('Huur Portaal for January 2014');
|
||||||
|
$I->submitForm(
|
||||||
|
'#update', [
|
||||||
|
'description' => 'Huur Portaal for January 2014!',
|
||||||
|
'account_id' => 1,
|
||||||
|
'expense_account' => 'Portaal',
|
||||||
|
'amount' => 500,
|
||||||
|
'date' => '2014-01-01',
|
||||||
|
'budget_id' => 2,
|
||||||
|
'category' => 'House',
|
||||||
|
'post_submit_action' => 'update'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$I->see('Huur Portaal for January 2014!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user