2017-02-12 12:00:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BudgetControllerTest.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-02-12 12:00:11 +01:00
|
|
|
*/
|
2017-07-08 06:28:44 +02:00
|
|
|
declare(strict_types=1);
|
2017-02-12 12:00:11 +01:00
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers;
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
2017-03-05 11:18:34 +01:00
|
|
|
use FireflyIII\Models\Budget;
|
|
|
|
use FireflyIII\Models\BudgetLimit;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2017-02-12 12:21:44 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
2017-03-05 11:18:34 +01:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2017-02-12 12:21:44 +01:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Illuminate\Support\Collection;
|
2018-03-24 06:08:50 +01:00
|
|
|
use Log;
|
2017-02-12 12:00:11 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2017-08-12 10:27:45 +02:00
|
|
|
/**
|
|
|
|
* Class BudgetControllerTest
|
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
*/
|
2017-02-12 12:00:11 +01:00
|
|
|
class BudgetControllerTest extends TestCase
|
|
|
|
{
|
2018-03-24 06:08:50 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2018-04-28 10:27:33 +02:00
|
|
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
2018-03-24 06:08:50 +01:00
|
|
|
}
|
|
|
|
|
2017-12-17 14:06:14 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testAmount(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testAmount()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
2017-11-24 23:05:44 +01:00
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
2018-03-24 10:35:42 +01:00
|
|
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-08-27 11:07:14 +02:00
|
|
|
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2018-06-01 22:04:52 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
|
|
|
|
*/
|
|
|
|
public function testAmountLargeDiff(): void
|
|
|
|
{
|
|
|
|
Log::debug('Now in testAmount()');
|
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
|
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
|
|
|
|
|
|
|
|
|
|
|
$data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('Normally you budget about \u20ac10.00 per day.');
|
|
|
|
}
|
|
|
|
|
2017-03-18 11:02:02 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testAmountZero(): void
|
2017-03-18 11:02:02 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testAmountZero()');
|
2017-03-18 11:02:02 +01:00
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-18 11:02:02 +01:00
|
|
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
2017-11-24 23:05:44 +01:00
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
2018-03-24 10:35:42 +01:00
|
|
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
2017-03-18 11:02:02 +01:00
|
|
|
|
2017-08-27 11:07:14 +02:00
|
|
|
$data = ['amount' => 0, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
2017-03-18 11:02:02 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2018-06-01 22:04:52 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
|
|
|
|
*/
|
|
|
|
public function testAmountOutOfRange(): void
|
|
|
|
{
|
|
|
|
Log::debug('Now in testAmountOutOfRange()');
|
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
|
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
|
|
|
|
|
|
|
$today = new Carbon;
|
|
|
|
$start = $today->startOfMonth()->format('Y-m-d');
|
|
|
|
$end = $today->endOfMonth()->format('Y-m-d');
|
|
|
|
$data = ['amount' => 200, 'start' => $start, 'end' => $end];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::create
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreate(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testCreate()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-05 11:18:34 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('budgets.create'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::delete
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testDelete(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testDelete()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-05 11:18:34 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('budgets.delete', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::destroy
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testDestroy(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testDestroy()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$repository->shouldReceive('destroy')->andReturn(true);
|
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['budgets.delete.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.destroy', [1]));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::edit
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testEdit(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testEdit()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-05 11:18:34 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('budgets.edit', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
2017-06-28 18:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndex(string $range): void
|
2017-06-28 18:05:38 +02:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testIndex(%s)', $range));
|
2017-06-28 18:05:38 +02:00
|
|
|
// mock stuff
|
|
|
|
$budget = factory(Budget::class)->make();
|
|
|
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
|
|
|
|
|
|
// set budget limit to current month:
|
|
|
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
|
|
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
2017-09-27 15:46:08 +02:00
|
|
|
$budgetInfo = [
|
|
|
|
$budget->id => [
|
|
|
|
'spent' => '0',
|
|
|
|
'budgeted' => '0',
|
|
|
|
'currentRep' => false,
|
|
|
|
],
|
|
|
|
];
|
2017-06-28 18:05:38 +02:00
|
|
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-06-28 18:05:38 +02:00
|
|
|
$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');
|
2017-09-27 15:46:08 +02:00
|
|
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
2017-06-28 18:05:38 +02:00
|
|
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2017-07-08 06:28:44 +02:00
|
|
|
$response = $this->get(route('budgets.index'));
|
2017-06-28 18:05:38 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2018-06-01 22:04:52 +02:00
|
|
|
|
2017-06-28 18:05:38 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndexWithDate(string $range): void
|
2017-06-28 18:05:38 +02:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testIndexWithDate(%s)', $range));
|
2017-06-28 18:05:38 +02:00
|
|
|
// mock stuff
|
|
|
|
$budget = factory(Budget::class)->make();
|
|
|
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
2017-11-15 11:33:07 +01:00
|
|
|
$budgetInfo = [
|
2017-09-27 15:46:08 +02:00
|
|
|
$budget->id => [
|
|
|
|
'spent' => '0',
|
|
|
|
'budgeted' => '0',
|
|
|
|
'currentRep' => false,
|
|
|
|
],
|
|
|
|
];
|
2017-06-28 18:05:38 +02:00
|
|
|
|
|
|
|
// set budget limit to current month:
|
|
|
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
|
|
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
|
|
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-06-28 18:05:38 +02:00
|
|
|
$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]));
|
2017-09-27 15:46:08 +02:00
|
|
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
2017-06-28 18:05:38 +02:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2017-07-08 06:28:44 +02:00
|
|
|
$response = $this->get(route('budgets.index', ['2017-01-01']));
|
2017-06-28 18:05:38 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
2017-02-12 12:21:44 +01:00
|
|
|
}
|
|
|
|
|
2018-06-01 22:04:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
|
|
|
public function testIndexOutOfRange(string $range): void
|
|
|
|
{
|
|
|
|
Log::debug(sprintf('Now in testIndexOutOfRange(%s)', $range));
|
|
|
|
// mock stuff
|
|
|
|
$budget = factory(Budget::class)->make();
|
|
|
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
|
|
$budgetInfo = [
|
|
|
|
$budget->id => [
|
|
|
|
'spent' => '0',
|
|
|
|
'budgeted' => '0',
|
|
|
|
'currentRep' => false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
// set budget limit to current month:
|
|
|
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
|
|
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
|
|
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$today = new Carbon;
|
|
|
|
$today->startOfMonth();
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.index', [$today->format('Y-m-d')]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
2017-02-17 20:14:38 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
2017-02-12 12:21:44 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndexWithInvalidDate(string $range): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testIndexWithInvalidDate(%s)', $range));
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2017-03-18 20:53:44 +01:00
|
|
|
$budget = factory(Budget::class)->make();
|
|
|
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
|
|
|
|
|
|
// set budget limit to current month:
|
|
|
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
|
|
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
2017-09-27 15:46:08 +02:00
|
|
|
$budgetInfo = [
|
|
|
|
$budget->id => [
|
|
|
|
'spent' => '0',
|
|
|
|
'budgeted' => '0',
|
|
|
|
'currentRep' => false,
|
|
|
|
],
|
|
|
|
];
|
2017-03-18 20:53:44 +01:00
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
2017-03-18 20:53:44 +01:00
|
|
|
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
2017-02-12 12:21:44 +01:00
|
|
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
|
|
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
2017-03-18 20:53:44 +01:00
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
|
|
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
2017-09-27 15:46:08 +02:00
|
|
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2017-07-08 06:28:44 +02:00
|
|
|
$response = $this->get(route('budgets.index', ['Hello-there']));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:32:43 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::infoIncome
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testInfoIncome(): void
|
2017-12-22 18:32:43 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testInfoIncome()');
|
2017-12-22 18:32:43 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-03-02 17:07:32 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2018-02-28 15:50:00 +01:00
|
|
|
|
2017-12-22 18:32:43 +01:00
|
|
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
2018-02-28 15:50:00 +01:00
|
|
|
$accountRepos->shouldReceive('setUser');
|
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
2017-12-22 18:32:43 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2017-12-23 17:42:07 +01:00
|
|
|
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::infoIncome
|
|
|
|
* @dataProvider dateRangeProvider
|
2018-03-11 16:24:07 +01:00
|
|
|
*
|
|
|
|
* @param string $range
|
2017-12-23 17:42:07 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testInfoIncomeExpanded(string $range): void
|
2017-12-23 17:42:07 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testInfoIncomeExpanded(%s)', $range));
|
2017-12-23 17:42:07 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-03-02 17:07:32 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-12-23 17:42:07 +01:00
|
|
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
2018-02-28 15:50:00 +01:00
|
|
|
$accountRepos->shouldReceive('setUser');
|
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
2017-12-23 17:42:07 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.income.info', ['20170301', '20170430']));
|
2017-12-22 18:32:43 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::noBudget
|
2017-03-18 08:09:14 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::getPeriodOverview
|
2017-02-12 12:21:44 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
2017-12-23 17:42:07 +01:00
|
|
|
*
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testNoBudget(string $range): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testNoBudget(%s)', $range));
|
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-05 11:18:34 +01:00
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-06-01 22:04:52 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector->shouldReceive('getJournals')->andReturn(new Collection);
|
2017-02-12 12:21:44 +01:00
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2017-02-12 12:21:44 +01:00
|
|
|
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
2017-02-12 12:21:44 +01:00
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
$date = new Carbon();
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.no-budget'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-03-09 21:05:37 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::noBudget
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testNoBudgetAll(string $range): void
|
2017-03-09 21:05:37 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testNoBudgetAll(%s)', $range));
|
2017-03-09 21:05:37 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-06-01 22:04:52 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
2017-03-09 21:05:37 +01:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector->shouldReceive('getJournals')->andReturn(new Collection);
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
|
|
|
|
|
|
$date = new Carbon();
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.no-budget', ['all']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::noBudget
|
2017-03-18 08:09:14 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::getPeriodOverview
|
2017-03-09 21:05:37 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testNoBudgetDate(string $range): void
|
2017-03-09 21:05:37 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testNoBudgetDate(%s)', $range));
|
2017-03-09 21:05:37 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-06-01 22:04:52 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
2017-03-09 21:05:37 +01:00
|
|
|
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('getJournals')->andReturn(new Collection);
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
2017-03-10 18:54:50 +01:00
|
|
|
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
2017-03-09 21:05:37 +01:00
|
|
|
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
|
|
|
|
|
|
$date = new Carbon();
|
|
|
|
$this->session(['start' => $date, 'end' => clone $date]);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.no-budget', ['2016-01-01']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::postUpdateIncome
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testPostUpdateIncome(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testPostUpdateIncome()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository->shouldReceive('setAvailableBudget');
|
2018-02-21 09:23:20 +01:00
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-09-27 15:46:08 +02:00
|
|
|
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.income.post'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::show
|
2017-02-22 21:27:39 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::getLimits
|
2017-02-12 12:21:44 +01:00
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShow(string $range): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testShow(%s)', $range));
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2017-03-18 20:53:44 +01:00
|
|
|
|
|
|
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
2017-03-05 11:19:06 +01:00
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
2017-02-12 12:21:44 +01:00
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setBudget')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
2017-10-15 08:44:16 +02:00
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
2017-02-12 12:21:44 +01:00
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
|
|
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-18 20:53:44 +01:00
|
|
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
|
|
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
2017-03-05 11:18:34 +01:00
|
|
|
|
|
|
|
$date = new Carbon();
|
|
|
|
$date->subDay();
|
|
|
|
$this->session(['first' => $date]);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.show', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::showByBudgetLimit
|
|
|
|
* @expectedExceptionMessage This budget limit is not part of
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowByBadBudgetLimit(): void
|
2017-03-18 20:53:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testShowByBadBudgetLimit()');
|
2017-03-18 20:53:44 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2017-03-18 20:53:44 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-18 20:53:44 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('budgets.show.limit', [1, 8]));
|
|
|
|
$response->assertStatus(500);
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::showByBudgetLimit()
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowByBudgetLimit(string $range): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug(sprintf('Now in testShowByBudgetLimit(%s)', $range));
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2017-03-05 11:19:06 +01:00
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
// mock account repository
|
|
|
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
|
|
|
|
|
|
// mock budget repository
|
|
|
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
|
|
|
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
|
|
|
|
|
|
|
// mock journal collector:
|
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
|
|
$collector->shouldReceive('setBudget')->andReturnSelf();
|
2017-10-15 08:44:16 +02:00
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
2017-02-12 12:21:44 +01:00
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$response = $this->get(route('budgets.show.limit', [1, 1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::store
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testStore(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testStore()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2017-03-05 11:19:06 +01:00
|
|
|
$budget = factory(Budget::class)->make();
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2018-03-28 19:38:20 +02:00
|
|
|
$repository->shouldReceive('findNull')->andReturn($budget);
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository->shouldReceive('store')->andReturn($budget);
|
2018-02-21 09:23:20 +01:00
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['budgets.create.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$data = [
|
2018-03-28 19:38:20 +02:00
|
|
|
'name' => 'New Budget ' . random_int(1000, 9999),
|
2017-02-12 12:21:44 +01:00
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.store'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::update
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdate(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testUpdate()');
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
2017-03-05 11:19:06 +01:00
|
|
|
$budget = factory(Budget::class)->make();
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2018-03-28 19:38:20 +02:00
|
|
|
$repository->shouldReceive('findNull')->andReturn($budget);
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository->shouldReceive('update');
|
2018-02-21 09:23:20 +01:00
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
2018-02-24 09:18:01 +01:00
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['budgets.edit.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
|
|
|
|
$data = [
|
2018-03-28 19:38:20 +02:00
|
|
|
'name' => 'Updated Budget ' . random_int(1000, 9999),
|
2017-02-12 12:21:44 +01:00
|
|
|
'active' => 1,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.update', [1]), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::updateIncome
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdateIncome(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2018-06-01 22:04:52 +02:00
|
|
|
Log::debug('Now in testUpdateIncome()');
|
2017-06-07 11:13:04 +02:00
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
|
2017-03-05 11:18:34 +01:00
|
|
|
// mock stuff
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
2018-04-28 10:27:33 +02:00
|
|
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
2017-03-05 11:18:34 +01:00
|
|
|
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
2017-06-07 11:13:04 +02:00
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
2017-03-05 11:18:34 +01:00
|
|
|
|
2017-08-27 11:07:14 +02:00
|
|
|
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
2017-02-16 22:33:32 +01:00
|
|
|
}
|