Improve test coverage and efficiency for accounts and budgets.

This commit is contained in:
James Cole
2019-06-23 11:13:36 +02:00
parent 8f25562923
commit 43d753e5bd
47 changed files with 919 additions and 985 deletions

View File

@@ -36,8 +36,13 @@ use View;
*/
class LinkController extends Controller
{
/** @var LinkTypeRepositoryInterface */
private $repository;
/**
* LinkController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -47,6 +52,7 @@ class LinkController extends Controller
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.administration'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
$this->repository = app(LinkTypeRepositoryInterface::class);
return $next($request);
}
@@ -61,11 +67,11 @@ class LinkController extends Controller
*/
public function create()
{
Log::channel('audit')->info('User visits link index.');
$subTitle = (string)trans('firefly.create_new_link_type');
$subTitleIcon = 'fa-link';
Log::channel('audit')->info('User visits link index.');
// put previous url in session if not redirect from store (not "create another").
if (true !== session('link-types.create.fromStore')) {
$this->rememberPreviousUri('link-types.create.uri');
@@ -77,13 +83,12 @@ class LinkController extends Controller
/**
* Delete a link form.
*
* @param Request $request
* @param LinkTypeRepositoryInterface $repository
* @param LinkType $linkType
* @param Request $request
* @param LinkType $linkType
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function delete(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
public function delete(Request $request, LinkType $linkType)
{
if (!$linkType->editable) {
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
@@ -92,18 +97,19 @@ class LinkController extends Controller
}
Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id));
$subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]);
$otherTypes = $repository->get();
$count = $repository->countJournals($linkType);
$otherTypes = $this->repository->get();
$count = $this->repository->countJournals($linkType);
$moveTo = [];
$moveTo[0] = (string)trans('firefly.do_not_save_connection');
/** @var LinkType $otherType */
foreach ($otherTypes as $otherType) {
if ($otherType->id !== $linkType->id) {
$moveTo[$otherType->id] = sprintf('%s (%s / %s)', $otherType->name, $otherType->inward, $otherType->outward);
}
}
// put previous url in session
$this->rememberPreviousUri('link-types.delete.uri');
@@ -113,18 +119,17 @@ class LinkController extends Controller
/**
* Actually destroy the link.
*
* @param Request $request
* @param LinkTypeRepositoryInterface $repository
* @param LinkType $linkType
* @param Request $request
* @param LinkType $linkType
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
public function destroy(Request $request, LinkType $linkType)
{
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
$name = $linkType->name;
$moveTo = $repository->findNull((int)$request->get('move_link_type_before_delete'));
$repository->destroy($linkType, $moveTo);
$moveTo = $this->repository->findNull((int)$request->get('move_link_type_before_delete'));
$this->repository->destroy($linkType, $moveTo);
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name]));
app('preferences')->mark();
@@ -135,7 +140,7 @@ class LinkController extends Controller
/**
* Edit a link form.
*
* @param Request $request
* @param Request $request
* @param LinkType $linkType
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
@@ -164,20 +169,18 @@ class LinkController extends Controller
/**
* Show index of all links.
*
* @param LinkTypeRepositoryInterface $repository
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(LinkTypeRepositoryInterface $repository)
public function index()
{
$subTitle = (string)trans('firefly.journal_link_configuration');
$subTitleIcon = 'fa-link';
$linkTypes = $repository->get();
$linkTypes = $this->repository->get();
Log::channel('audit')->info('User on index of link types in admin.');
$linkTypes->each(
function (LinkType $linkType) use ($repository) {
$linkType->journalCount = $repository->countJournals($linkType);
function (LinkType $linkType) {
$linkType->journalCount = $this->repository->countJournals($linkType);
}
);
@@ -195,7 +198,7 @@ class LinkController extends Controller
{
$subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]);
$subTitleIcon = 'fa-link';
$links = $linkType->transactionJournalLinks()->get();
$links = $this->repository->getJournalLinks($linkType);
Log::channel('audit')->info(sprintf('User viewing link type #%d', $linkType->id));
@@ -205,19 +208,18 @@ class LinkController extends Controller
/**
* Store the new link.
*
* @param LinkTypeFormRequest $request
* @param LinkTypeRepositoryInterface $repository
* @param LinkTypeFormRequest $request
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository)
public function store(LinkTypeFormRequest $request)
{
$data = [
'name' => $request->string('name'),
'inward' => $request->string('inward'),
'outward' => $request->string('outward'),
];
$linkType = $repository->store($data);
$linkType = $this->repository->store($data);
Log::channel('audit')->info('User stored new link type.', $linkType->toArray());
@@ -237,13 +239,12 @@ class LinkController extends Controller
/**
* Update an existing link.
*
* @param LinkTypeFormRequest $request
* @param LinkTypeRepositoryInterface $repository
* @param LinkType $linkType
* @param LinkTypeFormRequest $request
* @param LinkType $linkType
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
public function update(LinkTypeFormRequest $request, LinkType $linkType)
{
if (!$linkType->editable) {
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
@@ -256,7 +257,7 @@ class LinkController extends Controller
'inward' => $request->string('inward'),
'outward' => $request->string('outward'),
];
$repository->update($linkType, $data);
$this->repository->update($linkType, $data);
Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data);