Files
firefly-iii/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php

154 lines
7.1 KiB
PHP
Raw Normal View History

2017-03-25 13:41:17 +01:00
<?php
/**
* BudgetReportControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
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-03-25 13:41:17 +01:00
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
2017-04-28 20:17:10 +02:00
use FireflyIII\Helpers\Filter\TransferFilter;
2018-12-12 20:30:25 +01:00
use FireflyIII\Helpers\FiscalHelperInterface;
2017-03-25 13:41:17 +01:00
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
2018-03-24 06:08:50 +01:00
use Log;
2017-03-25 13:41:17 +01:00
use Tests\TestCase;
2017-08-12 10:27:45 +02:00
/**
* Class BudgetReportControllerTest
*/
2017-03-25 13:41:17 +01:00
class BudgetReportControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
2018-03-24 06:08:50 +01:00
{
parent::setUp();
2018-09-03 18:52:46 +02:00
Log::info(sprintf('Now in %s.', \get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-03-25 13:41:17 +01:00
/**
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 13:41:17 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testAccountExpense(): void
2017-03-25 13:41:17 +01:00
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
2018-12-12 20:30:25 +01:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2018-02-28 15:50:00 +01:00
2017-03-25 13:41:17 +01:00
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'account'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.budget.account-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 13:41:17 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testBudgetExpense(): void
2017-03-25 13:41:17 +01:00
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
2018-12-12 20:30:25 +01:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2017-03-25 13:41:17 +01:00
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'budget'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.budget.budget-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 13:41:17 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testMainChart(): void
2017-03-25 13:41:17 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
2018-12-12 20:30:25 +01:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2017-03-25 13:41:17 +01:00
2017-04-08 10:20:34 +02:00
$one = factory(BudgetLimit::class)->make();
$one->budget_id = 1;
$two = factory(BudgetLimit::class)->make();
$two->budget_id = 1;
$two->start_date = new Carbon('2012-01-01');
$two->end_date = new Carbon('2012-01-31');
$transaction = factory(Transaction::class)->make();
$transaction->transaction_amount = '-100';
$transaction->destination_amount = '-100';
$transaction->amount = '-100';
$transaction->opposing_account_id = 8;
2017-03-25 13:41:17 +01:00
$budgetRepos->shouldReceive('getAllBudgetLimits')->andReturn(new Collection([$one, $two]))->once();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
2017-04-28 20:17:10 +02:00
$collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
$collector->shouldReceive('addFilter')->withArgs([OpposingAccountFilter::class])->andReturnSelf();
$collector->shouldReceive('addFilter')->withArgs([PositiveAmountFilter::class])->andReturnSelf();
2017-03-25 13:41:17 +01:00
$collector->shouldReceive('setBudgets')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));
2017-03-25 13:41:17 +01:00
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.budget.main', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
2017-07-07 08:09:42 +02:00
}