mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up some tests
This commit is contained in:
@@ -103,6 +103,8 @@ class ShowControllerTest extends TestCase
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -154,6 +156,7 @@ class ShowControllerTest extends TestCase
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AmountControllerTest.php
|
||||
* Copyright (c) 2018 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\Budget;
|
||||
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class AmountControllerTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class AmountControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testAmount(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||
$response->assertStatus(200);
|
||||
// assert some reactions:
|
||||
$response->assertSee($budget->name);
|
||||
$response->assertSee('"amount":"200"');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testAmountLargeDiff(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
|
||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Usually you budget about 200 per day.');
|
||||
$response->assertSee($budget->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testPostUpdateIncome(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('setAvailableBudget');
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.income.post'), $data);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testUpdateIncome(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
@@ -30,12 +30,17 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\Support\TestDataTrait;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -47,6 +52,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
use TestDataTrait;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -69,35 +75,31 @@ class IndexControllerTest extends TestCase
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||
$budgetInfo = [
|
||||
$budget->id => [
|
||||
'spent' => '0',
|
||||
'budgeted' => '0',
|
||||
'currentRep' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('cleanupBudgets')->atLeast()->once();
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
|
||||
|
||||
$blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
|
||||
|
||||
$currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
|
||||
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -113,6 +115,7 @@ class IndexControllerTest extends TestCase
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testIndexOutOfRange(string $range): void
|
||||
@@ -135,27 +138,29 @@ class IndexControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
|
||||
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$repository->shouldReceive('cleanupBudgets')->atLeast()->once();
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
$abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
|
||||
$blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
|
||||
$currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -173,6 +178,7 @@ class IndexControllerTest extends TestCase
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testIndexWithDate(string $range): void
|
||||
@@ -195,25 +201,27 @@ class IndexControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
$repository->shouldReceive('cleanupBudgets')->atLeast()->once();
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
|
||||
$blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
|
||||
$currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -229,6 +237,7 @@ class IndexControllerTest extends TestCase
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testIndexWithInvalidDate(string $range): void
|
||||
@@ -240,6 +249,11 @@ class IndexControllerTest extends TestCase
|
||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
@@ -264,12 +278,13 @@ class IndexControllerTest extends TestCase
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$data = [
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$data = [
|
||||
'budgetIds' => [1, 2],
|
||||
'page' => 1,
|
||||
];
|
||||
|
@@ -30,7 +30,9 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -96,6 +98,8 @@ class ShowControllerTest extends TestCase
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||
|
||||
@@ -140,6 +144,7 @@ class ShowControllerTest extends TestCase
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
try {
|
||||
@@ -170,10 +175,10 @@ class ShowControllerTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
|
||||
|
||||
// mock calls
|
||||
$pref = new Preference;
|
||||
@@ -189,14 +194,11 @@ class ShowControllerTest extends TestCase
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
$blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]))->atLeast()->once();
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-1')->atLeast()->once();
|
||||
|
||||
try {
|
||||
$date = new Carbon;
|
||||
@@ -226,7 +228,8 @@ class ShowControllerTest extends TestCase
|
||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
@@ -238,15 +241,14 @@ class ShowControllerTest extends TestCase
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||
$blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -30,11 +30,15 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\Support\TestDataTrait;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -45,6 +49,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class BudgetControllerTest extends TestCase
|
||||
{
|
||||
use TestDataTrait;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -64,6 +69,10 @@ class BudgetControllerTest extends TestCase
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$date = new Carbon('2015-01-01');
|
||||
} catch (Exception $e) {
|
||||
@@ -74,9 +83,9 @@ class BudgetControllerTest extends TestCase
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$repository->shouldReceive('firstUseDate')->andReturn($date)->once();
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
|
||||
$generator->shouldReceive('singleSet')->andReturn([])->once();
|
||||
$repository->shouldReceive('firstUseDate')->andReturn($date)->atLeast()->once();
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
$generator->shouldReceive('singleSet')->andReturn([])->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -94,13 +103,16 @@ class BudgetControllerTest extends TestCase
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
|
||||
$generator->shouldReceive('singleSet')->once()->andReturn([]);
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
$generator->shouldReceive('singleSet')->andReturn([])->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -115,6 +127,10 @@ class BudgetControllerTest extends TestCase
|
||||
{
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$this->mock(GeneratorInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$budget = $this->getRandomBudget();
|
||||
$limit = BudgetLimit::where('budget_id', '!=', $budget->id)->first();
|
||||
|
||||
@@ -139,8 +155,12 @@ class BudgetControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
@@ -151,7 +171,7 @@ class BudgetControllerTest extends TestCase
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
|
||||
$generator->shouldReceive('pieChart')->once()->andReturn([]);
|
||||
$generator->shouldReceive('pieChart')->atLeast()->once()->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -168,9 +188,13 @@ class BudgetControllerTest extends TestCase
|
||||
public function testExpenseCategory(string $range): void
|
||||
{
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$catRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$catRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$category = $this->user()->categories()->find($withdrawal['category_id']);
|
||||
|
||||
@@ -183,9 +207,9 @@ class BudgetControllerTest extends TestCase
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
|
||||
$catRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
|
||||
$catRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->atLeast()->once();
|
||||
|
||||
$generator->shouldReceive('pieChart')->once()->andReturn([]);
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -205,21 +229,25 @@ class BudgetControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
|
||||
$collector->shouldReceive('withAccountInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->atLeast()->once();
|
||||
|
||||
$generator->shouldReceive('pieChart')->once()->andReturn([]);
|
||||
|
||||
@@ -237,9 +265,13 @@ class BudgetControllerTest extends TestCase
|
||||
*/
|
||||
public function testFrontPage(string $range): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$budget = $this->getRandomBudget();
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
|
||||
@@ -248,16 +280,16 @@ class BudgetControllerTest extends TestCase
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->atLeast()->once()->andReturn(new Collection([$budgetLimit]));
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
|
||||
|
||||
$generator->shouldReceive('multiSet')->once()->andReturn([]);
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -277,17 +309,21 @@ class BudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
$limit1 = $this->getRandomBudgetLimit();
|
||||
$limit2 = $this->getRandomBudgetLimit();
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$budget = $this->getRandomBudget();
|
||||
$limit1 = $this->getRandomBudgetLimit();
|
||||
$limit2 = $this->getRandomBudgetLimit();
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$limit1, $limit2]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$limit1, $limit2]));
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
@@ -314,20 +350,23 @@ class BudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$budget = $this->getRandomBudget();
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
|
||||
$blRepos->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
|
||||
//$collector->shouldReceive('getTransactions')->andReturn([$withdrawal])->once();
|
||||
$collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
|
||||
|
||||
$generator->shouldReceive('multiSet')->once()->andReturn([]);
|
||||
@@ -347,7 +386,11 @@ class BudgetControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$date = new Carbon;
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
@@ -357,12 +400,12 @@ class BudgetControllerTest extends TestCase
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$repository->shouldReceive('getBudgetPeriodReport')->andReturn([])->once();
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$blRepos->shouldReceive('find')->atLeast()->once()->andReturn($budgetLimit);
|
||||
$generator->shouldReceive('multiSet')->once()->andReturn([]);
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.budget.period', [$budgetLimit->budget_id, '1', '20120101', '20120131']));
|
||||
$response = $this->get(route('chart.budget.period', [$budgetLimit->budget_id, 1, 1, '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -374,7 +417,11 @@ class BudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
|
||||
|
||||
$date = new Carbon;
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
@@ -383,11 +430,12 @@ class BudgetControllerTest extends TestCase
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$repository->shouldReceive('getNoBudgetPeriodReport')->andReturn([])->once();
|
||||
$generator->shouldReceive('singleSet')->once()->andReturn([]);
|
||||
|
||||
$nbRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.budget.period.no-budget', ['1', '20120101', '20120131']));
|
||||
$response = $this->get(route('chart.budget.period.no-budget', ['1','1', '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
@@ -29,9 +29,11 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\Support\TestDataTrait;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
@@ -43,6 +45,8 @@ use Tests\TestCase;
|
||||
*/
|
||||
class BudgetReportControllerTest extends TestCase
|
||||
{
|
||||
use TestDataTrait;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -52,28 +56,6 @@ class BudgetReportControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
|
||||
*/
|
||||
public function testAccountExpense(): void
|
||||
{
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
|
||||
*/
|
||||
@@ -82,15 +64,18 @@ class BudgetReportControllerTest extends TestCase
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
|
||||
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->once();
|
||||
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.budget.budget-expense', ['1', '1', '20120101', '20120131', 0]));
|
||||
@@ -108,6 +93,7 @@ class BudgetReportControllerTest extends TestCase
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon;
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$asset = $this->getRandomAsset();
|
||||
@@ -127,16 +113,9 @@ class BudgetReportControllerTest extends TestCase
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$budgetRepos->shouldReceive('getAllBudgetLimits')->andReturn(new Collection([$limit1, $limit2, $limit3]))->once();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
|
||||
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudgets')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -27,8 +27,10 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\Support\TestDataTrait;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
@@ -40,6 +42,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class CategoryReportControllerTest extends TestCase
|
||||
{
|
||||
use TestDataTrait;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -49,47 +52,6 @@ class CategoryReportControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
|
||||
*/
|
||||
public function testAccountExpense(): void
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.account-expense', ['1', '1', '20120101', '20120131', 0]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
|
||||
*/
|
||||
public function testAccountIncome(): void
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.account-income', ['1', '1', '20120101', '20120131', 0]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
|
||||
@@ -98,6 +60,7 @@ class CategoryReportControllerTest extends TestCase
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
@@ -105,7 +68,9 @@ class CategoryReportControllerTest extends TestCase
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->once();
|
||||
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
|
||||
|
||||
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.category-expense', ['1', '1', '20120101', '20120131', 0]));
|
||||
@@ -119,14 +84,16 @@ class CategoryReportControllerTest extends TestCase
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$generator->shouldReceive('pieChart')->andReturn([])->once();
|
||||
$generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
|
||||
|
||||
$opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.category-income', ['1', '1', '20120101', '20120131', 0]));
|
||||
@@ -141,24 +108,19 @@ class CategoryReportControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon;
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setCategories')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
|
||||
$opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.main', ['1', '1', '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
|
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ExpenseReportControllerTest.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\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ExpenseReportControllerTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class ExpenseReportControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController
|
||||
*/
|
||||
public function testMainChart(): void
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$expense = $this->getRandomExpense();
|
||||
$date = new Carbon;
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.expense.main', ['1', $expense->id, '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same test, but with a deposit
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController
|
||||
*/
|
||||
public function testMainChartDeposit(): void
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$expense = $this->getRandomExpense();
|
||||
$date = new Carbon;
|
||||
$deposit = $this->getRandomDepositAsArray();
|
||||
|
||||
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$deposit])->atLeast()->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.expense.main', ['1', $expense->id, '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
@@ -1,234 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ExpenseControllerTest.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\Report;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ExpenseControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ExpenseControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController
|
||||
*/
|
||||
public function testBudget(): void
|
||||
{
|
||||
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$expense = $this->getRandomExpense();
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$date = new Carbon;
|
||||
$transactions = [$this->getRandomWithdrawalAsArray()];
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
|
||||
// dont care about any calls, just return a default set of fake transactions:
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn($transactions)->atLeast()->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.budget', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController
|
||||
*/
|
||||
public function testCategory(): void
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$expense = $this->getRandomExpense();
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$date = new Carbon;
|
||||
$one = $this->getRandomWithdrawalAsArray();
|
||||
$two = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
// two categories
|
||||
$oneCat = $this->getRandomCategory();
|
||||
$twoCat = $this->user()->categories()->where('id', '!=', $oneCat->id)->inRandomOrder()->first();
|
||||
|
||||
$one['category_id'] = $oneCat->id;
|
||||
$one['category_name'] = $oneCat->name;
|
||||
$two['category_id'] = $twoCat->id;
|
||||
$two['category_name'] = $twoCat->name;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([$one], [$two])->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.category', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController
|
||||
*/
|
||||
public function testSpent(): void
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$expense = $this->getRandomExpense();
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$date = new Carbon;
|
||||
$transactions = [$this->getRandomWithdrawalAsArray()];
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn($transactions)->atLeast()->once();
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.spent', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController
|
||||
*/
|
||||
public function testTopExpense(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in test %s', __METHOD__));
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$expense = $this->getRandomExpense();
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$date = new Carbon;
|
||||
$transactions = [$this->getRandomWithdrawalAsArray()];
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
||||
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn($transactions)->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController
|
||||
*/
|
||||
public function testTopIncome(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in test %s', __METHOD__));
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$expense = $this->getRandomExpense();
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$date = new Carbon;
|
||||
$transactions = [$this->getRandomWithdrawalAsArray()];
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn($transactions)->atLeast()->once();
|
||||
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user