mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand tests.
This commit is contained in:
parent
d4aee258c4
commit
96ccce5db3
@ -63,6 +63,9 @@ class SplitController extends Controller
|
|||||||
/** @var JournalTaskerInterface */
|
/** @var JournalTaskerInterface */
|
||||||
private $tasker;
|
private $tasker;
|
||||||
|
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -78,6 +81,7 @@ class SplitController extends Controller
|
|||||||
$this->tasker = app(JournalTaskerInterface::class);
|
$this->tasker = app(JournalTaskerInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$this->currencies = app(CurrencyRepositoryInterface::class);
|
$this->currencies = app(CurrencyRepositoryInterface::class);
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
app('view')->share('mainTitleIcon', 'fa-share-alt');
|
app('view')->share('mainTitleIcon', 'fa-share-alt');
|
||||||
app('view')->share('title', trans('firefly.split-transactions'));
|
app('view')->share('title', trans('firefly.split-transactions'));
|
||||||
|
|
||||||
@ -142,18 +146,17 @@ class SplitController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SplitJournalFormRequest $request
|
* @param SplitJournalFormRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(SplitJournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
public function update(SplitJournalFormRequest $request, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
if ($this->isOpeningBalance($journal)) {
|
if ($this->isOpeningBalance($journal)) {
|
||||||
return $this->redirectToAccount($journal);
|
return $this->redirectToAccount($journal);
|
||||||
}
|
}
|
||||||
$data = $this->arrayFromInput($request);
|
$data = $this->arrayFromInput($request);
|
||||||
$journal = $repository->updateSplitJournal($journal, $data);
|
$journal = $this->repository->updateSplitJournal($journal, $data);
|
||||||
/** @var array $files */
|
/** @var array $files */
|
||||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||||
// save attachments:
|
// save attachments:
|
||||||
@ -229,7 +232,8 @@ class SplitController extends Controller
|
|||||||
$destinationAccounts = $journal->destinationAccountList();
|
$destinationAccounts = $journal->destinationAccountList();
|
||||||
$notes = '';
|
$notes = '';
|
||||||
/** @var Note $note */
|
/** @var Note $note */
|
||||||
$note = $journal->notes()->first();
|
|
||||||
|
$note = $this->repository->getNote($journal);
|
||||||
if (null !== $note) {
|
if (null !== $note) {
|
||||||
$notes = $note->text;
|
$notes = $note->text;
|
||||||
}
|
}
|
||||||
@ -259,6 +263,7 @@ class SplitController extends Controller
|
|||||||
'transactions' => $this->getTransactionDataFromJournal($journal),
|
'transactions' => $this->getTransactionDataFromJournal($journal),
|
||||||
];
|
];
|
||||||
// update transactions array with old request data.
|
// update transactions array with old request data.
|
||||||
|
|
||||||
$array['transactions'] = $this->updateWithPrevious($array['transactions'], $request->old());
|
$array['transactions'] = $this->updateWithPrevious($array['transactions'], $request->old());
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
@ -346,6 +351,7 @@ class SplitController extends Controller
|
|||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
$old = $old['transactions'];
|
$old = $old['transactions'];
|
||||||
|
|
||||||
foreach ($old as $index => $row) {
|
foreach ($old as $index => $row) {
|
||||||
if (isset($array[$index])) {
|
if (isset($array[$index])) {
|
||||||
$array[$index] = array_merge($array[$index], $row);
|
$array[$index] = array_merge($array[$index], $row);
|
||||||
|
@ -108,7 +108,7 @@ class Tag extends Model
|
|||||||
*
|
*
|
||||||
* @throws \FireflyIII\Exceptions\FireflyException
|
* @throws \FireflyIII\Exceptions\FireflyException
|
||||||
*/
|
*/
|
||||||
public static function tagSum(self $tag): string
|
public static function tagSum(Tag $tag): string
|
||||||
{
|
{
|
||||||
$sum = '0';
|
$sum = '0';
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
|
@ -55,7 +55,7 @@ class TransactionCurrency extends Model
|
|||||||
*
|
*
|
||||||
* @return TransactionCurrency
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
public static function routeBinder(self $currency)
|
public static function routeBinder(TransactionCurrency $currency)
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
return $currency;
|
return $currency;
|
||||||
|
@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Transaction;
|
|||||||
|
|
||||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@ -48,6 +49,7 @@ class SplitControllerTest extends TestCase
|
|||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::updateWithPrevious
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
||||||
*/
|
*/
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
@ -74,6 +76,90 @@ class SplitControllerTest extends TestCase
|
|||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::updateWithPrevious
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
||||||
|
*/
|
||||||
|
public function testEditOldInput()
|
||||||
|
{
|
||||||
|
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||||
|
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
|
||||||
|
$account = $destination->account;
|
||||||
|
$transactions = factory(Transaction::class, 3)->make();
|
||||||
|
$tasker = $this->mock(JournalTaskerInterface::class);
|
||||||
|
|
||||||
|
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||||
|
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
|
||||||
|
->andReturn(new Collection([$account]))->once();
|
||||||
|
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||||
|
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
|
||||||
|
|
||||||
|
$old = [
|
||||||
|
'transactions' => [
|
||||||
|
[
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'transaction_currency_code' => 'AB',
|
||||||
|
'transaction_currency_symbol' => 'X',
|
||||||
|
'foreign_amount' => '0',
|
||||||
|
'foreign_currency_id' => 2,
|
||||||
|
'foreign_currency_code' => 'CD',
|
||||||
|
'foreign_currency_symbol' => 'Y',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'transaction_currency_code' => 'AB',
|
||||||
|
'transaction_currency_symbol' => 'X',
|
||||||
|
'foreign_amount' => '0',
|
||||||
|
'foreign_currency_id' => 2,
|
||||||
|
'foreign_currency_code' => 'CD',
|
||||||
|
'foreign_currency_symbol' => 'Y',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'transaction_currency_code' => 'AB',
|
||||||
|
'transaction_currency_symbol' => 'X',
|
||||||
|
'foreign_amount' => '0',
|
||||||
|
'foreign_currency_id' => 2,
|
||||||
|
'foreign_currency_code' => 'CD',
|
||||||
|
'foreign_currency_symbol' => 'Y',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'transaction_currency_code' => 'AB',
|
||||||
|
'transaction_currency_symbol' => 'X',
|
||||||
|
'foreign_amount' => '0',
|
||||||
|
'foreign_currency_id' => 2,
|
||||||
|
'foreign_currency_code' => 'CD',
|
||||||
|
'foreign_currency_symbol' => 'Y',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'transaction_currency_code' => 'AB',
|
||||||
|
'transaction_currency_symbol' => 'X',
|
||||||
|
'foreign_amount' => '0',
|
||||||
|
'foreign_currency_id' => 2,
|
||||||
|
'foreign_currency_code' => 'CD',
|
||||||
|
'foreign_currency_symbol' => 'Y',
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$this->session(['_old_input' => $old]);
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// has bread crumb
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||||
*/
|
*/
|
||||||
@ -89,6 +175,7 @@ class SplitControllerTest extends TestCase
|
|||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::updateWithPrevious
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
||||||
*/
|
*/
|
||||||
public function testEditSingle()
|
public function testEditSingle()
|
||||||
@ -96,12 +183,19 @@ class SplitControllerTest extends TestCase
|
|||||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$note = new Note();
|
||||||
|
$note->id = 1;
|
||||||
|
$note->text = 'Hallo';
|
||||||
$transactions = factory(Transaction::class, 1)->make();
|
$transactions = factory(Transaction::class, 1)->make();
|
||||||
$tasker = $this->mock(JournalTaskerInterface::class);
|
$tasker = $this->mock(JournalTaskerInterface::class);
|
||||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||||
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
|
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = $destination->account;
|
$account = $destination->account;
|
||||||
|
|
||||||
|
$repository->shouldReceive('getNote')->andReturn($note);
|
||||||
|
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
|
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||||
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
|
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
|
||||||
->andReturn(new Collection([$account]))->once();
|
->andReturn(new Collection([$account]))->once();
|
||||||
@ -122,8 +216,6 @@ class SplitControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
//$this->markTestIncomplete('Mockery cannot yet handle PHP7.1 null argument method things.');
|
|
||||||
|
|
||||||
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
|
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
|
||||||
$deposit = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
|
$deposit = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
|
||||||
$data = [
|
$data = [
|
||||||
@ -171,6 +263,7 @@ class SplitControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::isOpeningBalance
|
||||||
*/
|
*/
|
||||||
public function testUpdateOpeningBalance()
|
public function testUpdateOpeningBalance()
|
||||||
{
|
{
|
||||||
@ -178,6 +271,22 @@ class SplitControllerTest extends TestCase
|
|||||||
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
|
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
|
||||||
$data = [
|
$data = [
|
||||||
'id' => $opening->id,
|
'id' => $opening->id,
|
||||||
|
'what' => 'deposit',
|
||||||
|
'journal_description' => 'Updated salary',
|
||||||
|
'journal_currency_id' => 1,
|
||||||
|
'journal_destination_account_id' => 1,
|
||||||
|
'journal_amount' => 1591,
|
||||||
|
'date' => '2014-01-24',
|
||||||
|
'tags' => '',
|
||||||
|
'transactions' => [
|
||||||
|
[
|
||||||
|
'description' => 'Split #1',
|
||||||
|
'source_account_name' => 'Job',
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'amount' => 1591,
|
||||||
|
'category' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
|
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
|
||||||
|
Loading…
Reference in New Issue
Block a user