Files
firefly-iii/tests/Feature/Controllers/Json/BoxControllerTest.php

146 lines
5.4 KiB
PHP
Raw Normal View History

2017-12-23 17:42:07 +01:00
<?php
/**
* BoxControllerTest.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\Json;
use Carbon\Carbon;
2018-02-28 15:50:00 +01:00
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
2017-12-23 17:42:07 +01:00
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
2018-02-28 15:50:00 +01:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2017-12-23 17:42:07 +01:00
use Illuminate\Support\Collection;
2018-03-24 06:08:50 +01:00
use Log;
2018-03-28 19:38:20 +02:00
use Mockery;
2017-12-23 17:42:07 +01:00
use Tests\TestCase;
/**
* Class BoxControllerTest
*/
class BoxControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
public function setUp()
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-12-23 17:42:07 +01:00
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController::available
*/
public function testAvailable()
{
$return = [
0 => [
'spent' => '-1200', // more than budgeted.
],
];
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('getAvailableBudget')->andReturn('1000');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$repository->shouldReceive('collectBudgetInformation')->andReturn($return);
$this->be($this->user());
$response = $this->get(route('json.box.available'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController::balance
*/
public function testBalance()
{
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
// try a collector for income:
/** @var JournalCollectorInterface $collector */
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
2017-12-23 17:42:07 +01:00
$this->be($this->user());
$response = $this->get(route('json.box.balance'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController::bills
*/
public function testBills()
{
2018-02-28 15:50:00 +01:00
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('getBillsPaidInRange')->andReturn('0');
$billRepos->shouldReceive('getBillsUnpaidInRange')->andReturn('0');
2017-12-23 17:42:07 +01:00
$this->be($this->user());
$response = $this->get(route('json.box.bills'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
*/
public function testNetWorth()
{
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
2018-02-28 15:50:00 +01:00
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
2018-03-28 19:38:20 +02:00
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
2017-12-23 17:42:07 +01:00
$this->be($this->user());
$response = $this->get(route('json.box.net-worth'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
*/
public function testNetWorthFuture()
{
2018-02-28 15:50:00 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
2018-02-28 15:50:00 +01:00
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
2018-03-28 19:38:20 +02:00
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
2018-02-28 15:50:00 +01:00
2017-12-23 17:42:07 +01:00
$start = new Carbon;
$start->addMonths(6)->startOfMonth();
$end = clone $start;
$end->endOfMonth();
$this->session(['start' => $start, 'end' => $end]);
$this->be($this->user());
$response = $this->get(route('json.box.net-worth'));
$response->assertStatus(200);
}
}