Expand test code.

This commit is contained in:
James Cole
2017-12-17 18:23:10 +01:00
parent c1e1da12c2
commit c7d4ff6f27
15 changed files with 446 additions and 42 deletions

View File

@@ -183,7 +183,7 @@ class ReconcileController extends Controller
$currencyId = intval($account->getMeta('currency_id'));
$currency = $currencyRepos->find($currencyId);
if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrency();
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
}
// no start or end:
@@ -233,9 +233,10 @@ class ReconcileController extends Controller
// get main transaction:
$transaction = $repository->getAssetTransaction($journal);
$account = $transaction->account;
return view('accounts.reconcile.show', compact('journal', 'subTitle', 'transaction'));
return view('accounts.reconcile.show', compact('journal', 'subTitle', 'transaction', 'account'));
}
/**
@@ -250,7 +251,7 @@ class ReconcileController extends Controller
{
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$transactions = $repository->getTransactionsById($request->get('transactions'));
$transactions = $repository->getTransactionsById($request->get('transactions') ?? []);
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$repository->reconcile($transaction); // mark as reconciled.
@@ -313,7 +314,7 @@ class ReconcileController extends Controller
$currencyId = intval($account->getMeta('currency_id'));
$currency = $currencyRepos->find($currencyId);
if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrency();
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
}
$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);
@@ -383,7 +384,7 @@ class ReconcileController extends Controller
/** @var Transaction $transaction */
$transaction = $account->transactions()->first();
if (null === $transaction) {
throw new FireflyException('Expected a transaction. This account has none. BEEP, error.');
throw new FireflyException(sprintf('Expected a transaction. Account #%d has none. BEEP, error.', $account->id)); // @codeCoverageIgnore
}
$journal = $transaction->transactionJournal;

View File

@@ -32,21 +32,15 @@ use Illuminate\Http\Request;
use Schema;
/**
* @codeCoverageIgnore
* Class LoginController
*
* This controller handles authenticating users for the application and
* redirecting them to your home screen. The controller uses a trait
* to conveniently provide its functionality to your applications.
*/
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**

View File

@@ -32,20 +32,15 @@ use Illuminate\Support\Facades\Validator;
use Session;
/**
* @codeCoverageIgnore
* Class RegisterController
*
* This controller handles the registration of new users as well as their
* validation and creation. By default this controller uses a trait to
* provide this functionality without requiring any additional code.
*/
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;

View File

@@ -26,21 +26,15 @@ use FireflyIII\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
/**
* @codeCoverageIgnore
* Class ResetPasswordController
*
* This controller is responsible for handling password reset requests
* and uses a simple trait to include this behavior. You're free to
* explore this trait and override any methods you wish to tweak.
*/
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**

View File

@@ -303,7 +303,7 @@ class BudgetController extends Controller
++$count;
}
if ($count === 0) {
$count = 1;
$count = 1; // @codeCoverageIgnore
}
$result['available'] = bcdiv($total, strval($count));

View File

@@ -73,7 +73,7 @@ class CategoryController extends Controller
$start = $repository->firstUseDate($category);
if (null === $start) {
$start = new Carbon;
$start = new Carbon; // @codeCoverageIgnore
}
$range = Preferences::get('viewRange', '1M')->data;

View File

@@ -82,7 +82,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
// return Response::json($cache->get()); // @codeCoverageIgnore
return Response::json($cache->get()); // @codeCoverageIgnore
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);

View File

@@ -417,7 +417,7 @@ class RuleController extends Controller
$triggers = $rule->ruleTriggers;
if (0 === count($triggers)) {
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore
}
$limit = intval(config('firefly.test-triggers.limit'));

View File

@@ -98,6 +98,23 @@ Breadcrumbs::register(
}
);
Breadcrumbs::register(
'accounts.reconcile',
function (BreadCrumbGenerator $breadcrumbs, Account $account) {
$breadcrumbs->parent('accounts.show', $account, '(nothing)', new Carbon, new Carbon);
$breadcrumbs->push(trans('firefly.reconcile_account', ['account' => e($account->name)]), route('accounts.reconcile', [$account->id]));
}
);
Breadcrumbs::register(
'accounts.reconcile.show',
function (BreadCrumbGenerator $breadcrumbs, Account $account, TransactionJournal $journal) {
$breadcrumbs->parent('accounts.show', $account, '(nothing)', new Carbon, new Carbon);
$title = trans('firefly.reconciliation') . ' "' . $journal->description . '"';
$breadcrumbs->push($title, route('accounts.reconcile.show', [$journal->id]));
}
);
Breadcrumbs::register(
'accounts.delete',
function (BreadCrumbGenerator $breadcrumbs, Account $account) {

View File

@@ -1,7 +1,7 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journal) }}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, account, journal) }}
{% endblock %}
{% block content %}

View File

