mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-10 23:45:48 -06:00
Fix some tests
This commit is contained in:
parent
dfca5b8722
commit
a416b682e0
@ -121,7 +121,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->post(route('api.v1.link_types.store'), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('You need the \"owner\"-role to do this.');
|
||||
$response->assertSee('200005');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,7 +211,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('You cannot edit this link type ');
|
||||
$response->assertSee('200020');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,7 +253,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('You need the \"owner\"-role to do this.');
|
||||
$response->assertSee('200005');
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
@ -95,14 +96,14 @@ class PiggyBankControllerTest extends TestCase
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNull(): void
|
||||
public function testStoreThrowError(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('store')->once()->andReturn(null)->once();
|
||||
$repository->shouldReceive('store')->once()->andThrow(new FireflyException('400005'));
|
||||
|
||||
|
||||
$data = [
|
||||
@ -116,7 +117,7 @@ class PiggyBankControllerTest extends TestCase
|
||||
$response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
$response->assertSee('Could not store new piggy bank.');
|
||||
$response->assertSee('400005');
|
||||
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1055,6 @@ class RecurrenceControllerTest extends TestCase
|
||||
'errors' => [
|
||||
'transactions.0.source_id' => [
|
||||
null,
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
'transactions.0.source_name' => [
|
||||
null,
|
||||
@ -1196,7 +1195,6 @@ class RecurrenceControllerTest extends TestCase
|
||||
'errors' => [
|
||||
'transactions.0.source_id' => [
|
||||
null,
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
'transactions.0.source_name' => [
|
||||
null,
|
||||
|
@ -175,7 +175,7 @@ class RuleGroupControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('{"message":"No rules in this rule group.","exception":"FireflyIII\\\\Exceptions\\\\FireflyException"');
|
||||
$response->assertSee('200023');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,29 +136,33 @@ class SummaryControllerTest extends TestCase
|
||||
// budget repos
|
||||
$abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
[
|
||||
[
|
||||
'currency_id' => 3,
|
||||
'currency_code' => 'EUR',
|
||||
'currency_symbol' => 'x',
|
||||
'currency_decimal_places' => 2,
|
||||
'amount' => 321.21,
|
||||
],
|
||||
[
|
||||
'currency_id' => 1,
|
||||
'currency_code' => 'EUR',
|
||||
'currency_symbol' => 'x',
|
||||
'currency_decimal_places' => 2,
|
||||
'amount' => 321.21,
|
||||
],
|
||||
|
||||
]
|
||||
);
|
||||
// new stuff
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
|
||||
|
||||
|
||||
//$opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
// [
|
||||
// [
|
||||
// 'currency_id' => 3,
|
||||
// 'currency_code' => 'EUR',
|
||||
// 'currency_symbol' => 'x',
|
||||
// 'currency_decimal_places' => 2,
|
||||
// 'amount' => 321.21,
|
||||
// ],
|
||||
// [
|
||||
// 'currency_id' => 1,
|
||||
// 'currency_code' => 'EUR',
|
||||
// 'currency_symbol' => 'x',
|
||||
// 'currency_decimal_places' => 2,
|
||||
// 'amount' => 321.21,
|
||||
// ],
|
||||
//
|
||||
// ]
|
||||
// );
|
||||
|
||||
// account repos:
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
|
||||
|
||||
// net worth calculator
|
||||
@ -169,9 +173,10 @@ class SummaryControllerTest extends TestCase
|
||||
'end' => $date->addWeek()->format('Y-m-d'),
|
||||
];
|
||||
|
||||
// TODO AFTER 4.8,0: check if JSON is correct
|
||||
$response = $this->get(route('api.v1.summary.basic') . '?' . http_build_query($parameters));
|
||||
$response->assertStatus(200);
|
||||
// TODO AFTER 4.8,0: check if JSON is correct
|
||||
//$response->assertSee('hi there');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,21 +242,24 @@ class SummaryControllerTest extends TestCase
|
||||
// budget repos
|
||||
$abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123']);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
[
|
||||
[
|
||||
'currency_id' => 1,
|
||||
'currency_code' => 'EUR',
|
||||
'currency_symbol' => 'x',
|
||||
'currency_decimal_places' => 2,
|
||||
'amount' => 321.21,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// new stuff
|
||||
$opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
|
||||
|
||||
// $opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
// [
|
||||
// [
|
||||
// 'currency_id' => 1,
|
||||
// 'currency_code' => 'EUR',
|
||||
// 'currency_symbol' => 'x',
|
||||
// 'currency_decimal_places' => 2,
|
||||
// 'amount' => 321.21,
|
||||
// ],
|
||||
// ]
|
||||
// );
|
||||
|
||||
// account repos:
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
|
||||
|
||||
// net worth calculator
|
||||
|
@ -720,8 +720,8 @@ class TransactionControllerTest extends TestCase
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
@ -779,8 +779,8 @@ class TransactionControllerTest extends TestCase
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
@ -845,8 +845,8 @@ class TransactionControllerTest extends TestCase
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
//$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
@ -260,7 +260,7 @@ class TransactionLinkControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Source or destination is NULL.'); // the creation moment.
|
||||
$response->assertSee('200024'); // the creation moment.
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ class TransactionLinkControllerTest extends TestCase
|
||||
Log::warning('The following error is part of a test.');
|
||||
$response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Source or destination is NULL.'); // the creation moment.
|
||||
$response->assertSee('200024'); // the creation moment.
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,6 @@ class DeleteEmptyGroupsTest extends TestCase
|
||||
{
|
||||
// assume there are no empty groups..
|
||||
$this->artisan('firefly-iii:delete-empty-groups')
|
||||
->expectsOutput('No empty transaction groups.')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Factory;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use Log;
|
||||
@ -64,6 +65,7 @@ class TransactionCurrencyFactoryTest extends TestCase
|
||||
*/
|
||||
public function testCreateEmpty(): void
|
||||
{
|
||||
$this->expectException(FireflyException::class);
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
Log::warning('The following error is part of a test.');
|
||||
|
@ -66,6 +66,9 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$checkConfig = new Configuration;
|
||||
$checkConfig->data = time() - 604810;
|
||||
|
||||
$channelConfig = new Configuration;
|
||||
$channelConfig->data = 'stable';
|
||||
|
||||
|
||||
$event = new RequestedVersionCheckStatus($this->user());
|
||||
$request = $this->mock(UpdateRequest::class);
|
||||
@ -75,10 +78,11 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
||||
|
||||
// request thing:
|
||||
$request->shouldReceive('call')->once()->andThrow(new FireflyException('Errrr'));
|
||||
$request->shouldNotReceive('getReleases');
|
||||
//$request->shouldReceive('call')->once()->andThrow(new FireflyException('Errrr'));
|
||||
//$request->shouldNotReceive('getReleases');
|
||||
|
||||
|
||||
$handler = new VersionCheckEventHandler;
|
||||
@ -96,6 +100,8 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$updateConfig->data = 1;
|
||||
$checkConfig = new Configuration;
|
||||
$checkConfig->data = time() - 604800;
|
||||
$channelConfig = new Configuration;
|
||||
$channelConfig->data = 'stable';
|
||||
|
||||
|
||||
$event = new RequestedVersionCheckStatus($this->user());
|
||||
@ -109,10 +115,11 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
||||
|
||||
// request thing:
|
||||
$request->shouldReceive('call')->once();
|
||||
$request->shouldReceive('getReleases')->once()->andReturn([$first]);
|
||||
//$request->shouldReceive('call')->once();
|
||||
//$request->shouldReceive('getReleases')->once()->andReturn([$first]);
|
||||
|
||||
|
||||
$handler = new VersionCheckEventHandler;
|
||||
@ -130,6 +137,8 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$updateConfig->data = 1;
|
||||
$checkConfig = new Configuration;
|
||||
$checkConfig->data = time() - 604800;
|
||||
$channelConfig = new Configuration;
|
||||
$channelConfig->data = 'stable';
|
||||
|
||||
|
||||
$event = new RequestedVersionCheckStatus($this->user());
|
||||
@ -143,10 +152,11 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
||||
|
||||
// request thing:
|
||||
$request->shouldReceive('call')->once();
|
||||
$request->shouldReceive('getReleases')->once()->andReturn([$first]);
|
||||
//$request->shouldReceive('call')->once();
|
||||
//$request->shouldReceive('getReleases')->once()->andReturn([$first]);
|
||||
|
||||
$handler = new VersionCheckEventHandler;
|
||||
$handler->checkForUpdates($event);
|
||||
@ -184,7 +194,8 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$updateConfig->data = -1;
|
||||
$checkConfig = new Configuration;
|
||||
$checkConfig->data = time() - 604800;
|
||||
|
||||
$channelConfig = new Configuration;
|
||||
$channelConfig->data = 'stable';
|
||||
|
||||
$event = new RequestedVersionCheckStatus($this->user());
|
||||
$repos = $this->mock(UserRepositoryInterface::class);
|
||||
@ -193,6 +204,7 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
||||
|
||||
$handler = new VersionCheckEventHandler;
|
||||
$handler->checkForUpdates($event);
|
||||
@ -231,7 +243,6 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$repos = $this->mock(UserRepositoryInterface::class);
|
||||
$repos->shouldReceive('hasRole')->andReturn(true)->once();
|
||||
|
||||
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
|
||||
|
@ -38,6 +38,7 @@ use Illuminate\Support\Facades\Event;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* Class CreateRecurringTransactionsTest
|
||||
@ -66,6 +67,8 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
Event::fake();
|
||||
$date = new Carbon();
|
||||
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
|
||||
$carbon = new Carbon;
|
||||
$carbon->subDays(4);
|
||||
@ -138,6 +141,8 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
$date = new Carbon();
|
||||
$this->expectsEvents([StoredTransactionGroup::class]);
|
||||
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
// overrule some fields in the recurrence.
|
||||
$carbon = new Carbon;
|
||||
$carbon->subDays(4);
|
||||
@ -201,6 +206,9 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
{
|
||||
Event::fake();
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
// mock classes
|
||||
$date = new Carbon;
|
||||
$date->subDays(4);
|
||||
@ -257,7 +265,6 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
|
||||
$date = new Carbon();
|
||||
$job = new CreateRecurringTransactions($date);
|
||||
|
||||
@ -380,6 +387,7 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
|
||||
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
$job = new CreateRecurringTransactions($date);
|
||||
$job->handle();
|
||||
@ -508,6 +516,7 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
|
||||
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
// return data:
|
||||
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
|
||||
@ -564,9 +573,10 @@ class CreateRecurringTransactionsTest extends TestCase
|
||||
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
|
||||
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
|
||||
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
|
||||
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturn($piggy);
|
||||
$piggyEventFactory->shouldReceive('create')->once();
|
||||
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturn($piggy->id);
|
||||
//$piggyEventFactory->shouldReceive('create')->once();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
|
||||
|
||||
// return data:
|
||||
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
|
||||
|
@ -1003,174 +1003,6 @@ class BinderTest extends TestCase
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal user can access file routine
|
||||
*
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\ImportProvider
|
||||
*/
|
||||
public function testImportProvider(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(PrerequisitesInterface::class);
|
||||
|
||||
// mock all prerequisite classes.
|
||||
$bunq = $this->mock(BunqPrerequisites::class);
|
||||
$spectre = $this->mock(SpectrePrerequisites::class);
|
||||
$ynab = $this->mock(YnabPrerequisites::class);
|
||||
|
||||
$bunq->shouldReceive('setUser')->atLeast()->once();
|
||||
$spectre->shouldReceive('setUser')->atLeast()->once();
|
||||
$ynab->shouldReceive('setUser')->atLeast()->once();
|
||||
$bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{import_provider}', static function (string $name) {
|
||||
return sprintf('import_provider: %s', $name);
|
||||
}
|
||||
);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/file');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Nobody can access "bad" import routine.
|
||||
*
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\ImportProvider
|
||||
*/
|
||||
public function testImportProviderBad(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(PrerequisitesInterface::class);
|
||||
|
||||
// mock all prerequisite classes.
|
||||
$bunq = $this->mock(BunqPrerequisites::class);
|
||||
$spectre = $this->mock(SpectrePrerequisites::class);
|
||||
$ynab = $this->mock(YnabPrerequisites::class);
|
||||
|
||||
$bunq->shouldReceive('setUser')->atLeast()->once();
|
||||
$spectre->shouldReceive('setUser')->atLeast()->once();
|
||||
$ynab->shouldReceive('setUser')->atLeast()->once();
|
||||
$bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{import_provider}', static function (string $name) {
|
||||
return sprintf('import_provider: %s', $name);
|
||||
}
|
||||
);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/bad');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Demo user cannot access file import routine.
|
||||
*
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\ImportProvider
|
||||
*/
|
||||
public function testImportProviderDemoFile(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(PrerequisitesInterface::class);
|
||||
|
||||
// mock all prerequisite classes.
|
||||
$bunq = $this->mock(BunqPrerequisites::class);
|
||||
$spectre = $this->mock(SpectrePrerequisites::class);
|
||||
$ynab = $this->mock(YnabPrerequisites::class);
|
||||
$fake = $this->mock(FakePrerequisites::class);
|
||||
|
||||
$fake->shouldReceive('setUser')->atLeast()->once();
|
||||
$fake->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{import_provider}', static function (string $name) {
|
||||
return sprintf('import_provider: %s', $name);
|
||||
}
|
||||
);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/file');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal user cannot access fake import routine.
|
||||
*
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\ImportProvider
|
||||
*/
|
||||
public function testImportProviderFake(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(PrerequisitesInterface::class);
|
||||
|
||||
// mock all prerequisite classes.
|
||||
$bunq = $this->mock(BunqPrerequisites::class);
|
||||
$spectre = $this->mock(SpectrePrerequisites::class);
|
||||
$ynab = $this->mock(YnabPrerequisites::class);
|
||||
|
||||
$bunq->shouldReceive('setUser')->atLeast()->once();
|
||||
$spectre->shouldReceive('setUser')->atLeast()->once();
|
||||
$ynab->shouldReceive('setUser')->atLeast()->once();
|
||||
$bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
$ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{import_provider}', static function (string $name) {
|
||||
return sprintf('import_provider: %s', $name);
|
||||
}
|
||||
);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/fake');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\ImportProvider
|
||||
*/
|
||||
public function testImportProviderNotLoggedIn(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(PrerequisitesInterface::class);
|
||||
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{import_provider}', static function (string $name) {
|
||||
return sprintf('import_provider: %s', $name);
|
||||
}
|
||||
);
|
||||
|
||||
$response = $this->get('/_test/binder/file');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder
|
||||
* @covers \FireflyIII\Support\Binder\JournalList
|
||||
|
Loading…
Reference in New Issue
Block a user