From c7d4ff6f27afff136a693e87126b86bced8ae28d Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 17 Dec 2017 18:23:10 +0100 Subject: [PATCH] Expand test code. --- .../Account/ReconcileController.php | 11 +- app/Http/Controllers/Auth/LoginController.php | 16 +- .../Controllers/Auth/RegisterController.php | 15 +- .../Auth/ResetPasswordController.php | 16 +- app/Http/Controllers/BudgetController.php | 2 +- .../Controllers/Chart/CategoryController.php | 2 +- .../Chart/ExpenseReportController.php | 2 +- app/Http/Controllers/RuleController.php | 2 +- app/Http/breadcrumbs.php | 17 ++ resources/views/accounts/reconcile/show.twig | 2 +- .../Account/ReconcileControllerTest.php | 286 ++++++++++++++++++ .../Controllers/Admin/HomeControllerTest.php | 13 + .../Controllers/Admin/UserControllerTest.php | 25 ++ .../Auth/TwoFactorControllerTest.php | 1 + .../Chart/ExpenseReportControllerTest.php | 78 +++++ 15 files changed, 446 insertions(+), 42 deletions(-) create mode 100644 tests/Feature/Controllers/Account/ReconcileControllerTest.php create mode 100644 tests/Feature/Controllers/Chart/ExpenseReportControllerTest.php diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 04152582fe..897e4b9dee 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -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; diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 858e889edb..45f273a65d 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -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; /** diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index be017a3e17..39dff86f73 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -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; diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 3dce99c529..d07102819d 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -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; /** diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 87608ada26..b1b145b07b 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -303,7 +303,7 @@ class BudgetController extends Controller ++$count; } if ($count === 0) { - $count = 1; + $count = 1; // @codeCoverageIgnore } $result['available'] = bcdiv($total, strval($count)); diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index c699b4a2a7..1c0a8ddcac 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -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; diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php index ec042edbed..59e9b9150c 100644 --- a/app/Http/Controllers/Chart/ExpenseReportController.php +++ b/app/Http/Controllers/Chart/ExpenseReportController.php @@ -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); diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index 2dcfad0eab..2744d77fd4 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -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')); diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 64665ece61..7d3b8acf3b 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -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) { diff --git a/resources/views/accounts/reconcile/show.twig b/resources/views/accounts/reconcile/show.twig index 0dab366f46..f18ebaf3b5 100644 --- a/resources/views/accounts/reconcile/show.twig +++ b/resources/views/accounts/reconcile/show.twig @@ -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 %} diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php new file mode 100644 index 0000000000..ed20501594 --- /dev/null +++ b/tests/Feature/Controllers/Account/ReconcileControllerTest.php @@ -0,0 +1,286 @@ +. + */ + +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('