2017-02-12 10:58:16 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AccountControllerTest.php
|
|
|
|
* Copyright (c) 2017 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/>.
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2017-03-25 07:41:17 -05:00
|
|
|
declare(strict_types=1);
|
2017-02-12 10:58:16 -06:00
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers\Chart;
|
|
|
|
|
2017-03-11 15:28:51 -06:00
|
|
|
use Carbon\Carbon;
|
2019-07-24 12:02:41 -05:00
|
|
|
use Exception;
|
2017-03-11 15:28:51 -06:00
|
|
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
2019-06-25 12:24:01 -05:00
|
|
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
2019-06-29 12:47:31 -05:00
|
|
|
|
2019-06-23 03:40:46 -05:00
|
|
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
2017-03-25 07:41:17 -05:00
|
|
|
use FireflyIII\Models\Account;
|
2017-03-11 15:28:51 -06:00
|
|
|
use FireflyIII\Models\AccountType;
|
2019-06-25 12:24:01 -05:00
|
|
|
use FireflyIII\Models\Preference;
|
2017-03-25 07:41:17 -05:00
|
|
|
use FireflyIII\Models\Transaction;
|
2018-02-28 08:50:00 -06:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2017-03-11 15:28:51 -06:00
|
|
|
use FireflyIII\Models\TransactionType;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
2018-02-28 08:50:00 -06:00
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2017-03-11 15:28:51 -06:00
|
|
|
use Illuminate\Support\Collection;
|
2018-03-24 00:08:50 -05:00
|
|
|
use Log;
|
2018-09-04 02:52:19 -05:00
|
|
|
use Mockery;
|
2017-03-25 07:41:17 -05:00
|
|
|
use Preferences;
|
2017-03-11 15:28:51 -06:00
|
|
|
use Steam;
|
2017-02-12 10:58:16 -06:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2017-03-12 03:22:33 -05:00
|
|
|
/**
|
|
|
|
* Class AccountControllerTest
|
2019-07-24 12:02:41 -05:00
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2017-03-12 03:22:33 -05:00
|
|
|
*/
|
2017-02-12 10:58:16 -06:00
|
|
|
class AccountControllerTest extends TestCase
|
|
|
|
{
|
2018-03-24 00:08:50 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-09-02 13:27:26 -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
|
|
|
}
|
2017-03-17 10:34:57 -05:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testExpenseAccounts(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-02-28 08:50:00 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$euro = $this->getEuro();
|
|
|
|
$dollar = $this->getDollar();
|
2018-09-04 02:52:19 -05:00
|
|
|
|
2018-08-27 13:33:52 -05:00
|
|
|
// grab two expense accounts from the current user.
|
|
|
|
$accounts = $this->user()->accounts()->where('account_type_id', 4)->take(2)->get();
|
|
|
|
|
2019-06-25 12:24:01 -05:00
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
2018-08-27 13:33:52 -05:00
|
|
|
$firstId = $accounts->first()->id;
|
|
|
|
$secondId = $accounts->first()->id;
|
|
|
|
// for each a set of balances:
|
|
|
|
$start = [$firstId => [1 => '123.45', 2 => '200.01',], $secondId => [1 => '123.45', 2 => '200.01',],];
|
|
|
|
$end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
|
|
|
|
|
|
|
|
// return them when collected:
|
2019-01-27 05:30:52 -06:00
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])->andReturn($accounts);
|
2018-08-27 13:33:52 -05:00
|
|
|
|
|
|
|
// and return start and end balances:
|
|
|
|
Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
|
|
|
|
|
|
|
|
// currency should be looking for the currency ID's:
|
2019-06-25 12:24:01 -05:00
|
|
|
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($euro);
|
|
|
|
$currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn($dollar);
|
2018-08-27 13:33:52 -05:00
|
|
|
|
|
|
|
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
|
|
|
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.expense'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testExpenseBudget(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-09-04 02:52:19 -05:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2018-09-04 02:52:19 -05:00
|
|
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$this->mock(AccountRepositoryInterface::class);
|
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
$date = new Carbon;
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->atLeast()->once();
|
|
|
|
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-03-25 07:41:17 -05:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-03-25 07:41:17 -05:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testExpenseBudgetAll(string $range): void
|
2017-03-25 07:41:17 -05:00
|
|
|
{
|
2018-12-12 13:30:25 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
2017-03-25 07:41:17 -05:00
|
|
|
|
2018-09-10 13:22:02 -05:00
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
|
2019-06-25 12:24:01 -05:00
|
|
|
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
|
2019-04-09 08:32:48 -05:00
|
|
|
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
|
2017-03-25 07:41:17 -05:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.expense-budget-all', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testExpenseCategory(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2017-03-11 15:28:51 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2017-03-11 15:28:51 -06:00
|
|
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$this->mock(AccountRepositoryInterface::class);
|
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$category = $this->user()->categories()->find($withdrawal['category_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
|
|
|
$date = new Carbon;
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
|
|
|
|
|
|
|
|
2018-09-10 13:22:02 -05:00
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
|
2017-03-25 07:41:17 -05:00
|
|
|
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-03-25 07:41:17 -05:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-03-25 07:41:17 -05:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testExpenseCategoryAll(string $range): void
|
2017-03-25 07:41:17 -05:00
|
|
|
{
|
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2017-03-25 07:41:17 -05:00
|
|
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$category = $this->user()->categories()->find($withdrawal['category_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
2018-09-04 02:52:19 -05:00
|
|
|
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
2017-03-25 07:41:17 -05:00
|
|
|
|
2018-09-10 13:22:02 -05:00
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
|
2017-03-25 07:41:17 -05:00
|
|
|
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
2019-04-09 08:32:48 -05:00
|
|
|
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
|
2017-03-25 07:41:17 -05:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.expense-category-all', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testFrontpage(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-02-28 08:50:00 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-01-01 11:03:24 -06:00
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
2019-06-25 12:24:01 -05:00
|
|
|
|
2017-03-25 07:41:17 -05:00
|
|
|
// change the preference:
|
2019-06-25 12:24:01 -05:00
|
|
|
$emptyPref = new Preference;
|
|
|
|
$emptyPref->data = [];
|
|
|
|
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
|
|
|
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', []]);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
2017-03-25 07:41:17 -05:00
|
|
|
|
2017-03-11 15:28:51 -06:00
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
|
|
|
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
|
|
|
|
Steam::shouldReceive('balanceInRange')->andReturn([]);
|
|
|
|
$generator->shouldReceive('multiSet')->andReturn([]);
|
|
|
|
|
2018-02-28 08:50:00 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.frontpage'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testIncomeCategory(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2017-03-11 15:28:51 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2017-03-11 15:28:51 -06:00
|
|
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
2018-09-04 02:52:19 -05:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$category = $this->user()->categories()->find($withdrawal['category_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
|
|
|
$date = new Carbon;
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
|
|
|
|
2018-09-10 13:22:02 -05:00
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
|
2019-06-25 12:24:01 -05:00
|
|
|
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-03-25 07:41:17 -05:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-03-25 07:41:17 -05:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testIncomeCategoryAll(string $range): void
|
2017-03-25 07:41:17 -05:00
|
|
|
{
|
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
2017-03-25 07:41:17 -05:00
|
|
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-09-04 02:52:19 -05:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
$withdrawal = $this->getRandomWithdrawalAsArray();
|
|
|
|
$category = $this->user()->categories()->find($withdrawal['category_id']);
|
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
2017-03-25 07:41:17 -05:00
|
|
|
|
2018-09-10 13:22:02 -05:00
|
|
|
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
|
2019-06-25 12:24:01 -05:00
|
|
|
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
2019-04-09 08:32:48 -05:00
|
|
|
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
|
2017-03-25 07:41:17 -05:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.income-category-all', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testPeriod(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-12-12 13:30:25 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-09-04 02:52:19 -05:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
2018-12-12 13:30:25 -06:00
|
|
|
$date = new Carbon;
|
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
2017-03-11 15:28:51 -06:00
|
|
|
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
|
|
|
|
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
|
|
|
|
$generator->shouldReceive('singleSet')->andReturn([]);
|
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2018-02-28 08:50:00 -06:00
|
|
|
$response = $this->get(route('chart.account.period', [1, '2012-01-01', '2012-01-31']));
|
2017-02-12 10:58:16 -06:00
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testReport(): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-02-28 08:50:00 -06:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-09-04 02:52:19 -05:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
2018-12-12 13:30:25 -06:00
|
|
|
$date = new Carbon;
|
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
|
|
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
|
2018-09-04 02:52:19 -05:00
|
|
|
|
|
|
|
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1), null);
|
|
|
|
|
2018-03-28 12:38:20 -05:00
|
|
|
$generator->shouldReceive('multiSet')->andReturn([]);
|
2017-03-17 10:34:57 -05:00
|
|
|
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
2018-06-01 15:04:52 -05:00
|
|
|
$response = $this->get(route('chart.account.report', ['1,2', '20120101', '20120131']));
|
2017-02-12 10:58:16 -06:00
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 02:27:22 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Chart\AccountController
|
2017-02-12 10:58:16 -06:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2019-07-24 12:02:41 -05:00
|
|
|
* @throws Exception
|
2017-02-12 10:58:16 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testRevenueAccounts(string $range): void
|
2017-02-12 10:58:16 -06:00
|
|
|
{
|
2018-08-27 13:33:52 -05:00
|
|
|
$generator = $this->mock(GeneratorInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2018-12-12 13:30:25 -06:00
|
|
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
2019-06-25 12:24:01 -05:00
|
|
|
|
|
|
|
// mock default session
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
|
|
|
|
|
|
|
|
2019-01-01 11:03:24 -06:00
|
|
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
|
|
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
2018-08-27 13:33:52 -05:00
|
|
|
// grab two expense accounts from the current user.
|
|
|
|
$accounts = $this->user()->accounts()->where('account_type_id', 5)->take(2)->get();
|
|
|
|
|
|
|
|
$firstId = $accounts->first()->id;
|
|
|
|
$secondId = $accounts->first()->id;
|
|
|
|
// for each a set of balances:
|
|
|
|
$start = [$firstId => [1 => '123.45', 2 => '200.01',], $secondId => [1 => '123.45', 2 => '200.01',],];
|
|
|
|
$end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
|
|
|
|
|
|
|
|
// return them when collected:
|
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->andReturn($accounts);
|
|
|
|
|
|
|
|
// and return start and end balances:
|
|
|
|
Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
|
|
|
|
|
|
|
|
// currency should be looking for the currency ID's:
|
|
|
|
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));
|
|
|
|
$currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));
|
|
|
|
|
|
|
|
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
2017-03-11 15:28:51 -06:00
|
|
|
|
2017-02-12 10:58:16 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('chart.account.revenue'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-16 15:33:32 -06:00
|
|
|
}
|