firefly-iii/tests/Feature/Controllers/Category/NoCategoryControllerTest.php

195 lines
8.0 KiB
PHP
Raw Normal View History

2018-07-14 15:48:22 -05:00
<?php
/**
* NoCategoryControllerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-07-14 15:48:22 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-14 15:48:22 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-07-14 15:48:22 -05:00
*
* This program is distributed in the hope that it will be useful,
2018-07-14 15:48:22 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-07-14 15:48:22 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-14 15:48:22 -05:00
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Category;
use Carbon\Carbon;
2019-07-24 12:02:41 -05:00
use Exception;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
2019-06-23 03:40:46 -05:00
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Preference;
2018-07-14 15:48:22 -05:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
2018-09-03 11:52:46 -05:00
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-07-14 15:48:22 -05:00
use Illuminate\Pagination\LengthAwarePaginator;
use Log;
2018-09-03 11:52:46 -05:00
use Mockery;
2018-07-14 15:48:22 -05:00
use Navigation;
use Preferences;
2018-07-14 15:48:22 -05:00
use Tests\TestCase;
2019-07-24 12:02:41 -05:00
2018-07-14 15:48:22 -05:00
/**
*
* Class NoCategoryControllerTest
2019-07-24 12:02:41 -05:00
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-07-14 15:48:22 -05:00
*/
class NoCategoryControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-07-14 15:48:22 -05:00
}
/**
* @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testNoCategory(string $range): void
{
2019-07-25 07:19:49 -05:00
$collector = $this->mock(GroupCollectorInterface::class);
2019-07-24 12:02:41 -05:00
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
2019-07-25 07:19:49 -05:00
$userRepos = $this->mock(UserRepositoryInterface::class);
2018-07-14 15:48:22 -05:00
$this->mockDefaultSession();
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$this->mockLastActivity();
2018-07-14 15:48:22 -05:00
// get the journal with the most recent date for firstNull:
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2018-07-14 15:48:22 -05:00
$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();
2018-07-14 15:48:22 -05:00
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
2018-07-14 15:48:22 -05:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.no-category'));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
* @dataProvider dateRangeProvider
*
* @param string $range
2019-07-24 12:02:41 -05:00
* @throws Exception
2018-07-14 15:48:22 -05:00
*/
public function testNoCategoryAll(string $range): void
{
2019-07-25 07:19:49 -05:00
$collector = $this->mock(GroupCollectorInterface::class);
2019-07-24 12:02:41 -05:00
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
2019-07-25 07:19:49 -05:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
2018-12-12 13:30:25 -06:00
$this->mockDefaultSession();
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
2019-01-01 11:03:24 -06:00
$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2018-07-14 15:48:22 -05:00
$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();
2018-07-14 15:48:22 -05:00
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
2018-07-14 15:48:22 -05:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.no-category', ['all']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
* @dataProvider dateRangeProvider
*
* @param string $range
2019-07-24 12:02:41 -05:00
* @throws Exception
2018-07-14 15:48:22 -05:00
*/
public function testNoCategoryDate(string $range): void
{
2019-07-25 07:19:49 -05:00
$collector = $this->mock(GroupCollectorInterface::class);
2019-07-24 12:02:41 -05:00
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
2019-07-25 07:19:49 -05:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
2018-12-12 13:30:25 -06:00
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
2018-09-03 11:52:46 -05:00
$this->mockDefaultSession();
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$this->mockLastActivity();
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2018-07-14 15:48:22 -05:00
$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()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
2018-07-14 15:48:22 -05:00
Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);
Navigation::shouldReceive('startOfPeriod')->andReturn(new Carbon);
Navigation::shouldReceive('endOfPeriod')->andReturn(new Carbon);
Navigation::shouldReceive('periodShow')->andReturn('Some date');
Navigation::shouldReceive('blockPeriods')->andReturn([['period' => '1M', 'start' => new Carbon, 'end' => new Carbon]])->once();
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.no-category', ['2016-01-01']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
2018-07-22 13:33:17 -05:00
}