Files
firefly-iii/tests/Feature/Controllers/Transaction/ConvertControllerTest.php

491 lines
21 KiB
PHP
Raw Normal View History

2017-02-12 18:40:39 +01:00
<?php
/**
* ConvertControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* 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
2017-12-17 14:42:21 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-02-12 18:40:39 +01:00
*/
2017-06-28 18:05:38 +02:00
declare(strict_types=1);
2017-02-12 18:40:39 +01:00
namespace Tests\Feature\Controllers\Transaction;
2018-03-07 10:18:22 +01:00
use Amount;
2017-03-04 11:20:57 +01:00
use DB;
2017-03-04 15:29:20 +01:00
use FireflyIII\Models\Account;
2018-03-07 10:18:22 +01:00
use FireflyIII\Models\TransactionCurrency;
2017-02-12 18:40:39 +01:00
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2018-03-07 10:18:22 +01:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2017-03-04 11:20:57 +01:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
2017-03-04 11:20:57 +01:00
use Illuminate\Support\MessageBag;
2018-03-24 06:08:50 +01:00
use Log;
2017-02-12 18:40:39 +01:00
use Tests\TestCase;
/**
* Class ConvertControllerTest
*
2017-08-12 10:27:45 +02:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-02-12 18:40:39 +01:00
*/
class ConvertControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
2018-03-24 06:08:50 +01:00
{
parent::setUp();
2018-09-03 18:52:46 +02:00
Log::info(sprintf('Now in %s.', \get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-02-12 18:40:39 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexDepositTransfer(): void
2017-02-12 18:40:39 +01:00
{
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2017-02-12 18:40:39 +01:00
2018-07-01 09:27:22 +02:00
// find deposit:
2018-09-02 20:13:25 +02:00
$deposit = $this->getRandomDeposit();
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$account = factory(Account::class)->make();
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
2018-03-07 10:18:22 +01:00
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
2017-02-12 18:40:39 +01:00
$this->be($this->user());
2018-07-01 09:27:22 +02:00
2017-02-12 18:40:39 +01:00
$response = $this->get(route('transactions.convert.index', ['transfer', $deposit->id]));
$response->assertStatus(200);
$response->assertSee('Convert a deposit into a transfer');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexDepositWithdrawal(): void
2017-02-12 18:40:39 +01:00
{
2017-03-04 11:20:57 +01:00
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
// find deposit:
2018-09-02 20:13:25 +02:00
$deposit = $this->getRandomDeposit();
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->twice();
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
2018-07-01 09:27:22 +02:00
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $deposit->id]));
$response->assertStatus(200);
$response->assertSee('Convert a deposit into a withdrawal');
}
2017-03-04 11:20:57 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexSameType(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff:
2018-07-01 09:27:22 +02:00
// find deposit:
2018-09-02 20:13:25 +02:00
$deposit = $this->getRandomDeposit();
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
2017-03-04 11:20:57 +01:00
$this->be($this->user());
2018-07-01 09:27:22 +02:00
2017-03-04 11:20:57 +01:00
$response = $this->get(route('transactions.convert.index', ['deposit', $deposit->id]));
$response->assertStatus(302);
$response->assertSessionHas('info');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexSplit(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->once();
2017-03-04 11:20:57 +01:00
$this->be($this->user());
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at')
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->orderBy('ct', 'DESC')
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
$response = $this->get(route('transactions.convert.index', ['deposit', $withdrawal->id]));
$response->assertStatus(302);
$response->assertSessionHas('error');
}
2017-02-12 18:40:39 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexTransferDeposit(): void
2017-02-12 18:40:39 +01:00
{
2017-03-04 11:20:57 +01:00
// mock stuff:
2018-07-01 09:27:22 +02:00
// find transfer:
2018-09-02 20:13:25 +02:00
$transfer = $this->getRandomTransfer();
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $transfer->id]));
$response->assertStatus(200);
$response->assertSee('Convert a transfer into a deposit');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexTransferWithdrawal(): void
2017-02-12 18:40:39 +01:00
{
2018-07-01 09:27:22 +02:00
// find transfer:
2018-09-02 20:13:25 +02:00
$transfer = $this->getRandomTransfer();
2017-03-04 11:20:57 +01:00
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $transfer->id]));
$response->assertStatus(200);
$response->assertSee('Convert a transfer into a withdrawal');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexWithdrawalDeposit(): void
2017-02-12 18:40:39 +01:00
{
2018-07-01 09:27:22 +02:00
// find withdrawal:
2018-09-02 20:13:25 +02:00
$withdrawal = $this->getRandomWithdrawal();
2017-03-04 11:20:57 +01:00
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $withdrawal->id]));
$response->assertStatus(200);
$response->assertSee('Convert a withdrawal into a deposit');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndexWithdrawalTransfer(): void
2017-02-12 18:40:39 +01:00
{
2018-07-01 09:27:22 +02:00
// find withdrawal:
2018-09-02 20:13:25 +02:00
$withdrawal = $this->getRandomWithdrawal();
2017-03-04 11:20:57 +01:00
// mock stuff:
2018-02-28 15:50:00 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
2018-03-07 10:18:22 +01:00
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['transfer', $withdrawal->id]));
$response->assertStatus(200);
$response->assertSee('Convert a withdrawal into a transfer');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexDepositTransfer(): void
2017-02-12 18:40:39 +01:00
{
2017-03-04 11:20:57 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
2017-03-04 11:20:57 +01:00
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
2017-03-04 15:29:20 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('find')->andReturn(new Account);
2017-03-04 11:20:57 +01:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['source_account_asset' => 1];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$deposit->id]));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexDepositWithdrawal(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff
2018-02-28 15:50:00 +01:00
2017-03-04 11:20:57 +01:00
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
2017-03-04 15:29:20 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('store')->andReturn(new Account);
2018-02-28 15:50:00 +01:00
$account = $this->user()->accounts()->first();
2017-03-04 15:29:20 +01:00
2017-03-04 11:20:57 +01:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
2017-11-22 21:12:27 +01:00
$data = ['destination_account_expense' => 'New expense name.'];
2017-03-04 11:20:57 +01:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$deposit->id]));
}
2017-06-28 18:05:38 +02:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-06-28 18:05:38 +02:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexDepositWithdrawalEmptyName(): void
2017-06-28 18:05:38 +02:00
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-06-28 18:05:38 +02:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-07-01 09:27:22 +02:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['destination_account_expense' => ''];
2017-06-28 18:05:38 +02:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$deposit->id]));
}
2017-03-04 11:20:57 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexErrored(): void
2017-03-04 11:20:57 +01:00
{
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->user()->accounts()->first();
2018-07-01 09:27:22 +02:00
// find withdrawal:
2018-09-02 20:13:25 +02:00
$withdrawal = $this->getRandomWithdrawal();
2018-02-28 15:50:00 +01:00
2017-03-04 11:20:57 +01:00
// mock stuff
$messageBag = new MessageBag;
$messageBag->add('fake', 'fake error');
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn($messageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
2018-02-28 15:50:00 +01:00
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$accountRepos->shouldReceive('findNull')->andReturn($account)->once();
2018-07-01 09:27:22 +02:00
$data = [
2017-03-04 11:20:57 +01:00
'destination_account_asset' => 2,
];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.convert.index', ['transfer', $withdrawal->id]));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexSameType(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
2017-03-04 11:20:57 +01:00
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$data = [
'destination_account_asset' => 2,
];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexSplit(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
2017-03-04 11:20:57 +01:00
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at')
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->orderBy('ct', 'DESC')
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
$data = [
'destination_account_asset' => 2,
];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexTransferDeposit(): void
2017-03-04 11:20:57 +01:00
{
2018-07-01 09:27:22 +02:00
// find transfer:
2018-09-02 20:27:26 +02:00
$transfer = $this->getRandomTransfer();
2018-07-01 09:27:22 +02:00
2017-03-04 11:20:57 +01:00
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
2017-03-04 15:29:20 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2017-06-28 18:05:38 +02:00
$accountRepos->shouldReceive('store')->andReturn(new Account)->once();
2017-03-04 15:29:20 +01:00
2018-02-28 15:50:00 +01:00
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
2018-07-01 09:27:22 +02:00
$data = ['source_account_revenue' => 'New rev'];
2017-03-04 11:20:57 +01:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $transfer->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$transfer->id]));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexWithdrawalDeposit(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
2017-11-22 21:12:27 +01:00
$data = ['source_account_revenue' => 'New revenue name.'];
2017-03-04 11:20:57 +01:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-06-28 18:05:38 +02:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexWithdrawalDepositEmptyName(): void
2017-06-28 18:05:38 +02:00
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-06-28 18:05:38 +02:00
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
2017-11-22 21:12:27 +01:00
$data = ['source_account_revenue' => ''];
2017-06-28 18:05:38 +02:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
2017-03-04 11:20:57 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testPostIndexWithdrawalTransfer(): void
2017-03-04 11:20:57 +01:00
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-04 11:20:57 +01:00
2017-03-04 15:29:20 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-02-28 15:50:00 +01:00
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
2018-02-28 15:50:00 +01:00
$data = ['destination_account_asset' => 2,];
2017-02-12 18:40:39 +01:00
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
2017-02-16 22:33:32 +01:00
}