2017-02-12 11:25:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* ShowControllerTest.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
2017-02-12 11:25:17 +01:00
|
|
|
*
|
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 11:25:17 +01:00
|
|
|
*/
|
2018-07-14 11:45:05 +02:00
|
|
|
|
2017-04-22 07:05:31 +02:00
|
|
|
declare(strict_types=1);
|
2017-02-12 11:25:17 +01:00
|
|
|
|
2018-07-14 11:45:05 +02:00
|
|
|
namespace Tests\Feature\Controllers\Account;
|
2017-02-12 11:25:17 +01:00
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2018-08-11 14:33:47 +02:00
|
|
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
2018-12-12 20:30:25 +01:00
|
|
|
use FireflyIII\Helpers\FiscalHelperInterface;
|
2017-03-04 19:14:36 +01:00
|
|
|
use FireflyIII\Models\Transaction;
|
2017-04-22 07:05:31 +02:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2017-03-05 11:18:34 +01:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2017-02-12 11:25:17 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
2017-03-04 19:14:36 +01:00
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2017-03-05 11:18:34 +01:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2018-09-03 08:41:03 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2017-02-12 11:25:17 +01:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Illuminate\Support\Collection;
|
2018-03-24 06:08:50 +01:00
|
|
|
use Log;
|
2018-09-03 08:41:03 +02:00
|
|
|
use Mockery;
|
2017-02-12 11:25:17 +01:00
|
|
|
use Tests\TestCase;
|
2018-03-31 21:05:06 +02:00
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
/**
|
|
|
|
*
|
2018-07-14 11:45:05 +02:00
|
|
|
* Class ShowControllerTest
|
2017-03-05 11:18:34 +01:00
|
|
|
*/
|
2018-07-14 11:45:05 +02:00
|
|
|
class ShowControllerTest extends TestCase
|
2017-02-12 11:25:17 +01:00
|
|
|
{
|
2018-03-24 06:08:50 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-07-14 11:45:05 +02:00
|
|
|
public function setUp(): void
|
2018-03-24 06:08:50 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-03-24 06:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-12 11:25:17 +01:00
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2017-02-12 11:25:17 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShow(string $range): void
|
2017-02-12 11:25:17 +01:00
|
|
|
{
|
2019-04-09 15:32:48 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShow(%s)', $range));
|
2017-02-12 11:25:17 +01:00
|
|
|
$date = new Carbon;
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
// mock stuff:
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2018-03-02 17:07:32 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
|
|
|
|
// mock hasRole for user repository:
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
2018-02-28 15:50:00 +01:00
|
|
|
|
|
|
|
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-02-12 11:25:17 +01:00
|
|
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
|
|
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
|
|
|
|
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
2017-03-10 18:54:50 +01:00
|
|
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
2018-03-23 05:31:30 +01:00
|
|
|
$repository->shouldReceive('getMetaValue')->andReturn('');
|
2018-08-23 18:33:39 +02:00
|
|
|
$repository->shouldReceive('isLiability')->andReturn(false);
|
2018-03-23 05:31:30 +01:00
|
|
|
|
2017-02-12 11:25:17 +01:00
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
$transaction = factory(Transaction::class)->make();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector = $this->mock(TransactionCollectorInterface::class);
|
2017-02-12 11:25:17 +01:00
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
2017-04-22 07:05:31 +02:00
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
2017-02-12 11:25:17 +01:00
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2017-04-22 07:05:31 +02:00
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));
|
|
|
|
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10));
|
2017-02-12 11:25:17 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('accounts.show', [1]));
|
|
|
|
$response->assertStatus(200);
|
2018-06-01 22:04:52 +02:00
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2018-06-01 22:04:52 +02:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
|
|
|
public function testShowAll(string $range): void
|
|
|
|
{
|
2019-04-09 15:32:48 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowAll(%s)', $range));
|
2018-06-01 22:04:52 +02:00
|
|
|
$date = new Carbon;
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
|
|
|
// mock stuff:
|
|
|
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
// mock hasRole for user repository:
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
2018-06-01 22:04:52 +02:00
|
|
|
|
|
|
|
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
|
|
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
|
|
|
|
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
|
|
|
$repository->shouldReceive('getMetaValue')->andReturn('');
|
2018-08-23 18:33:39 +02:00
|
|
|
$repository->shouldReceive('isLiability')->andReturn(false);
|
2018-06-01 22:04:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
$transaction = factory(Transaction::class)->make();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector = $this->mock(TransactionCollectorInterface::class);
|
2018-06-01 22:04:52 +02:00
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));
|
|
|
|
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10));
|
2018-06-01 22:04:52 +02:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('accounts.show.all', [1]));
|
|
|
|
$response->assertStatus(200);
|
2017-02-12 11:25:17 +01:00
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2018-03-03 14:24:06 +01:00
|
|
|
/**
|
2018-08-06 19:14:30 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2018-03-03 14:24:06 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowBrokenBadDates(): void
|
2018-03-03 14:24:06 +01:00
|
|
|
{
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowBrokenBadDates(%s)', ''));
|
2018-03-03 14:24:06 +01:00
|
|
|
// mock
|
2018-09-03 08:41:03 +02:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-12-12 20:30:25 +01:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
|
|
$date = new Carbon;
|
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2018-09-03 18:52:46 +02:00
|
|
|
|
|
|
|
$accountRepos->shouldReceive('isLiability')->atLeast()->once()->andReturn(false);
|
|
|
|
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2018-03-03 14:24:06 +01:00
|
|
|
$this->session(['start' => '2018-01-01', 'end' => '2017-12-01']);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$account = $this->user()->accounts()->where('account_type_id', 3)->orderBy('id', 'ASC')->whereNull('deleted_at')->first();
|
|
|
|
$response = $this->get(route('accounts.show', [$account->id, '2018-01-01', '2017-12-01']));
|
|
|
|
$response->assertStatus(500);
|
2018-09-03 18:52:46 +02:00
|
|
|
$response->assertSee('End is after start!');
|
2018-03-03 14:24:06 +01:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
/**
|
2018-08-06 19:14:30 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2017-03-04 19:14:36 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowBrokenInitial(): void
|
2017-03-04 19:14:36 +01:00
|
|
|
{
|
2019-04-09 15:32:48 +02:00
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowBrokenInitial(%s)', ''));
|
2017-03-12 21:24:34 +01:00
|
|
|
// mock
|
2018-03-02 17:07:32 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:19:06 +01:00
|
|
|
$date = new Carbon;
|
2017-03-04 19:14:36 +01:00
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$account = $this->user()->accounts()->where('account_type_id', 6)->orderBy('id', 'ASC')->whereNull('deleted_at')->first();
|
|
|
|
$response = $this->get(route('accounts.show', [$account->id]));
|
2018-08-09 19:44:36 +02:00
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertRedirect(route('index'));
|
|
|
|
$response->assertSessionHas('error');
|
2017-03-04 19:14:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2017-03-04 19:14:36 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowByDateEmpty(string $range): void
|
2017-03-04 19:14:36 +01:00
|
|
|
{
|
2019-04-09 15:32:48 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowByDateEmpty(%s)', $range));
|
2017-03-04 19:14:36 +01:00
|
|
|
// mock stuff
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector = $this->mock(TransactionCollectorInterface::class);
|
2018-03-02 17:07:32 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-02-28 15:50:00 +01:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
2018-12-12 20:30:25 +01:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
|
|
$date = new Carbon;
|
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2018-09-03 08:41:03 +02:00
|
|
|
|
|
|
|
// mock hasRole for user repository:
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
2018-09-03 08:41:03 +02:00
|
|
|
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-04 19:14:36 +01:00
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
2017-03-04 19:14:36 +01:00
|
|
|
|
2018-09-03 08:41:03 +02:00
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
$repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
|
2018-03-23 05:31:30 +01:00
|
|
|
$repository->shouldReceive('getMetaValue')->andReturn('');
|
2018-08-23 18:33:39 +02:00
|
|
|
$repository->shouldReceive('isLiability')->andReturn(false);
|
2017-04-22 07:05:31 +02:00
|
|
|
|
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
2018-08-11 14:33:47 +02:00
|
|
|
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
2017-03-04 19:14:36 +01:00
|
|
|
|
2018-02-28 15:50:00 +01:00
|
|
|
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2017-03-10 18:54:50 +01:00
|
|
|
$response = $this->get(route('accounts.show', [1, '2016-01-01']));
|
2017-03-04 19:14:36 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
2017-03-04 19:14:36 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowInitial(): void
|
2017-03-04 19:14:36 +01:00
|
|
|
{
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowInitial(%s)', ''));
|
2017-03-12 21:24:34 +01:00
|
|
|
// mock stuff
|
2018-03-02 17:07:32 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:19:06 +01:00
|
|
|
$date = new Carbon;
|
2017-03-04 19:14:36 +01:00
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$account = $this->user()->accounts()->where('account_type_id', 6)->orderBy('id', 'DESC')->whereNull('deleted_at')->first();
|
|
|
|
$response = $this->get(route('accounts.show', [$account->id]));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
2018-09-02 20:27:26 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
|
|
|
public function testShowLiability(string $range): void
|
|
|
|
{
|
2018-12-12 20:30:25 +01:00
|
|
|
Log::info(sprintf('testShowLiability(%s)', $range));
|
2018-09-02 20:27:26 +02:00
|
|
|
$date = new Carbon;
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
$account = $this->user()->accounts()->where('account_type_id', 12)->whereNull('deleted_at')->first();
|
|
|
|
|
|
|
|
// mock stuff:
|
|
|
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-09-03 08:41:03 +02:00
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
2018-09-02 20:27:26 +02:00
|
|
|
|
|
|
|
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
|
|
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
|
|
|
|
2018-09-03 08:41:03 +02:00
|
|
|
|
2018-09-02 20:27:26 +02:00
|
|
|
$repository->shouldReceive('getMetaValue')->andReturn('');
|
|
|
|
$repository->shouldReceive('isLiability')->andReturn(true);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('accounts.show', [$account->id]));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertRedirect(route('accounts.show.all', [$account->id]));
|
|
|
|
}
|
|
|
|
|
2018-07-22 20:33:17 +02:00
|
|
|
}
|