mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-08-29 01:13:08 +00:00
Refactor account controller and some associated tests.
This commit is contained in:
125
app/Http/Controllers/Account/CreateController.php
Normal file
125
app/Http/Controllers/Account/CreateController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateController.php
|
||||
* Copyright (c) 2018 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 FireflyIII\Http\Controllers\Account;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CreateController
|
||||
*/
|
||||
class CreateController extends Controller
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string|null $what
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request, string $what = null)
|
||||
{
|
||||
$what = $what ?? 'asset';
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$subTitle = trans('firefly.make_new_' . $what . '_account');
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string)trans('firefly.account_role_' . $role);
|
||||
}
|
||||
|
||||
// pre fill some data
|
||||
$request->session()->flash('preFilled', ['currency_id' => $defaultCurrency->id]);
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (true !== session('accounts.create.fromStore')) {
|
||||
$this->rememberPreviousUri('accounts.create.uri');
|
||||
}
|
||||
$request->session()->forget('accounts.create.fromStore');
|
||||
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'roles'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(AccountFormRequest $request)
|
||||
{
|
||||
$data = $request->getAccountData();
|
||||
$account = $this->repository->store($data);
|
||||
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
// update preferences if necessary:
|
||||
$frontPage = Preferences::get('frontPageAccounts', [])->data;
|
||||
if (AccountType::ASSET === $account->accountType->type && \count($frontPage) > 0) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$frontPage[] = $account->id;
|
||||
Preferences::set('frontPageAccounts', $frontPage);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// redirect to previous URL.
|
||||
$redirect = redirect($this->getPreviousUri('accounts.create.uri'));
|
||||
if (1 === (int)$request->get('create_another')) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
$request->session()->put('accounts.create.fromStore', true);
|
||||
|
||||
$redirect = redirect(route('accounts.create', [$request->input('what')]))->withInput();
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
}
|
101
app/Http/Controllers/Account/DeleteController.php
Normal file
101
app/Http/Controllers/Account/DeleteController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* DeleteController.php
|
||||
* Copyright (c) 2018 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 FireflyIII\Http\Controllers\Account;
|
||||
|
||||
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class DeleteController
|
||||
*/
|
||||
class DeleteController extends Controller
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function delete(Account $account)
|
||||
{
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||
$subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]);
|
||||
$accountList = ExpandedForm::makeSelectListWithEmpty($this->repository->getAccountsByType([$account->accountType->type]));
|
||||
unset($accountList[$account->id]);
|
||||
|
||||
// put previous url in session
|
||||
$this->rememberPreviousUri('accounts.delete.uri');
|
||||
|
||||
return view('accounts.delete', compact('account', 'subTitle', 'accountList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(Request $request, Account $account)
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||
$name = $account->name;
|
||||
$moveTo = $this->repository->findNull((int)$request->get('move_account_before_delete'));
|
||||
|
||||
$this->repository->destroy($account, $moveTo);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.' . $typeName . '_deleted', ['name' => $name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect($this->getPreviousUri('accounts.delete.uri'));
|
||||
}
|
||||
|
||||
}
|
153
app/Http/Controllers/Account/EditController.php
Normal file
153
app/Http/Controllers/Account/EditController.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* EditController.php
|
||||
* Copyright (c) 2018 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 FireflyIII\Http\Controllers\Account;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class EditController
|
||||
*/
|
||||
class EditController extends Controller
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $currencyRepos;
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit(Request $request, Account $account, AccountRepositoryInterface $repository)
|
||||
{
|
||||
$what = config('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string)trans('firefly.account_role_' . $role);
|
||||
}
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (true !== session('accounts.edit.fromUpdate')) {
|
||||
$this->rememberPreviousUri('accounts.edit.uri');
|
||||
}
|
||||
$request->session()->forget('accounts.edit.fromUpdate');
|
||||
|
||||
// pre fill some useful values.
|
||||
|
||||
// the opening balance is tricky:
|
||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
$currency = $this->currencyRepos->findNull((int)$repository->getMetaValue($account, 'currency_id'));
|
||||
if (null === $currency) {
|
||||
$currency = $default;
|
||||
}
|
||||
|
||||
// code to handle active-checkboxes
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
$preFilled = [
|
||||
'accountNumber' => $repository->getMetaValue($account, 'accountNumber'),
|
||||
'accountRole' => $repository->getMetaValue($account, 'accountRole'),
|
||||
'ccType' => $repository->getMetaValue($account, 'ccType'),
|
||||
'ccMonthlyPaymentDate' => $repository->getMetaValue($account, 'ccMonthlyPaymentDate'),
|
||||
'BIC' => $repository->getMetaValue($account, 'BIC'),
|
||||
'openingBalanceDate' => $openingBalanceDate,
|
||||
'openingBalance' => $openingBalanceAmount,
|
||||
'virtualBalance' => $account->virtual_balance,
|
||||
'currency_id' => $currency->id,
|
||||
'notes' => '',
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
|
||||
];
|
||||
/** @var Note $note */
|
||||
$note = $this->repository->getNote($account);
|
||||
if (null !== $note) {
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
return view('accounts.edit', compact('account', 'currency', 'subTitle', 'subTitleIcon', 'what', 'roles', 'preFilled'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(AccountFormRequest $request, Account $account)
|
||||
{
|
||||
$data = $request->getAccountData();
|
||||
$this->repository->update($account, $data);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
$redirect = redirect($this->getPreviousUri('accounts.edit.uri'));
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
$request->session()->put('accounts.edit.fromUpdate', true);
|
||||
|
||||
$redirect = redirect(route('accounts.edit', [$account->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
}
|
@@ -284,6 +284,9 @@ class ReconcileController extends Controller
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function update(ReconciliationUpdateRequest $request, TransactionJournal $journal)
|
||||
{
|
||||
|
@@ -30,7 +30,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -74,134 +73,6 @@ class AccountController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string|null $what
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request, string $what = null)
|
||||
{
|
||||
$what = $what ?? 'asset';
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$subTitle = trans('firefly.make_new_' . $what . '_account');
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string)trans('firefly.account_role_' . $role);
|
||||
}
|
||||
|
||||
// pre fill some data
|
||||
$request->session()->flash('preFilled', ['currency_id' => $defaultCurrency->id]);
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (true !== session('accounts.create.fromStore')) {
|
||||
$this->rememberPreviousUri('accounts.create.uri');
|
||||
}
|
||||
$request->session()->forget('accounts.create.fromStore');
|
||||
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'roles'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function delete(Account $account)
|
||||
{
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||
$subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]);
|
||||
$accountList = ExpandedForm::makeSelectListWithEmpty($this->repository->getAccountsByType([$account->accountType->type]));
|
||||
unset($accountList[$account->id]);
|
||||
|
||||
// put previous url in session
|
||||
$this->rememberPreviousUri('accounts.delete.uri');
|
||||
|
||||
return view('accounts.delete', compact('account', 'subTitle', 'accountList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(Request $request, Account $account)
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||
$name = $account->name;
|
||||
$moveTo = $this->repository->findNull((int)$request->get('move_account_before_delete'));
|
||||
|
||||
$this->repository->destroy($account, $moveTo);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.' . $typeName . '_deleted', ['name' => $name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect($this->getPreviousUri('accounts.delete.uri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit(Request $request, Account $account, AccountRepositoryInterface $repository)
|
||||
{
|
||||
$what = config('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string)trans('firefly.account_role_' . $role);
|
||||
}
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (true !== session('accounts.edit.fromUpdate')) {
|
||||
$this->rememberPreviousUri('accounts.edit.uri');
|
||||
}
|
||||
$request->session()->forget('accounts.edit.fromUpdate');
|
||||
|
||||
// pre fill some useful values.
|
||||
|
||||
// the opening balance is tricky:
|
||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
$currency = $this->currencyRepos->findNull((int)$repository->getMetaValue($account, 'currency_id'));
|
||||
if (null === $currency) {
|
||||
$currency = $default;
|
||||
}
|
||||
|
||||
// code to handle active-checkboxes
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
$preFilled = [
|
||||
'accountNumber' => $repository->getMetaValue($account, 'accountNumber'),
|
||||
'accountRole' => $repository->getMetaValue($account, 'accountRole'),
|
||||
'ccType' => $repository->getMetaValue($account, 'ccType'),
|
||||
'ccMonthlyPaymentDate' => $repository->getMetaValue($account, 'ccMonthlyPaymentDate'),
|
||||
'BIC' => $repository->getMetaValue($account, 'BIC'),
|
||||
'openingBalanceDate' => $openingBalanceDate,
|
||||
'openingBalance' => $openingBalanceAmount,
|
||||
'virtualBalance' => $account->virtual_balance,
|
||||
'currency_id' => $currency->id,
|
||||
'notes' => '',
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
|
||||
];
|
||||
/** @var Note $note */
|
||||
$note = $this->repository->getNote($account);
|
||||
if (null !== $note) {
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
return view('accounts.edit', compact('account', 'currency', 'subTitle', 'subTitleIcon', 'what', 'roles', 'preFilled'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $what
|
||||
@@ -351,63 +222,6 @@ class AccountController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(AccountFormRequest $request)
|
||||
{
|
||||
$data = $request->getAccountData();
|
||||
$account = $this->repository->store($data);
|
||||
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
// update preferences if necessary:
|
||||
$frontPage = Preferences::get('frontPageAccounts', [])->data;
|
||||
if (AccountType::ASSET === $account->accountType->type && \count($frontPage) > 0) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$frontPage[] = $account->id;
|
||||
Preferences::set('frontPageAccounts', $frontPage);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// redirect to previous URL.
|
||||
$redirect = redirect($this->getPreviousUri('accounts.create.uri'));
|
||||
if (1 === (int)$request->get('create_another')) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
$request->session()->put('accounts.create.fromStore', true);
|
||||
|
||||
$redirect = redirect(route('accounts.create', [$request->input('what')]))->withInput();
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(AccountFormRequest $request, Account $account)
|
||||
{
|
||||
$data = $request->getAccountData();
|
||||
$this->repository->update($account, $data);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
$redirect = redirect($this->getPreviousUri('accounts.edit.uri'));
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
$request->session()->put('accounts.edit.fromUpdate', true);
|
||||
|
||||
$redirect = redirect(route('accounts.edit', [$account->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
|
@@ -109,30 +109,40 @@ Route::group(
|
||||
Route::group(
|
||||
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'accounts', 'as' => 'accounts.'], function () {
|
||||
Route::get('{what}', ['uses' => 'AccountController@index', 'as' => 'index'])->where('what', 'revenue|asset|expense');
|
||||
Route::get('create/{what}', ['uses' => 'AccountController@create', 'as' => 'create'])->where('what', 'revenue|asset|expense');
|
||||
Route::get('edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'edit']);
|
||||
Route::get('delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'delete']);
|
||||
|
||||
|
||||
// create
|
||||
Route::get('create/{what}', ['uses' => 'Account\CreateController@create', 'as' => 'create'])->where('what', 'revenue|asset|expense');
|
||||
Route::post('store', ['uses' => 'Account\CreateController@store', 'as' => 'store']);
|
||||
|
||||
|
||||
// edit
|
||||
Route::get('edit/{account}', ['uses' => 'Account\EditController@edit', 'as' => 'edit']);
|
||||
Route::post('update/{account}', ['uses' => 'Account\EditController@update', 'as' => 'update']);
|
||||
|
||||
// delete
|
||||
Route::get('delete/{account}', ['uses' => 'Account\DeleteController@delete', 'as' => 'delete']);
|
||||
Route::post('destroy/{account}', ['uses' => 'Account\DeleteController@destroy', 'as' => 'destroy']);
|
||||
|
||||
// show
|
||||
Route::get('show/{account}/all', ['uses' => 'AccountController@showAll', 'as' => 'show.all']);
|
||||
Route::get('show/{account}/{start_date?}/{end_date?}', ['uses' => 'AccountController@show', 'as' => 'show']);
|
||||
|
||||
// reconcile routes:
|
||||
Route::get('reconcile/{account}/index/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@reconcile', 'as' => 'reconcile']);
|
||||
|
||||
|
||||
Route::post('reconcile/{account}/submit/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@submit', 'as' => 'reconcile.submit']);
|
||||
|
||||
// reconcile JSON routes
|
||||
Route::get('reconcile/{account}/overview/{start_date?}/{end_date?}', ['uses' => 'Json\ReconcileController@overview', 'as' => 'reconcile.overview']);
|
||||
Route::get('reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Json\ReconcileController@transactions', 'as' => 'reconcile.transactions']);
|
||||
Route::get(
|
||||
'reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Json\ReconcileController@transactions', 'as' => 'reconcile.transactions']
|
||||
);
|
||||
|
||||
// show reconciliation
|
||||
Route::get('reconcile/show/{tj}', ['uses' => 'Account\ReconcileController@show', 'as' => 'reconcile.show']);
|
||||
Route::get('reconcile/edit/{tj}', ['uses' => 'Account\ReconcileController@edit', 'as' => 'reconcile.edit']);
|
||||
Route::post('reconcile/update/{tj}', ['uses' => 'Account\ReconcileController@update', 'as' => 'reconcile.update']);
|
||||
|
||||
Route::post('store', ['uses' => 'AccountController@store', 'as' => 'store']);
|
||||
Route::post('update/{account}', ['uses' => 'AccountController@update', 'as' => 'update']);
|
||||
Route::post('destroy/{account}', ['uses' => 'AccountController@destroy', 'as' => 'destroy']);
|
||||
|
||||
}
|
||||
);
|
||||
|
128
tests/Feature/Controllers/Account/CreateControllerTest.php
Normal file
128
tests/Feature/Controllers/Account/CreateControllerTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateControllerTest.php
|
||||
* Copyright (c) 2018 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\Account;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CreateControllerTest
|
||||
*/
|
||||
class CreateControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\CreateController
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.create', ['asset']));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// change the preference:
|
||||
Preferences::setForUser($this->user(), 'frontPageAccounts', [1]);
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'new account ' . random_int(1000, 9999),
|
||||
'what' => 'asset',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.store', ['asset']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testStoreAnother(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'new account ' . random_int(1000, 9999),
|
||||
'what' => 'asset',
|
||||
'create_another' => 1,
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.store', ['asset']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
86
tests/Feature/Controllers/Account/DeleteControllerTest.php
Normal file
86
tests/Feature/Controllers/Account/DeleteControllerTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* DeleteControllerTest.php
|
||||
* Copyright (c) 2018 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\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class DeleteControllerTest
|
||||
*/
|
||||
class DeleteControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\DeleteController
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.delete', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\DeleteController
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('accounts.destroy', [$account->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
|
||||
}
|
170
tests/Feature/Controllers/Account/EditControllerTest.php
Normal file
170
tests/Feature/Controllers/Account/EditControllerTest.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
* EditControllerTest.php
|
||||
* Copyright (c) 2018 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 Amount;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class EditControllerTest
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.edit', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(2));
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(null);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.edit', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'updated account ' . random_int(1000, 9999),
|
||||
'active' => 1,
|
||||
'what' => 'asset',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
*/
|
||||
public function testUpdateAgain(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'updated account ' . random_int(1000, 9999),
|
||||
'active' => 1,ss
|
||||
'what' => 'asset',
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
}
|
@@ -62,138 +62,6 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::create
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('accounts.create', ['asset']));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::delete
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::rememberPreviousUri
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.delete', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::destroy
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('accounts.destroy', [$account->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::edit
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.edit', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(2));
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(null);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
$response = $this->get(route('accounts.edit', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::index
|
||||
@@ -418,114 +286,4 @@ class AccountControllerTest extends TestCase
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::store
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// change the preference:
|
||||
Preferences::setForUser($this->user(), 'frontPageAccounts', [1]);
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'new account ' . random_int(1000, 9999),
|
||||
'what' => 'asset',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.store', ['asset']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::store
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri
|
||||
*/
|
||||
public function testStoreAnother(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'new account ' . random_int(1000, 9999),
|
||||
'what' => 'asset',
|
||||
'create_another' => 1,
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.store', ['asset']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::update
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'updated account ' . random_int(1000, 9999),
|
||||
'active' => 1,
|
||||
'what' => 'asset',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::update
|
||||
* @covers \FireflyIII\Http\Requests\AccountFormRequest
|
||||
* @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri
|
||||
*/
|
||||
public function testUpdateAgain(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['accounts.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'updated account ' . random_int(1000, 9999),
|
||||
'active' => 1,
|
||||
'what' => 'asset',
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
||||
|
@@ -326,6 +326,7 @@ class ImportableConverterTest extends TestCase
|
||||
|
||||
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
|
||||
|
||||
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||
|
||||
@@ -341,9 +342,10 @@ class ImportableConverterTest extends TestCase
|
||||
$this->assertEquals(2, $result[0]['bill_id']); // will NOT be ignored.
|
||||
$this->assertEquals($importable->billName, $result[0]['bill_name']);
|
||||
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||
|
||||
// since amount is positive, $asset recieves the money
|
||||
$this->assertEquals($asset->id, $result[0]['transactions'][0]['source_id']);
|
||||
$this->assertEquals($other->id, $result[0]['transactions'][0]['destination_id']);
|
||||
$this->assertEquals($other->id, $result[0]['transactions'][0]['source_id']);
|
||||
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,9 +413,10 @@ class ImportableConverterTest extends TestCase
|
||||
$this->assertEquals(3, $result[0]['bill_id']);
|
||||
$this->assertEquals($importable->billName, $result[0]['bill_name']);
|
||||
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||
|
||||
// since amount is negative, $asset sends the money
|
||||
$this->assertEquals($other->id, $result[0]['transactions'][0]['source_id']);
|
||||
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
|
||||
$this->assertEquals($asset->id, $result[0]['transactions'][0]['source_id']);
|
||||
$this->assertEquals($other->id, $result[0]['transactions'][0]['destination_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user