Fix test coverage.

This commit is contained in:
James Cole 2019-07-20 22:32:40 +02:00
parent 58d370a893
commit 8f9ba21f4d
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
7 changed files with 90 additions and 2010 deletions

View File

@ -87,403 +87,4 @@ class SingleController extends Controller
);
}
/**
* CLone a transaction.
*
* @param TransactionJournal $journal
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function cloneTransaction(TransactionJournal $journal)
{
$source = $this->repository->getJournalSourceAccounts($journal)->first();
$destination = $this->repository->getJournalDestinationAccounts($journal)->first();
$budgetId = $this->repository->getJournalBudgetId($journal);
$categoryName = $this->repository->getJournalCategoryName($journal);
$tags = implode(',', $this->repository->getTags($journal));
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
$amount = app('steam')->positive($transaction->amount);
$foreignAmount = null === $transaction->foreign_amount ? null : app('steam')->positive($transaction->foreign_amount);
// make sure previous URI is correct:
session()->put('transactions.create.fromStore', true);
session()->put('transactions.create.uri', app('url')->previous());
$preFilled = [
'description' => $journal->description,
'source_id' => $source->id,
'source_name' => $source->name,
'destination_id' => $destination->id,
'destination_name' => $destination->name,
'amount' => $amount,
'source_amount' => $amount,
'destination_amount' => $foreignAmount,
'foreign_amount' => $foreignAmount,
'native_amount' => $foreignAmount,
'amount_currency_id_amount' => $transaction->foreign_currency_id ?? 0,
'date' => (new Carbon())->format('Y-m-d'),
'budget_id' => $budgetId,
'category' => $categoryName,
'tags' => $tags,
'interest_date' => $this->repository->getMetaField($journal, 'interest_date'),
'book_date' => $this->repository->getMetaField($journal, 'book_date'),
'process_date' => $this->repository->getMetaField($journal, 'process_date'),
'due_date' => $this->repository->getMetaField($journal, 'due_date'),
'payment_date' => $this->repository->getMetaField($journal, 'payment_date'),
'invoice_date' => $this->repository->getMetaField($journal, 'invoice_date'),
'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),
'notes' => $this->repository->getNoteText($journal),
];
session()->flash('preFilled', $preFilled);
return redirect(route('transactions.create', [strtolower($journal->transactionType->type)]));
}
/**
* Create a new journal.
*
* @param Request $request
* @param string|null $what
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function create(Request $request, string $what = null)
{
$what = strtolower($what ?? TransactionType::DEPOSIT);
$what = (string)($request->old('what') ?? $what);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
$subTitle = (string)trans('form.add_new_' . $what);
$subTitleIcon = 'fa-plus';
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$source = (int)$request->get('source');
// grab old currency ID from old data:
$currencyID = (int)$request->old('amount_currency_id_amount');
$preFilled['amount_currency_id_amount'] = $currencyID;
if (('withdrawal' === $what || 'transfer' === $what) && $source > 0) {
$preFilled['source_id'] = $source;
}
if ('deposit' === $what && $source > 0) {
$preFilled['destination_id'] = $source;
}
session()->put('preFilled', $preFilled);
// put previous url in session if not redirect from store (not "create another").
if (true !== session('transactions.create.fromStore')) {
$this->rememberPreviousUri('transactions.create.uri');
}
session()->forget('transactions.create.fromStore');
return view(
'transactions.single.create',
compact('subTitleIcon', 'budgets', 'what', 'subTitle', 'optionalFields', 'preFilled')
);
}
/**
* Show a special JSONified view of a transaction, for easier debug purposes.
*
* @param TransactionJournal $journal
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function debugShow(TransactionJournal $journal): JsonResponse
{
$array = $journal->toArray();
$array['transactions'] = [];
$array['meta'] = [];
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$array['transactions'][] = $transaction->toArray();
}
/** @var TransactionJournalMeta $meta */
foreach ($journal->transactionJournalMeta as $meta) {
$array['meta'][] = $meta->toArray();
}
return response()->json($array);
}
/**
* Shows the form that allows a user to delete a transaction journal.
*
* @param TransactionJournal $journal
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function delete(TransactionJournal $journal)
{
Log::debug(sprintf('Start of delete view for journal #%d', $journal->id));
// Covered by another controller's tests
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal);
}
// @codeCoverageIgnoreEnd
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = (string)trans('firefly.delete_' . $what, ['description' => $journal->description]);
// put previous url in session
Log::debug('Will try to remember previous URI');
$this->rememberPreviousUri('transactions.delete.uri');
return view('transactions.single.delete', compact('journal', 'subTitle', 'what'));
}
/**
* Actually destroys the journal.
*
* @param TransactionJournal $transactionJournal
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(TransactionJournal $transactionJournal): RedirectResponse
{
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($transactionJournal)) {
return $this->redirectToAccount($transactionJournal);
}
// @codeCoverageIgnoreEnd
$type = $this->repository->getTransactionType($transactionJournal);
session()->flash('success', (string)trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description]));
$this->repository->destroy($transactionJournal);
app('preferences')->mark();
return redirect($this->getPreviousUri('transactions.delete.uri'));
}
/**
* Edit a journal.
*
* @param TransactionJournal $journal
*
* @param JournalRepositoryInterface $repository
*
* @return mixed
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function edit(TransactionJournal $journal, JournalRepositoryInterface $repository)
{
$transactionType = $repository->getTransactionType($journal);
// redirect to account:
if ($transactionType === TransactionType::OPENING_BALANCE) {
return $this->redirectToAccount($journal);
}
// redirect to reconcile edit:
if ($transactionType === TransactionType::RECONCILIATION) {
return redirect(route('accounts.reconcile.edit', [$journal->id]));
}
$what = strtolower($transactionType);
$budgetList = app('expandedform')->makeSelectListWithEmpty($this->budgets->getBudgets());
// view related code
$subTitle = (string)trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
// journal related code
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$pTransaction = $repository->getFirstPosTransaction($journal);
$foreignCurrency = $pTransaction->foreignCurrency ?? $pTransaction->transactionCurrency;
$preFilled = [
'date' => $repository->getJournalDate($journal, null), // $journal->dateAsString()
'interest_date' => $repository->getJournalDate($journal, 'interest_date'),
'book_date' => $repository->getJournalDate($journal, 'book_date'),
'process_date' => $repository->getJournalDate($journal, 'process_date'),
'category' => $repository->getJournalCategoryName($journal),
'budget_id' => $repository->getJournalBudgetId($journal),
'tags' => implode(',', $repository->getTags($journal)),
'source_id' => $sourceAccounts->first()->id,
'source_name' => $sourceAccounts->first()->edit_name,
'destination_id' => $destinationAccounts->first()->id,
'destination_name' => $destinationAccounts->first()->edit_name,
'bill_id' => $journal->bill_id,
'bill_name' => null === $journal->bill_id ? null : $journal->bill->name,
// new custom fields:
'due_date' => $repository->getJournalDate($journal, 'due_date'),
'payment_date' => $repository->getJournalDate($journal, 'payment_date'),
'invoice_date' => $repository->getJournalDate($journal, 'invoice_date'),
'interal_reference' => $repository->getMetaField($journal, 'internal_reference'),
'notes' => $repository->getNoteText($journal),
// amount fields
'amount' => $pTransaction->amount,
'source_amount' => $pTransaction->amount,
'native_amount' => $pTransaction->amount,
'destination_amount' => $pTransaction->foreign_amount,
'currency' => $pTransaction->transactionCurrency,
'source_currency' => $pTransaction->transactionCurrency,
'native_currency' => $pTransaction->transactionCurrency,
'foreign_currency' => $foreignCurrency,
'destination_currency' => $foreignCurrency,
];
// amounts for withdrawals and deposits:
// amount, native_amount, source_amount, destination_amount
if (null !== $pTransaction->foreign_amount && ($journal->isWithdrawal() || $journal->isDeposit())) {
$preFilled['amount'] = $pTransaction->foreign_amount;
$preFilled['currency'] = $pTransaction->foreignCurrency;
}
session()->flash('preFilled', $preFilled);
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('transactions.edit.fromUpdate')) {
$this->rememberPreviousUri('transactions.edit.uri');
}
session()->forget('transactions.edit.fromUpdate');
return view(
'transactions.single.edit',
compact('journal', 'optionalFields', 'what', 'budgetList', 'subTitle')
)->with('data', $preFilled);
}
/**
* Stores a new journal.
*
* @param JournalFormRequest $request
* @param JournalRepositoryInterface $repository
*
* @return RedirectResponse
* @throws \FireflyIII\Exceptions\FireflyException
*
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository): RedirectResponse
{
$doSplit = 1 === (int)$request->get('split_journal');
$createAnother = 1 === (int)$request->get('create_another');
$data = $request->getJournalData();
$group = $repository->store($data);
throw new FireflyException('Needs refactor');
if (null === $journal->id) {
// error!
Log::error('Could not store transaction journal.');
session()->flash('error', (string)trans('firefly.unknown_journal_error'));
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files);
// store the journal only, flash the rest.
Log::debug(sprintf('Count of error messages is %d', $this->attachments->getErrors()->count()));
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
}
// flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
event(new StoredTransactionGroup($group));
session()->flash('success_uri', route('transactions.show', [$journal->id]));
session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
app('preferences')->mark();
// @codeCoverageIgnoreStart
if (true === $createAnother) {
session()->put('transactions.create.fromStore', true);
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
if (true === $doSplit) {
return redirect(route('transactions.split.edit', [$journal->id]));
}
// @codeCoverageIgnoreEnd
return redirect($this->getPreviousUri('transactions.create.uri'));
}
/**
* Update a journal.
*
* @param JournalFormRequest $request
* @param JournalRepositoryInterface $repository
* @param TransactionJournal $journal
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
{
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal);
}
// @codeCoverageIgnoreEnd
$data = $request->getJournalData();
// keep current bill:
$data['bill_id'] = $journal->bill_id;
// remove it if no checkbox:
if (!$request->boolean('keep_bill_id')) {
$data['bill_id'] = null;
}
throw new FireflyException('Needs refactor');
$journal = $repository->update($journal, $data);
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files);
// @codeCoverageIgnoreStart
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
// @codeCoverageIgnoreEnd
event(new UpdatedTransactionGroup($group));
// update, get events by date and sort DESC
$type = strtolower($this->repository->getTransactionType($journal));
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $data['description']]));
app('preferences')->mark();
// @codeCoverageIgnoreStart
if (1 === (int)$request->get('return_to_edit')) {
session()->put('transactions.edit.fromUpdate', true);
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
}
// @codeCoverageIgnoreEnd
// redirect to previous URL.
return redirect($this->getPreviousUri('transactions.edit.uri'));
}
}

View File

@ -99,15 +99,11 @@ class IndexControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
// generic set for the info blocks:
$groupArray = [$this->getRandomWithdrawalAsArray()];
// role?
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);
// make paginator.
$paginator = new LengthAwarePaginator([$group], 1, 40, 1);
//Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');
$collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
@ -117,13 +113,10 @@ class IndexControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
//$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$this->be($this->user());
$response = $this->get(route('transactions.index.all', ['withdrawal']));

View File

@ -0,0 +1,85 @@
<?php
/**
* ShowControllerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Controllers\Transaction;
use Amount;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionGroupTransformer;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class ShowControllerTest
*/
class ShowControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ShowController
*/
public function testShow(): void
{
$this->mockDefaultSession();
// values
$withdrawal = $this->getRandomWithdrawalGroup();
$array = $this->getRandomWithdrawalGroupAsArray();
$array[0]['transactions'][0]['foreign_amount'] = '10';
$array[0]['transactions'][0]['foreign_currency_symbol'] = 'x';
$array[0]['transactions'][0]['foreign_currency_decimal_places'] = 2;
$groupRepository = $this->mock(TransactionGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionGroupTransformer::class);
// mock for transformer:
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array[0]);
// mock for repos
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$groupRepository->shouldReceive('getPiggyEvents')->atLeast()->once()->andReturn([]);
$groupRepository->shouldReceive('getAttachments')->atLeast()->once()->andReturn([]);
$groupRepository->shouldReceive('getLinks')->atLeast()->once()->andReturn([]);
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$this->be($this->user());
$response = $this->get(route('transactions.show', [$withdrawal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,458 +0,0 @@
<?php
/**
* SplitControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class SplitControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SplitControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
*/
public function testEdit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$deposit = $this->getRandomDeposit();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
// mock calls
$journalRepos->shouldReceive('firstNull')->once()->andReturn($deposit);
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection)->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$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
*/
public function testEditOldInput(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$deposit = $this->getRandomDeposit();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
// mock calls
$journalRepos->shouldReceive('firstNull')->once()->andReturn($deposit);
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection)->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$old = [
'transactions' => [
[
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'currency_id' => 1,
'currency_code' => 'AB',
'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
*/
public function testEditOpeningBalance(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$journalRepos->shouldReceive('firstNull')->once()->andReturn($opening);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$opening->id]));
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdate(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$ruleRepos = $this->mock(RuleGroupRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$deposit = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
$data = [
'id' => $deposit->id,
'what' => 'deposit',
'journal_description' => 'Updated salary',
'journal_currency_id' => 1,
'journal_destination_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'transaction_description' => 'Split #1',
'source_name' => 'Job',
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
],
];
// mock stuff
$journalRepos->shouldReceive('update')->andReturn($deposit);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getTransactionType')->andReturn('Deposit');
$attHelper->shouldReceive('saveAttachmentsForModel');
$attHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateOpeningBalance(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$data = [
'id' => $opening->id,
'what' => 'opening balance',
'journal_description' => 'Updated salary',
'journal_currency_id' => 1,
'journal_destination_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'transaction_description' => 'Split #1',
'source_name' => 'Job',
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
],
];
$journalRepos->shouldReceive('firstNull')->once()->andReturn($opening);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
$response->assertStatus(302);
$response->assertSessionMissing('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateTransfer(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$ruleRepos = $this->mock(RuleGroupRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$data = [
'id' => $transfer->id,
'what' => 'transfer',
'journal_description' => 'Some updated withdrawal',
'journal_currency_id' => 1,
'journal_source_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'transaction_description' => 'Split #1',
'source_id' => '1',
'destination_id' => '2',
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
],
];
// mock stuff
$journalRepos->shouldReceive('update')->andReturn($transfer);
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
$journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal');
$attHelper->shouldReceive('saveAttachmentsForModel');
$attHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$transfer->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateWithdrawal(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$ruleRepos = $this->mock(RuleGroupRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$withdrawal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$data = [
'id' => $withdrawal->id,
'what' => 'withdrawal',
'journal_description' => 'Some updated withdrawal',
'journal_currency_id' => 1,
'journal_source_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'transaction_description' => 'Split #1',
'source_id' => '1',
'destination_name' => 'some expense',
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
],
];
// mock stuff
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
$journalRepos->shouldReceive('firstNull')->andReturn($withdrawal);
$journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal');
$attHelper->shouldReceive('saveAttachmentsForModel');
$attHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
}
}

View File

@ -207,13 +207,14 @@ abstract class TestCase extends BaseTestCase
'currency_id' => $euro->id,
'foreign_currency_id' => null,
'date' => $date,
'source_account_id' => 1,
'destination_account_id' => 4,
'source_id' => 1,
'destination_id' => 4,
'currency_name' => $euro->name,
'currency_code' => $euro->code,
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places,
'amount' => '-30',
'foreign_amount' => null,
'budget_id' => $budget->id,
],
],

View File

@ -75,7 +75,7 @@ class NetWorthTest extends TestCase
// mock other calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->times(2)->andReturn('defaultAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset');
$currencyRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->times(1);
@ -112,7 +112,7 @@ class NetWorthTest extends TestCase
// mock other calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->times(2)->andReturn('defaultAsset', 'ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset', 'ccAsset');
$currencyRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->times(1);