Files
firefly-iii/tests/acceptance/Controllers/Chart/CategoryControllerTest.php

149 lines
5.5 KiB
PHP
Raw Normal View History

2016-11-19 20:30:30 +01:00
<?php
2016-12-06 09:16:36 +01:00
/**
* CategoryControllerTest.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2016-11-19 20:30:30 +01:00
namespace Chart;
2016-11-20 11:43:19 +01:00
2016-12-18 19:34:03 +01:00
use Carbon\Carbon;
2016-12-22 07:13:37 +01:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2016-12-18 19:34:03 +01:00
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
2016-12-22 07:13:37 +01:00
use Illuminate\Support\Collection;
2016-11-19 20:30:30 +01:00
use TestCase;
/**
2016-12-10 06:54:50 +01:00
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:40.
2016-11-19 20:30:30 +01:00
*/
class CategoryControllerTest extends TestCase
{
2016-11-20 07:24:18 +01:00
2016-11-19 20:30:30 +01:00
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
2016-11-20 08:30:25 +01:00
parent::setUp();
2016-11-19 20:30:30 +01:00
}
/**
2016-12-10 07:29:36 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::all
* @dataProvider dateRangeProvider
2016-12-15 17:16:46 +01:00
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-12-10 07:29:36 +01:00
public function testAll(string $range)
2016-11-19 20:30:30 +01:00
{
2016-12-18 19:34:03 +01:00
$catRepository = $this->mock(CategoryRepositoryInterface::class);
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$catRepository->shouldReceive('firstUseDate')->andReturn(new Carbon);
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.all', [1]));
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-10 07:29:36 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::currentPeriod
2016-12-22 07:13:37 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
2016-12-10 07:29:36 +01:00
* @dataProvider dateRangeProvider
2016-12-15 17:16:46 +01:00
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-12-10 07:29:36 +01:00
public function testCurrentPeriod(string $range)
2016-11-19 20:30:30 +01:00
{
2016-12-22 07:13:37 +01:00
// 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');
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.current', [1]));
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-10 07:29:36 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::frontpage
* @dataProvider dateRangeProvider
2016-12-15 17:16:46 +01:00
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-12-10 07:29:36 +01:00
public function testFrontpage(string $range)
2016-11-19 20:30:30 +01:00
{
2016-12-22 07:13:37 +01:00
$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');
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-12-22 07:13:37 +01:00
$this->call('get', route('chart.category.frontpage', [1]));
2016-12-10 07:29:36 +01:00
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
2016-12-04 08:11:29 +01:00
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::reportPeriod
2016-12-04 08:11:29 +01:00
*/
public function testReportPeriod()
{
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->call('get', route('chart.category.period', [1, '1', '20120101', '20120131']));
$this->assertResponseStatus(200);
2016-12-04 08:11:29 +01:00
}
2016-12-06 09:16:36 +01:00
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::reportPeriodNoCategory
2016-12-06 09:16:36 +01:00
*/
public function testReportPeriodNoCategory()
{
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->call('get', route('chart.category.period.no-category', ['1', '20120101', '20120131']));
$this->assertResponseStatus(200);
2016-12-06 09:16:36 +01:00
}
2016-11-19 20:30:30 +01:00
/**
2016-12-15 17:16:46 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::specificPeriod
2016-12-22 07:13:37 +01:00
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
2016-12-10 07:29:36 +01:00
* @dataProvider dateRangeProvider
2016-12-15 17:16:46 +01:00
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-12-10 07:29:36 +01:00
public function testSpecificPeriod(string $range)
2016-11-20 11:43:19 +01:00
{
2016-12-22 07:13:37 +01:00
$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');
2016-12-10 07:29:36 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.specific', ['1', '2012-01-01']));
$this->assertResponseStatus(200);
2016-11-20 11:43:19 +01:00
}
2016-11-19 20:30:30 +01:00
}