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

139 lines
6.1 KiB
PHP
Raw Normal View History

2017-03-25 07:41:17 -05:00
<?php
/**
* BudgetReportControllerTest.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-03-25 07:41:17 -05: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 13:17:10 -05:00
use FireflyIII\Helpers\Filter\TransferFilter;
2017-03-25 07:41:17 -05: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 00:08:50 -05:00
use Log;
2017-03-25 07:41:17 -05:00
use Tests\TestCase;
2017-08-12 03:27:45 -05:00
/**
* Class BudgetReportControllerTest
*/
2017-03-25 07:41:17 -05:00
class BudgetReportControllerTest extends TestCase
{
2018-03-24 00:08:50 -05:00
/**
*
*/
public function setUp()
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
2018-03-24 00:08:50 -05:00
}
2017-03-25 07:41:17 -05:00
/**
2018-07-01 02:27:22 -05:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 07:41:17 -05:00
*/
2018-05-11 12:58:10 -05:00
public function testAccountExpense(): void
2017-03-25 07:41:17 -05:00
{
2018-02-28 08:50:00 -06:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
2017-03-25 07:41:17 -05:00
2018-02-28 08:50:00 -06:00
2017-03-25 07:41:17 -05: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 02:27:22 -05:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 07:41:17 -05:00
*/
2018-05-11 12:58:10 -05:00
public function testBudgetExpense(): void
2017-03-25 07:41:17 -05:00
{
2018-02-28 08:50:00 -06:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
2017-03-25 07:41:17 -05: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 02:27:22 -05:00
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
2017-03-25 07:41:17 -05:00
*/
2018-05-11 12:58:10 -05:00
public function testMainChart(): void
2017-03-25 07:41:17 -05:00
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
2017-03-25 07:41:17 -05:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
2017-04-08 03:20:34 -05: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 07:41:17 -05: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 13:17:10 -05: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 07:41:17 -05:00
$collector->shouldReceive('setBudgets')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));
2017-03-25 07:41:17 -05: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 01:09:42 -05:00
}