mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Improve test coverage and efficiency for accounts and budgets.
This commit is contained in:
@@ -63,28 +63,19 @@ class CreateControllerTest extends TestCase
|
||||
public function testCreate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// mock hasRole for user repository:
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
// mock default calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
// mock default calls
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
||||
|
||||
// mock default calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
// get all types:
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||
@@ -105,31 +96,22 @@ class CreateControllerTest extends TestCase
|
||||
public function testStore(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$repository->shouldReceive('store')->once()->andReturn($asset);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// mock default calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
$repository->shouldReceive('store')->once()->andReturn($asset);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// change the preference:
|
||||
$emptyPref = new Preference;
|
||||
$emptyPref->data = [];
|
||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
|
||||
// mock default calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost/x']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
@@ -151,28 +133,20 @@ class CreateControllerTest extends TestCase
|
||||
public function testStoreAnother(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
|
||||
$repository->shouldReceive('store')->once()->andReturn($asset);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// change the preference:
|
||||
$emptyPref = new Preference;
|
||||
$emptyPref->data = [];
|
||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
|
||||
// mock default calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
//$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
||||
|
||||
// mock default calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
|
||||
@@ -201,28 +175,18 @@ class CreateControllerTest extends TestCase
|
||||
public function testStoreLiability(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$liability = $this->getRandomLoan();
|
||||
$loan = AccountType::where('type', AccountType::LOAN)->first();
|
||||
$euro = $this->getEuro();
|
||||
$repository->shouldReceive('store')->once()->andReturn($liability);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// change the preference:
|
||||
$emptyPref = new Preference;
|
||||
$emptyPref->data = [];
|
||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||
|
||||
// mock default calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
//$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
||||
|
||||
// mock default calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
|
@@ -62,25 +62,15 @@ class DeleteControllerTest extends TestCase
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$asset = $this->getRandomAsset();
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// mock hasRole for user repository:
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
// mock Amount
|
||||
$euro = $this->getEuro();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.delete', [$asset->id]));
|
||||
@@ -96,25 +86,16 @@ class DeleteControllerTest extends TestCase
|
||||
public function testDestroy(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
// mock Amount
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -62,25 +62,20 @@ class EditControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// mock preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
//$repository->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->atLeast()->once();
|
||||
|
||||
// mock hasRole for user repository:
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('get')->andReturn(new Collection)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull()->atLeast()->once();
|
||||
@@ -100,12 +95,6 @@ class EditControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
||||
|
||||
// mock calls to Preferences:
|
||||
//$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.edit', [$asset->id]));
|
||||
$response->assertStatus(200);
|
||||
@@ -120,7 +109,6 @@ class EditControllerTest extends TestCase
|
||||
*/
|
||||
public function testEditLiability(): void
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
@@ -131,7 +119,7 @@ class EditControllerTest extends TestCase
|
||||
|
||||
//$repository->shouldReceive('findNull')->once()->andReturn($euro);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
@@ -151,16 +139,8 @@ class EditControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
||||
|
||||
// mock Amount
|
||||
$euro = $this->getEuro();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.edit', [$loan->id]));
|
||||
@@ -177,7 +157,6 @@ class EditControllerTest extends TestCase
|
||||
public function testEditNull(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
@@ -185,10 +164,7 @@ class EditControllerTest extends TestCase
|
||||
// mock hasRole for user repository:
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(2));
|
||||
//$repository->shouldReceive('findNull')->once()->andReturn(null);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
@@ -203,11 +179,8 @@ class EditControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
||||
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// get all types:
|
||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
||||
@@ -232,18 +205,15 @@ class EditControllerTest extends TestCase
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$euro = $this->getEuro();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
@@ -252,12 +222,6 @@ class EditControllerTest extends TestCase
|
||||
'what' => 'asset',
|
||||
];
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
@@ -271,11 +235,9 @@ class EditControllerTest extends TestCase
|
||||
public function testUpdateAgain(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
@@ -286,15 +248,10 @@ class EditControllerTest extends TestCase
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
|
||||
$euro = $this->getEuro();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
|
@@ -67,7 +67,6 @@ class IndexControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$account = $this->getRandomAsset();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
@@ -76,17 +75,12 @@ class IndexControllerTest extends TestCase
|
||||
|
||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
|
||||
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
|
||||
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
||||
|
||||
|
||||
// mock calls to Preferences:
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// mock calls to Configuration:
|
||||
$this->mockDefaultConfiguration();
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
@@ -94,7 +88,6 @@ class IndexControllerTest extends TestCase
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
||||
|
@@ -23,16 +23,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Account;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionGroupFactory;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@@ -67,24 +64,21 @@ class ReconcileControllerTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$this->mock(GroupCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
$asset = $this->getRandomAsset();
|
||||
$date = new Carbon;
|
||||
$euro = $this->getEuro();
|
||||
$asset = $this->getRandomAsset();
|
||||
$date = new Carbon;
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturnTrue();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$this->mockDefaultConfiguration();
|
||||
$this->mockDefaultPreferences();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
|
||||
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.reconcile', [$asset->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
@@ -103,7 +97,7 @@ class ReconcileControllerTest extends TestCase
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$date = new Carbon;
|
||||
@@ -112,16 +106,9 @@ class ReconcileControllerTest extends TestCase
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
$this->mock(GroupCollectorInterface::class);
|
||||
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$journalRepos->shouldReceive('reconcileById')->times(3);
|
||||
@@ -130,6 +117,7 @@ class ReconcileControllerTest extends TestCase
|
||||
$factory->shouldReceive('setUser')->atLeast()->once();
|
||||
$factory->shouldReceive('create')->andReturn($group);
|
||||
|
||||
|
||||
$data = [
|
||||
'journals' => [1, 2, 3],
|
||||
'reconcile' => 'create',
|
||||
@@ -154,23 +142,14 @@ class ReconcileControllerTest extends TestCase
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$date = new Carbon;
|
||||
$factory = $this->mock(TransactionGroupFactory::class);
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
$this->mock(GroupCollectorInterface::class);
|
||||
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
@@ -27,11 +27,9 @@ use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Log;
|
||||
@@ -68,12 +66,10 @@ class ShowControllerTest extends TestCase
|
||||
$this->session(['start' => $date, 'end' => clone $date]);
|
||||
|
||||
// mock stuff:
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
//$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$this->mock(CurrencyRepositoryInterface::class);
|
||||
//$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journal = $this->getRandomWithdrawalAsArray();
|
||||
@@ -81,26 +77,19 @@ class ShowControllerTest extends TestCase
|
||||
$asset = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// mock stuff
|
||||
$this->mockDefaultConfiguration();
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// amount mocks:
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
||||
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
||||
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
||||
$this->mockLastActivity();
|
||||
// mock hasRole for user repository:
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
@@ -132,8 +121,6 @@ class ShowControllerTest extends TestCase
|
||||
$date = new Carbon;
|
||||
$this->session(['start' => $date, 'end' => clone $date]);
|
||||
// mock stuff:
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
@@ -145,22 +132,12 @@ class ShowControllerTest extends TestCase
|
||||
$euro = $this->getEuro();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// mock stuff
|
||||
$this->mockDefaultConfiguration();
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
// amount mocks:
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
// Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
|
||||
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
||||
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
||||
|
||||
|
||||
// used for session range.
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
|
@@ -22,11 +22,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Admin;
|
||||
|
||||
use Amount;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -44,14 +48,19 @@ class ConfigurationControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// for session
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
$this->be($this->user());
|
||||
$falseConfig = new Configuration;
|
||||
@@ -72,10 +81,19 @@ class ConfigurationControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
* @covers \FireflyIII\Http\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testPostIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// for session
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
@@ -86,6 +104,7 @@ class ConfigurationControllerTest extends TestCase
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['single_user_mode', false])->once();
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['is_demo_site', false])->once();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.configuration.index.post'));
|
||||
|
@@ -22,8 +22,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Admin;
|
||||
|
||||
use Amount;
|
||||
use Event;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@@ -49,6 +52,14 @@ class HomeControllerTest extends TestCase
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// default for session
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
@@ -65,6 +76,13 @@ class HomeControllerTest extends TestCase
|
||||
public function testTestMessage(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
@@ -29,6 +29,7 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class LinkControllerTest
|
||||
@@ -50,6 +51,11 @@ class LinkControllerTest extends TestCase
|
||||
public function testCreate(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
@@ -66,17 +72,23 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
$newType = LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType]));
|
||||
$another= LinkType::where('editable', 0)->first();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType, $another]));
|
||||
$repository->shouldReceive('countJournals')->andReturn(2);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
$newType->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +100,9 @@ class LinkControllerTest extends TestCase
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->be($this->user());
|
||||
@@ -107,6 +122,10 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
||||
|
||||
@@ -126,10 +145,14 @@ class LinkControllerTest extends TestCase
|
||||
public function testEditEditable(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
|
||||
|
||||
@@ -145,10 +168,15 @@ class LinkControllerTest extends TestCase
|
||||
public function testEditNonEditable(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
||||
@@ -162,9 +190,13 @@ class LinkControllerTest extends TestCase
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$linkTypes = LinkType::inRandomOrder()->take(3)->get();
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
@@ -181,8 +213,11 @@ class LinkControllerTest extends TestCase
|
||||
public function testShow(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$repository->shouldReceive('getJournalLinks')->andReturn(new Collection);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$linkType = LinkType::first();
|
||||
@@ -203,10 +238,13 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(LinkType::first());
|
||||
$repository->shouldReceive('findNull')->andReturn(LinkType::first());
|
||||
@@ -230,10 +268,13 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'create_another' => '1',
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(new LinkType);
|
||||
@@ -260,10 +301,14 @@ class LinkControllerTest extends TestCase
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
@@ -284,12 +329,14 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
@@ -314,10 +361,14 @@ class LinkControllerTest extends TestCase
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
|
@@ -52,25 +52,22 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
$config = new Configuration;
|
||||
$config->data = -1;
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
// mock update calls.
|
||||
$config = new Configuration;
|
||||
$config->data = -1;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
|
||||
// call service
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.update-check'));
|
||||
$response->assertStatus(200);
|
||||
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
@@ -79,17 +76,19 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testPost(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
// mock update calls
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
// call service
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
|
||||
$response->assertSessionHas('success');
|
||||
@@ -103,16 +102,16 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateCheck(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// set some data
|
||||
$version = config('firefly.version');
|
||||
$date = new Carbon;
|
||||
$date->subDays(5);
|
||||
@@ -138,14 +137,13 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateCheckCurrent(): void
|
||||
{
|
||||
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$date = new Carbon;
|
||||
@@ -175,13 +173,10 @@ class UpdateControllerTest extends TestCase
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$version = config('firefly.version') . '-alpha';
|
||||
$releases = [];
|
||||
$updater = $this->mock(UpdateRequest::class);
|
||||
$updater->shouldReceive('call')->andThrow(FireflyException::class, 'Something broke.');
|
||||
@@ -203,10 +198,8 @@ class UpdateControllerTest extends TestCase
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$version = config('firefly.version') . '-alpha';
|
||||
|
@@ -26,6 +26,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,9 @@ class UserControllerTest extends TestCase
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -67,6 +71,8 @@ class UserControllerTest extends TestCase
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.users.destroy', ['2']));
|
||||
$response->assertStatus(302);
|
||||
@@ -81,6 +87,9 @@ class UserControllerTest extends TestCase
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -98,6 +107,15 @@ class UserControllerTest extends TestCase
|
||||
$user = $this->user();
|
||||
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
|
||||
|
||||
Preferences::shouldReceive('getArrayForUser')->atLeast()->once()->andReturn(
|
||||
[
|
||||
'twoFactorAuthEnabled' => false,
|
||||
'twoFactorAuthSecret' => null,
|
||||
]
|
||||
);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($user);
|
||||
$response = $this->get(route('admin.users'));
|
||||
$response->assertStatus(200);
|
||||
@@ -120,6 +138,8 @@ class UserControllerTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.show', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -129,6 +149,7 @@ class UserControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\UserController
|
||||
* @covers \FireflyIII\Http\Requests\UserFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@@ -138,6 +159,10 @@ class UserControllerTest extends TestCase
|
||||
$repository->shouldReceive('updateEmail')->once();
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark');
|
||||
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'email' => 'test@example.com',
|
||||
|
@@ -24,17 +24,15 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Budget;
|
||||
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -57,24 +55,24 @@ class AmountControllerTest extends TestCase
|
||||
*/
|
||||
public function testAmount(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Now in testAmount()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
||||
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||
$response->assertStatus(200);
|
||||
// assert some reactions:
|
||||
$response->assertSee($budget->name);
|
||||
$response->assertSee('"amount":"200"');
|
||||
}
|
||||
|
||||
|
||||
@@ -83,211 +81,23 @@ class AmountControllerTest extends TestCase
|
||||
*/
|
||||
public function testAmountLargeDiff(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
|
||||
return;
|
||||
Log::info('Now in testAmountLargeDiff()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testAmountOutOfRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Now in testAmountOutOfRange()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testAmountZero(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Now in testAmountZero()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::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' => 0, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testInfoIncome(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Now in testInfoIncome()');
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
||||
|
||||
// collect transactions to return. First an expense, then income.
|
||||
$income = new Transaction;
|
||||
$income->transaction_amount = '150';
|
||||
$incomeCollection = new Collection([$income]);
|
||||
$expense = new Transaction;
|
||||
$expense->transaction_amount = '100';
|
||||
$expenseCollection = new Collection([$expense]);
|
||||
|
||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
||||
|
||||
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*/
|
||||
public function testInfoIncomeExpanded(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Now in testInfoIncomeExpanded(%s)', $range));
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
||||
|
||||
// collect transactions to return. First an expense, then income.
|
||||
$income = new Transaction;
|
||||
$income->transaction_amount = '150';
|
||||
$incomeCollection = new Collection([$income]);
|
||||
$expense = new Transaction;
|
||||
$expense->transaction_amount = '100';
|
||||
$expenseCollection = new Collection([$expense]);
|
||||
|
||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('budgets.income.info', ['20170301', '20170430']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
||||
*/
|
||||
public function testInfoIncomeInversed(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
|
||||
Log::info('Now in testInfoIncomeInversed()');
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
||||
|
||||
// collect transactions to return. First an expense, then income.
|
||||
$income = new Transaction;
|
||||
$income->transaction_amount = '100';
|
||||
$incomeCollection = new Collection([$income]);
|
||||
$expense = new Transaction;
|
||||
$expense->transaction_amount = '150';
|
||||
$expenseCollection = new Collection([$expense]);
|
||||
|
||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
||||
|
||||
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
||||
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Usually you budget about 200 per day.');
|
||||
$response->assertSee($budget->name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,23 +105,13 @@ class AmountControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostUpdateIncome(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
|
||||
Log::info('Now in testPostUpdateIncome()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
//$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
//$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('setAvailableBudget');
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.income.post'), $data);
|
||||
@@ -324,26 +124,19 @@ class AmountControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateIncome(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
|
||||
Log::info('Now in testUpdateIncome()');
|
||||
// must be in list
|
||||
$this->be($this->user());
|
||||
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
@@ -25,12 +25,11 @@ namespace Tests\Feature\Controllers\Budget;
|
||||
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -54,14 +53,13 @@ class CreateControllerTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
Log::debug('Now in testCreate()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.create'));
|
||||
@@ -78,20 +76,20 @@ class CreateControllerTest extends TestCase
|
||||
{
|
||||
Log::debug('Now in testStore()');
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$budget = $this->getRandomBudget();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('store')->andReturn($budget);
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->session(['budgets.create.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
'name' => 'New Budget ' . $this->randomInt(),
|
||||
'name' => sprintf('New Budget %s', $this->randomInt()),
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.store'), $data);
|
||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -54,12 +55,13 @@ class DeleteControllerTest extends TestCase
|
||||
{
|
||||
Log::debug('Now in testDelete()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.delete', [1]));
|
||||
@@ -75,11 +77,11 @@ class DeleteControllerTest extends TestCase
|
||||
{
|
||||
Log::debug('Now in testDestroy()');
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
|
||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -55,13 +56,11 @@ class EditControllerTest extends TestCase
|
||||
{
|
||||
Log::debug('Now in testEdit()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -77,16 +76,17 @@ class EditControllerTest extends TestCase
|
||||
{
|
||||
Log::debug('Now in testUpdate()');
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budget = $this->getRandomBudget();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('update');
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->session(['budgets.edit.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
|
@@ -24,9 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
@@ -35,6 +35,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Amount;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -60,14 +62,9 @@ class IndexControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(string $range): void
|
||||
{
|
||||
|
||||
|
||||
Log::info(sprintf('Now in testIndex(%s)', $range));
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
|
||||
// set budget limit to current month:
|
||||
$budget = $this->getRandomBudget();
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||
$budgetInfo = [
|
||||
@@ -80,11 +77,9 @@ class IndexControllerTest extends TestCase
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
@@ -95,6 +90,14 @@ class IndexControllerTest extends TestCase
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('budgets.index'));
|
||||
@@ -111,10 +114,8 @@ class IndexControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexOutOfRange(string $range): void
|
||||
{
|
||||
Log::info(sprintf('Now in testIndexOutOfRange(%s)', $range));
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
$budget = $this->getRandomBudget();
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$budgetInfo = [
|
||||
$budget->id => [
|
||||
'spent' => '0',
|
||||
@@ -129,7 +130,6 @@ class IndexControllerTest extends TestCase
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
@@ -137,7 +137,6 @@ class IndexControllerTest extends TestCase
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
@@ -148,6 +147,14 @@ class IndexControllerTest extends TestCase
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$today = new Carbon;
|
||||
$today->startOfMonth();
|
||||
@@ -166,10 +173,8 @@ class IndexControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexWithDate(string $range): void
|
||||
{
|
||||
Log::info(sprintf('Now in testIndexWithDate(%s)', $range));
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
$budget = $this->getRandomBudget();
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$budgetInfo = [
|
||||
$budget->id => [
|
||||
'spent' => '0',
|
||||
@@ -184,17 +189,13 @@ class IndexControllerTest extends TestCase
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$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);
|
||||
@@ -203,6 +204,14 @@ class IndexControllerTest extends TestCase
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('budgets.index', ['2017-01-01']));
|
||||
@@ -219,36 +228,24 @@ class IndexControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexWithInvalidDate(string $range): void
|
||||
{
|
||||
Log::info(sprintf('Now in testIndexWithInvalidDate(%s)', $range));
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
|
||||
// set budget limit to current month:
|
||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||
$budgetInfo = [
|
||||
$budget->id => [
|
||||
'spent' => '0',
|
||||
'budgeted' => '0',
|
||||
'currentRep' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('budgets.index', ['Hello-there']));
|
||||
|
@@ -23,10 +23,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Budget;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
@@ -36,11 +38,13 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ShowControllerTest
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
class ShowControllerTest extends TestCase
|
||||
{
|
||||
@@ -63,36 +67,41 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoBudget(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
|
||||
Log::info(sprintf('Now in testNoBudget(%s)', $range));
|
||||
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
try {
|
||||
$date = new Carbon;
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
// mock calls
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->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'));
|
||||
$response = $this->get(route('budgets.no-budget', ['2019-01-01', '2019-01-31']));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
@@ -106,30 +115,35 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoBudgetAll(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
$this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
try {
|
||||
$date = new Carbon;
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Now in testNoBudgetAll(%s)', $range));
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
// mock calls
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
$date = new Carbon();
|
||||
try {
|
||||
$date = new Carbon;
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
$this->session(['start' => $date, 'end' => clone $date]);
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -140,53 +154,6 @@ class ShowControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*/
|
||||
public function testNoBudgetDate(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Now in testNoBudgetDate(%s)', $range));
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->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">');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
@@ -195,31 +162,29 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testShow(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Now in testShow(%s)', $range));
|
||||
// mock stuff
|
||||
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetLimit = $this->getRandomBudgetLimit();
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// mock calls
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
@@ -228,9 +193,14 @@ class ShowControllerTest extends TestCase
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
|
||||
$date = new Carbon();
|
||||
$date->subDay();
|
||||
$this->session(['first' => $date]);
|
||||
try {
|
||||
$date = new Carbon;
|
||||
$date->subDay();
|
||||
$this->session(['first' => $date]);
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -239,24 +209,6 @@ class ShowControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||
*/
|
||||
public function testShowByBadBudgetLimit(): void
|
||||
{
|
||||
Log::info('Now in testShowByBadBudgetLimit()');
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.show.limit', [1, 8]));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
@@ -265,29 +217,32 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testShowByBudgetLimit(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Now in testShowByBudgetLimit(%s)', $range));
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
// mock calls
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
|
Reference in New Issue
Block a user