2017-02-12 11:25:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* ShowControllerTest.php
|
2020-02-16 13:59:55 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-02-12 11:25:17 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:45:03 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://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
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
use Amount;
|
2017-02-12 11:25:17 +01:00
|
|
|
use Carbon\Carbon;
|
2019-07-23 17:33:23 +02:00
|
|
|
use Exception;
|
2019-06-23 05:53:01 +02:00
|
|
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
|
|
|
use FireflyIII\Models\Preference;
|
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;
|
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;
|
2018-03-24 06:08:50 +01:00
|
|
|
use Log;
|
2018-09-03 08:41:03 +02:00
|
|
|
use Mockery;
|
2019-06-23 05:53:01 +02:00
|
|
|
use Preferences;
|
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
|
2019-07-23 17:33:23 +02:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
2019-08-17 10:48:28 +02:00
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
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
|
2019-07-23 17:33:23 +02:00
|
|
|
* @throws Exception
|
2017-02-12 11:25:17 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShow(string $range): void
|
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:
|
2019-07-23 17:33:23 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
2019-07-23 17:33:23 +02:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$journal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$group = $this->getRandomWithdrawalGroup();
|
|
|
|
$asset = $this->getRandomAsset();
|
|
|
|
$euro = $this->getEuro();
|
2018-09-03 08:41:03 +02:00
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-02-28 15:50:00 +01:00
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
// amount mocks:
|
|
|
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
2017-02-12 11:25:17 +01:00
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
2017-03-10 18:54:50 +01:00
|
|
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
2020-01-05 19:29:28 +01:00
|
|
|
$repository->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
|
2018-03-23 05:31:30 +01:00
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
// list size
|
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 50;
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockLastActivity();
|
2019-06-23 05:53:01 +02:00
|
|
|
// mock hasRole for user repository:
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
2017-02-12 11:25:17 +01:00
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2019-06-23 05:53:01 +02:00
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
|
|
|
|
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
|
2019-09-04 21:05:50 +02:00
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
|
2017-02-12 11:25:17 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2019-06-23 05:53:01 +02:00
|
|
|
$response = $this->get(route('accounts.show', [$asset->id]));
|
2017-02-12 11:25:17 +01:00
|
|
|
$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
|
2019-07-23 17:33:23 +02:00
|
|
|
* @throws Exception
|
2018-06-01 22:04:52 +02:00
|
|
|
*/
|
|
|
|
public function testShowAll(string $range): void
|
|
|
|
{
|
|
|
|
$date = new Carbon;
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
// mock stuff:
|
2019-07-23 17:33:23 +02:00
|
|
|
$this->mock(AccountTaskerInterface::class);
|
2019-07-24 19:02:41 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-07-23 17:33:23 +02:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$this->mock(AccountRepositoryInterface::class);
|
2019-07-24 19:02:41 +02:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
|
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$journal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$group = $this->getRandomWithdrawalGroup();
|
|
|
|
$euro = $this->getEuro();
|
|
|
|
$asset = $this->getRandomAsset();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-03-03 14:24:06 +01:00
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
$repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
|
|
|
|
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
|
|
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
2020-01-05 19:29:28 +01:00
|
|
|
$repository->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
|
2019-04-09 15:32:48 +02:00
|
|
|
|
2019-06-23 05:53:01 +02:00
|
|
|
// list size
|
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 50;
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
2020-01-05 19:29:28 +01:00
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
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();
|
2019-06-23 05:53:01 +02:00
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
2017-03-04 19:14:36 +01:00
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2019-06-23 05:53:01 +02:00
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
|
|
|
|
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
|
2019-09-04 21:05:50 +02:00
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
2019-06-23 05:53:01 +02:00
|
|
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
|
2018-02-28 15:50:00 +01:00
|
|
|
|
2017-03-04 19:14:36 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2019-06-23 05:53:01 +02:00
|
|
|
$response = $this->get(route('accounts.show.all', [$asset->id]));
|
2017-03-04 19:14:36 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
2018-07-22 20:33:17 +02:00
|
|
|
}
|