mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Big bunch of code to improve test coverage.
This commit is contained in:
94
tests/Feature/Controllers/Category/CreateControllerTest.php
Normal file
94
tests/Feature/Controllers/Category/CreateControllerTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateControllerTest.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class CreateControllerTest
|
||||
*/
|
||||
class CreateControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\CreateController
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
Log::debug('TestCreate()');
|
||||
// mock stuff
|
||||
$this->mock(CategoryRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('categories.create'));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\CategoryFormRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
Log::debug('Test store()');
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
$repository->shouldReceive('findNull')->andReturn(new Category);
|
||||
$repository->shouldReceive('store')->andReturn(new Category);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
|
||||
$this->session(['categories.create.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
'name' => 'New Category ' . $this->randomInt(),
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('categories.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
88
tests/Feature/Controllers/Category/DeleteControllerTest.php
Normal file
88
tests/Feature/Controllers/Category/DeleteControllerTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* DeleteControllerTest.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class DeleteControllerTest
|
||||
*/
|
||||
class DeleteControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\DeleteController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
Log::debug('Test Delete()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('categories.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\DeleteController
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
Log::debug('Test destroy()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
$categoryRepos->shouldReceive('destroy')->andReturn(true);
|
||||
|
||||
$this->session(['categories.delete.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('categories.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
101
tests/Feature/Controllers/Category/EditControllerTest.php
Normal file
101
tests/Feature/Controllers/Category/EditControllerTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* EditControllerTest.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class EditControllerTest
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\EditController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
Log::debug('Test edit()');
|
||||
// mock stuff
|
||||
$this->mock(CategoryRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('categories.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\EditController
|
||||
* @covers \FireflyIII\Http\Requests\CategoryFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
Log::debug('Test update()');
|
||||
$category = Category::first();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||
|
||||
$repository->shouldReceive('update');
|
||||
$repository->shouldReceive('findNull')->andReturn($category);
|
||||
|
||||
$this->session(['categories.edit.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
'name' => 'Updated Category ' . $this->randomInt(),
|
||||
'active' => 1,
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('categories.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
80
tests/Feature/Controllers/Category/IndexControllerTest.php
Normal file
80
tests/Feature/Controllers/Category/IndexControllerTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexControllerTest.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IndexControllerTest
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\IndexController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
Log::debug('Test index()');
|
||||
// mock stuff
|
||||
$category = factory(Category::class)->make();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
|
||||
$categoryRepos->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('categories.index'));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
}
|
@@ -25,9 +25,11 @@ namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
@@ -38,6 +40,7 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -64,37 +67,30 @@ class NoCategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategory(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Test noCategory()');
|
||||
// mock stuff
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
||||
$this->mockDefaultSession();
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
$this->mockLastActivity();
|
||||
|
||||
// get the journal with the most recent date for firstNull:
|
||||
$journal = $this->user()->transactionJournals()->orderBy('date', 'DESC')->first();
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn($journal);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -113,35 +109,30 @@ class NoCategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategoryAll(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Test nocategoryAll()');
|
||||
// mock stuff
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -159,35 +150,32 @@ class NoCategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategoryDate(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info('Test nocategorydate()');
|
||||
// mock stuff
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::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);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
||||
$this->mockDefaultSession();
|
||||
// list size
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
$this->mockLastActivity();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||
|
||||
Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
|
||||
Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);
|
||||
|
@@ -25,9 +25,11 @@ namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -39,6 +41,7 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -65,44 +68,38 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testShow(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Test show(%s)', $range));
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
||||
|
||||
// mock stuff
|
||||
$categoryRepos->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);
|
||||
$categoryRepos->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);
|
||||
$categoryRepos->shouldReceive('firstUseDate')->andReturnNull();
|
||||
|
||||
//$accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
|
||||
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
|
||||
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);
|
||||
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||
|
||||
Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
|
||||
Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);
|
||||
@@ -126,36 +123,28 @@ class ShowControllerTest extends TestCase
|
||||
*/
|
||||
public function testShowAll(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Test showAll(%s)', $range));
|
||||
// mock stuff
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
|
||||
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());
|
||||
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -164,115 +153,4 @@ class ShowControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*/
|
||||
public function testShowByDate(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
Log::info(sprintf('Test testShowByDate(%s)', $range));
|
||||
// mock stuff
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::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'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$month = new Carbon();
|
||||
$month->startOfMonth();
|
||||
$journal = TransactionJournal::where('date', '>=', $month->format('Y-m-d') . ' 00:00:00')->first();
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn($journal);
|
||||
|
||||
//$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
|
||||
|
||||
$repository->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);
|
||||
$repository->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$today = new Carbon();
|
||||
$today->subDay();
|
||||
$response = $this->get(route('categories.show', [1, $today->format('Y-m-d')]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Category\ShowController
|
||||
*
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*/
|
||||
public function testShowEmpty(string $range): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$latestJournal = $this->user()->transactionJournals()
|
||||
->orderBy('date', 'DESC')->first();
|
||||
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn($latestJournal);
|
||||
|
||||
// mock stuff
|
||||
$repository->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);
|
||||
$repository->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
// $accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
|
||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast(1);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('categories.show', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user