@@ -0,0 +1,286 @@
<?php
/**
* ReconcileControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* 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/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Account;
use FireflyIII\Models\Transaction;
use Tests\TestCase;
/**
* Class ConfigurationControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ReconcileControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::edit
*/
public function testEdit()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.edit', [$journal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::edit
*/
public function testEditRedirect()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.edit', [$journal->id]));
$response->assertStatus(302);
$response->assertRedirect(route('transactions.edit', [$journal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::overview()
*/
public function testOverview()
{
$parameters = [
'startBalance' => '0',
'endBalance' => '10',
'transactions' => [1, 2, 3],
'cleared' => [4, 5, 6],
];
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.overview', [1, '20170101', '20170131']) . '?' . http_build_query($parameters));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::overview()
* @expectedExceptionMessage is not an asset account
*/
public function testOverviewNotAsset()
{
$account = $this->user()->accounts()->where('account_type_id', '!=', 3)->first();
$parameters = [
'startBalance' => '0',
'endBalance' => '10',
'transactions' => [1, 2, 3],
'cleared' => [4, 5, 6],
];
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.overview', [$account->id, '20170101', '20170131']) . '?' . http_build_query($parameters));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::__construct
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::reconcile()
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::redirectToOriginalAccount()
*/
public function testReconcile()
{
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [1, '20170101', '20170131']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::__construct
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::reconcile()
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::redirectToOriginalAccount()
*/
public function testReconcileInitialBalance()
{
$transaction = Transaction::leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->where('accounts.user_id', $this->user()->id)->where('accounts.account_type_id', 6)->first(['account_id']);
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [$transaction->account_id, '20170101', '20170131']));
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::__construct
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::reconcile()
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::redirectToOriginalAccount()
*/
public function testReconcileNoDates()
{
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::__construct
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::reconcile()
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::redirectToOriginalAccount()
*/
public function testReconcileNoEndDate()
{
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [1, '20170101']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::__construct
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::reconcile()
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::redirectToOriginalAccount()
*/
public function testReconcileNotAsset()
{
$account = $this->user()->accounts()->where('account_type_id', '!=', 6)->where('account_type_id', '!=', 3)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [$account->id, '20170101', '20170131']));
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::show()
*/
public function testShow()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.show', [$journal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::show()
*/
public function testShowSomethingElse()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.show', [$journal->id]));
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$journal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::submit()
*/
public function testSubmit()
{
$data = [
'transactions' => [1, 2, 3],
'reconcile' => 'create',
'difference' => '5',
'end' => '20170131',
];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.submit', [1, '20170101', '20170131']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::transactions()
*/
public function testTransactions()
{
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.transactions', [1, '20170101', '20170131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::transactions()
*/
public function testTransactionsInitialBalance()
{
$transaction = Transaction::leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->where('accounts.user_id', $this->user()->id)->where('accounts.account_type_id', 6)->first(['account_id']);
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.transactions', [$transaction->account_id, '20170101', '20170131']));
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::update
*/
public function testUpdate()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$data = [
'amount' => '5',
];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.update', [$journal->id]), $data);
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::update
*/
public function testUpdateNotReconcile()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$data = [
'amount' => '5',
];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.update', [$journal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$journal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Account\ReconcileController::update
*/
public function testUpdateZero()
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$data = [
'amount' => '0',
];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.update', [$journal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
}

View File

@@ -22,6 +22,8 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Admin;
use Event;
use FireflyIII\Events\AdminRequestedTestMessage;
use Tests\TestCase;
/**
@@ -35,6 +37,7 @@ class HomeControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Admin\HomeController::index
* @covers \FireflyIII\Http\Controllers\Admin\HomeController::__construct
*/
public function testIndex()
{
@@ -44,4 +47,14 @@ class HomeControllerTest extends TestCase
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
public function testTestMessage() {
Event::fake();
$this->be($this->user());
$response = $this->post(route('admin.test-message'));
$response->assertStatus(302);
Event::assertDispatched(AdminRequestedTestMessage::class);
}
}

View File

@@ -35,6 +35,31 @@ use Tests\TestCase;
*/
class UserControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Admin\UserController::delete
*/
public function testDelete()
{
$this->be($this->user());
$response = $this->get(route('admin.users.delete', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Admin\UserController::destroy
*/
public function testDestroy()
{
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('destroy')->once();
$this->be($this->user());
$response = $this->post(route('admin.users.destroy', ['2']));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Admin\UserController::edit
*/

View File

@@ -121,6 +121,7 @@ class TwoFactorControllerTest extends TestCase
$data = ['code' => '123456'];
$google = $this->mock(Google2FA::class);
$google->shouldReceive('verifyKey')->andReturn(true)->once();
$this->session(['remember_login' => true]);
$this->be($this->user());
$response = $this->post(route('two-factor.post'), $data);

View File

@@ -0,0 +1,78 @@
<?php
/**
* ExpenseReportControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* 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/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
* Class ExpenseReportControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ExpenseReportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::__construct
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::groupByName
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::mainChart()
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::getExpenses
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::getIncome
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController::combineAccounts
*/
public function testMainChart()
{
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
$set = new Collection;
$transaction = new Transaction();
$transaction->opposing_account_name = 'Somebody';
$transaction->transaction_amount = '5';
$set->push($transaction);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($set);
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.expense.main', ['1', $expense->id, '20120101', '20120131']));
$response->assertStatus(200);
}
}