Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Big bunch of code to improve test coverage.
James Colecf904eb6775b
diff --git a/app/Http/Controllers/Category/CreateController.php b/app/Http/Controllers/Category/CreateController.phpnew file mode 100644index 0000000000..f0cfb0a21a--- /dev/null+++ b/app/Http/Controllers/Category/CreateController.php@@ -0,0 +1,103 @@+<?php+/**+ * CreateController.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace FireflyIII\Http\Controllers\Category;+++use FireflyIII\Http\Controllers\Controller;+use FireflyIII\Http\Requests\CategoryFormRequest;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use Illuminate\Http\Request;++/**+ * Class CreateController+ */+class CreateController extends Controller+{+ /** @var CategoryRepositoryInterface The category repository */+ private $repository;++ /**+ * CategoryController constructor.+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();++ $this->middleware(+ function ($request, $next) {+ app('view')->share('title', (string)trans('firefly.categories'));+ app('view')->share('mainTitleIcon', 'fa-bar-chart');+ $this->repository = app(CategoryRepositoryInterface::class);++ return $next($request);+ }+ );+ }+++ /**+ * Create category.+ *+ * @param Request $request+ *+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+ */+ public function create(Request $request)+ {+ if (true !== session('categories.create.fromStore')) {+ $this->rememberPreviousUri('categories.create.uri');+ }+ $request->session()->forget('categories.create.fromStore');+ $subTitle = (string)trans('firefly.create_new_category');++ return view('categories.create', compact('subTitle'));+ }+++ /**+ * Store new category.+ *+ * @param CategoryFormRequest $request+ *+ * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector+ */+ public function store(CategoryFormRequest $request)+ {+ $data = $request->getCategoryData();+ $category = $this->repository->store($data);++ $request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name]));+ app('preferences')->mark();++ $redirect = redirect(route('categories.index'));+ if (1 === (int)$request->get('create_another')) {+ // @codeCoverageIgnoreStart+ $request->session()->put('categories.create.fromStore', true);++ $redirect = redirect(route('categories.create'))->withInput();+ // @codeCoverageIgnoreEnd+ }++ return $redirect;+ }+}\ No newline at end of filediff --git a/app/Http/Controllers/Category/DeleteController.php b/app/Http/Controllers/Category/DeleteController.phpnew file mode 100644index 0000000000..44cd8773c6--- /dev/null+++ b/app/Http/Controllers/Category/DeleteController.php@@ -0,0 +1,92 @@+<?php+/**+ * DeleteController.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace FireflyIII\Http\Controllers\Category;+++use FireflyIII\Http\Controllers\Controller;+use FireflyIII\Models\Category;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use Illuminate\Http\Request;++/**+ * Class DeleteController+ */+class DeleteController extends Controller+{+ /** @var CategoryRepositoryInterface The category repository */+ private $repository;++ /**+ * CategoryController constructor.+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();++ $this->middleware(+ function ($request, $next) {+ app('view')->share('title', (string)trans('firefly.categories'));+ app('view')->share('mainTitleIcon', 'fa-bar-chart');+ $this->repository = app(CategoryRepositoryInterface::class);++ return $next($request);+ }+ );+ }++ /**+ * Delete a category.+ *+ * @param Category $category+ *+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+ */+ public function delete(Category $category)+ {+ $subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]);++ // put previous url in session+ $this->rememberPreviousUri('categories.delete.uri');++ return view('categories.delete', compact('category', 'subTitle'));+ }++ /**+ * Destroy a category.+ *+ * @param Request $request+ * @param Category $category+ *+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector+ */+ public function destroy(Request $request, Category $category)+ {+ $name = $category->name;+ $this->repository->destroy($category);++ $request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name]));+ app('preferences')->mark();++ return redirect($this->getPreviousUri('categories.delete.uri'));+ }+}\ No newline at end of filediff --git a/app/Http/Controllers/Category/EditController.php b/app/Http/Controllers/Category/EditController.phpnew file mode 100644index 0000000000..76991b0369--- /dev/null+++ b/app/Http/Controllers/Category/EditController.php@@ -0,0 +1,109 @@+<?php+/**+ * EditController.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace FireflyIII\Http\Controllers\Category;+++use FireflyIII\Http\Controllers\Controller;+use FireflyIII\Http\Requests\CategoryFormRequest;+use FireflyIII\Models\Category;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use Illuminate\Http\Request;++/**+ * Class EditController+ */+class EditController extends Controller+{++ /** @var CategoryRepositoryInterface The category repository */+ private $repository;++ /**+ * CategoryController constructor.+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();++ $this->middleware(+ function ($request, $next) {+ app('view')->share('title', (string)trans('firefly.categories'));+ app('view')->share('mainTitleIcon', 'fa-bar-chart');+ $this->repository = app(CategoryRepositoryInterface::class);++ return $next($request);+ }+ );+ }+++ /**+ * Edit a category.+ *+ * @param Request $request+ * @param Category $category+ *+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+ */+ public function edit(Request $request, Category $category)+ {+ $subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);++ // put previous url in session if not redirect from store (not "return_to_edit").+ if (true !== session('categories.edit.fromUpdate')) {+ $this->rememberPreviousUri('categories.edit.uri');+ }+ $request->session()->forget('categories.edit.fromUpdate');++ return view('categories.edit', compact('category', 'subTitle'));+ }++ /**+ * Update category.+ *+ * @param CategoryFormRequest $request+ * @param Category $category+ *+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector+ */+ public function update(CategoryFormRequest $request, Category $category)+ {+ $data = $request->getCategoryData();+ $this->repository->update($category, $data);++ $request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name]));+ app('preferences')->mark();++ $redirect = redirect($this->getPreviousUri('categories.edit.uri'));++ if (1 === (int)$request->get('return_to_edit')) {+ // @codeCoverageIgnoreStart+ $request->session()->put('categories.edit.fromUpdate', true);++ $redirect = redirect(route('categories.edit', [$category->id]));+ // @codeCoverageIgnoreEnd+ }++ return $redirect;+ }+}\ No newline at end of filediff --git a/app/Http/Controllers/Category/IndexController.php b/app/Http/Controllers/Category/IndexController.phpnew file mode 100644index 0000000000..cd39646a2c--- /dev/null+++ b/app/Http/Controllers/Category/IndexController.php@@ -0,0 +1,89 @@+<?php+/**+ * IndexController.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace FireflyIII\Http\Controllers\Category;+++use FireflyIII\Http\Controllers\Controller;+use FireflyIII\Models\Category;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use Illuminate\Http\Request;+use Illuminate\Pagination\LengthAwarePaginator;+use Illuminate\Support\Collection;++/**+ * Class IndexController+ */+class IndexController extends Controller+{+ /** @var CategoryRepositoryInterface The category repository */+ private $repository;++ /**+ * CategoryController constructor.+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();++ $this->middleware(+ function ($request, $next) {+ app('view')->share('title', (string)trans('firefly.categories'));+ app('view')->share('mainTitleIcon', 'fa-bar-chart');+ $this->repository = app(CategoryRepositoryInterface::class);++ return $next($request);+ }+ );+ }++++ /**+ * Show all categories.+ *+ * @param Request $request+ *+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+ */+ public function index(Request $request)+ {+ $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');+ $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;+ $collection = $this->repository->getCategories();+ $total = $collection->count();+ $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);++ $collection->each(+ function (Category $category) {+ $category->lastActivity = $this->repository->lastUseDate($category, new Collection);+ }+ );++ // paginate categories+ $categories = new LengthAwarePaginator($collection, $total, $pageSize, $page);+ $categories->setPath(route('categories.index'));++ return view('categories.index', compact('categories'));+ }++}\ No newline at end of filediff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.phpindex 803cb3498e..aa8df71950 100644--- a/app/Http/Controllers/Category/NoCategoryController.php+++ b/app/Http/Controllers/Category/NoCategoryController.php@@ -46,6 +46,7 @@ class NoCategoryController extends Controller/*** CategoryController constructor.+ * @codeCoverageIgnore*/public function __construct(){diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.phpindex f3db0b5df3..da2e40a7f9 100644--- a/app/Http/Controllers/Category/ShowController.php+++ b/app/Http/Controllers/Category/ShowController.php@@ -47,6 +47,7 @@ class ShowController extends Controller/*** CategoryController constructor.+ * @codeCoverageIgnore*/public function __construct(){@@ -85,7 +86,8 @@ class ShowController extends Controller$subTitleIcon = 'fa-bar-chart';$page = (int)$request->get('page');$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;- $periods = $this->getCategoryPeriodOverview($category, $end);+ $oldest = $this->repository->firstUseDate($category) ?? Carbon::create()->startOfYear();+ $periods = $this->getCategoryPeriodOverview($category, $oldest, $end);$path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);$subTitle = trans('firefly.journals_in_period_for_category',diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.phpindex c051b36b1c..50ecaa557d 100644--- a/app/Http/Controllers/CategoryController.php+++ b/app/Http/Controllers/CategoryController.php@@ -55,168 +55,11 @@ class CategoryController extends Controller);}- /**- * Create category.- *- * @param Request $request- *- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View- */- public function create(Request $request)- {- if (true !== session('categories.create.fromStore')) {- $this->rememberPreviousUri('categories.create.uri');- }- $request->session()->forget('categories.create.fromStore');- $subTitle = (string)trans('firefly.create_new_category');-- return view('categories.create', compact('subTitle'));- }-- /**- * Delete a category.- *- * @param Category $category- *- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View- */- public function delete(Category $category)- {- $subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]);-- // put previous url in session- $this->rememberPreviousUri('categories.delete.uri');-- return view('categories.delete', compact('category', 'subTitle'));- }-- /**- * Destroy a category.- *- * @param Request $request- * @param Category $category- *- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- */- public function destroy(Request $request, Category $category)- {- $name = $category->name;- $this->repository->destroy($category);-- $request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name]));- app('preferences')->mark();-- return redirect($this->getPreviousUri('categories.delete.uri'));- }-- /**- * Edit a category.- *- * @param Request $request- * @param Category $category- *- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View- */- public function edit(Request $request, Category $category)- {- $subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);-- // put previous url in session if not redirect from store (not "return_to_edit").- if (true !== session('categories.edit.fromUpdate')) {- $this->rememberPreviousUri('categories.edit.uri');- }- $request->session()->forget('categories.edit.fromUpdate');-- return view('categories.edit', compact('category', 'subTitle'));- }- /**- * Show all categories.- *- * @param Request $request- *- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View- */- public function index(Request $request)- {- $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');- $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;- $collection = $this->repository->getCategories();- $total = $collection->count();- $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);-- $collection->each(- function (Category $category) {- $category->lastActivity = $this->repository->lastUseDate($category, new Collection);- }- );-- // paginate categories- $categories = new LengthAwarePaginator($collection, $total, $pageSize, $page);- $categories->setPath(route('categories.index'));-- return view('categories.index', compact('categories'));- }--- /**- * Store new category.- *- * @param CategoryFormRequest $request- * @param CategoryRepositoryInterface $repository- *- * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- */- public function store(CategoryFormRequest $request, CategoryRepositoryInterface $repository)- {- $data = $request->getCategoryData();- $category = $repository->store($data);-- $request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name]));- app('preferences')->mark();- $redirect = redirect(route('categories.index'));- if (1 === (int)$request->get('create_another')) {- // @codeCoverageIgnoreStart- $request->session()->put('categories.create.fromStore', true);- $redirect = redirect(route('categories.create'))->withInput();- // @codeCoverageIgnoreEnd- }-- return $redirect;- }- /**- * Update category.- *- * @param CategoryFormRequest $request- * @param CategoryRepositoryInterface $repository- * @param Category $category- *- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- */- public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category)- {- $data = $request->getCategoryData();- $repository->update($category, $data);-- $request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name]));- app('preferences')->mark();-- $redirect = redirect($this->getPreviousUri('categories.edit.uri'));-- if (1 === (int)$request->get('return_to_edit')) {- // @codeCoverageIgnoreStart- $request->session()->put('categories.edit.fromUpdate', true);-- $redirect = redirect(route('categories.edit', [$category->id]));- // @codeCoverageIgnoreEnd- }-- return $redirect;- }}diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.phpindex 555ce5c9de..5335d0b8a5 100644--- a/app/Http/Controllers/Chart/AccountController.php+++ b/app/Http/Controllers/Chart/AccountController.php@@ -62,6 +62,7 @@ class AccountController extends Controller/*** AccountController constructor.+ * @codeCoverageIgnore*/public function __construct(){@@ -341,9 +342,8 @@ class AccountController extends ControllerLog::debug('Frontpage preference set is ', $frontPage->data);if (0 === count($frontPage->data)) {- $frontPage->data = $defaultSet;+ app('preferences')->set('frontPageAccounts', $defaultSet);Log::debug('frontpage set is empty!');- $frontPage->save();}$accounts = $repository->getAccountsById($frontPage->data);diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.phpindex f96e7a1f4e..bd079cb551 100644--- a/app/Http/Controllers/Chart/BillController.php+++ b/app/Http/Controllers/Chart/BillController.php@@ -42,6 +42,7 @@ class BillController extends Controller/*** BillController constructor.+ * @codeCoverageIgnore*/public function __construct(){diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.phpindex a5a402a2bc..d6a1f36286 100644--- a/app/Support/Http/Controllers/PeriodOverview.php+++ b/app/Support/Http/Controllers/PeriodOverview.php@@ -30,7 +30,6 @@ use FireflyIII\Models\Category;use FireflyIII\Models\Tag;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionType;-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\Tag\TagRepositoryInterface;use FireflyIII\Support\CacheProperties;@@ -52,6 +51,7 @@ use Log;* earned (array),* transferred_away (array)* transferred_in (array)+ * transferred (array)** each array has the following format:* currency_id => [@@ -125,16 +125,15 @@ trait PeriodOverview// loop datesforeach ($dates as $currentDate) {- $title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);-+ $title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);$transferredAway = $this->filterTransferredAway($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));$entries[] =[- 'title' => $title,- 'route' =>+ 'title' => $title,+ 'route' =>route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),@@ -153,19 +152,13 @@ trait PeriodOverview* Overview for single category. Has been refactored recently.** @param Category $category- * @param Carbon $date- *- * @return Collection+ * @param Carbon $start+ * @param Carbon $end+ * @return array*/- protected function getCategoryPeriodOverview(Category $category, Carbon $date): Collection+ protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array{- die('not yet complete');- /** @var JournalRepositoryInterface $journalRepository */- $journalRepository = app(JournalRepositoryInterface::class);- $range = app('preferences')->get('viewRange', '1M')->data;- $first = $journalRepository->firstNull();- $end = null === $first ? new Carbon : $first->date;- $start = clone $date;+ $range = app('preferences')->get('viewRange', '1M')->data;if ($end < $start) {[$start, $end] = [$end, $start]; // @codeCoverageIgnore@@ -180,39 +173,53 @@ trait PeriodOverview$cache->addProperty($category->id);if ($cache->has()) {- return $cache->get(); // @codeCoverageIgnore+ //return $cache->get(); // @codeCoverageIgnore}/** @var array $dates */$dates = app('navigation')->blockPeriods($start, $end, $range);- $entries = new Collection;- /** @var CategoryRepositoryInterface $categoryRepository */- $categoryRepository = app(CategoryRepositoryInterface::class);+ $entries = [];- foreach ($dates as $currentDate) {- $spent = $categoryRepository->spentInPeriodCollection(new Collection([$category]), new Collection, $currentDate['start'], $currentDate['end']);- $earned = $categoryRepository->earnedInPeriodCollection(new Collection([$category]), new Collection, $currentDate['start'], $currentDate['end']);- $spent = $this->groupByCurrency($spent);- $earned = $this->groupByCurrency($earned);+ // collect all expenses in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setCategory($category);+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::DEPOSIT]);+ $earnedSet = $collector->getExtractedJournals();- // amount transferred- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);+ // collect all income in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setCategory($category);+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::WITHDRAWAL]);+ $spentSet = $collector->getExtractedJournals();- $collector->setRange($currentDate['start'], $currentDate['end'])->setCategory($category)- ->setTypes([TransactionType::TRANSFER]);- $transferred = $this->groupByCurrency($collector->getExtractedJournals());+ // collect all transfers in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setCategory($category);+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::TRANSFER]);+ $transferSet = $collector->getExtractedJournals();- $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);- $entries->push(++ foreach ($dates as $currentDate) {+ $spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);+ $earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);+ $transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);+ $entries[] =[- 'transactions' => 0,- 'title' => $title,- 'spent' => $spent,- 'earned' => $earned,- 'transferred' => $transferred,- 'route' => route('categories.show', [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),- ]- );+ 'transactions' => 0,+ 'title' => $title,+ 'route' => route('categories.show',+ [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),+ 'total_transactions' => count($spent) + count($earned) + count($transferred),+ 'spent' => $this->groupByCurrency($spent),+ 'earned' => $this->groupByCurrency($earned),+ 'transferred' => $this->groupByCurrency($transferred),+ ];}$cache->store($entries);@@ -231,7 +238,7 @@ trait PeriodOverview*/protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array{- $range = app('preferences')->get('viewRange', '1M')->data;+ $range = app('preferences')->get('viewRange', '1M')->data;if ($end < $start) {[$start, $end] = [$end, $start]; // @codeCoverageIgnore@@ -258,12 +265,12 @@ trait PeriodOverview$journals = $collector->getExtractedJournals();foreach ($dates as $currentDate) {- $set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);- $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);- $entries[] =+ $set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);+ $entries[] =['title' => $title,- 'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),+ 'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),'total_transactions' => count($set),'spent' => $this->groupByCurrency($set),'earned' => [],@@ -277,18 +284,15 @@ trait PeriodOverview}/**- * TODO has to be synced with the others.- ** Show period overview for no category view.** @param Carbon $theDate*- * @return Collection+ * @return array* @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/- protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.+ protected function getNoCategoryPeriodOverview(Carbon $theDate): array{- die('not yet complete');Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));$range = app('preferences')->get('viewRange', '1M')->data;$first = $this->journalRepos->firstNull();@@ -305,58 +309,51 @@ trait PeriodOverview$cache->addProperty('no-category-period-entries');if ($cache->has()) {- return $cache->get(); // @codeCoverageIgnore+ //return $cache->get(); // @codeCoverageIgnore}$dates = app('navigation')->blockPeriods($start, $end, $range);- $entries = new Collection;-- foreach ($dates as $date) {+ $entries = [];- // count journals without category in this period:- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);- $collector->setRange($date['start'], $date['end'])->withoutCategory()- ->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);- $count = count($collector->getExtractedJournals());+ // collect all expenses in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->withoutCategory();+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::DEPOSIT]);+ $earnedSet = $collector->getExtractedJournals();- // amount transferred- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);- $collector->setRange($date['start'], $date['end'])->withoutCategory()- ->setTypes([TransactionType::TRANSFER]);- $transferred = app('steam')->positive((string)$collector->getSum());+ // collect all income in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->withoutCategory();+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::WITHDRAWAL]);+ $spentSet = $collector->getExtractedJournals();- // amount spent- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);- $collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(- [TransactionType::WITHDRAWAL]- );- $spent = $collector->getSum();+ // collect all transfers in this period:+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->withoutCategory();+ $collector->setRange($start, $end);+ $collector->setTypes([TransactionType::TRANSFER]);+ $transferSet = $collector->getExtractedJournals();- // amount earned- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);- $collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(- [TransactionType::DEPOSIT]- );- $earned = $collector->getSum();- /** @noinspection PhpUndefinedMethodInspection */- $dateStr = $date['end']->format('Y-m-d');- $dateName = app('navigation')->periodShow($date['end'], $date['period']);- $entries->push(+ /** @var array $currentDate */+ foreach ($dates as $currentDate) {+ $spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);+ $earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);+ $transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);+ $entries[] =[- 'string' => $dateStr,- 'name' => $dateName,- 'count' => $count,- 'spent' => $spent,- 'earned' => $earned,- 'transferred' => $transferred,- 'start' => clone $date['start'],- 'end' => clone $date['end'],- ]- );+ 'title' => $title,+ 'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),+ 'total_transactions' => count($spent) + count($earned) + count($transferred),+ 'spent' => $this->groupByCurrency($spent),+ 'earned' => $this->groupByCurrency($earned),+ 'transferred' => $this->groupByCurrency($transferred),+ ];}Log::debug('End of loops');$cache->store($entries);diff --git a/composer.lock b/composer.lockindex 212736344e..cdce73ba39 100644--- a/composer.lock+++ b/composer.lock@@ -929,16 +929,16 @@},{"name": "egulias/email-validator",- "version": "2.1.8",+ "version": "2.1.9","source": {"type": "git","url": "https://github.com/egulias/EmailValidator.git",- "reference": "c26463ff9241f27907112fbcd0c86fa670cfef98"+ "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/c26463ff9241f27907112fbcd0c86fa670cfef98",- "reference": "c26463ff9241f27907112fbcd0c86fa670cfef98",+ "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/128cc721d771ec2c46ce59698f4ca42b73f71b25",+ "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25","shasum": ""},"require": {@@ -982,7 +982,7 @@"validation","validator"],- "time": "2019-05-16T22:02:54+00:00"+ "time": "2019-06-23T10:14:27+00:00"},{"name": "erusev/parsedown",@@ -2309,16 +2309,16 @@},{"name": "nesbot/carbon",- "version": "2.19.2",+ "version": "2.20.0","source": {"type": "git","url": "https://github.com/briannesbitt/Carbon.git",- "reference": "adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b"+ "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b",- "reference": "adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b",+ "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bc671b896c276795fad8426b0aa24e8ade0f2498",+ "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498","shasum": ""},"require": {@@ -2365,7 +2365,7 @@"datetime","time"],- "time": "2019-06-07T09:56:45+00:00"+ "time": "2019-06-25T10:00:57+00:00"},{"name": "opis/closure",@@ -2587,16 +2587,16 @@},{"name": "phpseclib/phpseclib",- "version": "2.0.19",+ "version": "2.0.20","source": {"type": "git","url": "https://github.com/phpseclib/phpseclib.git",- "reference": "d2085db7b7394baa071a69c8f9159723c250f2ba"+ "reference": "d6819a55b05e123db1e881d8b230d57f912126be"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d2085db7b7394baa071a69c8f9159723c250f2ba",- "reference": "d2085db7b7394baa071a69c8f9159723c250f2ba",+ "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d6819a55b05e123db1e881d8b230d57f912126be",+ "reference": "d6819a55b05e123db1e881d8b230d57f912126be","shasum": ""},"require": {@@ -2675,7 +2675,7 @@"x.509","x509"],- "time": "2019-06-20T03:34:11+00:00"+ "time": "2019-06-23T16:33:11+00:00"},{"name": "pragmarx/google2fa",@@ -5555,16 +5555,16 @@},{"name": "filp/whoops",- "version": "2.3.2",+ "version": "2.4.0","source": {"type": "git","url": "https://github.com/filp/whoops.git",- "reference": "a28d5cef33627c069a2bd8fbb35ebe1a54881d35"+ "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/filp/whoops/zipball/a28d5cef33627c069a2bd8fbb35ebe1a54881d35",- "reference": "a28d5cef33627c069a2bd8fbb35ebe1a54881d35",+ "url": "https://api.github.com/repos/filp/whoops/zipball/1a1a1044ad00e285bd2825fac4c3a0443d90ad33",+ "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33","shasum": ""},"require": {@@ -5612,7 +5612,7 @@"throwable","whoops"],- "time": "2019-06-21T09:00:00+00:00"+ "time": "2019-06-23T09:00:00+00:00"},{"name": "fzaninotto/faker",@@ -6597,12 +6597,12 @@"source": {"type": "git","url": "https://github.com/Roave/SecurityAdvisories.git",- "reference": "baeb6f512b5ec8f0fd58bf890082b179f985c5a4"+ "reference": "a53a6f855cbff7edb078f87c72bb808c89443a00"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/baeb6f512b5ec8f0fd58bf890082b179f985c5a4",- "reference": "baeb6f512b5ec8f0fd58bf890082b179f985c5a4",+ "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/a53a6f855cbff7edb078f87c72bb808c89443a00",+ "reference": "a53a6f855cbff7edb078f87c72bb808c89443a00","shasum": ""},"conflict": {@@ -6640,6 +6640,7 @@"drupal/core": ">=7,<7.67|>=8,<8.6.16|>=8.7,<8.7.1","drupal/drupal": ">=7,<7.67|>=8,<8.6.16|>=8.7,<8.7.1","erusev/parsedown": "<1.7.2",+ "ezsystems/ezplatform-admin-ui": ">=1.3,<1.3.5|>=1.4,<1.4.4","ezsystems/ezpublish-kernel": ">=5.3,<5.3.12.1|>=5.4,<5.4.13.1|>=6,<6.7.9.1|>=6.8,<6.13.5.1|>=7,<7.2.4.1|>=7.3,<7.3.2.1","ezsystems/ezpublish-legacy": ">=5.3,<5.3.12.6|>=5.4,<5.4.12.3|>=2011,<2017.12.4.3|>=2018.6,<2018.6.1.4|>=2018.9,<2018.9.1.3","ezsystems/repository-forms": ">=2.3,<2.3.2.1",@@ -6748,8 +6749,8 @@"titon/framework": ">=0,<9.9.99","truckersmp/phpwhois": "<=4.3.1","twig/twig": "<1.38|>=2,<2.7",- "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.25|>=9,<9.5.6",- "typo3/cms-core": ">=8,<8.7.25|>=9,<9.5.6",+ "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.27|>=9,<9.5.8",+ "typo3/cms-core": ">=8,<8.7.27|>=9,<9.5.8","typo3/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.10|>=3.1,<3.1.7|>=3.2,<3.2.7|>=3.3,<3.3.5","typo3/neos": ">=1.1,<1.1.3|>=1.2,<1.2.13|>=2,<2.0.4","typo3/phar-stream-wrapper": ">=1,<2.1.1|>=3,<3.1.1",@@ -6803,7 +6804,7 @@}],"description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it",- "time": "2019-06-14T17:56:32+00:00"+ "time": "2019-06-25T10:37:35+00:00"},{"name": "sebastian/code-unit-reverse-lookup",diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xmlindex 2437e877f1..2bd193e356 100644--- a/phpunit.coverage.specific.xml+++ b/phpunit.coverage.specific.xml@@ -46,6 +46,9 @@</testsuite><testsuite name="Feature"><directory suffix="Test.php">./tests/Feature/Controllers/Account</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Category</directory></testsuite>diff --git a/phpunit.coverage.xml b/phpunit.coverage.xmlindex d06dd51f11..5bb3cd9969 100644--- a/phpunit.coverage.xml+++ b/phpunit.coverage.xml@@ -46,6 +46,9 @@</testsuite><testsuite name="Feature"><directory suffix="Test.php">./tests/Feature/Controllers/Account</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Category</directory></testsuite>diff --git a/phpunit.xml b/phpunit.xmlindex e1fe86d3fb..3faf2448de 100644--- a/phpunit.xml+++ b/phpunit.xml@@ -46,6 +46,9 @@</testsuite><testsuite name="Feature"><directory suffix="Test.php">./tests/Feature/Controllers/Account</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>+ <directory suffix="Test.php">./tests/Feature/Controllers/Category</directory></testsuite><!--diff --git a/resources/views/v1/categories/no-category.twig b/resources/views/v1/categories/no-category.twigindex 62527a6ec1..85d03066bc 100644--- a/resources/views/v1/categories/no-category.twig+++ b/resources/views/v1/categories/no-category.twig@@ -7,7 +7,7 @@{% block content %}{# upper show-all instruction #}- {% if periods.count > 0 %}+ {% if periods|length > 0 %}<div class="row"><div class="col-lg-offset-10 col-lg-2 col-md-offset-9 col-md-3 col-sm-12 col-xs-12"><p class="small text-center"><a href="{{ route('categories.no-category.all') }}">{{ 'showEverything'|_ }}</a></p>@@ -16,14 +16,14 @@{% endif %}<div class="row">- <div class="{% if periods.count > 0 %}col-lg-10 col-md-9 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">+ <div class="{% if periods|length > 0 %}col-lg-10 col-md-9 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}"><div class="box"><div class="box-header with-border"><h3 class="box-title">{{ subTitle }}</h3></div><div class="box-body ">- {% if periods.count > 0 %}+ {% if periods|length > 0 %}{% include 'list.groups' %}<p><i class="fa fa-calendar"></i>@@ -40,51 +40,16 @@</div></div>- {% if periods.count > 0 %}- <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12">- {% for period in periods %}- {% if period.count > 0 %}- <div class="box {% if period.date == end %}box-solid box-primary{% endif %}">- <div class="box-header with-border">- <h3 class="box-title"><a href="{{ route('categories.no-category', [period.start.format('Y-m-d'), period.end.format('Y-m-d')]) }}">{{ period.name }}</a>- </h3>- </div>- <div class="box-body no-padding">- <table class="table table-hover">- <tr>- <td style="width:33%;">{{ 'transactions'|_ }}</td>- <td style="text-align: right;">{{ period.count }}</td>- </tr>- {% if period.spent != 0 %}- <tr>- <td style="width:33%;">{{ 'spent'|_ }}</td>- <td style="text-align: right;">{{ period.spent|formatAmount }}</td>- </tr>- {% endif %}- {% if period.earned != 0 %}- <tr>- <td style="width:33%;">{{ 'earned'|_ }}</td>- <td style="text-align: right;">{{ period.earned|formatAmount }}</td>- </tr>- {% endif %}- {% if period.transferred != 0 %}- <tr>- <td style="width:33%;">{{ 'transferred'|_ }}</td>- <td style="text-align: right;" class="text-info">{{ period.transferred|formatAmountPlain }}</td>- </tr>- {% endif %}- </table>- </div>- </div>- {% endif %}- {% endfor %}+ {% if periods|length > 0 %}+ <div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">+ {% include 'list.periods' %}</div>{% endif %}</div>{# lower show-all instruction #}- {% if periods.count > 0 %}+ {% if periods|length > 0 %}<div class="row"><div class="col-lg-offset-10 col-lg-2 col-md-offset-9 col-md-3 col-sm-12 col-xs-12"><p class="small text-center"><a href="{{ route('categories.no-category',['all']) }}">{{ 'showEverything'|_ }}</a></p>diff --git a/resources/views/v1/categories/show.twig b/resources/views/v1/categories/show.twigindex ac1b637cc4..68645eb570 100644--- a/resources/views/v1/categories/show.twig+++ b/resources/views/v1/categories/show.twig@@ -49,7 +49,7 @@</div>{% endif %}</div>- {% if periods.count > 0 %}+ {% if periods|length > 0 %}<div class="row"><div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12"><p class="small text-center"><a href="{{ route('categories.show.all',[category.id]) }}">{{ 'showEverything'|_ }}</a></p>@@ -58,14 +58,14 @@{% endif %}<div class="row">- <div class="{% if periods.count > 0 %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">+ <div class="{% if periods|length > 0 %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}"><div class="box"><div class="box-header with-border"><h3 class="box-title">{{ 'transactions'|_ }}</h3></div><div class="box-body">- {% if periods.count > 0 %}+ {% if periods|length > 0 %}{% include 'list.groups' %}<p><i class="fa fa-calendar"></i>@@ -85,7 +85,7 @@</div></div></div>- {% if periods.count > 0 %}+ {% if periods|length > 0 %}<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">{% include 'list.periods' %}</div>diff --git a/resources/views/v1/list/periods.twig b/resources/views/v1/list/periods.twigindex 98daf0eba0..2fde0b1c41 100644--- a/resources/views/v1/list/periods.twig+++ b/resources/views/v1/list/periods.twig@@ -39,6 +39,19 @@{% endif %}{% endfor %}+ {% for entry in period.transferred %}+ {% if entry.amount != 0 %}+ <tr>+ <td style="width:33%;">{{ 'transferred'|_ }}</td>+ <td style="text-align: right;">+ <span title="{{ entry.count }}">+ {{ formatAmountBySymbol(entry.amount*-1, entry.currency_symbol, entry.currency_decimal_places) }}+ </span>+ </td>+ </tr>+ {% endif %}+ {% endfor %}+{% for entry in period.transferred_away %}{% if entry.amount != 0 %}<tr>diff --git a/routes/web.php b/routes/web.phpindex bc535be081..a909ded271 100644--- a/routes/web.php+++ b/routes/web.php@@ -233,19 +233,19 @@ Route::group(['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'categories', 'as' => 'categories.'], function () {// index:- Route::get('', ['uses' => 'CategoryController@index', 'as' => 'index']);+ Route::get('', ['uses' => 'Category\IndexController@index', 'as' => 'index']);// create- Route::get('create', ['uses' => 'CategoryController@create', 'as' => 'create']);- Route::post('store', ['uses' => 'CategoryController@store', 'as' => 'store']);+ Route::get('create', ['uses' => 'Category\CreateController@create', 'as' => 'create']);+ Route::post('store', ['uses' => 'Category\CreateController@store', 'as' => 'store']);// edit- Route::get('edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'edit']);- Route::post('update/{category}', ['uses' => 'CategoryController@update', 'as' => 'update']);+ Route::get('edit/{category}', ['uses' => 'Category\EditController@edit', 'as' => 'edit']);+ Route::post('update/{category}', ['uses' => 'Category\EditController@update', 'as' => 'update']);// delete- Route::get('delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'delete']);- Route::post('destroy/{category}', ['uses' => 'CategoryController@destroy', 'as' => 'destroy']);+ Route::get('delete/{category}', ['uses' => 'Category\DeleteController@delete', 'as' => 'delete']);+ Route::post('destroy/{category}', ['uses' => 'Category\DeleteController@destroy', 'as' => 'destroy']);// show category:Route::get('show/{category}/all', ['uses' => 'Category\ShowController@showAll', 'as' => 'show.all']);diff --git a/tests/Feature/Controllers/Category/CreateControllerTest.php b/tests/Feature/Controllers/Category/CreateControllerTest.phpnew file mode 100644index 0000000000..bae2ad0541--- /dev/null+++ b/tests/Feature/Controllers/Category/CreateControllerTest.php@@ -0,0 +1,94 @@+<?php+/**+ * CreateControllerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace Tests\Feature\Controllers\Category;+++use FireflyIII\Models\Category;+use FireflyIII\Models\TransactionJournal;+use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;+use Log;+use Mockery;+use Preferences;+use Tests\TestCase;++/**+ * Class CreateControllerTest+ */+class CreateControllerTest extends TestCase+{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Category\CreateController+ */+ public function testCreate(): void+ {+ Log::debug('TestCreate()');+ // mock stuff+ $this->mock(CategoryRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);++ $this->mockDefaultSession();++ $this->be($this->user());+ $response = $this->get(route('categories.create'));+ $response->assertStatus(200);+ // has bread crumb+ $response->assertSee('<ol class="breadcrumb">');+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Category\CreateController+ * @covers \FireflyIII\Http\Requests\CategoryFormRequest+ */+ public function testStore(): void+ {+ Log::debug('Test store()');+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $this->mockDefaultSession();+ $repository->shouldReceive('findNull')->andReturn(new Category);+ $repository->shouldReceive('store')->andReturn(new Category);+ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();++ $this->session(['categories.create.uri' => 'http://localhost']);++ $data = [+ 'name' => 'New Category ' . $this->randomInt(),+ ];+ $this->be($this->user());+ $response = $this->post(route('categories.store'), $data);+ $response->assertStatus(302);+ $response->assertSessionHas('success');+ }+}\ No newline at end of filediff --git a/tests/Feature/Controllers/Category/DeleteControllerTest.php b/tests/Feature/Controllers/Category/DeleteControllerTest.phpnew file mode 100644index 0000000000..69d5543959--- /dev/null+++ b/tests/Feature/Controllers/Category/DeleteControllerTest.php@@ -0,0 +1,88 @@+<?php+/**+ * DeleteControllerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace Tests\Feature\Controllers\Category;+++use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;+use Log;+use Mockery;+use Preferences;+use Tests\TestCase;++/**+ * Class DeleteControllerTest+ */+class DeleteControllerTest extends TestCase+{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Category\DeleteController+ */+ public function testDelete(): void+ {+ Log::debug('Test Delete()');+ // mock stuff+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $this->mockDefaultSession();++ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);++ $this->be($this->user());+ $response = $this->get(route('categories.delete', [1]));+ $response->assertStatus(200);+ // has bread crumb+ $response->assertSee('<ol class="breadcrumb">');+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Category\DeleteController+ */+ public function testDestroy(): void+ {+ Log::debug('Test destroy()');+ // mock stuff+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $this->mockDefaultSession();+ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();+ $categoryRepos->shouldReceive('destroy')->andReturn(true);++ $this->session(['categories.delete.uri' => 'http://localhost']);+ $this->be($this->user());+ $response = $this->post(route('categories.destroy', [1]));+ $response->assertStatus(302);+ $response->assertSessionHas('success');+ }+}\ No newline at end of filediff --git a/tests/Feature/Controllers/Category/EditControllerTest.php b/tests/Feature/Controllers/Category/EditControllerTest.phpnew file mode 100644index 0000000000..3f76f6c5be--- /dev/null+++ b/tests/Feature/Controllers/Category/EditControllerTest.php@@ -0,0 +1,101 @@+<?php+/**+ * EditControllerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace Tests\Feature\Controllers\Category;+++use FireflyIII\Models\Category;+use FireflyIII\Models\TransactionJournal;+use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;+use Log;+use Mockery;+use Preferences;+use Tests\TestCase;++/**+ * Class EditControllerTest+ */+class EditControllerTest extends TestCase+{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Category\EditController+ */+ public function testEdit(): void+ {+ Log::debug('Test edit()');+ // mock stuff+ $this->mock(CategoryRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $this->mockDefaultSession();++ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);++ $this->be($this->user());+ $response = $this->get(route('categories.edit', [1]));+ $response->assertStatus(200);+ // has bread crumb+ $response->assertSee('<ol class="breadcrumb">');+ }++++ /**+ * @covers \FireflyIII\Http\Controllers\Category\EditController+ * @covers \FireflyIII\Http\Requests\CategoryFormRequest+ */+ public function testUpdate(): void+ {+ Log::debug('Test update()');+ $category = Category::first();+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $this->mockDefaultSession();+ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();++ $repository->shouldReceive('update');+ $repository->shouldReceive('findNull')->andReturn($category);++ $this->session(['categories.edit.uri' => 'http://localhost']);++ $data = [+ 'name' => 'Updated Category ' . $this->randomInt(),+ 'active' => 1,+ ];+ $this->be($this->user());+ $response = $this->post(route('categories.update', [1]), $data);+ $response->assertStatus(302);+ $response->assertSessionHas('success');+ }+}\ No newline at end of filediff --git a/tests/Feature/Controllers/Category/IndexControllerTest.php b/tests/Feature/Controllers/Category/IndexControllerTest.phpnew file mode 100644index 0000000000..8c0df207b5--- /dev/null+++ b/tests/Feature/Controllers/Category/IndexControllerTest.php@@ -0,0 +1,80 @@+<?php+/**+ * IndexControllerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * 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/>.+ */++namespace Tests\Feature\Controllers\Category;+++use Carbon\Carbon;+use FireflyIII\Models\Category;+use FireflyIII\Models\Preference;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;+use Illuminate\Support\Collection;+use Log;+use Mockery;+use Preferences;+use Tests\TestCase;++/**+ * Class IndexControllerTest+ */+class IndexControllerTest extends TestCase+{++ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Category\IndexController+ */+ public function testIndex(): void+ {+ Log::debug('Test index()');+ // mock stuff+ $category = factory(Category::class)->make();+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);++ $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();+ $categoryRepos->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);++ $this->mockDefaultSession();+ // list size+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+++ $this->be($this->user());+ $response = $this->get(route('categories.index'));+ $response->assertStatus(200);+ // has bread crumb+ $response->assertSee('<ol class="breadcrumb">');+ }+}\ No newline at end of filediff --git a/tests/Feature/Controllers/Category/NoCategoryControllerTest.php b/tests/Feature/Controllers/Category/NoCategoryControllerTest.phpindex cc13e702d5..679beb540d 100644--- a/tests/Feature/Controllers/Category/NoCategoryControllerTest.php+++ b/tests/Feature/Controllers/Category/NoCategoryControllerTest.php@@ -25,9 +25,11 @@ namespace Tests\Feature\Controllers\Category;use Carbon\Carbon;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Helpers\Collector\TransactionCollectorInterface;use FireflyIII\Helpers\Filter\InternalTransferFilter;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;+use FireflyIII\Models\Preference;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Category\CategoryRepositoryInterface;@@ -38,6 +40,7 @@ use Illuminate\Support\Collection;use Log;use Mockery;use Navigation;+use Preferences;use Tests\TestCase;/**@@ -64,37 +67,30 @@ class NoCategoryControllerTest extends TestCase*/public function testNoCategory(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info('Test noCategory()');- // mock stuff- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);+ $this->mockDefaultSession();+ // list size+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+ $this->mockLastActivity();// get the journal with the most recent date for firstNull:- $journal = $this->user()->transactionJournals()->orderBy('date', 'DESC')->first();- $journalRepos->shouldReceive('firstNull')->twice()->andReturn($journal);$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();- $collector->shouldReceive('setTypes')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withoutCategory')->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));+ $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();+ $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();- $collector->shouldReceive('setPage')->andReturnSelf();- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();- $collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();$this->be($this->user());$this->changeDateRange($this->user(), $range);@@ -113,35 +109,30 @@ class NoCategoryControllerTest extends TestCase*/public function testNoCategoryAll(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info('Test nocategoryAll()');- // mock stuff- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $this->mockDefaultSession();+ // list size+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);- $journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();- $collector->shouldReceive('setTypes')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withoutCategory')->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));+ $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();- $collector->shouldReceive('setPage')->andReturnSelf();- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();- $collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();$this->be($this->user());$this->changeDateRange($this->user(), $range);@@ -159,35 +150,32 @@ class NoCategoryControllerTest extends TestCase*/public function testNoCategoryDate(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info('Test nocategorydate()');- // mock stuff- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);$date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);- $journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());+ $this->mockDefaultSession();+ // list size+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+ $this->mockLastActivity();+$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();- $collector->shouldReceive('setTypes')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withoutCategory')->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));-- $collector->shouldReceive('setPage')->andReturnSelf();- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();- $collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();++ $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);diff --git a/tests/Feature/Controllers/Category/ShowControllerTest.php b/tests/Feature/Controllers/Category/ShowControllerTest.phpindex bba6520c2a..27d5512491 100644--- a/tests/Feature/Controllers/Category/ShowControllerTest.php+++ b/tests/Feature/Controllers/Category/ShowControllerTest.php@@ -25,9 +25,11 @@ namespace Tests\Feature\Controllers\Category;use Carbon\Carbon;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Helpers\Collector\TransactionCollectorInterface;use FireflyIII\Helpers\Filter\InternalTransferFilter;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;+use FireflyIII\Models\Preference;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Account\AccountRepositoryInterface;@@ -39,6 +41,7 @@ use Illuminate\Support\Collection;use Log;use Mockery;use Navigation;+use Preferences;use Tests\TestCase;/**@@ -65,44 +68,38 @@ class ShowControllerTest extends TestCase*/public function testShow(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info(sprintf('Test show(%s)', $range));- $transaction = factory(Transaction::class)->make();+ $withdrawal = $this->getRandomWithdrawalAsArray();$categoryRepos = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);+ $collector = $this->mock(GroupCollectorInterface::class);++ $this->mockDefaultSession();$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');- $journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());// mock stuff$categoryRepos->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);$categoryRepos->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);+ $categoryRepos->shouldReceive('firstUseDate')->andReturnNull();- //$accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);- $collector = $this->mock(TransactionCollectorInterface::class);$collector->shouldReceive('setPage')->andReturnSelf()->once();$collector->shouldReceive('setLimit')->andReturnSelf()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(2);$collector->shouldReceive('setRange')->andReturnSelf()->atLeast(2);- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(2);$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(2);+ $collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();+ $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);+ $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);@@ -126,36 +123,28 @@ class ShowControllerTest extends TestCase*/public function testShowAll(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info(sprintf('Test showAll(%s)', $range));- // mock stuff- $transaction = factory(Transaction::class)->make();- $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $withdrawal = $this->getRandomWithdrawalAsArray();$repository = $this->mock(CategoryRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);++ $this->mockDefaultSession();+ $pref = new Preference;+ $pref->data = 50;+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);$collector->shouldReceive('setPage')->andReturnSelf()->once();$collector->shouldReceive('setLimit')->andReturnSelf()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();$collector->shouldReceive('setRange')->andReturnSelf()->once();$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->once();-- $collector->shouldReceive('setCategory')->andReturnSelf()->once();- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();+ $collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();+ $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);+ $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);$this->be($this->user());@@ -164,115 +153,4 @@ class ShowControllerTest extends TestCase$response->assertStatus(200);$response->assertSee('<ol class="breadcrumb">');}-- /**- * @covers \FireflyIII\Http\Controllers\Category\ShowController- * @dataProvider dateRangeProvider- *- * @param string $range- */- public function testShowByDate(string $range): void- {- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- Log::info(sprintf('Test testShowByDate(%s)', $range));- // mock stuff- $transaction = factory(Transaction::class)->make();- $repository = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);-- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $month = new Carbon();- $month->startOfMonth();- $journal = TransactionJournal::where('date', '>=', $month->format('Y-m-d') . ' 00:00:00')->first();- $journalRepos->shouldReceive('firstNull')->twice()->andReturn($journal);-- //$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);-- $collector->shouldReceive('setPage')->andReturnSelf()->once();- $collector->shouldReceive('setLimit')->andReturnSelf()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();-- $repository->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);- $repository->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);-- $this->be($this->user());- $this->changeDateRange($this->user(), $range);- $today = new Carbon();- $today->subDay();- $response = $this->get(route('categories.show', [1, $today->format('Y-m-d')]));- $response->assertStatus(200);- $response->assertSee('<ol class="breadcrumb">');- }-- /**- * @covers \FireflyIII\Http\Controllers\Category\ShowController- *- * @dataProvider dateRangeProvider- *- * @param string $range- */- public function testShowEmpty(string $range): void- {- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $latestJournal = $this->user()->transactionJournals()- ->orderBy('date', 'DESC')->first();-- $userRepos = $this->mock(UserRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $repository = $this->mock(CategoryRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);-- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $journalRepos->shouldReceive('firstNull')->twice()->andReturn($latestJournal);-- // mock stuff- $repository->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);- $repository->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- // $accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);- $collector->shouldReceive('setPage')->andReturnSelf()->once();- $collector->shouldReceive('setLimit')->andReturnSelf()->once();- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(1);- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);- $collector->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast(1);- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast(1);-- $this->be($this->user());- $this->changeDateRange($this->user(), $range);- $response = $this->get(route('categories.show', [1]));- $response->assertStatus(200);- $response->assertSee('<ol class="breadcrumb">');- }-}diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.phpindex d1f8081433..591eae877e 100644--- a/tests/Feature/Controllers/CategoryControllerTest.php+++ b/tests/Feature/Controllers/CategoryControllerTest.php@@ -52,93 +52,7 @@ class CategoryControllerTest extends TestCaseLog::info(sprintf('Now in %s.', get_class($this)));}- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- */- public function testCreate(): void- {- Log::debug('TestCreate()');- // mock stuff- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);-- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $this->be($this->user());- $response = $this->get(route('categories.create'));- $response->assertStatus(200);- // has bread crumb- $response->assertSee('<ol class="breadcrumb">');- }-- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- */- public function testDelete(): void- {- Log::debug('Test Delete()');- // mock stuff- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);-- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $this->be($this->user());- $response = $this->get(route('categories.delete', [1]));- $response->assertStatus(200);- // has bread crumb- $response->assertSee('<ol class="breadcrumb">');- }-- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- */- public function testDestroy(): void- {- Log::debug('Test destroy()');- // mock stuff- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);-- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $categoryRepos->shouldReceive('destroy')->andReturn(true);- $this->session(['categories.delete.uri' => 'http://localhost']);- $this->be($this->user());- $response = $this->post(route('categories.destroy', [1]));- $response->assertStatus(302);- $response->assertSessionHas('success');- }-- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- */- public function testEdit(): void- {- Log::debug('Test edit()');- // mock stuff- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);-- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $this->be($this->user());- $response = $this->get(route('categories.edit', [1]));- $response->assertStatus(200);- // has bread crumb- $response->assertSee('<ol class="breadcrumb">');- }/*** @covers \FireflyIII\Http\Controllers\CategoryController@@ -165,59 +79,5 @@ class CategoryControllerTest extends TestCase$response->assertSee('<ol class="breadcrumb">');}- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- * @covers \FireflyIII\Http\Requests\CategoryFormRequest- */- public function testStore(): void- {- Log::debug('Test store()');- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $repository = $this->mock(CategoryRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);-- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $repository->shouldReceive('findNull')->andReturn(new Category);- $repository->shouldReceive('store')->andReturn(new Category);-- $this->session(['categories.create.uri' => 'http://localhost']);-- $data = [- 'name' => 'New Category ' . $this->randomInt(),- ];- $this->be($this->user());- $response = $this->post(route('categories.store'), $data);- $response->assertStatus(302);- $response->assertSessionHas('success');- }-- /**- * @covers \FireflyIII\Http\Controllers\CategoryController- * @covers \FireflyIII\Http\Requests\CategoryFormRequest- */- public function testUpdate(): void- {- Log::debug('Test update()');- $category = Category::first();- $repository = $this->mock(CategoryRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);- $journalRepos->shouldReceive('firstNull')->once()->andReturn(TransactionJournal::first());- $repository->shouldReceive('update');- $repository->shouldReceive('findNull')->andReturn($category);-- $this->session(['categories.edit.uri' => 'http://localhost']);-- $data = [- 'name' => 'Updated Category ' . $this->randomInt(),- 'active' => 1,- ];- $this->be($this->user());- $response = $this->post(route('categories.update', [1]), $data);- $response->assertStatus(302);- $response->assertSessionHas('success');- }}diff --git a/tests/Feature/Controllers/Chart/AccountControllerTest.php b/tests/Feature/Controllers/Chart/AccountControllerTest.phpindex f7e6688b8c..1ca58eb4a1 100644--- a/tests/Feature/Controllers/Chart/AccountControllerTest.php+++ b/tests/Feature/Controllers/Chart/AccountControllerTest.php@@ -24,11 +24,12 @@ namespace Tests\Feature\Controllers\Chart;use Carbon\Carbon;use FireflyIII\Generator\Chart\Basic\GeneratorInterface;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Helpers\Collector\TransactionCollectorInterface;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;-use FireflyIII\Models\Category;+use FireflyIII\Models\Preference;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\TransactionType;@@ -68,11 +69,17 @@ class AccountControllerTest extends TestCase$generator = $this->mock(GeneratorInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);-+ $euro = $this->getEuro();+ $dollar = $this->getDollar();// grab two expense accounts from the current user.$accounts = $this->user()->accounts()->where('account_type_id', 4)->take(2)->get();+ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++$firstId = $accounts->first()->id;$secondId = $accounts->first()->id;// for each a set of balances:@@ -86,8 +93,8 @@ class AccountControllerTest extends TestCaseSteam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);// currency should be looking for the currency ID's:- $currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));- $currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));+ $currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($euro);+ $currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn($dollar);$generator->shouldReceive('multiSet')->andReturn([])->once();@@ -106,27 +113,31 @@ class AccountControllerTest extends TestCase*/public function testExpenseBudget(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$budgetRepos = $this->mock(BudgetRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $budget = $this->user()->budgets()->find($withdrawal['budget_id']);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);- $transaction = factory(Transaction::class)->make();- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);- $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();+ $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->atLeast()->once();+ $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();$this->be($this->user());$this->changeDateRange($this->user(), $range);@@ -142,23 +153,28 @@ class AccountControllerTest extends TestCase*/public function testExpenseBudgetAll(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$budgetRepos = $this->mock(BudgetRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);- $transaction = factory(Transaction::class)->make();+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $budget = $this->user()->budgets()->find($withdrawal['budget_id']);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);- $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);+ $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());$this->be($this->user());@@ -175,26 +191,32 @@ class AccountControllerTest extends TestCase*/public function testExpenseCategory(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $transaction = factory(Transaction::class)->make();- $category = factory(Category::class)->make();$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $category = $this->user()->categories()->find($withdrawal['category_id']);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+++ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();++$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));@@ -212,23 +234,24 @@ class AccountControllerTest extends TestCase*/public function testExpenseCategoryAll(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $transaction = factory(Transaction::class)->make();- $category = factory(Category::class)->make();$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $category = $this->user()->categories()->find($withdrawal['category_id']);+ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());@@ -253,8 +276,16 @@ class AccountControllerTest extends TestCase$fiscalHelper = $this->mock(FiscalHelperInterface::class);$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);+// change the preference:- Preferences::setForUser($this->user(), 'frontPageAccounts', []);+ $emptyPref = new Preference;+ $emptyPref->data = [];+ Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);+ Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', []]);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);@@ -276,28 +307,33 @@ class AccountControllerTest extends TestCase*/public function testIncomeCategory(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $transaction = factory(Transaction::class)->make();- $account = factory(Account::class)->make();$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $category = $this->user()->categories()->find($withdrawal['category_id']);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+++ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();+$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$account]));+ $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));$this->be($this->user());$this->changeDateRange($this->user(), $range);@@ -313,24 +349,26 @@ class AccountControllerTest extends TestCase*/public function testIncomeCategoryAll(string $range): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $transaction = factory(Transaction::class)->make();- $account = factory(Account::class)->make();$generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);$categoryRepos = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $category = $this->user()->categories()->find($withdrawal['category_id']);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();- $collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));$generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$account]));+ $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));$accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());$this->be($this->user());@@ -351,6 +389,12 @@ class AccountControllerTest extends TestCase$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++$date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);@@ -374,6 +418,12 @@ class AccountControllerTest extends TestCase$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$generator = $this->mock(GeneratorInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++$date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);@@ -401,6 +451,12 @@ class AccountControllerTest extends TestCase$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$fiscalHelper = $this->mock(FiscalHelperInterface::class);++ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++$fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);$fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);// grab two expense accounts from the current user.diff --git a/tests/Feature/Controllers/Chart/BillControllerTest.php b/tests/Feature/Controllers/Chart/BillControllerTest.phpindex ac44a9f0d0..0c48fb61da 100644--- a/tests/Feature/Controllers/Chart/BillControllerTest.php+++ b/tests/Feature/Controllers/Chart/BillControllerTest.php@@ -23,13 +23,12 @@ declare(strict_types=1);namespace Tests\Feature\Controllers\Chart;use FireflyIII\Generator\Chart\Basic\GeneratorInterface;-use FireflyIII\Helpers\Collector\TransactionCollectorInterface;-use FireflyIII\Models\Transaction;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;-use Illuminate\Support\Collection;use Log;+use Preferences;use Tests\TestCase;/**@@ -58,6 +57,10 @@ class BillControllerTest extends TestCase$repository = $this->mock(BillRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+$amounts = [1 => '100',2 => '100',@@ -81,17 +84,16 @@ class BillControllerTest extends TestCase*/public function testSingle(): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;- $transaction = factory(Transaction::class)->make();- $generator = $this->mock(GeneratorInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);+ $withdrawal = $this->getRandomWithdrawalAsArray();+ $generator = $this->mock(GeneratorInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();- $collector->shouldReceive('setBills')->andReturnSelf()->once();- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]))->once();+ // mock default session+ $this->mockDefaultSession();+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+ $collector->shouldReceive('setBill')->andReturnSelf()->once();+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->once();$generator->shouldReceive('multiSet')->once()->andReturn([]);$this->be($this->user());diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 4fbb5637ad..1da9b1e977 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -35,6 +35,7 @@ use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Models\Budget;use FireflyIII\Models\BudgetLimit;+use FireflyIII\Models\Category;use FireflyIII\Models\Configuration;use FireflyIII\Models\Preference;use FireflyIII\Models\TransactionCurrency;@@ -66,6 +67,14 @@ abstract class TestCase extends BaseTestCasereturn $this->user()->budgets()->inRandomOrder()->first();}+ /**+ * @return Category+ */+ public function getRandomCategory(): Category+ {+ return $this->user()->categories()->inRandomOrder()->first();+ }+/*** @return BudgetLimit*/@@ -132,12 +141,19 @@ abstract class TestCase extends BaseTestCase{$withdrawal = $this->getRandomWithdrawal();$euro = $this->getEuro();+ $budget = $this->getRandomBudget();+ $category = $this->getRandomCategory();+ try {+ $date = new Carbon;+ } catch (Exception $e) {+ $e->getMessage();+ }return ['transaction_journal_id' => $withdrawal->id,'currency_id' => $euro->id,'foreign_currency_id' => null,- 'date' => new Carbon,+ 'date' => $date,'source_account_id' => 1,'destination_account_id' => 4,'currency_name' => $euro->name,@@ -145,6 +161,46 @@ abstract class TestCase extends BaseTestCase'currency_symbol' => $euro->symbol,'currency_decimal_places' => $euro->decimal_places,'amount' => '-30',+ 'budget_id' => $budget->id,+ 'category_id' => $category->id,+ ];+ }++ /**+ * @return array+ * @throws Exception+ */+ public function getRandomWithdrawalGroupAsArray(): array+ {+ $withdrawal = $this->getRandomWithdrawal();+ $euro = $this->getEuro();+ $budget = $this->getRandomBudget();+ try {+ $date = new Carbon;+ } catch (Exception $e) {+ $e->getMessage();+ }++ return [+ [+ 'group_title' => null,+ 'transactions' => [+ [+ 'transaction_journal_id' => $withdrawal->id,+ 'currency_id' => $euro->id,+ 'foreign_currency_id' => null,+ 'date' => $date,+ 'source_account_id' => 1,+ 'destination_account_id' => 4,+ 'currency_name' => $euro->name,+ 'currency_code' => $euro->code,+ 'currency_symbol' => $euro->symbol,+ 'currency_decimal_places' => $euro->decimal_places,+ 'amount' => '-30',+ 'budget_id' => $budget->id,+ ],+ ],+ ],];}