mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-20 03:10:57 +00:00
Expand tests.
This commit is contained in:
@@ -13,11 +13,20 @@ namespace Tests\Feature\Controllers\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class CategoryControllerTest
|
||||
*
|
||||
* @package Tests\Feature\Controllers\Chart
|
||||
*/
|
||||
class CategoryControllerTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -30,11 +39,15 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testAll(string $range)
|
||||
{
|
||||
$catRepository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
|
||||
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$catRepository->shouldReceive('firstUseDate')->andReturn(new Carbon);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
|
||||
$generator->shouldReceive('multiSet')->once()->andReturn([]);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -52,15 +65,17 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testCurrentPeriod(string $range)
|
||||
{
|
||||
// this is actually for makePeriodChart
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$account = factory(Account::class)->make();
|
||||
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('chart.category.current', [1]));
|
||||
@@ -75,17 +90,17 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testFrontpage(string $range)
|
||||
{
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$category = $this->user()->categories()->first();
|
||||
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
// get one category
|
||||
$categoryRepository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
||||
// get one account
|
||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
// always return zero
|
||||
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$categoryRepository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$category = factory(Category::class)->make();
|
||||
$account = factory(Account::class)->make();
|
||||
|
||||
$repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
|
||||
$generator->shouldReceive('singleSet')->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -98,6 +113,14 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testReportPeriod()
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
|
||||
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
|
||||
$repository->shouldReceive('periodIncome')->andReturn([])->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.period', [1, '1', '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
@@ -108,6 +131,13 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testReportPeriodNoCategory()
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
|
||||
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
|
||||
$repository->shouldReceive('periodIncomeNoCategory')->andReturn([])->once();
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.category.period.no-category', ['1', '20120101', '20120131']));
|
||||
$response->assertStatus(200);
|
||||
@@ -122,12 +152,15 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testSpecificPeriod(string $range)
|
||||
{
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$account = factory(Account::class)->make();
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
|
Reference in New Issue
Block a user