New tests

This commit is contained in:
James Cole
2017-02-12 17:58:16 +01:00
parent ec146d4cbe
commit 2c36820622
12 changed files with 761 additions and 14 deletions

View File

@@ -0,0 +1,57 @@
<?php
/**
* TwoFactorControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Auth;
use FireflyIII\Models\Preference;
use Preferences;
use Tests\TestCase;
class TwoFactorControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::index
*/
public function testIndex()
{
$this->be($this->user());
$falsePreference = new Preference;
$falsePreference->data = true;
$secretPreference = new Preference;
$secretPreference->data = 'BlablaSeecret';
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
$response = $this->get(route('two-factor.index'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::lostTwoFactor
*/
public function testLostTwoFactor()
{
$this->be($this->user());
$truePreference = new Preference;
$truePreference->data = true;
$secretPreference = new Preference;
$secretPreference->data = 'BlablaSeecret';
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
$response = $this->get(route('two-factor.lost'));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* AccountControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Tests\TestCase;
class AccountControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseAccounts
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testExpenseAccounts(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseBudget
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testExpenseBudget(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseCategory
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testExpenseCategory(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::frontpage
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testFrontpage(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.frontpage'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::incomeCategory
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testIncomeCategory(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::period
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testPeriod(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.period', [1, '2012-01-01']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::report
*/
public function testReport()
{
$this->be($this->user());
$response = $this->get(route('chart.account.report', ['1', '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::revenueAccounts
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testRevenueAccounts(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.revenue'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::single
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testSingle(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.single', [1]));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* BillControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Tests\TestCase;
class BillControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\BillController::frontpage
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testFrontpage(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.bill.frontpage'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\BillController::single
*/
public function testSingle()
{
$this->be($this->user());
$response = $this->get(route('chart.bill.single', [1]));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* BudgetControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Tests\TestCase;
class BudgetControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::budget
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testBudget(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('firstUseDate')->andReturn(new Carbon('2015-01-01'));
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.budget.budget', [1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::budgetLimit
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testBudgetLimit(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.budget.budget-limit', [1,1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::frontpage
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testFrontpage(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.budget.frontpage'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::period
*/
public function testPeriod()
{
$this->be($this->user());
$response = $this->get(route('chart.budget.period', [1,'1','20120101','20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::periodNoBudget
*/
public function testPeriodNoBudget()
{
$this->be($this->user());
$response = $this->get(route('chart.budget.period.no-budget', ['1','20120101','20120131']));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* CategoryControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
class CategoryControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::all
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testAll(string $range)
{
$catRepository = $this->mock(CategoryRepositoryInterface::class);
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$catRepository->shouldReceive('firstUseDate')->andReturn(new Carbon);
$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::currentPeriod
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
* @dataProvider dateRangeProvider
*
* @param string $range
*/
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');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.current', [1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::frontpage
* @dataProvider dateRangeProvider
*
* @param string $range
*/
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');
$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()
{
$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()
{
$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)
{
$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');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.specific', ['1', '2012-01-01']));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* CategoryReportControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Tests\TestCase;
class CategoryReportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::accountExpense
*/
public function testAccountExpense()
{
$this->be($this->user());
$response = $this->get(route('chart.category.account-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::accountIncome
*/
public function testAccountIncome()
{
$this->be($this->user());
$response = $this->get(route('chart.category.account-income', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::categoryExpense
*/
public function testCategoryExpense()
{
$this->be($this->user());
$response = $this->get(route('chart.category.category-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::categoryIncome
*/
public function testCategoryIncome()
{
$this->be($this->user());
$response = $this->get(route('chart.category.category-income', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::mainChart
*/
public function testMainChart()
{
$this->be($this->user());
$response = $this->get(route('chart.category.main', ['1', '1', '20120101', '20120131']));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* PiggyBankControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Tests\TestCase;
class PiggyBankControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\PiggyBankController::history
*/
public function testHistory()
{
$this->be($this->user());
$response = $this->get(route('chart.piggy-bank.history', [1]));
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* ReportControllerTest.php
* Copyright (c) 2017 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.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use Tests\TestCase;
class ReportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::netWorth
*/
public function testNetWorth()
{
$this->be($this->user());
$response = $this->get(route('chart.report.net-worth', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::operations
*/
public function testOperations()
{
$this->be($this->user());
$response = $this->get(route('chart.report.operations', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::sum
*/
public function testSum()
{
$this->be($this->user());
$response = $this->get(route('chart.report.sum', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
}