firefly-iii/tests/Feature/Controllers/Chart/CategoryControllerTest.php

154 lines
6.2 KiB
PHP
Raw Normal View History

2017-02-12 10:58:16 -06:00
<?php
/**
* CategoryControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* 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/>.
2017-02-12 10:58:16 -06:00
*/
2017-07-07 23:28:44 -05:00
declare(strict_types=1);
2017-02-12 10:58:16 -06:00
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
2017-03-12 03:22:33 -05:00
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
2017-02-12 10:58:16 -06:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
2017-03-12 03:22:33 -05:00
/**
* Class CategoryControllerTest
*
2017-08-12 03:27:45 -05:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-03-12 03:22:33 -05:00
*/
2017-02-12 10:58:16 -06:00
class CategoryControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::all
2017-02-17 13:14:38 -06:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::__construct
2017-02-12 10:58:16 -06:00
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testAll(string $range)
{
2017-03-12 03:22:33 -05:00
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
2017-02-12 10:58:16 -06:00
2017-03-12 03:22:33 -05:00
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
2017-03-25 07:41:17 -05:00
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon('1900-01-01'))->once();
2017-03-12 03:22:33 -05:00
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
2017-02-12 10:58:16 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.all', [1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::frontpage
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testFrontpage(string $range)
{
2017-03-12 03:22:33 -05:00
$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([]);
2017-02-12 10:58:16 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.frontpage', [1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::reportPeriod
*/
public function testReportPeriod()
{
2017-03-12 03:22:33 -05:00
$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();
2017-02-12 10:58:16 -06:00
$this->be($this->user());
$response = $this->get(route('chart.category.period', [1, '1', '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::reportPeriodNoCategory
*/
public function testReportPeriodNoCategory()
{
2017-03-12 03:22:33 -05:00
$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();
2017-02-12 10:58:16 -06:00
$this->be($this->user());
$response = $this->get(route('chart.category.period.no-category', ['1', '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::specificPeriod
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testSpecificPeriod(string $range)
{
2017-03-12 03:22:33 -05:00
$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();
2017-02-12 10:58:16 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.specific', ['1', '2012-01-01']));
$response->assertStatus(200);
}
2017-02-16 15:33:32 -06:00
}