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

111 lines
4.0 KiB
PHP
Raw Normal View History

2018-07-14 04:45:05 -05:00
<?php
/**
* IndexControllerTest.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\Account;
2019-06-22 03:25:34 -05:00
use Amount;
use FireflyIII\Models\Preference;
2018-07-14 04:45:05 -05:00
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-07-14 04:45:05 -05:00
use Illuminate\Support\Collection;
use Log;
use Mockery;
2019-06-22 03:25:34 -05:00
use Preferences;
2018-07-14 04:45:05 -05:00
use Steam;
use Tests\TestCase;
2019-06-22 03:25:34 -05:00
2018-07-14 04:45:05 -05:00
/**
* Class IndexControllerTest
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-07-14 04:45:05 -05:00
}
/**
* @covers \FireflyIII\Http\Controllers\Account\IndexController
* @dataProvider dateRangeProvider
*
* @param string $range
*
*/
public function testIndex(string $range): void
{
// mock stuff
2019-06-22 03:25:34 -05:00
$account = $this->getRandomAsset();
2018-07-14 04:45:05 -05:00
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
2019-06-22 03:25:34 -05:00
$euro = $this->getEuro();
// mock hasRole for user repository:
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2018-07-14 04:45:05 -05:00
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2019-06-22 03:25:34 -05:00
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
2018-07-14 04:45:05 -05:00
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
Steam::shouldReceive('getLastActivities')->andReturn([]);
2019-06-22 03:25:34 -05:00
// mock calls to Preferences:
$this->mockDefaultPreferences();
// mock calls to Configuration:
$this->mockDefaultConfiguration();
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Amount::shouldReceive('formatAnything')->andReturn('123');
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
2018-08-05 13:42:45 -05:00
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
2019-06-22 03:25:34 -05:00
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123');
2018-07-14 04:45:05 -05:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('accounts.index', ['asset']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
}