firefly-iii/tests/Feature/Controllers/Account/ShowControllerTest.php

163 lines
6.6 KiB
PHP
Raw Normal View History

<?php
/**
2018-07-14 04:45:05 -05:00
* ShowControllerTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05: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 07:42:21 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2018-07-14 04:45:05 -05:00
declare(strict_types=1);
2018-07-14 04:45:05 -05:00
namespace Tests\Feature\Controllers\Account;
2019-06-22 22:53:01 -05:00
use Amount;
use Carbon\Carbon;
2019-06-22 22:53:01 -05:00
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
2017-03-04 12:14:36 -06:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
2018-03-24 00:08:50 -05:00
use Log;
use Mockery;
2019-06-22 22:53:01 -05:00
use Preferences;
use Tests\TestCase;
2018-03-31 14:05:06 -05:00
2017-03-05 04:18:34 -06:00
/**
*
2018-07-14 04:45:05 -05:00
* Class ShowControllerTest
2017-03-05 04:18:34 -06:00
*/
2018-07-14 04:45:05 -05:00
class ShowControllerTest extends TestCase
{
2018-03-24 00:08:50 -05:00
/**
*
*/
2018-07-14 04:45:05 -05:00
public function setUp(): void
2018-03-24 00:08:50 -05:00
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-03-24 00:08:50 -05:00
}
/**
2018-07-14 04:45:05 -05:00
* @covers \FireflyIII\Http\Controllers\Account\ShowController
* @dataProvider dateRangeProvider
*
* @param string $range
*/
2018-05-11 12:58:10 -05:00
public function testShow(string $range): void
{
2018-12-12 13:30:25 -06:00
Log::info(sprintf('testShow(%s)', $range));
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
2017-03-04 12:14:36 -06:00
// mock stuff:
//$tasker = $this->mock(AccountTaskerInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
//$accountRepos = $this->mock(AccountRepositoryInterface::class);
2019-06-22 22:53:01 -05:00
$collector = $this->mock(GroupCollectorInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journal = $this->getRandomWithdrawalAsArray();
$group = $this->getRandomWithdrawalGroup();
$asset = $this->getRandomAsset();
$euro = $this->getEuro();
$this->mockDefaultSession();
2018-02-28 08:50:00 -06:00
2019-06-22 22:53:01 -05:00
// amount mocks:
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
2019-06-22 22:53:01 -05:00
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
2018-03-22 23:31:30 -05:00
2019-06-22 22:53:01 -05:00
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$this->mockLastActivity();
2019-06-22 22:53:01 -05: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();
$collector->shouldReceive('setPage')->andReturnSelf();
2019-06-22 22:53:01 -05:00
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2019-06-22 22:53:01 -05:00
$response = $this->get(route('accounts.show', [$asset->id]));
$response->assertStatus(200);
2018-06-01 15:04:52 -05:00
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-07-14 04:45:05 -05:00
* @covers \FireflyIII\Http\Controllers\Account\ShowController
2018-06-01 15:04:52 -05:00
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowAll(string $range): void
{
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff:
2019-06-22 22:53:01 -05:00
$tasker = $this->mock(AccountTaskerInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
2018-09-03 11:52:46 -05:00
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2019-06-22 22:53:01 -05: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 11:52:46 -05:00
$this->mockDefaultSession();
2018-03-03 07:24:06 -06:00
2019-06-22 22:53:01 -05:00
$repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
2019-06-22 22:53:01 -05:00
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
// mock hasRole for user repository:
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2019-06-22 22:53:01 -05:00
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
2017-03-04 12:14:36 -06:00
$collector->shouldReceive('setPage')->andReturnSelf();
2019-06-22 22:53:01 -05:00
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
2018-02-28 08:50:00 -06:00
2017-03-04 12:14:36 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2019-06-22 22:53:01 -05:00
$response = $this->get(route('accounts.show.all', [$asset->id]));
2017-03-04 12:14:36 -06:00
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
2018-07-22 13:33:17 -05:00
}