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

147 lines
5.6 KiB
PHP
Raw Normal View History

<?php
/**
* ReconcileControllerTest.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\Json;
2019-06-29 19:47:31 +02:00
use Amount;
2018-12-12 20:30:25 +01:00
use Carbon\Carbon;
2019-06-29 19:47:31 +02:00
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
2019-06-23 10:40:46 +02:00
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Log;
use Mockery;
2019-06-29 19:47:31 +02:00
use Preferences;
use Tests\TestCase;
2019-08-29 17:53:25 +02:00
use Steam;
/**
*
* Class ReconcileControllerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ReconcileControllerTest extends TestCase
{
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Test overview of reconciliation.
*
* @covers \FireflyIII\Http\Controllers\Json\ReconcileController
*/
public function testOverview(): void
{
2019-06-29 19:47:31 +02:00
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(RecurringRepositoryInterface::class);
$this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
2018-12-12 20:30:25 +01:00
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
2019-06-29 19:47:31 +02:00
$euro = $this->getEuro();
$withdrawal = $this->getRandomWithdrawalAsArray();
2018-12-12 20:30:25 +01:00
$date = new Carbon;
2019-06-29 19:47:31 +02:00
$account = $this->user()->accounts()->where('id', $withdrawal['source_account_id'])->first();
2018-12-12 20:30:25 +01:00
2019-06-29 19:47:31 +02:00
// make sure it falls into the current range
$withdrawal['date'] = new Carbon('2017-01-30');
2018-10-27 05:39:11 +02:00
2019-06-29 19:47:31 +02:00
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
$collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawal]);
Amount::shouldReceive('formatAnything')->andReturn('-100');
Amount::shouldReceive('getDefaultCurrency')->andReturn($euro);
2018-12-12 20:30:25 +01:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2019-06-29 19:47:31 +02:00
$parameters = [
'startBalance' => '0',
'endBalance' => '10',
2019-06-29 19:47:31 +02:00
'journals' => [1, 2, 3],
'cleared' => [4, 5, 6],
];
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.overview', [$account->id, '20170101', '20170131']) . '?' . http_build_query($parameters));
2019-06-29 19:47:31 +02:00
$response->assertStatus(200);
$response->assertSee('-100');
}
/**
* List transactions for reconciliation view.
*
* @covers \FireflyIII\Http\Controllers\Json\ReconcileController
*/
public function testTransactions(): void
{
2019-06-29 19:47:31 +02:00
$this->mock(RecurringRepositoryInterface::class);
$this->mockDefaultSession();
2019-07-25 14:19:49 +02:00
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$date = new Carbon;
$euro = $this->getEuro();
$withdrawal = $this->getRandomWithdrawalAsArray();
2019-06-29 19:47:31 +02:00
2019-08-29 17:53:25 +02:00
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('20');
2019-06-29 19:47:31 +02:00
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
2019-08-29 17:53:25 +02:00
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
2019-06-29 19:47:31 +02:00
Amount::shouldReceive('formatAnything')->andReturn('-100');
2018-12-12 20:30:25 +01:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2019-08-12 17:36:37 +02:00
//$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
2019-06-29 19:47:31 +02:00
2018-12-12 20:30:25 +01:00
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
2019-06-29 19:47:31 +02:00
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
2018-12-12 20:30:25 +01:00
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
2019-06-29 19:47:31 +02:00
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawal]);
2018-12-12 20:30:25 +01:00
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.transactions', [1, '20170101', '20170131']));
$response->assertStatus(200);
2019-06-29 19:47:31 +02:00
$response->assertSee('-100');
}
2018-07-22 20:33:17 +02:00
}