Expand some tests.

This commit is contained in:
James Cole
2017-03-11 22:28:51 +01:00
parent 4abc271805
commit 8f14c78ba1
3 changed files with 102 additions and 5 deletions

View File

@@ -12,6 +12,16 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Steam;
use Tests\TestCase;
class AccountControllerTest extends TestCase
@@ -25,6 +35,14 @@ class AccountControllerTest extends TestCase
*/
public function testExpenseAccounts(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->andReturn(new Collection);
$generator->shouldReceive('singleSet')->andReturn([]);
Steam::shouldReceive('balancesById')->twice()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense'));
@@ -33,12 +51,26 @@ class AccountControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseBudget
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::getBudgetNames
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testExpenseBudget(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131']));
@@ -53,6 +85,18 @@ class AccountControllerTest extends TestCase
*/
public function testExpenseCategory(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131']));
@@ -70,6 +114,14 @@ class AccountControllerTest extends TestCase
*/
public function testFrontpage(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
Steam::shouldReceive('balanceInRange')->andReturn([]);
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.frontpage'));
@@ -84,6 +136,18 @@ class AccountControllerTest extends TestCase
*/
public function testIncomeCategory(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131']));
@@ -98,6 +162,13 @@ class AccountControllerTest extends TestCase
*/
public function testPeriod(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.period', [1, '2012-01-01']));
@@ -106,9 +177,13 @@ class AccountControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::report
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::accountBalanceChart
*/
public function testReport()
{
$generator = $this->mock(GeneratorInterface::class);
$generator->shouldReceive('multiSet')->andreturn([]);
$this->be($this->user());
$response = $this->get(route('chart.account.report', ['1', '20120101', '20120131']));
$response->assertStatus(200);
@@ -122,6 +197,13 @@ class AccountControllerTest extends TestCase
*/
public function testRevenueAccounts(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->andReturn(new Collection);
$generator->shouldReceive('singleSet')->andReturn([]);
Steam::shouldReceive('balancesById')->twice()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.revenue'));
@@ -136,6 +218,11 @@ class AccountControllerTest extends TestCase
*/
public function testSingle(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.single', [1]));