mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Improve test coverage.
This commit is contained in:
@@ -126,6 +126,7 @@ class AttachmentControllerTest extends TestCase
|
||||
$repository->shouldReceive('exists')->once()->andReturn(false);
|
||||
|
||||
|
||||
Log::warning('The following error is part of a test.');
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.download', [$attachment->id]));
|
||||
$response->assertStatus(500);
|
||||
|
@@ -22,12 +22,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Auth;
|
||||
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Google2FA;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
use FireflyConfig;
|
||||
/**
|
||||
* Class TwoFactorControllerTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
@@ -54,6 +55,11 @@ class TwoFactorControllerTest extends TestCase
|
||||
$langPreference = new Preference;
|
||||
$langPreference->data = 'en_US';
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig);
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
|
||||
|
||||
$response = $this->get(route('two-factor.lost'));
|
||||
|
@@ -166,14 +166,17 @@ class BillControllerTest extends TestCase
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
$euro = $this->getEuro();
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
//$pref = new Preference;
|
||||
//$pref->data = 50;
|
||||
//Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('-100');
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
|
||||
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
|
||||
['id' => 5, 'active' => true,
|
||||
'name' => 'x', 'next_expected_match' => '2018-01-01',
|
||||
'amount_min' => '10',
|
||||
'amount_max' => '10',
|
||||
'currency' => $this->getEuro(),
|
||||
'currency_id' => $euro->id,
|
||||
'currency_code' => $euro->code,
|
||||
@@ -185,7 +188,7 @@ class BillControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$collection = new Collection([$bill]);
|
||||
$repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();
|
||||
$repository->shouldReceive('getBills')->andReturn($collection)->once();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Hi there');
|
||||
$repository->shouldReceive('getRulesForBills')->andReturn([]);
|
||||
|
@@ -121,6 +121,7 @@ class BudgetControllerTest extends TestCase
|
||||
// mock default session
|
||||
$this->mockDefaultSession();
|
||||
|
||||
Log::warning('The following error is part of a test.');
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.budget.budget-limit', [$budget->id, $limit->id]));
|
||||
$response->assertStatus(500);
|
||||
|
@@ -295,6 +295,7 @@ class CurrencyControllerTest extends TestCase
|
||||
$repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
Log::warning('The following error is part of a test.');
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('currencies.disable', [$euro->id]));
|
||||
$response->assertStatus(500);
|
||||
|
@@ -275,6 +275,7 @@ class JobStatusControllerTest extends TestCase
|
||||
$routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));
|
||||
|
||||
// call thing.
|
||||
Log::warning('The following error is part of a test.');
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.job.start', [$job->key]));
|
||||
$response->assertStatus(200);
|
||||
@@ -308,6 +309,7 @@ class JobStatusControllerTest extends TestCase
|
||||
$routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));
|
||||
|
||||
// call thing.
|
||||
Log::warning('The following error is part of a test.');
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.job.start', [$job->key]));
|
||||
$response->assertStatus(200);
|
||||
|
@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@@ -115,6 +116,7 @@ class AutoCompleteControllerTest extends TestCase
|
||||
*/
|
||||
public function testAllJournals(): void
|
||||
{
|
||||
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$journal = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
@@ -134,6 +136,7 @@ class AutoCompleteControllerTest extends TestCase
|
||||
*/
|
||||
public function testAllJournalsWithId(): void
|
||||
{
|
||||
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$journal = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
@@ -155,12 +158,13 @@ class AutoCompleteControllerTest extends TestCase
|
||||
*/
|
||||
public function testAllJournalsWithIdNumeric(): void
|
||||
{
|
||||
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$journal = $this->getRandomWithdrawalAsArray();
|
||||
$journalObject = $this->getRandomWithdrawal();
|
||||
$journalObject = $this->getRandomWithdrawalGroup();
|
||||
|
||||
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
|
||||
$journalRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($journalObject);
|
||||
$groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -26,6 +26,7 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
use Amount;
|
||||
|
||||
/**
|
||||
* Class FrontpageControllerTest
|
||||
@@ -57,6 +58,8 @@ class FrontpageControllerTest extends TestCase
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy]));
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('10');
|
||||
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.fp.piggy-banks'));
|
||||
$response->assertStatus(200);
|
||||
|
@@ -35,6 +35,7 @@ use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -117,9 +118,11 @@ class ReconcileControllerTest extends TestCase
|
||||
$euro = $this->getEuro();
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('20');
|
||||
|
||||
|
||||
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
Amount::shouldReceive('formatAnything')->andReturn('-100');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
@@ -116,7 +116,8 @@ class ProfileControllerTest extends TestCase
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
|
||||
Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());
|
||||
// email_change_confirm_token
|
||||
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->get(route('profile.confirm-email-change', ['some-fake-token']));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
@@ -583,6 +584,7 @@ class ProfileControllerTest extends TestCase
|
||||
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
|
||||
Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
|
||||
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->get(route('profile.undo-email-change', ['token', $hash]));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
@@ -162,47 +162,5 @@ class IndexControllerTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
|
||||
[
|
||||
'id' => 5,
|
||||
'first_date' => '2018-01-01',
|
||||
'repeat_until' => null,
|
||||
'latest_date' => null,
|
||||
'recurrence_repetitions' => [
|
||||
[
|
||||
'occurrences' => [
|
||||
'2019-01-01',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.show', [$recurrence->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
96
tests/Feature/Controllers/Recurring/ShowControllerTest.php
Normal file
96
tests/Feature/Controllers/Recurring/ShowControllerTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* ShowControllerTest.php
|
||||
* Copyright (c) 2019 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\Recurring;
|
||||
|
||||
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Transformers\RecurrenceTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ShowControllerTest
|
||||
*/
|
||||
class ShowControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
|
||||
[
|
||||
'id' => 5,
|
||||
'first_date' => '2018-01-01',
|
||||
'repeat_until' => null,
|
||||
'latest_date' => null,
|
||||
'repetitions' => [
|
||||
[
|
||||
'occurrences' => [
|
||||
'2019-01-01',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.show', [$recurrence->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
}
|
@@ -86,7 +86,7 @@ class BudgetControllerTest extends TestCase
|
||||
$date = new Carbon;
|
||||
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
//Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('getBudgets')->andReturn(new Collection);
|
||||
|
@@ -26,9 +26,12 @@ use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\Support\TestDataTrait;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class CategoryControllerTest extends TestCase
|
||||
{
|
||||
use TestDataTrait;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -56,11 +60,16 @@ class CategoryControllerTest extends TestCase
|
||||
public function testExpenses(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$first = [1 => ['entries' => ['1', '1']]];
|
||||
$second = ['entries' => ['1', '1']];
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$first = [1 => ['entries' => ['1', '1']]];
|
||||
$second = ['entries' => ['1', '1']];
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
|
||||
$noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
|
||||
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
@@ -81,15 +90,22 @@ class CategoryControllerTest extends TestCase
|
||||
public function testIncome(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$first = [
|
||||
$first = [
|
||||
1 => ['entries' => ['1', '1']],
|
||||
2 => ['entries' => ['0']],
|
||||
];
|
||||
$second = ['entries' => ['1', '1']];
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$second = ['entries' => ['1', '1']];
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
|
||||
$noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
|
||||
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('getCategories')->andReturn(new Collection);
|
||||
@@ -107,12 +123,21 @@ class CategoryControllerTest extends TestCase
|
||||
public function testOperations(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$category = $this->getRandomCategory();
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$category = $this->getRandomCategory();
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
|
||||
$noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
|
||||
|
||||
$opsRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
|
||||
$noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
|
||||
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
//Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
||||
|
@@ -178,6 +178,8 @@ class ExpenseControllerTest extends TestCase
|
||||
$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);
|
||||
@@ -222,6 +224,7 @@ class ExpenseControllerTest extends TestCase
|
||||
$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']));
|
||||
|
@@ -114,7 +114,7 @@ class EditControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
@@ -59,11 +59,11 @@ class SelectControllerTest extends TestCase
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$account = $this->user()->accounts()->find(1);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$ruleEngine = $this->mock(RuleEngine::class);
|
||||
|
||||
@@ -100,9 +100,9 @@ class SelectControllerTest extends TestCase
|
||||
*/
|
||||
public function testSelectTransactions(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
@@ -187,6 +187,7 @@ class SelectControllerTest extends TestCase
|
||||
*/
|
||||
public function testTestTriggersMax(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$data = [
|
||||
'triggers' => [
|
||||
'name' => 'description',
|
||||
|
@@ -27,6 +27,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Engine\RuleEngine;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -59,12 +60,12 @@ class ExecutionControllerTest extends TestCase
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$ruleEngine = $this->mock(RuleEngine::class);
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
|
||||
|
||||
$groupRepos->shouldReceive('getActiveRules')->atLeast()->once()->andReturn(new Collection);
|
||||
// new mocks for ruleEngine
|
||||
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
|
||||
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
|
||||
@@ -96,6 +97,7 @@ class ExecutionControllerTest extends TestCase
|
||||
$this->mockDefaultSession();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
|
@@ -172,6 +172,10 @@ class TagControllerTest extends TestCase
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
//$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
|
||||
|
||||
|
||||
//Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
@@ -228,6 +232,9 @@ class TagControllerTest extends TestCase
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
|
||||
|
||||
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
|
||||
$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
|
||||
|
||||
@@ -279,6 +286,10 @@ class TagControllerTest extends TestCase
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
|
||||
|
||||
|
||||
//Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
|
@@ -23,8 +23,18 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Factory\TransactionFactory;
|
||||
use FireflyIII\Factory\TransactionTypeFactory;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepository;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
@@ -63,12 +73,18 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexDepositTransfer(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$deposit = $this->getRandomDepositGroup();
|
||||
@@ -123,10 +139,16 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexSameType(): void
|
||||
{
|
||||
// mock stuff:
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mockDefaultSession();
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
$this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
@@ -174,28 +196,38 @@ class ConvertControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
||||
*/
|
||||
public function testPostIndexDepositTransfer(): void
|
||||
public function testPostIndexBadDestination(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mockDefaultSession();
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(RuleGroupRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
|
||||
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$deposit = $this->getRandomDepositGroup();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
// first journal:
|
||||
$journal = $deposit->transactionJournals()->first();
|
||||
|
||||
$validator->shouldReceive('setUser')->atLeast()->once();
|
||||
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
|
||||
$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$data = ['source_account_id' => 1];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||
$response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));
|
||||
$response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,10 +235,18 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostIndexBadSource(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mockDefaultSession();
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(RuleGroupRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
|
||||
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$deposit = $this->getRandomDepositGroup();
|
||||
|
||||
@@ -230,29 +270,46 @@ class ConvertControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
||||
*/
|
||||
public function testPostIndexBadDestination(): void
|
||||
public function testPostIndexDepositTransfer(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(RuleGroupRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$deposit = $this->getRandomDepositGroup();
|
||||
|
||||
// first journal:
|
||||
$journal = $deposit->transactionJournals()->first();
|
||||
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$tagFactory = $this->mock(TagFactory::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepository::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
$typeFactory = $this->mock(TransactionTypeFactory::class);
|
||||
$ruleGroup = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
|
||||
$type = TransactionType::first();
|
||||
$typeFactory->shouldReceive('find')->atLeast()->once()->andReturn($type);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$deposit = $this->getRandomDepositGroup();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
|
||||
$validator->shouldReceive('setUser')->atLeast()->once();
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
|
||||
$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);
|
||||
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
|
||||
|
||||
|
||||
$data = ['source_account_id' => 1];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));
|
||||
$response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
|
||||
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||
}
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@ class CreateControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);
|
||||
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($empty);
|
||||
|
||||
|
||||
|
@@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -49,8 +50,10 @@ class EditControllerTest extends TestCase
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
$account = $this->getRandomAsset();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
|
||||
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($account);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user