mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improved test coverage.
This commit is contained in:
parent
bb1da31830
commit
ad1c61d959
@ -46,7 +46,7 @@ class AccountController extends Controller
|
|||||||
$cache->addProperty('all');
|
$cache->addProperty('all');
|
||||||
$cache->addProperty('accounts');
|
$cache->addProperty('accounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class AccountController extends Controller
|
|||||||
$cache->addProperty('frontpage');
|
$cache->addProperty('frontpage');
|
||||||
$cache->addProperty('accounts');
|
$cache->addProperty('accounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ class AccountController extends Controller
|
|||||||
$cache->addProperty('single');
|
$cache->addProperty('single');
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($end >= $current) {
|
while ($end >= $current) {
|
||||||
|
@ -44,7 +44,7 @@ class BillController extends Controller
|
|||||||
$cache->addProperty('bill');
|
$cache->addProperty('bill');
|
||||||
$cache->addProperty($bill->id);
|
$cache->addProperty($bill->id);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
// get first transaction or today for start:
|
// get first transaction or today for start:
|
||||||
@ -88,7 +88,7 @@ class BillController extends Controller
|
|||||||
$cache->addProperty('bills');
|
$cache->addProperty('bills');
|
||||||
$cache->addProperty('frontpage');
|
$cache->addProperty('frontpage');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
|
@ -49,7 +49,7 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty('budget');
|
$cache->addProperty('budget');
|
||||||
$cache->addProperty('budget');
|
$cache->addProperty('budget');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty($budget->id);
|
$cache->addProperty($budget->id);
|
||||||
$cache->addProperty($repetition->id);
|
$cache->addProperty($repetition->id);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.day'), 'date');
|
$chart->addColumn(trans('firefly.day'), 'date');
|
||||||
@ -149,7 +149,7 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty('budget');
|
$cache->addProperty('budget');
|
||||||
$cache->addProperty('all');
|
$cache->addProperty('all');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty('budget');
|
$cache->addProperty('budget');
|
||||||
$cache->addProperty('year');
|
$cache->addProperty('year');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
// add columns:
|
// add columns:
|
||||||
|
@ -84,7 +84,7 @@ class CategoryController extends Controller
|
|||||||
$cache->addProperty('category');
|
$cache->addProperty('category');
|
||||||
$cache->addProperty('frontpage');
|
$cache->addProperty('frontpage');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = $repository->getCategoriesAndExpensesCorrected($start, $end);
|
$set = $repository->getCategoriesAndExpensesCorrected($start, $end);
|
||||||
|
@ -99,79 +99,4 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts'));
|
return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
||||||
*/
|
|
||||||
public function routes()
|
|
||||||
{
|
|
||||||
$directory = '/vagrant_data/Sites/firefly-iii-help';
|
|
||||||
$languages = array_keys(Config::get('firefly.lang'));
|
|
||||||
$routes = [];
|
|
||||||
$ignored = [
|
|
||||||
'debugbar.openhandler', 'debugbar.assets.css', 'debugbar.assets.js', 'register', 'routes', 'daterange',
|
|
||||||
'flush', 'delete-account-post', 'change-password-post', 'logout', 'login', 'tags.hideTagHelp',
|
|
||||||
'budgets.postIncome', 'flush'
|
|
||||||
];
|
|
||||||
|
|
||||||
$ignoreMatch = ['.store', '.update', '.destroy', 'json.'];
|
|
||||||
|
|
||||||
$routeCollection = Route::getRoutes();
|
|
||||||
/** @var \Illuminate\Routing\Route $object */
|
|
||||||
foreach ($routeCollection as $object) {
|
|
||||||
// get name:
|
|
||||||
$name = $object->getName();
|
|
||||||
// has name and not in ignore list?
|
|
||||||
if (strlen($name) > 0 && !in_array($name, $ignored)) {
|
|
||||||
|
|
||||||
// not in ignoreMatch?
|
|
||||||
$continue = true;
|
|
||||||
foreach ($ignoreMatch as $ignore) {
|
|
||||||
$match = strpos($name, $ignore);
|
|
||||||
if (!($match === false)) {
|
|
||||||
$continue = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($ignore, $match);
|
|
||||||
|
|
||||||
if ($continue) {
|
|
||||||
|
|
||||||
$routes[] = $name;
|
|
||||||
|
|
||||||
// check all languages:
|
|
||||||
foreach ($languages as $lang) {
|
|
||||||
$file = $directory . '/' . $lang . '/' . $name . '.md';
|
|
||||||
if (!file_exists($file)) {
|
|
||||||
touch($file);
|
|
||||||
echo $name . '<br />';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop directories with language file.
|
|
||||||
// tag the ones not in the list of approved routes.
|
|
||||||
foreach ($languages as $lang) {
|
|
||||||
$dir = $directory . '/' . $lang;
|
|
||||||
$set = scandir($dir);
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
if ($entry != '.' && $entry != '..') {
|
|
||||||
$name = str_replace('.md', '', $entry);
|
|
||||||
if (!in_array($name, $routes)) {
|
|
||||||
$file = $dir . '/' . $entry;
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo 'Done!';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class JsonController extends Controller
|
|||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('box-bills-paid');
|
$cache->addProperty('box-bills-paid');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
@ -97,7 +97,7 @@ class JsonController extends Controller
|
|||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('box-bills-unpaid');
|
$cache->addProperty('box-bills-unpaid');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
@ -156,7 +156,7 @@ class JsonController extends Controller
|
|||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('box-in');
|
$cache->addProperty('box-in');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount');
|
$amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount');
|
||||||
@ -184,7 +184,7 @@ class JsonController extends Controller
|
|||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('box-out');
|
$cache->addProperty('box-out');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount');
|
$amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount');
|
||||||
|
@ -116,6 +116,6 @@ class NewUserController extends Controller
|
|||||||
Session::flash('success', 'New account(s) created!');
|
Session::flash('success', 'New account(s) created!');
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
return Redirect::route('home');
|
return Redirect::route('index');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -141,18 +141,9 @@ class ReportController extends Controller
|
|||||||
Session::flash('gaEventAction', 'year');
|
Session::flash('gaEventAction', 'year');
|
||||||
Session::flash('gaEventLabel', $start->format('Y'));
|
Session::flash('gaEventLabel', $start->format('Y'));
|
||||||
|
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'reports.year',
|
'reports.year',
|
||||||
compact(
|
compact('start', 'shared', 'accounts', 'incomes', 'expenses', 'subTitle', 'subTitleIcon', 'incomeTopLength', 'expenseTopLength')
|
||||||
'start', // the date for this report.
|
|
||||||
'shared', // is a shared report?
|
|
||||||
'accounts', // all accounts
|
|
||||||
'incomes', 'expenses', // expenses and incomes.
|
|
||||||
'subTitle', 'subTitleIcon', // subtitle and subtitle icon.
|
|
||||||
'incomeTopLength', // length of income top X
|
|
||||||
'expenseTopLength' // length of expense top X.
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,8 +183,6 @@ Route::controllers(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
Route::get('/routes', ['uses' => 'HomeController@routes', 'as' => 'routes']);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Home Controller
|
* Home Controller
|
||||||
*/
|
*/
|
||||||
|
@ -140,7 +140,7 @@ class TransactionJournal extends Model
|
|||||||
$cache->addProperty($this->id);
|
$cache->addProperty($this->id);
|
||||||
$cache->addProperty('amount');
|
$cache->addProperty('amount');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$cache->addProperty($preference->data);
|
$cache->addProperty($preference->data);
|
||||||
$cache->addProperty('frontPageaccounts');
|
$cache->addProperty('frontPageaccounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = Auth::user()
|
$set = Auth::user()
|
||||||
@ -233,7 +233,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$cache->addProperty($ids);
|
$cache->addProperty($ids);
|
||||||
$cache->addProperty('piggyAccounts');
|
$cache->addProperty('piggyAccounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = array_unique($ids);
|
$ids = array_unique($ids);
|
||||||
|
@ -89,7 +89,7 @@ class Amount
|
|||||||
$cache->addProperty('formatJournal');
|
$cache->addProperty('formatJournal');
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class Steam
|
|||||||
$cache->addProperty($date);
|
$cache->addProperty($date);
|
||||||
$cache->addProperty($ignoreVirtualBalance);
|
$cache->addProperty($ignoreVirtualBalance);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Journal extends Twig_Extension
|
|||||||
$cache->addProperty($journal->id);
|
$cache->addProperty($journal->id);
|
||||||
$cache->addProperty('typeIcon');
|
$cache->addProperty('typeIcon');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get();
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $journal->transactionType->type;
|
$type = $journal->transactionType->type;
|
||||||
|
@ -122,4 +122,32 @@ class HomeControllerTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers FireflyIII\Http\Controllers\HomeController::index
|
||||||
|
*/
|
||||||
|
public function testIndexEmpty()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
// mock ALL THE THINGS!
|
||||||
|
$repository->shouldReceive('countAccounts')->once()->andReturn(0);
|
||||||
|
|
||||||
|
// language preference:
|
||||||
|
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$language->data = 'en';
|
||||||
|
$language->save();
|
||||||
|
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
|
||||||
|
|
||||||
|
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$lastActivity->data = microtime();
|
||||||
|
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
|
||||||
|
|
||||||
|
$this->call('GET', '/');
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertRedirectedToRoute('new-user.index');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
108
tests/controllers/NewUserControllerTest.php
Normal file
108
tests/controllers/NewUserControllerTest.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class NewUserControllerTest
|
||||||
|
*/
|
||||||
|
class NewUserControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
|
* This method is called before a test is executed.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
|
* This method is called after a test is executed.
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers FireflyIII\Http\Controllers\NewUserController::index
|
||||||
|
*/
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
// mock ALL THE THINGS!
|
||||||
|
$repository->shouldReceive('countAccounts')->once()->andReturn(0);
|
||||||
|
|
||||||
|
// language preference:
|
||||||
|
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$language->data = 'en';
|
||||||
|
$language->save();
|
||||||
|
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
|
||||||
|
|
||||||
|
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$lastActivity->data = microtime();
|
||||||
|
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
|
||||||
|
|
||||||
|
$this->call('GET', '/new-user');
|
||||||
|
$this->assertResponseStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexNoAccounts()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
// mock ALL THE THINGS!
|
||||||
|
$repository->shouldReceive('countAccounts')->once()->andReturn(3);
|
||||||
|
|
||||||
|
// language preference:
|
||||||
|
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$language->data = 'en';
|
||||||
|
$language->save();
|
||||||
|
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
|
||||||
|
|
||||||
|
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$lastActivity->data = microtime();
|
||||||
|
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
|
||||||
|
|
||||||
|
$this->call('GET', '/new-user');
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertRedirectedToRoute('index');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostIndex()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'_token' => 'replaceMe',
|
||||||
|
'bank_name' => 'Some Bank',
|
||||||
|
'bank_balance' => '100',
|
||||||
|
'balance_currency_id' => $currency->id,
|
||||||
|
'savings_balance' => '100',
|
||||||
|
'credit_card_limit' => '100',
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$repository->shouldReceive('store')->andReturn($account);
|
||||||
|
|
||||||
|
$this->call('POST', '/new-user/submit', $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertRedirectedToRoute('index');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user