Skip to content

Firefly III: a personal finances manager

Refactored a lot of tests.

James Coleb7a4b0fdfd3d
diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php
index c0b15fe6fb..0fc0009e0b 100644
--- a/app/Http/Controllers/AttachmentController.php
+++ b/app/Http/Controllers/AttachmentController.php
@@ -41,6 +41,7 @@ class AttachmentController extends Controller
/**
* AttachmentController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index ac95d3c86e..4781aa94ae 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -55,6 +55,7 @@ class BillController extends Controller
/**
* BillController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -253,7 +254,7 @@ class BillController extends Controller
$matcher->setTriggeredLimit(100000); // large upper limit
$matcher->setRule($rule);
$matchingTransactions = $matcher->findTransactionsByRule();
- $total += $matchingTransactions->count();
+ $total += count($matchingTransactions);
$this->billRepository->linkCollectionToBill($bill, $matchingTransactions);
}
@@ -314,15 +315,18 @@ class BillController extends Controller
// transform any attachments as well.
$collection = $this->billRepository->getAttachments($bill);
$attachments = new Collection;
+
+ // @codeCoverageIgnoreStart
if ($collection->count() > 0) {
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$attachments = $collection->each(
- function (Attachment $attachment) use ($transformer) {
+ static function (Attachment $attachment) use ($transformer) {
return $transformer->transform($attachment);
}
);
}
+ // @codeCoverageIgnoreEnd
return view('bills.show', compact('attachments', 'groups', 'rules', 'yearAverage', 'overallAverage', 'year', 'object', 'bill', 'subTitle'));
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
deleted file mode 100644
index 50ecaa557d..0000000000
--- a/app/Http/Controllers/CategoryController.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-/**
- * CategoryController.php
- * Copyright (c) 2017 [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/>.
- */
-declare(strict_types=1);
-
-namespace FireflyIII\Http\Controllers;
-
-use FireflyIII\Http\Requests\CategoryFormRequest;
-use FireflyIII\Models\Category;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use Illuminate\Http\Request;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-
-/**
- * Class CategoryController.
- */
-class CategoryController extends Controller
-{
- /** @var CategoryRepositoryInterface The category repository */
- private $repository;
-
- /**
- * CategoryController constructor.
- */
- 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);
- }
- );
- }
-
-
-
-
-
-
-
-
-}
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index 286fcec349..c5c041a3aa 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -50,6 +50,7 @@ class Controller extends BaseController
/**
* Controller constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php
index ca34315bb8..ac09787506 100644
--- a/app/Http/Controllers/CurrencyController.php
+++ b/app/Http/Controllers/CurrencyController.php
@@ -47,6 +47,7 @@ class CurrencyController extends Controller
/**
* CurrencyController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
index 09f78085fd..8de8555f3d 100644
--- a/app/Http/Controllers/DebugController.php
+++ b/app/Http/Controllers/DebugController.php
@@ -46,7 +46,8 @@ class DebugController extends Controller
use GetConfigurationData;
/**
- * HomeController constructor.
+ * DebugController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 126798978a..f1618c2d49 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -43,6 +43,7 @@ class HomeController extends Controller
{
/**
* HomeController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/Json/RuleController.php
similarity index 92%
rename from app/Http/Controllers/JsonController.php
rename to app/Http/Controllers/Json/RuleController.php
index ee325185c9..1b6ebdd80b 100644
--- a/app/Http/Controllers/JsonController.php
+++ b/app/Http/Controllers/Json/RuleController.php
@@ -1,7 +1,7 @@
<?php
/**
- * JsonController.php
- * Copyright (c) 2017 [email protected]
+ * RuleController.php
+ * Copyright (c) 2019 [email protected]
*
* This file is part of Firefly III.
*
@@ -18,19 +18,20 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
-declare(strict_types=1);
-namespace FireflyIII\Http\Controllers;
+namespace FireflyIII\Http\Controllers\Json;
+
+use FireflyIII\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Log;
use Throwable;
/**
- * Class JsonController.
+ * Class RuleController
*/
-class JsonController extends Controller
+class RuleController extends Controller
{
/**
* Render HTML form for rule action.
@@ -91,4 +92,5 @@ class JsonController extends Controller
return response()->json(['html' => $view]);
}
-}
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php
index 6261a88888..618cd3c14e 100644
--- a/app/Http/Controllers/PiggyBankController.php
+++ b/app/Http/Controllers/PiggyBankController.php
@@ -56,6 +56,7 @@ class PiggyBankController extends Controller
/**
* PiggyBankController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php
index e4238c03c0..a9e58cf476 100644
--- a/app/Http/Controllers/PreferencesController.php
+++ b/app/Http/Controllers/PreferencesController.php
@@ -33,6 +33,7 @@ class PreferencesController extends Controller
{
/**
* PreferencesController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index 472255734d..282e0cebd0 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -59,13 +59,14 @@ class ProfileController extends Controller
/**
* ProfileController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
- function ($request, $next) {
+ static function ($request, $next) {
app('view')->share('title', (string)trans('firefly.profile'));
app('view')->share('mainTitleIcon', 'fa-user');
@@ -166,20 +167,20 @@ class ProfileController extends Controller
/** @var Collection $set */
$set = app('preferences')->findByName('email_change_confirm_token');
$user = null;
- Log::debug(sprintf('Found %d preferences', $set->count()));
+ //Log::debug(sprintf('Found %d preferences', $set->count()));
/** @var Preference $preference */
foreach ($set as $preference) {
if ($preference->data === $token) {
- Log::debug('Found user');
+ //Log::debug('Found user');
$user = $preference->user;
}
}
// update user to clear blocked and blocked_code.
if (null === $user) {
- Log::debug('Found no user');
+ //Log::debug('Found no user');
throw new FireflyException('Invalid token.');
}
- Log::debug('Will unblock user.');
+ //Log::debug('Will unblock user.');
$repository->unblockUser($user);
// return to login.
diff --git a/app/Http/Controllers/RuleGroup/CreateController.php b/app/Http/Controllers/RuleGroup/CreateController.php
new file mode 100644
index 0000000000..ddf41a733e
--- /dev/null
+++ b/app/Http/Controllers/RuleGroup/CreateController.php
@@ -0,0 +1,102 @@
+<?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\RuleGroup;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Http\Requests\RuleGroupFormRequest;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+
+/**
+ * Class CreateController
+ */
+class CreateController extends Controller
+{
+ /** @var RuleGroupRepositoryInterface */
+ private $repository;
+
+ /**
+ * CreateController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.rules'));
+ app('view')->share('mainTitleIcon', 'fa-random');
+
+ $this->repository = app(RuleGroupRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+ /**
+ * Create a new rule group.
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function create()
+ {
+ $subTitleIcon = 'fa-clone';
+ $subTitle = (string)trans('firefly.make_new_rule_group');
+
+ // put previous url in session if not redirect from store (not "create another").
+ if (true !== session('rule-groups.create.fromStore')) {
+ $this->rememberPreviousUri('rule-groups.create.uri');
+ }
+ session()->forget('rule-groups.create.fromStore');
+
+ return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
+ }
+
+ /**
+ * Store the rule group.
+ *
+ * @param RuleGroupFormRequest $request
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function store(RuleGroupFormRequest $request)
+ {
+ $data = $request->getRuleGroupData();
+ $ruleGroup = $this->repository->store($data);
+
+ session()->flash('success', (string)trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
+ app('preferences')->mark();
+
+ $redirect = redirect($this->getPreviousUri('rule-groups.create.uri'));
+ if (1 === (int)$request->get('create_another')) {
+ // @codeCoverageIgnoreStart
+ session()->put('rule-groups.create.fromStore', true);
+
+ $redirect = redirect(route('rule-groups.create'))->withInput();
+ // @codeCoverageIgnoreEnd
+ }
+
+ return $redirect;
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/RuleGroup/DeleteController.php b/app/Http/Controllers/RuleGroup/DeleteController.php
new file mode 100644
index 0000000000..1c0afeb52b
--- /dev/null
+++ b/app/Http/Controllers/RuleGroup/DeleteController.php
@@ -0,0 +1,98 @@
+<?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\RuleGroup;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use Illuminate\Http\Request;
+
+/**
+ * Class DeleteController
+ */
+class DeleteController extends Controller
+{
+ /** @var RuleGroupRepositoryInterface */
+ private $repository;
+
+ /**
+ * DeleteController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.rules'));
+ app('view')->share('mainTitleIcon', 'fa-random');
+
+ $this->repository = app(RuleGroupRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+
+ /**
+ * Delete a rule group.
+ *
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function delete(RuleGroup $ruleGroup)
+ {
+ $subTitle = (string)trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
+
+ // put previous url in session
+ $this->rememberPreviousUri('rule-groups.delete.uri');
+
+ return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle'));
+ }
+
+ /**
+ * Actually destroy the rule group.
+ *
+ * @param Request $request
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function destroy(Request $request, RuleGroup $ruleGroup)
+ {
+ $title = $ruleGroup->title;
+
+ /** @var RuleGroup $moveTo */
+ $moveTo = $this->repository->find((int)$request->get('move_rules_before_delete'));
+ $this->repository->destroy($ruleGroup, $moveTo);
+
+ session()->flash('success', (string)trans('firefly.deleted_rule_group', ['title' => $title]));
+ app('preferences')->mark();
+
+ return redirect($this->getPreviousUri('rule-groups.delete.uri'));
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/RuleGroup/EditController.php b/app/Http/Controllers/RuleGroup/EditController.php
new file mode 100644
index 0000000000..e6ab8aacf7
--- /dev/null
+++ b/app/Http/Controllers/RuleGroup/EditController.php
@@ -0,0 +1,150 @@
+<?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\RuleGroup;
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Http\Requests\RuleGroupFormRequest;
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use Illuminate\Http\Request;
+
+/**
+ * Class EditController
+ */
+class EditController extends Controller
+{
+ /** @var RuleGroupRepositoryInterface */
+ private $repository;
+
+ /**
+ * EditController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.rules'));
+ app('view')->share('mainTitleIcon', 'fa-random');
+
+ $this->repository = app(RuleGroupRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+ /**
+ * Move a rule group down.
+ *
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function down(RuleGroup $ruleGroup)
+ {
+ $this->repository->moveDown($ruleGroup);
+
+ return redirect(route('rules.index'));
+ }
+
+
+ /**
+ * Edit a rule group.
+ *
+ * @param Request $request
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function edit(Request $request, RuleGroup $ruleGroup)
+ {
+ $subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
+
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active,
+ ];
+
+
+ // put previous url in session if not redirect from store (not "return_to_edit").
+ if (true !== session('rule-groups.edit.fromUpdate')) {
+ $this->rememberPreviousUri('rule-groups.edit.uri');
+ }
+ session()->forget('rule-groups.edit.fromUpdate');
+ session()->flash('preFilled', $preFilled);
+
+ return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle'));
+ }
+
+ /**
+ * Move the rule group up.
+ *
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ *
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ */
+ public function up(RuleGroup $ruleGroup)
+ {
+ $this->repository->moveUp($ruleGroup);
+
+ return redirect(route('rules.index'));
+ }
+
+ /**
+ * Update the rule group.
+ *
+ * @param RuleGroupFormRequest $request
+ * @param RuleGroup $ruleGroup
+ *
+ * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function update(RuleGroupFormRequest $request, RuleGroup $ruleGroup)
+ {
+ $data = [
+ 'title' => $request->input('title'),
+ 'description' => $request->input('description'),
+ 'active' => 1 === (int)$request->input('active'),
+ ];
+
+ $this->repository->update($ruleGroup, $data);
+
+ session()->flash('success', (string)trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
+ app('preferences')->mark();
+ $redirect = redirect($this->getPreviousUri('rule-groups.edit.uri'));
+ if (1 === (int)$request->get('return_to_edit')) {
+ // @codeCoverageIgnoreStart
+ session()->put('rule-groups.edit.fromUpdate', true);
+
+ $redirect = redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]);
+ // @codeCoverageIgnoreEnd
+ }
+
+ // redirect to previous URL.
+ return $redirect;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/RuleGroup/ExecutionController.php b/app/Http/Controllers/RuleGroup/ExecutionController.php
new file mode 100644
index 0000000000..dc099d03e4
--- /dev/null
+++ b/app/Http/Controllers/RuleGroup/ExecutionController.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * ExecutionController.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\RuleGroup;
+
+
+use Carbon\Carbon;
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Http\Requests\SelectTransactionsRequest;
+use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use FireflyIII\User;
+use Illuminate\Http\RedirectResponse;
+
+/**
+ * Class ExecutionController
+ */
+class ExecutionController extends Controller
+{
+ /** @var AccountRepositoryInterface */
+ private $repository;
+
+ /**
+ * ExecutionController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.rules'));
+ app('view')->share('mainTitleIcon', 'fa-random');
+
+ $this->repository = app(AccountRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+
+ /**
+ * Execute the given rulegroup on a set of existing transactions.
+ *
+ * @param SelectTransactionsRequest $request
+ * @param RuleGroup $ruleGroup
+ *
+ * @return RedirectResponse
+ * @throws \Exception
+ */
+ public function execute(SelectTransactionsRequest $request, RuleGroup $ruleGroup): RedirectResponse
+ {
+ // Get parameters specified by the user
+ /** @var User $user */
+ $user = auth()->user();
+ $accounts = $this->repository->getAccountsById($request->get('accounts'));
+ $startDate = new Carbon($request->get('start_date'));
+ $endDate = new Carbon($request->get('end_date'));
+
+ // Create a job to do the work asynchronously
+ $job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup);
+
+ // Apply parameters to the job
+ $job->setUser($user);
+ $job->setAccounts($accounts);
+ $job->setStartDate($startDate);
+ $job->setEndDate($endDate);
+
+ // Dispatch a new job to execute it in a queue
+ $this->dispatch($job);
+
+ // Tell the user that the job is queued
+ session()->flash('success', (string)trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title]));
+
+ return redirect()->route('rules.index');
+ }
+
+ /**
+ * Select transactions to apply the group on.
+ *
+ * @param RuleGroup $ruleGroup
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function selectTransactions(RuleGroup $ruleGroup)
+ {
+ $first = session('first')->format('Y-m-d');
+ $today = Carbon::now()->format('Y-m-d');
+ $subTitle = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]);
+
+ return view('rules.rule-group.select-transactions', compact('first', 'today', 'ruleGroup', 'subTitle'));
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php
deleted file mode 100644
index c57a93bd2f..0000000000
--- a/app/Http/Controllers/RuleGroupController.php
+++ /dev/null
@@ -1,296 +0,0 @@
-<?php
-/**
- * RuleGroupController.php
- * Copyright (c) 2017 [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/>.
- */
-declare(strict_types=1);
-
-namespace FireflyIII\Http\Controllers;
-
-use Carbon\Carbon;
-use FireflyIII\Http\Requests\RuleGroupFormRequest;
-use FireflyIII\Http\Requests\SelectTransactionsRequest;
-use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\User;
-use Illuminate\Http\RedirectResponse;
-use Illuminate\Http\Request;
-
-/**
- * Class RuleGroupController.
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RuleGroupController extends Controller
-{
- /**
- * RuleGroupController constructor.
- */
- public function __construct()
- {
- parent::__construct();
-
- $this->middleware(
- function ($request, $next) {
- app('view')->share('title', (string)trans('firefly.rules'));
- app('view')->share('mainTitleIcon', 'fa-random');
-
- return $next($request);
- }
- );
- }
-
- /**
- * Create a new rule group.
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function create()
- {
- $subTitleIcon = 'fa-clone';
- $subTitle = (string)trans('firefly.make_new_rule_group');
-
- // put previous url in session if not redirect from store (not "create another").
- if (true !== session('rule-groups.create.fromStore')) {
- $this->rememberPreviousUri('rule-groups.create.uri');
- }
- session()->forget('rule-groups.create.fromStore');
-
- return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
- }
-
- /**
- * Delege a rule group.
- *
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function delete(RuleGroup $ruleGroup)
- {
- $subTitle = (string)trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
-
- // put previous url in session
- $this->rememberPreviousUri('rule-groups.delete.uri');
-
- return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle'));
- }
-
- /**
- * Actually destroy the rule group.
- *
- * @param Request $request
- * @param RuleGroupRepositoryInterface $repository
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function destroy(Request $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
- {
- /** @var User $user */
- $user = auth()->user();
- $title = $ruleGroup->title;
-
- /** @var RuleGroup $moveTo */
- $moveTo = $user->ruleGroups()->find((int)$request->get('move_rules_before_delete'));
-
- $repository->destroy($ruleGroup, $moveTo);
-
- session()->flash('success', (string)trans('firefly.deleted_rule_group', ['title' => $title]));
- app('preferences')->mark();
-
- return redirect($this->getPreviousUri('rule-groups.delete.uri'));
- }
-
- /**
- * Move a rule group down.
- *
- * @param RuleGroupRepositoryInterface $repository
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function down(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
- {
- $repository->moveDown($ruleGroup);
-
- return redirect(route('rules.index'));
- }
-
- /**
- * Edit a rule group.
- *
- * @param Request $request
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function edit(Request $request, RuleGroup $ruleGroup)
- {
- $subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
-
- $hasOldInput = null !== $request->old('_token');
- $preFilled = [
- 'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active,
- ];
-
-
- // put previous url in session if not redirect from store (not "return_to_edit").
- if (true !== session('rule-groups.edit.fromUpdate')) {
- $this->rememberPreviousUri('rule-groups.edit.uri');
- }
- session()->forget('rule-groups.edit.fromUpdate');
- session()->flash('preFilled', $preFilled);
-
- return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle'));
- }
-
- /**
- * Execute the given rulegroup on a set of existing transactions.
- *
- * @param SelectTransactionsRequest $request
- * @param AccountRepositoryInterface $repository
- * @param RuleGroup $ruleGroup
- *
- * @return RedirectResponse
- * @throws \Exception
- */
- public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup): RedirectResponse
- {
- // Get parameters specified by the user
- /** @var User $user */
- $user = auth()->user();
- $accounts = $repository->getAccountsById($request->get('accounts'));
- $startDate = new Carbon($request->get('start_date'));
- $endDate = new Carbon($request->get('end_date'));
-
- // Create a job to do the work asynchronously
- $job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup);
-
- // Apply parameters to the job
- $job->setUser($user);
- $job->setAccounts($accounts);
- $job->setStartDate($startDate);
- $job->setEndDate($endDate);
-
- // Dispatch a new job to execute it in a queue
- $this->dispatch($job);
-
- // Tell the user that the job is queued
- session()->flash('success', (string)trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title]));
-
- return redirect()->route('rules.index');
- }
-
- /**
- * Select transactions to apply the group on.
- *
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function selectTransactions(RuleGroup $ruleGroup)
- {
- $first = session('first')->format('Y-m-d');
- $today = Carbon::now()->format('Y-m-d');
- $subTitle = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]);
-
- return view('rules.rule-group.select-transactions', compact('first', 'today', 'ruleGroup', 'subTitle'));
- }
-
- /**
- * Store the rule group.
- *
- * @param RuleGroupFormRequest $request
- * @param RuleGroupRepositoryInterface $repository
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
- {
- $data = $request->getRuleGroupData();
- $ruleGroup = $repository->store($data);
-
- session()->flash('success', (string)trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
- app('preferences')->mark();
-
- $redirect = redirect($this->getPreviousUri('rule-groups.create.uri'));
- if (1 === (int)$request->get('create_another')) {
- // @codeCoverageIgnoreStart
- session()->put('rule-groups.create.fromStore', true);
-
- $redirect = redirect(route('rule-groups.create'))->withInput();
- // @codeCoverageIgnoreEnd
- }
-
- return $redirect;
- }
-
- /**
- * Move the rule group up.
- *
- * @param RuleGroupRepositoryInterface $repository
- * @param RuleGroup $ruleGroup
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- *
- * @SuppressWarnings(PHPMD.ShortMethodName)
- */
- public function up(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
- {
- $repository->moveUp($ruleGroup);
-
- return redirect(route('rules.index'));
- }
-
- /**
- * Update the rule group.
- *
- * @param RuleGroupFormRequest $request
- * @param RuleGroupRepositoryInterface $repository
- * @param RuleGroup $ruleGroup
- *
- * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
- {
- $data = [
- 'title' => $request->input('title'),
- 'description' => $request->input('description'),
- 'active' => 1 === (int)$request->input('active'),
- ];
-
- $repository->update($ruleGroup, $data);
-
- session()->flash('success', (string)trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
- app('preferences')->mark();
- $redirect = redirect($this->getPreviousUri('rule-groups.edit.uri'));
- if (1 === (int)$request->get('return_to_edit')) {
- // @codeCoverageIgnoreStart
- session()->put('rule-groups.edit.fromUpdate', true);
-
- $redirect = redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]);
- // @codeCoverageIgnoreEnd
- }
-
- // redirect to previous URL.
- return $redirect;
- }
-}
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index a97438fc3c..de033da43c 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -543,9 +543,9 @@ class BillRepository implements BillRepositoryInterface
* Link a set of journals to a bill.
*
* @param Bill $bill
- * @param Collection $transactions
+ * @param array $transactions
*/
- public function linkCollectionToBill(Bill $bill, Collection $transactions): void
+ public function linkCollectionToBill(Bill $bill, array $transactions): void
{
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php
index fe6b6aa387..310c4addf5 100644
--- a/app/Repositories/Bill/BillRepositoryInterface.php
+++ b/app/Repositories/Bill/BillRepositoryInterface.php
@@ -222,9 +222,9 @@ interface BillRepositoryInterface
* Link a set of journals to a bill.
*
* @param Bill $bill
- * @param Collection $journals
+ * @param array $transactions
*/
- public function linkCollectionToBill(Bill $bill, Collection $journals): void;
+ public function linkCollectionToBill(Bill $bill, array $transactions): void;
/**
* Given a bill and a date, this method will tell you at which moment this bill expects its next
diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.php
index 2ef02c9de8..b7c05fb049 100644
--- a/app/Support/Binder/AccountList.php
+++ b/app/Support/Binder/AccountList.php
@@ -44,9 +44,9 @@ class AccountList implements BinderInterface
*/
public static function routeBinder(string $value, Route $route): Collection
{
- Log::debug(sprintf('Now in AccountList::routeBinder("%s")', $value));
+ //Log::debug(sprintf('Now in AccountList::routeBinder("%s")', $value));
if (auth()->check()) {
- Log::debug('User is logged in.');
+ //Log::debug('User is logged in.');
$collection = new Collection;
if ('allAssetAccounts' === $value) {
/** @var Collection $collection */
@@ -55,7 +55,7 @@ class AccountList implements BinderInterface
->where('account_types.type', AccountType::ASSET)
->orderBy('accounts.name', 'ASC')
->get(['accounts.*']);
- Log::debug(sprintf('Collection length is %d', $collection->count()));
+ //Log::debug(sprintf('Collection length is %d', $collection->count()));
}
if ('allAssetAccounts' !== $value) {
$incoming = array_map('\intval', explode(',', $value));
@@ -66,7 +66,7 @@ class AccountList implements BinderInterface
->whereIn('accounts.id', $list)
->orderBy('accounts.name', 'ASC')
->get(['accounts.*']);
- Log::debug(sprintf('Collection length is %d', $collection->count()));
+ //Log::debug(sprintf('Collection length is %d', $collection->count()));
}
if ($collection->count() > 0) {
diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.php
index 629b282879..67a2595c70 100644
--- a/app/Support/Binder/BudgetList.php
+++ b/app/Support/Binder/BudgetList.php
@@ -43,12 +43,12 @@ class BudgetList implements BinderInterface
*/
public static function routeBinder(string $value, Route $route): Collection
{
- Log::debug(sprintf('Now in BudgetList::routeBinder("%s")', $value));
+ //Log::debug(sprintf('Now in BudgetList::routeBinder("%s")', $value));
if (auth()->check()) {
$list = array_unique(array_map('\intval', explode(',', $value)));
- Log::debug('List is now', $list);
+ //Log::debug('List is now', $list);
if (0 === count($list)) {
- Log::warning('List count is zero, return 404.');
+ Log::warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException; // @codeCoverageIgnore
}
@@ -57,22 +57,22 @@ class BudgetList implements BinderInterface
->where('active', 1)
->whereIn('id', $list)
->get();
- Log::debug(sprintf('Found %d active budgets', $collection->count()), $list);
+ //Log::debug(sprintf('Found %d active budgets', $collection->count()), $list);
// add empty budget if applicable.
if (in_array(0, $list, true)) {
- Log::debug('Add empty budget because $list contains 0.');
+ //Log::debug('Add empty budget because $list contains 0.');
$collection->push(new Budget);
}
if ($collection->count() > 0) {
- Log::debug(sprintf('List length is > 0 (%d), so return it.', $collection->count()));
+ //Log::debug(sprintf('List length is > 0 (%d), so return it.', $collection->count()));
return $collection;
}
- Log::debug('List length is zero, fall back to 404.');
+ //Log::debug('List length is zero, fall back to 404.');
}
- Log::debug('Final fallback to 404.');
+ Log::warning('BudgetList fallback to 404.');
throw new NotFoundHttpException;
}
}
diff --git a/app/Support/Http/Controllers/GetConfigurationData.php b/app/Support/Http/Controllers/GetConfigurationData.php
index 291f828a5a..31a2d69073 100644
--- a/app/Support/Http/Controllers/GetConfigurationData.php
+++ b/app/Support/Http/Controllers/GetConfigurationData.php
@@ -106,12 +106,12 @@ trait GetConfigurationData
// first range is the current range:
$title => [$start, $end],
];
- Log::debug(sprintf('viewRange is %s', $viewRange));
- Log::debug(sprintf('isCustom is %s', var_export($isCustom, true)));
+ //Log::debug(sprintf('viewRange is %s', $viewRange));
+ //Log::debug(sprintf('isCustom is %s', var_export($isCustom, true)));
// when current range is a custom range, add the current period as the next range.
if ($isCustom) {
- Log::debug('Custom is true.');
+ //Log::debug('Custom is true.');
$index = app('navigation')->periodShow($start, $viewRange);
$customPeriodStart = app('navigation')->startOfPeriod($start, $viewRange);
$customPeriodEnd = app('navigation')->endOfPeriod($customPeriodStart, $viewRange);
diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php
index af803a9047..e14abf840e 100644
--- a/app/Support/Http/Controllers/RequestInformation.php
+++ b/app/Support/Http/Controllers/RequestInformation.php
@@ -105,7 +105,7 @@ trait RequestInformation
}
$baseHref = route('index');
$helpString = sprintf(
- '<p><em><img alt="" src="%s/images/flags/%s.png" /> %s</em></p>', $baseHref, $originalLanguage, (string)trans('firefly.help_translating')
+ '<p><em><img alt="" src="%s/v1/images/flags/%s.png" /> %s</em></p>', $baseHref, $originalLanguage, (string)trans('firefly.help_translating')
);
$content = $helpString . $help->getFromGitHub($route, $language);
}
diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php
index e2d201240c..7fa8d39cb0 100644
--- a/app/Support/Navigation.php
+++ b/app/Support/Navigation.php
@@ -540,7 +540,7 @@ class Navigation
$subtract = $subtract ?? 1;
$date = clone $theDate;
// 1D 1W 1M 3M 6M 1Y
- Log::debug(sprintf('subtractPeriod: date is %s, repeat frequency is %s and subtract is %d', $date->format('Y-m-d'), $repeatFreq, $subtract));
+ //Log::debug(sprintf('subtractPeriod: date is %s, repeat frequency is %s and subtract is %d', $date->format('Y-m-d'), $repeatFreq, $subtract));
$functionMap = [
'1D' => 'subDays',
'daily' => 'subDays',
@@ -564,16 +564,16 @@ class Navigation
if (isset($functionMap[$repeatFreq])) {
$function = $functionMap[$repeatFreq];
$date->$function($subtract);
- Log::debug(sprintf('%s is in function map, execute %s with argument %d', $repeatFreq, $function, $subtract));
- Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
+ //Log::debug(sprintf('%s is in function map, execute %s with argument %d', $repeatFreq, $function, $subtract));
+ //Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
return $date;
}
if (isset($modifierMap[$repeatFreq])) {
$subtract *= $modifierMap[$repeatFreq];
$date->subMonths($subtract);
- Log::debug(sprintf('%s is in modifier map with value %d, execute subMonths with argument %d', $repeatFreq, $modifierMap[$repeatFreq], $subtract));
- Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
+ //Log::debug(sprintf('%s is in modifier map with value %d, execute subMonths with argument %d', $repeatFreq, $modifierMap[$repeatFreq], $subtract));
+ //Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
return $date;
}
@@ -586,10 +586,10 @@ class Navigation
/** @var Carbon $tEnd */
$tEnd = session('end', Carbon::now()->endOfMonth());
$diffInDays = $tStart->diffInDays($tEnd);
- Log::debug(sprintf('repeatFreq is %s, start is %s and end is %s (session data).', $repeatFreq, $tStart->format('Y-m-d'), $tEnd->format('Y-m-d')));
- Log::debug(sprintf('Diff in days is %d', $diffInDays));
+ //Log::debug(sprintf('repeatFreq is %s, start is %s and end is %s (session data).', $repeatFreq, $tStart->format('Y-m-d'), $tEnd->format('Y-m-d')));
+ //Log::debug(sprintf('Diff in days is %d', $diffInDays));
$date->subDays($diffInDays * $subtract);
- Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
+ //Log::debug(sprintf('subtractPeriod: resulting date is %s', $date->format('Y-m-d')));
return $date;
}
diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php
index ec8b8b3d61..ad712e781f 100644
--- a/app/Support/Twig/AmountFormat.php
+++ b/app/Support/Twig/AmountFormat.php
@@ -84,12 +84,6 @@ class AmountFormat extends Twig_Extension
return new Twig_SimpleFunction(
'formatAmountByAccount',
static function (AccountModel $account, string $amount, bool $coloured = null): string {
-
- if ('testing' === config('app.env')) {
- Log::warning('Twig AmountFormat::formatAmountByAccount should NOT be called in the TEST environment!');
- Log::warning('Make sure AccountRepos and Amount::getDefaultCurrency are mocked.');
- }
-
$coloured = $coloured ?? true;
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xml
index ce06301554..87cb0e2e09 100644
--- a/phpunit.coverage.specific.xml
+++ b/phpunit.coverage.specific.xml
@@ -56,6 +56,9 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Recurring</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Report</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Rule</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/RuleGroup</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/System</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Transaction</directory>
</testsuite>
diff --git a/phpunit.coverage.xml b/phpunit.coverage.xml
index e6c3676a7e..5554db36f8 100644
--- a/phpunit.coverage.xml
+++ b/phpunit.coverage.xml
@@ -56,6 +56,9 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Recurring</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Report</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Rule</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/RuleGroup</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/System</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Transaction</directory>
</testsuite>
diff --git a/phpunit.xml b/phpunit.xml
index 4d6b567484..d9961c48a3 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -56,6 +56,11 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Recurring</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Report</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Rule</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/RuleGroup</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/System</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Transaction</directory>
+ <file>./tests/Feature/Controllers/AttachmentControllerTest.php</file>
+
</testsuite>
<!--
diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php
index 72b7e53083..4f7cc1beba 100644
--- a/routes/breadcrumbs.php
+++ b/routes/breadcrumbs.php
@@ -43,7 +43,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\User;
use Illuminate\Support\Arr;
-use Illuminate\Support\Collection;
if (!function_exists('limitStringLength')) {
/**
@@ -288,7 +287,7 @@ try {
function (BreadcrumbsGenerator $breadcrumbs, Attachment $attachment) {
$object = $attachment->attachable;
if ($object instanceof TransactionJournal) {
- $breadcrumbs->parent('transactions.show', $object);
+ $breadcrumbs->parent('transactions.show', $object->transactionGroup);
$breadcrumbs->push(limitStringLength($attachment->filename), route('attachments.edit', [$attachment]));
}
}
@@ -298,14 +297,11 @@ try {
function (BreadcrumbsGenerator $breadcrumbs, Attachment $attachment) {
$object = $attachment->attachable;
if ($object instanceof TransactionJournal) {
- $breadcrumbs->parent('transactions.show', $object);
+ $breadcrumbs->parent('transactions.show', $object->transactionGroup);
$breadcrumbs->push(
trans('firefly.delete_attachment', ['name' => limitStringLength($attachment->filename)]), route('attachments.edit', [$attachment])
);
}
- else {
- throw new FireflyException('Cannot make breadcrumb for attachment connected to object of type ' . get_class($object));
- }
}
);
diff --git a/routes/web.php b/routes/web.php
index f7541a1028..37f85cd626 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -554,8 +554,8 @@ Route::group(
Route::get('box/net-worth', ['uses' => 'Json\BoxController@netWorth', 'as' => 'box.net-worth']);
// rules
- Route::get('trigger', ['uses' => 'JsonController@trigger', 'as' => 'trigger']);
- Route::get('action', ['uses' => 'JsonController@action', 'as' => 'action']);
+ Route::get('trigger', ['uses' => 'Json\RuleController@trigger', 'as' => 'trigger']);
+ Route::get('action', ['uses' => 'Json\RuleController@action', 'as' => 'action']);
// front page
Route::get('frontpage/piggy-banks', ['uses' => 'Json\FrontpageController@piggyBanks', 'as' => 'fp.piggy-banks']);
@@ -810,17 +810,17 @@ Route::group(
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'rule-groups', 'as' => 'rule-groups.'], function () {
- Route::get('create', ['uses' => 'RuleGroupController@create', 'as' => 'create']);
- Route::get('edit/{ruleGroup}', ['uses' => 'RuleGroupController@edit', 'as' => 'edit']);
- Route::get('delete/{ruleGroup}', ['uses' => 'RuleGroupController@delete', 'as' => 'delete']);
- Route::get('up/{ruleGroup}', ['uses' => 'RuleGroupController@up', 'as' => 'up']);
- Route::get('down/{ruleGroup}', ['uses' => 'RuleGroupController@down', 'as' => 'down']);
- Route::get('select/{ruleGroup}', ['uses' => 'RuleGroupController@selectTransactions', 'as' => 'select-transactions']);
-
- Route::post('store', ['uses' => 'RuleGroupController@store', 'as' => 'store']);
- Route::post('update/{ruleGroup}', ['uses' => 'RuleGroupController@update', 'as' => 'update']);
- Route::post('destroy/{ruleGroup}', ['uses' => 'RuleGroupController@destroy', 'as' => 'destroy']);
- Route::post('execute/{ruleGroup}', ['uses' => 'RuleGroupController@execute', 'as' => 'execute']);
+ Route::get('create', ['uses' => 'RuleGroup\CreateController@create', 'as' => 'create']);
+ Route::get('edit/{ruleGroup}', ['uses' => 'RuleGroup\EditController@edit', 'as' => 'edit']);
+ Route::get('delete/{ruleGroup}', ['uses' => 'RuleGroup\DeleteController@delete', 'as' => 'delete']);
+ Route::get('up/{ruleGroup}', ['uses' => 'RuleGroup\EditController@up', 'as' => 'up']);
+ Route::get('down/{ruleGroup}', ['uses' => 'RuleGroup\EditController@down', 'as' => 'down']);
+ Route::get('select/{ruleGroup}', ['uses' => 'RuleGroup\ExecutionController@selectTransactions', 'as' => 'select-transactions']);
+
+ Route::post('store', ['uses' => 'RuleGroup\CreateController@store', 'as' => 'store']);
+ Route::post('update/{ruleGroup}', ['uses' => 'RuleGroup\EditController@update', 'as' => 'update']);
+ Route::post('destroy/{ruleGroup}', ['uses' => 'RuleGroup\DeleteController@destroy', 'as' => 'destroy']);
+ Route::post('execute/{ruleGroup}', ['uses' => 'RuleGroup\ExecutionController@execute', 'as' => 'execute']);
}
);
diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php
index 5317002766..1725c4414c 100644
--- a/tests/Feature/Controllers/Account/EditControllerTest.php
+++ b/tests/Feature/Controllers/Account/EditControllerTest.php
@@ -24,13 +24,9 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Account;
-use Amount;
use FireflyIII\Models\AccountType;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@@ -205,7 +201,8 @@ class EditControllerTest extends TestCase
public function testUpdate(): void
{
// mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $account = $this->getRandomAsset();
+ $repository = $this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('update')->once();
@@ -222,7 +219,7 @@ class EditControllerTest extends TestCase
'what' => 'asset',
];
- $response = $this->post(route('accounts.update', [1]), $data);
+ $response = $this->post(route('accounts.update', [$account->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
@@ -235,7 +232,8 @@ class EditControllerTest extends TestCase
public function testUpdateAgain(): void
{
// mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $account = $this->getRandomAsset();
+ $repository = $this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('update')->once();
@@ -253,7 +251,7 @@ class EditControllerTest extends TestCase
// mock default session stuff
$this->mockDefaultSession();
- $response = $this->post(route('accounts.update', [1]), $data);
+ $response = $this->post(route('accounts.update', [$account->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
diff --git a/tests/Feature/Controllers/Account/ShowControllerTest.php b/tests/Feature/Controllers/Account/ShowControllerTest.php
index 4a825ca4ab..7948a8e56d 100644
--- a/tests/Feature/Controllers/Account/ShowControllerTest.php
+++ b/tests/Feature/Controllers/Account/ShowControllerTest.php
@@ -61,7 +61,7 @@ class ShowControllerTest extends TestCase
*/
public function testShow(string $range): void
{
- Log::info(sprintf('testShow(%s)', $range));
+ //Log::info(sprintf('testShow(%s)', $range));
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php
index de05ceee8b..8a0bf70364 100644
--- a/tests/Feature/Controllers/Admin/UserControllerTest.php
+++ b/tests/Feature/Controllers/Admin/UserControllerTest.php
@@ -55,7 +55,7 @@ class UserControllerTest extends TestCase
$this->mockDefaultSession();
$this->be($this->user());
- $response = $this->get(route('admin.users.delete', [1]));
+ $response = $this->get(route('admin.users.delete', [$this->user()->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -74,7 +74,7 @@ class UserControllerTest extends TestCase
$this->mockDefaultSession();
$this->be($this->user());
- $response = $this->post(route('admin.users.destroy', ['2']));
+ $response = $this->post(route('admin.users.destroy', [$this->user()->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
@@ -91,7 +91,7 @@ class UserControllerTest extends TestCase
$this->mockDefaultSession();
$this->be($this->user());
- $response = $this->get(route('admin.users.edit', [1]));
+ $response = $this->get(route('admin.users.edit', [$this->user()->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -141,7 +141,7 @@ class UserControllerTest extends TestCase
$this->mockDefaultSession();
$this->be($this->user());
- $response = $this->get(route('admin.users.show', [1]));
+ $response = $this->get(route('admin.users.show', [$this->user()->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php
index f1c86197d1..ca376c40ee 100644
--- a/tests/Feature/Controllers/AttachmentControllerTest.php
+++ b/tests/Feature/Controllers/AttachmentControllerTest.php
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -55,19 +56,19 @@ class AttachmentControllerTest extends TestCase
*/
public function testDelete(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $this->mockDefaultSession();
+
+ // data
+ $attachment = $this->getRandomAttachment();
- return;
// mock stuff
- $attachRepository = $this->mock(AttachmentRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.delete', [1]));
+ $response = $this->get(route('attachments.delete', [$attachment->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -78,17 +79,17 @@ class AttachmentControllerTest extends TestCase
*/
public function testDestroy(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
+ $attachment = $this->getRandomAttachment();
+ $repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['attachments.delete.uri' => 'http://localhost']);
$this->be($this->user());
- $response = $this->post(route('attachments.destroy', [1]));
+ $response = $this->post(route('attachments.destroy', [$attachment->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
@@ -98,17 +99,16 @@ class AttachmentControllerTest extends TestCase
*/
public function testDownload(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $attachment = $this->getRandomAttachment();
+ $repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.download', [1]));
+ $response = $this->get(route('attachments.download', [$attachment->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('This is attachment number one.');
@@ -119,16 +119,18 @@ class AttachmentControllerTest extends TestCase
*/
public function testDownloadFail(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
+ $attachment = $this->getRandomAttachment();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(false);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.download', [1]));
+ $response = $this->get(route('attachments.download', [$attachment->id]));
$response->assertStatus(500);
}
@@ -137,19 +139,15 @@ class AttachmentControllerTest extends TestCase
*/
public function testEdit(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
-
+ $attachment = $this->getRandomAttachment();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$attachRepository->shouldReceive('getNoteText')->andReturn('OK');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.edit', [1]));
+ $response = $this->get(route('attachments.edit', [$attachment->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -160,6 +158,7 @@ class AttachmentControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -180,13 +179,13 @@ class AttachmentControllerTest extends TestCase
*/
public function testUpdate(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
+ $repository = $this->mock(AttachmentRepositoryInterface::class);
+ $attachment = $this->getRandomAttachment();
$repository->shouldReceive('update')->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['attachments.edit.uri' => 'http://localhost']);
$data = [
@@ -196,50 +195,44 @@ class AttachmentControllerTest extends TestCase
];
$this->be($this->user());
- $response = $this->post(route('attachments.update', [1]), $data);
+ $response = $this->post(route('attachments.update', [$attachment->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
* @covers \FireflyIII\Http\Controllers\AttachmentController
*/
public function testView(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $attachment = $this->getRandomAttachment();
+ $this->mockDefaultSession();
- return;
$repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.view', [3]));
+ $response = $this->get(route('attachments.view', [$attachment->id]));
$response->assertStatus(200);
}
/**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
* @covers \FireflyIII\Http\Controllers\AttachmentController
*/
public function testViewFail(): void
{
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
+ $repository = $this->mock(AttachmentRepositoryInterface::class);
+ $attachment = $this->getRandomAttachment();
$repository->shouldReceive('exists')->once()->andReturn(false);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('attachments.view', [1]));
+ $response = $this->get(route('attachments.view', [$attachment->id]));
$response->assertStatus(500);
}
}
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
index fc36ff007b..8c913075e2 100644
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ b/tests/Feature/Controllers/BillControllerTest.php
@@ -22,10 +22,11 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use Amount;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Bill;
-use FireflyIII\Models\Rule;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
@@ -39,6 +40,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -65,18 +67,17 @@ class BillControllerTest extends TestCase
*/
public function testCreate(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_bills_create');
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $this->mock(AttachmentHelperInterface::class);
+ $this->mock(BillRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
$this->be($this->user());
$response = $this->get(route('bills.create'));
$response->assertStatus(200);
@@ -89,17 +90,15 @@ class BillControllerTest extends TestCase
*/
public function testDelete(): void
{
- $bill = $this->user()->bills()->where('active', 1)->first();
+ $this->mockDefaultSession();
+ $bill = $this->getRandomBill();
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $this->mock(AttachmentHelperInterface::class);
+ $this->mock(BillRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('bills.delete', [$bill->id]));
@@ -113,16 +112,15 @@ class BillControllerTest extends TestCase
*/
public function testDestroy(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $this->mock(AttachmentHelperInterface::class);
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
$repository->shouldReceive('destroy')->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->session(['bills.delete.uri' => 'http://localhost']);
$this->be($this->user());
@@ -136,17 +134,16 @@ class BillControllerTest extends TestCase
*/
public function testEdit(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $billRepos = $this->mock(BillRepositoryInterface::class);
+ $this->mock(AttachmentHelperInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
$billRepos->shouldReceive('getNoteText')->andReturn('Hello');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('bills.edit', [1]));
@@ -161,15 +158,21 @@ class BillControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_bills_index');
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $bill = factory(Bill::class)->make();
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
+ $this->mock(AttachmentHelperInterface::class);
+ $bill = $this->getRandomBill();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $transformer = $this->mock(BillTransformer::class);
+
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+ Amount::shouldReceive('formatAnything')->andReturn('-100');
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
@@ -197,29 +200,29 @@ class BillControllerTest extends TestCase
*/
public function testRescan(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $rule = Rule::first();
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journal = factory(TransactionJournal::class)->make();
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $rule = $this->getRandomRule();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $this->mock(AttachmentHelperInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection([$rule]));
//calls for transaction matcher:
- // todo bad to do this:
$matcher = $this->mock(TransactionMatcher::class);
$matcher->shouldReceive('setSearchLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setTriggeredLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
- $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn(new Collection);
+ $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
$repository->shouldReceive('linkCollectionToBill')->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+
$this->be($this->user());
$response = $this->get(route('bills.rescan', [1]));
$response->assertStatus(302);
@@ -231,16 +234,10 @@ class BillControllerTest extends TestCase
*/
public function testRescanInactive(): void
{
- $bill = $this->user()->bills()->where('active', 0)->first();
- // mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $this->mockDefaultSession();
+ $bill = $this->getRandomInactiveBill();
+ $this->mock(AttachmentHelperInterface::class);
+ $this->mock(BillRepositoryInterface::class);
$this->be($this->user());
$response = $this->get(route('bills.rescan', [$bill->id]));
@@ -253,18 +250,33 @@ class BillControllerTest extends TestCase
*/
public function testShow(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_bills_show');
- return;
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $transformer = $this->mock(BillTransformer::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $group = $this->getRandomWithdrawalGroup();
+ $this->mock(AttachmentHelperInterface::class);
+
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
+ $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
+
+ // mock collector:
+ $collector->shouldReceive('setBill')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
+
+ Amount::shouldReceive('formatAnything')->andReturn('-100');
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
@@ -277,24 +289,10 @@ class BillControllerTest extends TestCase
]
);
-
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$repository->shouldReceive('getYearAverage')->andReturn('0');
$repository->shouldReceive('getOverallAverage')->andReturn('0');
- // $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
- // $repository->shouldReceive('getNoteText')->andReturn('Hi there');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- //
- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
- $collector->shouldReceive('setBills')->andReturnSelf();
- $collector->shouldReceive('setLimit')->andReturnSelf();
- $collector->shouldReceive('setPage')->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
- $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
- // $repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
- // $repository->shouldReceive('setUser');
$this->be($this->user());
$response = $this->get(route('bills.show', [1]));
@@ -310,20 +308,18 @@ class BillControllerTest extends TestCase
*/
public function testStore(): void
{
+ $this->mockDefaultSession();
+
$this->be($this->user());
$bill = $this->user()->bills()->first();
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $attachHelper = $this->mock(AttachmentHelperInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn($bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$data = [
'name' => 'New Bill ' . $this->randomInt(),
@@ -349,19 +345,17 @@ class BillControllerTest extends TestCase
*/
public function testStoreCreateAnother(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $bill = $this->getRandomBill();
+ $attachHelper = $this->mock(AttachmentHelperInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
- $bill = $this->user()->bills()->first();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn($bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$data = [
'name' => 'New Bill ' . $this->randomInt(),
@@ -388,15 +382,12 @@ class BillControllerTest extends TestCase
*/
public function testStoreError(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $this->mock(AttachmentHelperInterface::class);
$repository->shouldReceive('store')->andReturn(null);
$data = [
@@ -423,18 +414,16 @@ class BillControllerTest extends TestCase
*/
public function testStoreNoGroup(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$data = [
'name' => 'New Bill ' . $this->randomInt(),
@@ -461,18 +450,16 @@ class BillControllerTest extends TestCase
*/
public function testUpdate(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$attachHelper = $this->mock(AttachmentHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$data = [
'id' => 1,
diff --git a/tests/Feature/Controllers/Budget/DeleteControllerTest.php b/tests/Feature/Controllers/Budget/DeleteControllerTest.php
index 2e0943841d..21621106d4 100644
--- a/tests/Feature/Controllers/Budget/DeleteControllerTest.php
+++ b/tests/Feature/Controllers/Budget/DeleteControllerTest.php
@@ -23,9 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
@@ -53,6 +51,8 @@ class DeleteControllerTest extends TestCase
*/
public function testDelete(): void
{
+ $this->mockDefaultSession();
+ $budget = $this->getRandomBudget();
Log::debug('Now in testDelete()');
// mock stuff
$this->mock(BudgetRepositoryInterface::class);
@@ -60,11 +60,9 @@ class DeleteControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $this->mockDefaultSession();
-
$this->be($this->user());
- $response = $this->get(route('budgets.delete', [1]));
+ $response = $this->get(route('budgets.delete', [$budget->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -75,19 +73,21 @@ class DeleteControllerTest extends TestCase
*/
public function testDestroy(): void
{
+ $this->mockDefaultSession();
+ $budget = $this->getRandomBudget();
Log::debug('Now in testDestroy()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
+
Preferences::shouldReceive('mark')->atLeast()->once();
$repository->shouldReceive('destroy')->andReturn(true);
$this->session(['budgets.delete.uri' => 'http://localhost']);
$this->be($this->user());
- $response = $this->post(route('budgets.destroy', [1]));
+ $response = $this->post(route('budgets.destroy', [$budget->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.php
deleted file mode 100644
index 591eae877e..0000000000
--- a/tests/Feature/Controllers/CategoryControllerTest.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-/**
- * CategoryControllerTest.php
- * Copyright (c) 2017 [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/>.
- */
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers;
-
-use Carbon\Carbon;
-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 Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class CategoryControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class CategoryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\CategoryController
- */
- public function testIndex(): void
- {
- Log::debug('Test index()');
- // mock stuff
- $category = factory(Category::class)->make();
- $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('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->be($this->user());
- $response = $this->get(route('categories.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php b/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
index cd3ccc8ed1..dcc3a58b37 100644
--- a/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
@@ -113,6 +113,7 @@ class BudgetReportControllerTest extends TestCase
}
/**
+ * TODO something in this method makes it return a 404.
* @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
*/
public function testMainChart(): void
diff --git a/tests/Feature/Controllers/Chart/TagReportControllerTest.php b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
index 9ef7d5b6c0..6f83c6849a 100644
--- a/tests/Feature/Controllers/Chart/TagReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
@@ -187,6 +187,8 @@ class TagReportControllerTest extends TestCase
}
/**
+ * TODO something in this test sometimes gives a 404 but not sure yet what it is.
+ *
* @covers \FireflyIII\Http\Controllers\Chart\TagReportController
*/
public function testMainChart(): void
@@ -198,7 +200,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
- $tag = $this->user()->tags()->inRandomOrder()->first();
+ $tag = $this->user()->tags()->where('tag','Expensive')->first();
$date = new Carbon;
$false = new Preference;
$false->data = false;
diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.php
index 438f966ace..12771839a0 100644
--- a/tests/Feature/Controllers/CurrencyControllerTest.php
+++ b/tests/Feature/Controllers/CurrencyControllerTest.php
@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
@@ -30,6 +31,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -56,13 +58,14 @@ class CurrencyControllerTest extends TestCase
*/
public function testCannotCreate(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_currencies_create');
+
// mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $userRepos->shouldReceive('hasRole')->once()->andReturn(false);
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(false);
$this->be($this->user());
$response = $this->get(route('currencies.create'));
@@ -75,16 +78,18 @@ class CurrencyControllerTest extends TestCase
*/
public function testCannotDelete(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
+
$repository->shouldReceive('currencyInUse')->andReturn(true);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$this->be($this->user());
- $response = $this->get(route('currencies.delete', [2]));
+ $response = $this->get(route('currencies.delete', [$euro->id]));
$response->assertStatus(302);
// has bread crumb
$response->assertSessionHas('error');
@@ -95,18 +100,20 @@ class CurrencyControllerTest extends TestCase
*/
public function testCannotDestroy(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
$repository->shouldReceive('currencyInUse')->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
+
$this->session(['currencies.delete.uri' => 'http://localhost']);
$this->be($this->user());
- $response = $this->post(route('currencies.destroy', [1]));
+ $response = $this->post(route('currencies.destroy', [$euro->id]));
$response->assertStatus(302);
$response->assertSessionHas('error');
}
@@ -116,12 +123,13 @@ class CurrencyControllerTest extends TestCase
*/
public function testCreate(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_currencies_create');
+
// mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
$this->be($this->user());
@@ -136,16 +144,19 @@ class CurrencyControllerTest extends TestCase
*/
public function testDefaultCurrency(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
$currencyRepos->shouldReceive('enable')->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
+
$this->be($this->user());
- $response = $this->get(route('currencies.default', [1]));
+ $response = $this->get(route('currencies.default', [$euro->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
@@ -155,17 +166,20 @@ class CurrencyControllerTest extends TestCase
*/
public function testDelete(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $euro = $this->getEuro();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('currencyInUse')->andReturn(false);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
$this->be($this->user());
- $response = $this->get(route('currencies.delete', [2]));
+ $response = $this->get(route('currencies.delete', [$euro->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -176,10 +190,13 @@ class CurrencyControllerTest extends TestCase
*/
public function testDestroy(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $euro = $this->getEuro();
$repository->shouldReceive('currencyInUse')->andReturn(false);
$repository->shouldReceive('destroy')->andReturn(true)->once();
@@ -188,7 +205,7 @@ class CurrencyControllerTest extends TestCase
$this->session(['currencies.delete.uri' => 'http://localhost']);
$this->be($this->user());
- $response = $this->post(route('currencies.destroy', [1]));
+ $response = $this->post(route('currencies.destroy', [$euro->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
@@ -198,17 +215,21 @@ class CurrencyControllerTest extends TestCase
*/
public function testDisable(): void
{
+ $this->mockDefaultSession();
+
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $currency = TransactionCurrency::first();
+ $euro = $this->getEuro();
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection([$currency]));
+ $repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection([$euro]));
$this->be($this->user());
- $response = $this->get(route('currencies.disable', [$currency->id]));
+ $response = $this->get(route('currencies.disable', [$euro->id]));
$response->assertStatus(302);
}
@@ -217,19 +238,23 @@ class CurrencyControllerTest extends TestCase
*/
public function testDisableEnableFirst(): void
{
+ $this->mockDefaultSession();
+
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $currency = TransactionCurrency::first();
+ $euro = $this->getEuro();
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
- $repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$currency]));
+ $repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$euro]));
$repository->shouldReceive('enable')->atLeast()->once()->andReturn(true);
+ Preferences::shouldReceive('mark')->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
$this->be($this->user());
- $response = $this->get(route('currencies.disable', [$currency->id]));
+ $response = $this->get(route('currencies.disable', [$euro->id]));
$response->assertStatus(302);
}
@@ -238,16 +263,19 @@ class CurrencyControllerTest extends TestCase
*/
public function testDisableInUse(): void
{
+ $this->mockDefaultSession();
+
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $currency = TransactionCurrency::first();
+ $euro = $this->getEuro();
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(true);
$repository->shouldNotReceive('disable');
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->be($this->user());
- $response = $this->get(route('currencies.disable', [$currency->id]));
+ $response = $this->get(route('currencies.disable', [$euro->id]));
$response->assertStatus(302);
}
@@ -256,18 +284,21 @@ class CurrencyControllerTest extends TestCase
*/
public function testDisableNothingLeft(): void
{
+ $this->mockDefaultSession();
+
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $currency = TransactionCurrency::first();
+ $euro = $this->getEuro();
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
$repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->be($this->user());
- $response = $this->get(route('currencies.disable', [$currency->id]));
+ $response = $this->get(route('currencies.disable', [$euro->id]));
$response->assertStatus(500);
$response->assertSee('No currencies found.');
}
@@ -277,16 +308,16 @@ class CurrencyControllerTest extends TestCase
*/
public function testEdit(): void
{
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ // mock stuff
+ $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
$this->be($this->user());
- $response = $this->get(route('currencies.edit', [1]));
+ $response = $this->get(route('currencies.edit', [$euro->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -297,14 +328,17 @@ class CurrencyControllerTest extends TestCase
*/
public function testEnable(): void
{
+ $this->mockDefaultSession();
+
$repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $currency = TransactionCurrency::first();
+ $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
$repository->shouldReceive('enable')->atLeast()->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->be($this->user());
- $response = $this->get(route('currencies.enable', [$currency->id]));
+ $response = $this->get(route('currencies.enable', [$euro->id]));
$response->assertStatus(302);
}
@@ -314,6 +348,9 @@ class CurrencyControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_currencies_index');
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
@@ -326,6 +363,14 @@ class CurrencyControllerTest extends TestCase
$repository->shouldReceive('getAll')->andReturn($currencies);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
+ $pref = new Preference;
+ $pref->data = 'EUR';
+ Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
+
$this->be($this->user());
$response = $this->get(route('currencies.index'));
$response->assertStatus(200);
@@ -339,6 +384,9 @@ class CurrencyControllerTest extends TestCase
*/
public function testIndexNoRights(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_currencies_index');
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
@@ -349,6 +397,14 @@ class CurrencyControllerTest extends TestCase
$repository->shouldReceive('getAll')->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(false);
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
+ $pref = new Preference;
+ $pref->data = 'EUR';
+ Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
+
$this->be($this->user());
$response = $this->get(route('currencies.index'));
$response->assertStatus(200);
@@ -363,6 +419,8 @@ class CurrencyControllerTest extends TestCase
*/
public function testStore(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -391,6 +449,8 @@ class CurrencyControllerTest extends TestCase
*/
public function testStoreError(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -419,6 +479,8 @@ class CurrencyControllerTest extends TestCase
*/
public function testStoreNoRights(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -447,6 +509,8 @@ class CurrencyControllerTest extends TestCase
*/
public function testUpdate(): void
{
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -455,6 +519,7 @@ class CurrencyControllerTest extends TestCase
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->andReturn(new TransactionCurrency);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['currencies.edit.uri' => 'http://localhost']);
$data = [
diff --git a/tests/Feature/Controllers/DebugControllerTest.php b/tests/Feature/Controllers/DebugControllerTest.php
index 244f995fc1..cfd4569b5c 100644
--- a/tests/Feature/Controllers/DebugControllerTest.php
+++ b/tests/Feature/Controllers/DebugControllerTest.php
@@ -27,6 +27,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -52,10 +53,9 @@ class DebugControllerTest extends TestCase
*/
public function testDisplayError(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$this->be($this->user());
@@ -69,12 +69,11 @@ class DebugControllerTest extends TestCase
*/
public function testFlush(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('flush'));
@@ -86,6 +85,7 @@ class DebugControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -99,6 +99,7 @@ class DebugControllerTest extends TestCase
*/
public function testRoutes(): void
{
+ $this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -112,12 +113,11 @@ class DebugControllerTest extends TestCase
*/
public function testTestFlash(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('test-flash'));
diff --git a/tests/Feature/Controllers/HelpControllerTest.php b/tests/Feature/Controllers/HelpControllerTest.php
index dad5fbeea5..1d7c375964 100644
--- a/tests/Feature/Controllers/HelpControllerTest.php
+++ b/tests/Feature/Controllers/HelpControllerTest.php
@@ -46,12 +46,12 @@ class HelpControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HelpController
- * @covers \FireflyIII\Http\Controllers\HelpController
* @covers \FireflyIII\Http\Controllers\HelpController
*/
public function testShow(): void
{
+ $this->mockDefaultSession();
+
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->andReturn(true)->once();
$help->shouldReceive('inCache')->andReturn(false)->once();
@@ -65,19 +65,16 @@ class HelpControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HelpController
* @covers \FireflyIII\Http\Controllers\HelpController
*/
public function testShowBackupFromCache(): void
{
- // force pref in dutch for test
- Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
- Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'nl_NL']);
+ $this->mockDefaultSession();
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
- $help->shouldReceive('inCache')->withArgs(['index', 'nl_NL'])->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
+ $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
+ $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
// is US in cache?
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once();
@@ -86,7 +83,7 @@ class HelpControllerTest extends TestCase
$this->be($this->user());
$response = $this->get(route('help.show', ['index']));
$response->assertStatus(200);
- $response->assertSee('US from cache.'); // Dutch translation
+ $response->assertSee('US from cache.');
// put English back:
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
@@ -94,19 +91,16 @@ class HelpControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HelpController
* @covers \FireflyIII\Http\Controllers\HelpController
*/
public function testShowBackupFromGithub(): void
{
- // force pref in dutch for test
- Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
- Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'nl_NL']);
+ $this->mockDefaultSession();
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
- $help->shouldReceive('inCache')->withArgs(['index', 'nl_NL'])->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
+ $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
+ $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
// is US in cache?
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
@@ -117,7 +111,7 @@ class HelpControllerTest extends TestCase
$this->be($this->user());
$response = $this->get(route('help.show', ['index']));
$response->assertStatus(200);
- $response->assertSee('Deze helptekst is nog niet beschikbaar in het Nederlands.'); // Dutch
+ $response->assertSee('This help text is not yet available in your language');
// put English back:
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
@@ -125,11 +119,12 @@ class HelpControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HelpController
* @covers \FireflyIII\Http\Controllers\HelpController
*/
public function testShowCached(): void
{
+ $this->mockDefaultSession();
+
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->andReturn(true)->once();
$help->shouldReceive('inCache')->andReturn(true)->once();
@@ -142,11 +137,12 @@ class HelpControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HelpController
* @covers \FireflyIII\Http\Controllers\HelpController
*/
public function testShowNoRoute(): void
{
+ $this->mockDefaultSession();
+
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->andReturn(false)->once();
diff --git a/tests/Feature/Controllers/HomeControllerTest.php b/tests/Feature/Controllers/HomeControllerTest.php
index c67d820cd0..b2680f7774 100644
--- a/tests/Feature/Controllers/HomeControllerTest.php
+++ b/tests/Feature/Controllers/HomeControllerTest.php
@@ -22,19 +22,20 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
-
-use FireflyIII\Models\Account;
+use Amount;
+use Event;
+use FireflyIII\Events\RequestedVersionCheckStatus;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\AccountType;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
+use Steam;
use Tests\TestCase;
/**
@@ -61,12 +62,7 @@ class HomeControllerTest extends TestCase
*/
public function testDateRange(): void
{
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
+ $this->mockDefaultSession();
$this->be($this->user());
$args = [
@@ -84,12 +80,7 @@ class HomeControllerTest extends TestCase
*/
public function testDateRangeCustom(): void
{
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
+ $this->mockDefaultSession();
$this->be($this->user());
$args = [
@@ -104,7 +95,6 @@ class HomeControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\Controller
* @dataProvider dateRangeProvider
@@ -113,42 +103,54 @@ class HomeControllerTest extends TestCase
*/
public function testIndex(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ Event::fake();
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_index');
+ $account = $this->getRandomAsset();
+
+ $pref = new Preference;
+ $pref->data = [$account->id];
+ Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$account->id]])->atLeast()->once()->andReturn($pref);
+ //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+ //FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+ Steam::shouldReceive('balance')->atLeast()->once()->andReturn('5');
// mock stuff
- $account = factory(Account::class)->make();
- $collector = $this->mock(TransactionCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $billRepos = $this->mock(BillRepositoryInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $accountRepos->shouldReceive('count')->andReturn(1);
+// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+//
+//
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+ $accountRepos->shouldReceive('count')->andReturn(1)->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]));
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
- $billRepos->shouldReceive('getBills')->andReturn(new Collection);
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
+ $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->atLeast()->once();
+ $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]))->atLeast()->once();
+ $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
+ $billRepos->shouldReceive('getBills')->andReturn(new Collection)->atLeast()->once();
+// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
+
+
+ $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection);
- $collector->shouldReceive('setAccounts')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('setLimit')->andReturnSelf();
- $collector->shouldReceive('setPage')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn(new Collection);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('index'));
$response->assertStatus(200);
+ Event::assertDispatched(RequestedVersionCheckStatus::class);
}
/**
- * @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\Controller
* @dataProvider dateRangeProvider
@@ -157,12 +159,10 @@ class HomeControllerTest extends TestCase
*/
public function testIndexEmpty(string $range): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_index');
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(0);
$this->be($this->user());
diff --git a/tests/Feature/Controllers/JavascriptControllerTest.php b/tests/Feature/Controllers/JavascriptControllerTest.php
index be1b041ce0..c515899e1a 100644
--- a/tests/Feature/Controllers/JavascriptControllerTest.php
+++ b/tests/Feature/Controllers/JavascriptControllerTest.php
@@ -23,14 +23,14 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use Amount;
-use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
-use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -57,15 +57,18 @@ class JavascriptControllerTest extends TestCase
*/
public function testAccounts(): void
{
+ $this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $account = factory(Account::class)->make();
+ $account = $this->getRandomAsset();
+ $euro = $this->getEuro();
+ $pref = new Preference;
+ $pref->data = 'EUR';
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))
- ->withArgs(
- [[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]]
- )->once();
- $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency);
+ Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
+
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))->withArgs([[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]])->once();
+ $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn($euro);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$this->be($this->user());
@@ -78,10 +81,10 @@ class JavascriptControllerTest extends TestCase
*/
public function testCurrencies(): void
{
+ $this->mockDefaultSession();
$repository = $this->mock(CurrencyRepositoryInterface::class);
- $currency = factory(TransactionCurrency::class)->make();
- $repository->shouldReceive('get')->andReturn(new Collection([$currency]));
-
+ $euro = $this->getEuro();
+ $repository->shouldReceive('get')->andReturn(new Collection([$euro]));
$this->be($this->user());
$response = $this->get(route('javascript.currencies'));
@@ -98,11 +101,17 @@ class JavascriptControllerTest extends TestCase
*/
public function testVariables(string $range): void
{
+ $this->mockDefaultSession();
+ $account = $this->getRandomAsset();
+ $euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn(new Account);
- $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
+
+ $accountRepos->shouldReceive('findNull')->andReturn($account);
+ $currencyRepos->shouldReceive('findNull')->andReturn($euro);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
+ Amount::shouldReceive('getJsConfig')->andReturn([])->once();
+
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('javascript.variables'));
@@ -118,11 +127,16 @@ class JavascriptControllerTest extends TestCase
*/
public function testVariablesCustom(string $range): void
{
+ $this->mockDefaultSession();
+ $account = $this->getRandomAsset();
+ $euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn(new Account);
- $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
+
+ $accountRepos->shouldReceive('findNull')->andReturn($account);
+ $currencyRepos->shouldReceive('findNull')->andReturn($euro);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
+ Amount::shouldReceive('getJsConfig')->andReturn([])->once();
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -140,12 +154,15 @@ class JavascriptControllerTest extends TestCase
*/
public function testVariablesNull(string $range): void
{
- Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1))->times(2);
+ $this->mockDefaultSession();
+ $account = $this->getRandomAsset();
+ $euro = $this->getEuro();
+ //Amount::shouldReceive('getDefaultCurrency')->andReturn($euro)->times(2);
Amount::shouldReceive('getJsConfig')->andReturn([])->once();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn(new Account);
+ $accountRepos->shouldReceive('findNull')->andReturn($account);
$currencyRepos->shouldReceive('findNull')->andReturn(null);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
diff --git a/tests/Feature/Controllers/JsonControllerTest.php b/tests/Feature/Controllers/Json/RuleControllerTest.php
similarity index 87%
rename from tests/Feature/Controllers/JsonControllerTest.php
rename to tests/Feature/Controllers/Json/RuleControllerTest.php
index 90b9ac738b..5dab8a5d41 100644
--- a/tests/Feature/Controllers/JsonControllerTest.php
+++ b/tests/Feature/Controllers/Json/RuleControllerTest.php
@@ -1,7 +1,7 @@
<?php
/**
- * JsonControllerTest.php
- * Copyright (c) 2017 [email protected]
+ * RuleControllerTest.php
+ * Copyright (c) 2019 [email protected]
*
* This file is part of Firefly III.
*
@@ -28,13 +28,13 @@ use Log;
use Tests\TestCase;
/**
- * Class JsonControllerTest
+ * Class RuleControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class JsonControllerTest extends TestCase
+class RuleControllerTest extends TestCase
{
/**
*
@@ -46,7 +46,7 @@ class JsonControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\JsonController
+ * @covers \FireflyIII\Http\Controllers\Json\RuleController
*/
public function testAction(): void
{
@@ -60,7 +60,7 @@ class JsonControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\JsonController
+ * @covers \FireflyIII\Http\Controllers\Json\RuleController
*/
public function testTrigger(): void
{
diff --git a/tests/Feature/Controllers/NewUserControllerTest.php b/tests/Feature/Controllers/NewUserControllerTest.php
index 23e018b05b..68d5db2707 100644
--- a/tests/Feature/Controllers/NewUserControllerTest.php
+++ b/tests/Feature/Controllers/NewUserControllerTest.php
@@ -23,13 +23,12 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -56,11 +55,10 @@ class NewUserControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(0);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@@ -76,12 +74,10 @@ class NewUserControllerTest extends TestCase
*/
public function testIndexExisting(): void
{
+ $this->mockDefaultSession();
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(1);
$this->be($this->user());
@@ -95,17 +91,20 @@ class NewUserControllerTest extends TestCase
*/
public function testSubmit(): void
{
+ $this->mockDefaultSession();
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $euro = $this->getEuro();
$accountRepos->shouldReceive('store')->times(3);
- $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
+ $currencyRepos->shouldReceive('findNull')->andReturn($euro);
$currencyRepos->shouldReceive('enable')->once();
+ Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
$data = [
'bank_name' => 'New bank',
'savings_balance' => '1000',
@@ -124,18 +123,22 @@ class NewUserControllerTest extends TestCase
*/
public function testSubmitNull(): void
{
+ $euro = $this->getEuro();
+ $this->mockDefaultSession();
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('store')->times(3);
$currencyRepos->shouldReceive('findNull')->andReturn(null);
- $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::find(2))->once();
+ $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn($euro)->once();
$currencyRepos->shouldReceive('enable')->once();
+ Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
$data = [
'bank_name' => 'New bank',
'savings_balance' => '1000',
@@ -154,17 +157,21 @@ class NewUserControllerTest extends TestCase
*/
public function testSubmitSingle(): void
{
+ $this->mockDefaultSession();
+ $euro = $this->getEuro();
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('store')->times(3);
- $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
+ $currencyRepos->shouldReceive('findNull')->andReturn($euro);
$currencyRepos->shouldReceive('enable')->once();
+ Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
$data = [
'bank_name' => 'New bank',
'bank_balance' => '100',
diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php
index 2e6f0a6af4..c78f7993f8 100644
--- a/tests/Feature/Controllers/PiggyBankControllerTest.php
+++ b/tests/Feature/Controllers/PiggyBankControllerTest.php
@@ -23,12 +23,11 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use Amount;
-use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankRepetition;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -39,6 +38,8 @@ use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
+use Steam;
use Tests\TestCase;
/**
@@ -65,23 +66,23 @@ class PiggyBankControllerTest extends TestCase
*/
public function testAdd(): void
{
+ $this->mockDefaultSession();
// mock stuff
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
$this->be($this->user());
- $response = $this->get(route('piggy-banks.add', [1]));
+ $response = $this->get(route('piggy-banks.add', [$piggyBank->id]));
$response->assertStatus(200);
}
@@ -90,24 +91,25 @@ class PiggyBankControllerTest extends TestCase
*/
public function testAddMobile(): void
{
+ $this->mockDefaultSession();
// mock stuff
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
$this->be($this->user());
- $response = $this->get(route('piggy-banks.add-money-mobile', [1]));
+ $response = $this->get(route('piggy-banks.add-money-mobile', [$piggyBank->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
@@ -117,23 +119,22 @@ class PiggyBankControllerTest extends TestCase
*/
public function testCreate(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_piggy-banks_create');
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
+ $this->mock(PiggyBankRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// new account list thing.
$currency = TransactionCurrency::first();
- $account = factory(Account::class)->make();
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('balance')->andReturn('0');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@@ -147,19 +148,19 @@ class PiggyBankControllerTest extends TestCase
*/
public function testDelete(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(PiggyBankRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
- $response = $this->get(route('piggy-banks.delete', [1]));
+ $response = $this->get(route('piggy-banks.delete', [$piggyBank->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
@@ -169,20 +170,19 @@ class PiggyBankControllerTest extends TestCase
*/
public function testDestroy(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $repository = $this->mock(PiggyBankRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(AccountRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['piggy-banks.delete.uri' => 'http://localhost']);
$this->be($this->user());
- $response = $this->post(route('piggy-banks.destroy', [2]));
+ $response = $this->post(route('piggy-banks.destroy', [$piggyBank->id]));
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertRedirect(route('index'));
@@ -193,20 +193,22 @@ class PiggyBankControllerTest extends TestCase
*/
public function testEdit(): void
{
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(PiggyBankRepositoryInterface::class);
+
+ Steam::shouldReceive('balance')->atLeast()->once()->andReturn('123');
// mock stuff
- $account = factory(Account::class)->make();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
- $account = factory(Account::class)->make();
+ $account = $this->getRandomAsset();
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
@@ -219,7 +221,7 @@ class PiggyBankControllerTest extends TestCase
$this->be($this->user());
- $response = $this->get(route('piggy-banks.edit', [1]));
+ $response = $this->get(route('piggy-banks.edit', [$piggyBank->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
@@ -229,14 +231,22 @@ class PiggyBankControllerTest extends TestCase
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_piggy-banks_index');
// mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
$accountTransformer = $this->mock(AccountTransformer::class);
+ $this->mock(CurrencyRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
+
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -274,23 +284,24 @@ class PiggyBankControllerTest extends TestCase
*/
public function testPostAdd(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+ Preferences::shouldReceive('mark')->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canAddAmount')->once()->andReturn(true);
$repository->shouldReceive('addAmount')->once()->andReturn(true);
$data = ['amount' => '1.123'];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.add', [1]), $data);
+ $response = $this->post(route('piggy-banks.add', [$piggyBank]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('success');
@@ -303,22 +314,23 @@ class PiggyBankControllerTest extends TestCase
*/
public function testPostAddTooMuch(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canAddAmount')->once()->andReturn(false);
$data = ['amount' => '1000'];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.add', [1]), $data);
+ $response = $this->post(route('piggy-banks.add', [$piggyBank->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('error');
@@ -329,23 +341,24 @@ class PiggyBankControllerTest extends TestCase
*/
public function testPostRemove(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+ Preferences::shouldReceive('mark')->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canRemoveAmount')->once()->andReturn(true);
$repository->shouldReceive('removeAmount')->once()->andReturn(true);
$data = ['amount' => '1.123'];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.remove', [1]), $data);
+ $response = $this->post(route('piggy-banks.remove', [$piggyBank->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('success');
@@ -356,22 +369,22 @@ class PiggyBankControllerTest extends TestCase
*/
public function testPostRemoveTooMuch(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canRemoveAmount')->once()->andReturn(false);
$data = ['amount' => '1.123'];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.remove', [1]), $data);
+ $response = $this->post(route('piggy-banks.remove', [$piggyBank->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('error');
@@ -382,24 +395,21 @@ class PiggyBankControllerTest extends TestCase
*/
public function testRemove(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
$repetition = PiggyBankRepetition::first();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$piggyRepos->shouldReceive('getRepetition')->once()->andReturn($repetition);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$this->be($this->user());
- $response = $this->get(route('piggy-banks.remove', [1]));
+ $response = $this->get(route('piggy-banks.remove', [$piggyBank->id]));
$response->assertStatus(200);
}
@@ -408,25 +418,24 @@ class PiggyBankControllerTest extends TestCase
*/
public function testRemoveMobile(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$repetition = PiggyBankRepetition::first();
+ $piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+
$piggyRepos->shouldReceive('getRepetition')->once()->andReturn($repetition);
$this->be($this->user());
- $response = $this->get(route('piggy-banks.remove-money-mobile', [1]));
+ $response = $this->get(route('piggy-banks.remove-money-mobile', [$piggyBank->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
@@ -438,17 +447,18 @@ class PiggyBankControllerTest extends TestCase
*/
public function testSetOrder(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(CurrencyRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setOrder')->once()->withArgs([Mockery::any(), 3])->andReturn(false);
$data = ['order' => '3'];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.set-order', [1]), $data);
+ $response = $this->post(route('piggy-banks.set-order', [$piggyBank->id]), $data);
$response->assertStatus(200);
$response->assertExactJson(['data' => 'OK']);
}
@@ -458,14 +468,17 @@ class PiggyBankControllerTest extends TestCase
*/
public function testShow(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_piggy-banks_show');
// mock stuff
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(CurrencyRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -476,10 +489,11 @@ class PiggyBankControllerTest extends TestCase
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->andReturn($first)->atLeast()->once();
$repository->shouldReceive('getEvents')->andReturn(new Collection)->atLeast()->once();
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$this->be($this->user());
- $response = $this->get(route('piggy-banks.show', [1]));
+ $response = $this->get(route('piggy-banks.show', [$piggyBank->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
@@ -490,15 +504,14 @@ class PiggyBankControllerTest extends TestCase
*/
public function testStore(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $this->mock(CurrencyRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn(new PiggyBank);
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['piggy-banks.create.uri' => 'http://localhost']);
$data = [
@@ -520,16 +533,17 @@ class PiggyBankControllerTest extends TestCase
*/
public function testUpdate(): void
{
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $piggyBank = $this->getRandomPiggyBank();
+ $this->mock(CurrencyRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->andReturn(new PiggyBank);
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
$this->session(['piggy-banks.edit.uri' => 'http://localhost']);
$data = [
'id' => 3,
@@ -539,7 +553,7 @@ class PiggyBankControllerTest extends TestCase
'amount_currency_id_targetamount' => 1,
];
$this->be($this->user());
- $response = $this->post(route('piggy-banks.update', [3]), $data);
+ $response = $this->post(route('piggy-banks.update', [$piggyBank->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertRedirect(route('index'));
diff --git a/tests/Feature/Controllers/PreferencesControllerTest.php b/tests/Feature/Controllers/PreferencesControllerTest.php
index 9f86768fb8..37ab7f2c46 100644
--- a/tests/Feature/Controllers/PreferencesControllerTest.php
+++ b/tests/Feature/Controllers/PreferencesControllerTest.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\AccountType;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -30,6 +31,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -52,21 +54,44 @@ class PreferencesControllerTest extends TestCase
/**
- * @covers \FireflyIII\Http\Controllers\PreferencesController
* @covers \FireflyIII\Http\Controllers\PreferencesController
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_preferences_index');
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
-
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
+ // mock get preferences:
+
+ $frontPage = new Preference;
+ $frontPage->data = [];
+ Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', []])->andReturn($frontPage)->atLeast()->once();
+
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
+ $pref = new Preference;
+ $pref->data = 0;
+ Preferences::shouldReceive('get')->withArgs(['customFiscalYear', 0])->atLeast()->once()->andReturn($pref);
+
+ $pref = new Preference;
+ $pref->data = '01-01';
+ Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once()->andReturn($pref);
+
+ $pref = new Preference;
+ $pref->data = [];
+ Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($pref);
+
+
$this->be($this->user());
$response = $this->get(route('preferences.index'));
$response->assertStatus(200);
@@ -78,6 +103,7 @@ class PreferencesControllerTest extends TestCase
*/
public function testPostIndex(): void
{
+ $this->mockDefaultSession();
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -95,6 +121,16 @@ class PreferencesControllerTest extends TestCase
'tj' => [],
];
+ Preferences::shouldReceive('set')->withArgs(['frontPageAccounts', [1]])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['viewRange', '1M'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['customFiscalYear', false])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['listPageSize', 100])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['listPageSize', 50])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
+ Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
$this->be($this->user());
$response = $this->post(route('preferences.update'), $data);
$response->assertStatus(302);
diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php
index 51d7659861..16bd5d1553 100644
--- a/tests/Feature/Controllers/ProfileControllerTest.php
+++ b/tests/Feature/Controllers/ProfileControllerTest.php
@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use Amount;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -57,6 +58,7 @@ class ProfileControllerTest extends TestCase
*/
public function testChangeEmail(): void
{
+ $this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -72,10 +74,10 @@ class ProfileControllerTest extends TestCase
*/
public function testChangePassword(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@@ -90,13 +92,13 @@ class ProfileControllerTest extends TestCase
*/
public function testCode(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');
Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');
@@ -111,8 +113,8 @@ class ProfileControllerTest extends TestCase
*/
public function testConfirmEmailChangeNoToken(): void
{
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
+ $this->mockDefaultSession();
+ $this->mock(UserRepositoryInterface::class);
Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());
// email_change_confirm_token
@@ -125,6 +127,7 @@ class ProfileControllerTest extends TestCase
*/
public function testConfirmEmailWithToken(): void
{
+ $this->mockDefaultSession();
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('unblockUser');
@@ -144,15 +147,13 @@ class ProfileControllerTest extends TestCase
*/
public function testDeleteAccount(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
$this->be($this->user());
$response = $this->get(route('profile.delete-account'));
$response->assertStatus(200);
@@ -164,13 +165,15 @@ class ProfileControllerTest extends TestCase
*/
public function testDeleteCode(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ Preferences::shouldReceive('delete')->withArgs(['twoFactorAuthEnabled'])->atLeast()->once();
+ Preferences::shouldReceive('delete')->withArgs(['twoFactorAuthSecret'])->atLeast()->once();
+
$this->be($this->user());
$response = $this->get(route('profile.delete-code'));
@@ -185,37 +188,10 @@ class ProfileControllerTest extends TestCase
*/
public function testEnable2FANoSecret(): void
{
+ $this->mockDefaultSession();
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
- // ask about language:
- $langPreference = new Preference;
- $langPreference->data = 'en_US';
- Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference)->times(2);
-
- // ask about twoFactorAuthEnabled
- $truePref = new Preference;
- $truePref->data = true;
- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->times(1);
-
- // ask about range
- $rangePref = new Preference;
- $rangePref->data = '1M';
- Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($rangePref)->once();
-
- // ask about list length:
- $listPref = new Preference;
- $listPref->data = '50';
- Preferences::shouldReceive('get')->withArgs(['list-length', '10'])->andReturn($listPref)->once();
-
-
- // ask about currency
- $currencyPref = new Preference;
- $currencyPref->data = 'EUR';
- Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($currencyPref);
- Preferences::shouldReceive('lastActivity')->once();
- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->twice()->andReturnNull();
-
$this->be($this->user());
$response = $this->post(route('profile.enable2FA'));
$response->assertStatus(302);
@@ -227,43 +203,45 @@ class ProfileControllerTest extends TestCase
*/
public function testEnable2FASecret(): void
{
- $repository = $this->mock(UserRepositoryInterface::class);
+ //$this->mockDefaultSession(); // DISABLED ON PURPOSE
+ $this->mockDefaultConfiguration();
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $euro = $this->getEuro();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
- // ask about language:
- $langPreference = new Preference;
- $langPreference->data = 'en_US';
- Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference)->times(2);
+ Preferences::shouldReceive('set')->once()->withArgs(['twoFactorAuthEnabled', 1]);
+ //Preferences::shouldReceive('lastActivity')->once();
- // ask about twoFactorAuthEnabled
- $truePref = new Preference;
- $truePref->data = true;
- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->times(1);
+ $pref = new Preference;
+ $pref->data = false;
+ Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->atLeast()->once()->andReturn($pref);
- // ask about range
- $rangePref = new Preference;
- $rangePref->data = '1M';
- Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($rangePref)->once();
+ $pref = new Preference;
+ $pref->data = 'super-secret';
+ Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->atLeast()->once()->andReturn($pref);
- // ask about list length:
- $listPref = new Preference;
- $listPref->data = '50';
- Preferences::shouldReceive('get')->withArgs(['list-length', '10'])->andReturn($listPref)->once();
+ $view = new Preference;
+ $view->data = '1M';
+ Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view)->atLeast()->once();
- $secretPref = new Preference;
- $secretPref->data = 'X';
- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->twice()->andReturn(null, $secretPref);
+ $lang = new Preference;
+ $lang->data = 'en_US';
+ Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($lang)->atLeast()->once();
- // set pref
- Preferences::shouldReceive('set')->once()->withArgs(['twoFactorAuthEnabled', 1]);
+// $pref = new Preference;
+// $pref->data = 'EUR';
+// Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
+ $list = new Preference;
+ $list->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['list-length', 10])->andReturn($list)->atLeast()->once();
- // ask about currency
- $currencyPref = new Preference;
- $currencyPref->data = 'EUR';
- Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($currencyPref);
- Preferences::shouldReceive('lastActivity')->once();
+ Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
+ $this->session(['rule-groups.delete.uri' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('profile.enable2FA'));
@@ -276,16 +254,43 @@ class ProfileControllerTest extends TestCase
*/
public function testIndex(): void
{
- // delete access token.
- Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->delete();
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $pref = new Preference;
+ $pref->data = 'token';
+ Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturn($pref);
+
+ Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
+
+ $this->be($this->user());
+ $response = $this->get(route('profile.index'));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController
+ */
+ public function testIndexEmptyToken(): void
+ {
+ $this->mockDefaultSession();
+ // mock stuff
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+
+ $pref = new Preference;
+ $pref->data = 'token';
+
+ Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturnNull();
+ Preferences::shouldReceive('set')->withArgs(['access_token', Mockery::any()])->atLeast()->once()->andReturn($pref);
+
+ Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
$this->be($this->user());
$response = $this->get(route('profile.index'));
@@ -298,6 +303,7 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangeEmail(): void
{
+ $this->mockDefaultSession();
$data = [
'email' => '[email protected]',
];
@@ -307,6 +313,13 @@ class ProfileControllerTest extends TestCase
$repository->shouldReceive('changeEmail')->once()->andReturn(true);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
+ $pref = new Preference;
+ $pref->data = 'invalid';
+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_confirm_token', 'invalid'])->andReturn($pref);
+ $pref = new Preference;
+ $pref->data = 'invalid';
+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_undo_token', 'invalid'])->andReturn($pref);
+
$this->be($this->user());
$response = $this->post(route('profile.change-email.post'), $data);
$response->assertStatus(302);
@@ -319,7 +332,7 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangeEmailExisting(): void
{
-
+ $this->mockDefaultSession();
$data = [
'email' => '[email protected]',
];
@@ -339,6 +352,7 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangeEmailSame(): void
{
+ $this->mockDefaultSession();
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
$data = [
@@ -356,9 +370,9 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangePassword(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
@@ -379,9 +393,9 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangePasswordNotCorrect(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
@@ -402,9 +416,9 @@ class ProfileControllerTest extends TestCase
*/
public function testPostChangePasswordSameNew(): void
{
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
@@ -425,7 +439,9 @@ class ProfileControllerTest extends TestCase
*/
public function testPostCode(): void
{
- $userRepos = $this->mock(UserRepositoryInterface::class);
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
+
$secret = '0123456789abcde';
$key = '123456';
@@ -454,9 +470,10 @@ class ProfileControllerTest extends TestCase
*/
public function testPostDeleteAccount(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('destroy')->once();
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
@@ -474,10 +491,10 @@ class ProfileControllerTest extends TestCase
*/
public function testPostDeleteAccountWrong(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
// mock stuff
- $repository = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ $repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
$data = [
'password' => 'james2',
@@ -494,26 +511,18 @@ class ProfileControllerTest extends TestCase
*/
public function testRegenerate(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $token = '';
- $currentToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
- if (null !== $currentToken) {
- $token = $currentToken->data;
- }
+
+ Preferences::shouldReceive('set')->withArgs(['access_token', Mockery::any()])->atLeast()->once();
+
$this->be($this->user());
$response = $this->post(route('profile.regenerate'));
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertRedirect(route('profile.index'));
-
- $newToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
- $this->assertNotEquals($newToken->data, $token);
-
- // reset token for later test:
- $newToken->data = 'token';
- $newToken->save();
-
}
/**
@@ -521,6 +530,9 @@ class ProfileControllerTest extends TestCase
*/
public function testUndoEmailChange(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(UserRepositoryInterface::class);
$hash = hash('sha256', '[email protected]');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
@@ -551,7 +563,9 @@ class ProfileControllerTest extends TestCase
*/
public function testUndoEmailChangeBadHash(): void
{
- $repository = $this->mock(UserRepositoryInterface::class);
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(UserRepositoryInterface::class);
$hash = hash('sha256', '[email protected]');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
@@ -575,7 +589,9 @@ class ProfileControllerTest extends TestCase
*/
public function testUndoEmailChangeBadToken(): void
{
- $repository = $this->mock(UserRepositoryInterface::class);
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(UserRepositoryInterface::class);
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection);
$response = $this->get(route('profile.undo-email-change', ['token', 'some-hash']));
diff --git a/tests/Feature/Controllers/ReportControllerTest.php b/tests/Feature/Controllers/ReportControllerTest.php
index 98b359a127..6d3369c1ba 100644
--- a/tests/Feature/Controllers/ReportControllerTest.php
+++ b/tests/Feature/Controllers/ReportControllerTest.php
@@ -33,19 +33,17 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\Category;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\Tag;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -72,18 +70,17 @@ class ReportControllerTest extends TestCase
*/
public function testAccountReport(): void
{
+ $this->mockDefaultSession();
+ $this->mock(ReportHelperInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$generator = $this->mock(AcYRG::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
+ $start = Carbon::now()->startOfYear();
+ $end = Carbon::now()->endOfYear();
+ $account = $this->getRandomAsset();
+ $expense = $this->getRandomExpense();
$budgetRepository->shouldReceive('cleanupBudgets');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
@@ -94,7 +91,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('generate')->once()->andReturn('here-be-report');
$this->be($this->user());
- $response = $this->get(route('reports.report.account', [1, 2, '20160101', '20161231']));
+ $response = $this->get(route('reports.report.account', [$account->id, $expense->id, '20160101', '20161231']));
$response->assertStatus(200);
}
@@ -103,20 +100,19 @@ class ReportControllerTest extends TestCase
*/
public function testAuditReport(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_report_audit');
+ $this->mock(ReportHelperInterface::class);
+
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$generator = $this->mock(AYRG::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
+ $start = Carbon::now()->startOfYear();
+ $end = Carbon::now()->endOfYear();
+ $account = $this->getRandomAsset();
$budgetRepository->shouldReceive('cleanupBudgets');
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
@@ -126,7 +122,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('generate')->once()->andReturn('here-be-report');
$this->be($this->user());
- $response = $this->get(route('reports.report.audit', [1, '20160101', '20161231']));
+ $response = $this->get(route('reports.report.audit', [$account->id, '20160101', '20161231']));
$response->assertStatus(200);
}
@@ -135,12 +131,12 @@ class ReportControllerTest extends TestCase
*/
public function testBudgetReport(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_report_budget');
+ $this->mock(ReportHelperInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$generator = $this->mock(BYRG::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$start = Carbon::now()->startOfYear();
$end = Carbon::now()->endOfYear();
@@ -148,7 +144,7 @@ class ReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
$budgetRepository->shouldReceive('cleanupBudgets');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
@@ -165,12 +161,12 @@ class ReportControllerTest extends TestCase
*/
public function testCategoryReport(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_report_category');
+ $this->mock(ReportHelperInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$generator = $this->mock(CYRG::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$start = Carbon::now()->startOfYear();
$end = Carbon::now()->endOfYear();
@@ -180,7 +176,6 @@ class ReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
@@ -197,12 +192,12 @@ class ReportControllerTest extends TestCase
*/
public function testDefaultReport(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_report_default');
+ $this->mock(ReportHelperInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$generator = $this->mock(SYRG::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$start = Carbon::now()->startOfYear();
$end = Carbon::now()->endOfYear();
@@ -210,7 +205,7 @@ class ReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
$budgetRepository->shouldReceive('cleanupBudgets');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
@@ -226,18 +221,18 @@ class ReportControllerTest extends TestCase
*/
public function testDefaultReportBadDate(): void
{
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_report_default');
+ $this->mock(ReportHelperInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$start = Carbon::now()->startOfYear();
$end = Carbon::now()->endOfYear();
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
$budgetRepository->shouldReceive('cleanupBudgets');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('reports.report.default', [1, '20160101', '20150131']));
@@ -250,19 +245,26 @@ class ReportControllerTest extends TestCase
*/
public function testIndex(): void
{
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mockIntroPreference('shown_demo_reports_index');
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$helper = $this->mock(ReportHelperInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$budgetRepository->shouldReceive('cleanupBudgets');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$helper->shouldReceive('listOfMonths')->andReturn([]);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
+ // get some preferences:
+ $false = new Preference;
+ $false->data = false;
+ Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($false);
+
+
$this->be($this->user());
$response = $this->get(route('reports.index'));
$response->assertStatus(200);
@@ -274,13 +276,10 @@ class ReportControllerTest extends TestCase
*/
public function testOptions(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
$this->be($this->user());
$response = $this->get(route('reports.options', ['default']));
@@ -292,11 +291,10 @@ class ReportControllerTest extends TestCase
*/
public function testOptionsAccount(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$account = new Account();
@@ -304,7 +302,7 @@ class ReportControllerTest extends TestCase
$account->id = 3;
$collection = new Collection([$account]);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE]])->once()->andReturn($collection);
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
@@ -318,15 +316,12 @@ class ReportControllerTest extends TestCase
*/
public function testOptionsBudget(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $budget = factory(Budget::class)->make();
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(ReportHelperInterface::class);
+ $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
+ $budget = $this->getRandomBudget();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
@@ -341,15 +336,14 @@ class ReportControllerTest extends TestCase
*/
public function testOptionsCategory(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $category = factory(Category::class)->make();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $category = $this->getRandomCategory();
+
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
$this->be($this->user());
@@ -362,15 +356,12 @@ class ReportControllerTest extends TestCase
*/
public function testOptionsTag(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = factory(Tag::class)->make();
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $tagRepos = $this->mock(TagRepositoryInterface::class);
+ $tag = $this->getRandomTag();
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
@@ -386,14 +377,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexAccountError(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$asset = $this->getRandomAsset();
// find the user's asset account
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($asset)->atLeast()->once();
@@ -402,8 +392,6 @@ class ReportControllerTest extends TestCase
$accountRepos->shouldReceive('findNull')->withArgs([4])->andReturnNull()->atLeast()->once();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
$data = [
'accounts' => ['1'],
'exp_rev' => ['4'],
@@ -424,17 +412,15 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexAccountOK(): void
{
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
+ Log::debug(sprintf('Now in test %s', __METHOD__));
+ $this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
-
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->times(4);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$data = [
'accounts' => ['1'],
@@ -455,16 +441,12 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexAuditOK(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -485,17 +467,12 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexBudgetError(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
-
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -518,16 +495,14 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexBudgetOK(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$budgetRepository->shouldReceive('findNull')->andReturn($this->user()->budgets()->find(1))->twice();
@@ -550,16 +525,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexCategoryError(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -582,16 +554,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexCategoryOK(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('findNull')->andReturn($this->user()->categories()->find(1))->twice();
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@@ -614,16 +583,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexDefaultOK(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -644,16 +610,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexDefaultStartEnd(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -674,16 +637,13 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexTagError(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@@ -706,21 +666,20 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexTagOK(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
Log::debug(sprintf('Now in test %s', __METHOD__));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
/** @var Tag $tag */
$tag = $this->user()->tags()->find(1);
$tag2 = $this->user()->tags()->find(3);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$tagRepos->shouldReceive('findByTag')->andReturn($tag, null)->times(4);
@@ -745,21 +704,19 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexTagOKNoID(): void
{
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
Log::debug(sprintf('Now in test %s', __METHOD__));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
- /** @var Tag $tag */
- $tag = $this->user()->tags()->find(1);
+
$tag2 = $this->user()->tags()->find(3);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$tagRepos->shouldReceive('findByTag')->andReturn(null)->times(4);
@@ -784,17 +741,12 @@ class ReportControllerTest extends TestCase
*/
public function testPostIndexZeroAccounts(): void
{
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
$data = [
'accounts' => [],
'daterange' => '2016-01-01 - 2016-01-31',
@@ -813,15 +765,18 @@ class ReportControllerTest extends TestCase
*/
public function testTagReport(): void
{
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $this->mockDefaultSession();
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(ReportHelperInterface::class);
+ $this->mock(CategoryRepositoryInterface::class);
+ $this->mock(TagRepositoryInterface::class);
+ $this->mock(AccountRepositoryInterface::class);
+
+ $this->mockIntroPreference('shown_demo_reports_report_tag');
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$generator = $this->mock(TYRG::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $reportHelper = $this->mock(ReportHelperInterface::class);
$tag = $this->user()->tags()->find(1);
$start = Carbon::now()->startOfYear();
$end = Carbon::now()->endOfYear();
@@ -832,7 +787,7 @@ class ReportControllerTest extends TestCase
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
$budgetRepository->shouldReceive('cleanupBudgets');
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
diff --git a/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php b/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php
new file mode 100644
index 0000000000..9f8ba888f1
--- /dev/null
+++ b/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php
@@ -0,0 +1,90 @@
+<?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\RuleGroup;
+
+
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+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\RuleGroup\CreateController
+ */
+ public function testCreate(): void
+ {
+ $this->mockDefaultSession();
+ $this->mock(RuleGroupRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.create'));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\CreateController
+ * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
+ */
+ public function testStore(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+ $this->session(['rule-groups.create.uri' => 'http://localhost']);
+ $repository->shouldReceive('store')->andReturn(new RuleGroup);
+ $repository->shouldReceive('find')->andReturn(new RuleGroup);
+ $data = [
+ 'title' => 'A',
+ 'description' => 'No description',
+ ];
+
+ $this->be($this->user());
+ $response = $this->post(route('rule-groups.store', [1]), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php b/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php
new file mode 100644
index 0000000000..9f6a37bed6
--- /dev/null
+++ b/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php
@@ -0,0 +1,84 @@
+<?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\RuleGroup;
+
+
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
+use Illuminate\Support\Collection;
+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\RuleGroup\DeleteController
+ */
+ public function testDelete(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('get')->andReturn(new Collection);
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.delete', [1]));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\DeleteController
+ */
+ public function testDestroy(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+ $repository->shouldReceive('destroy');
+ $repository->shouldReceive('find')->atLeast()->once()->andReturnNull();
+
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+ $this->session(['rule-groups.delete.uri' => 'http://localhost']);
+ $this->be($this->user());
+ $response = $this->post(route('rule-groups.destroy', [1]));
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ $response->assertRedirect(route('index'));
+ }
+}
\ No newline at end of file
diff --git a/tests/Feature/Controllers/RuleGroup/EditControllerTest.php b/tests/Feature/Controllers/RuleGroup/EditControllerTest.php
new file mode 100644
index 0000000000..927657d640
--- /dev/null
+++ b/tests/Feature/Controllers/RuleGroup/EditControllerTest.php
@@ -0,0 +1,128 @@
+<?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\RuleGroup;
+
+
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+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\RuleGroup\EditController
+ */
+ public function testDown(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+
+ $repository->shouldReceive('moveDown');
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.down', [1]));
+ $response->assertStatus(302);
+ $response->assertRedirect(route('rules.index'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
+ */
+ public function testEdit(): void
+ {
+ $this->mockDefaultSession();
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+
+ /** @var RuleGroup $ruleGroup */
+ $ruleGroup = $this->user()->ruleGroups()->first();
+ $ruleGroup->description = 'Some description ' . $this->randomInt();
+ $ruleGroup->save();
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.edit', [1]));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ $response->assertSee($ruleGroup->description);
+ }
+
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
+ */
+ public function testUp(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+
+ $repository->shouldReceive('moveUp');
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.up', [1]));
+ $response->assertStatus(302);
+ $response->assertRedirect(route('rules.index'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
+ * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
+ */
+ public function testUpdate(): void
+ {
+ $this->mockDefaultSession();
+ $repository = $this->mock(RuleGroupRepositoryInterface::class);
+
+ $data = [
+ 'id' => 1,
+ 'title' => 'C',
+ 'description' => 'XX',
+ ];
+ $this->session(['rule-groups.edit.uri' => 'http://localhost']);
+
+ $repository->shouldReceive('update');
+ $repository->shouldReceive('find')->andReturn(RuleGroup::first());
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+ $this->be($this->user());
+ $response = $this->post(route('rule-groups.update', [1]), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ }
+}
\ No newline at end of file
diff --git a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
new file mode 100644
index 0000000000..bd3dcfd5cb
--- /dev/null
+++ b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * ExecutionControllerTest.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\RuleGroup;
+
+
+use Carbon\Carbon;
+use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
+use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
+use Illuminate\Support\Collection;
+use Log;
+use Mockery;
+use Tests\TestCase;
+
+class ExecutionControllerTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
+ */
+ public function testExecute(): void
+ {
+ $this->mockDefaultSession();
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
+
+ $this->expectsJobs(ExecuteRuleGroupOnExistingTransactions::class);
+
+ $this->session(['first' => new Carbon('2010-01-01')]);
+ $data = [
+ 'accounts' => [1],
+ 'start_date' => '2010-01-02',
+ 'end_date' => '2010-01-02',
+ ];
+ $this->be($this->user());
+ $response = $this->post(route('rule-groups.execute', [1]), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ $response->assertRedirect(route('rules.index'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
+ */
+ public function testSelectTransactions(): void
+ {
+ $this->mockDefaultSession();
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
+
+ $this->be($this->user());
+ $response = $this->get(route('rule-groups.select-transactions', [1]));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Feature/Controllers/RuleGroupControllerTest.php b/tests/Feature/Controllers/RuleGroupControllerTest.php
deleted file mode 100644
index 89fb3a515e..0000000000
--- a/tests/Feature/Controllers/RuleGroupControllerTest.php
+++ /dev/null
@@ -1,275 +0,0 @@
-<?php
-/**
- * RuleGroupControllerTest.php
- * Copyright (c) 2017 [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/>.
- */
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers;
-
-use Carbon\Carbon;
-use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class RuleGroupControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class RuleGroupControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testCreate(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.create'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testDelete(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('get')->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.delete', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testDestroy(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('destroy');
-
-
- $this->session(['rule-groups.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('rule-groups.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testDown(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('moveDown');
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.down', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testEdit(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- /** @var RuleGroup $ruleGroup */
- $ruleGroup = $this->user()->ruleGroups()->first();
- $ruleGroup->description = 'Some description ' . periods|length(1, 10000);
- $ruleGroup->save();
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee($ruleGroup->description);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testExecute(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
-
- $this->expectsJobs(ExecuteRuleGroupOnExistingTransactions::class);
-
- $this->session(['first' => new Carbon('2010-01-01')]);
- $data = [
- 'accounts' => [1],
- 'start_date' => '2010-01-02',
- 'end_date' => '2010-01-02',
- ];
- $this->be($this->user());
- $response = $this->post(route('rule-groups.execute', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testSelectTransactions(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.select-transactions', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
- */
- public function testStore(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
- $this->session(['rule-groups.create.uri' => 'http://localhost']);
- $repository->shouldReceive('store')->andReturn(new RuleGroup);
- $repository->shouldReceive('find')->andReturn(new RuleGroup);
- $data = [
- 'title' => 'A',
- 'description' => 'No description',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('rule-groups.store', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- */
- public function testUp(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('moveUp');
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.up', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroupController
- * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
- */
- public function testUpdate(): void
- {
- // mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
- $data = [
- 'id' => 1,
- 'title' => 'C',
- 'description' => 'XX',
- ];
- $this->session(['rule-groups.edit.uri' => 'http://localhost']);
-
- $repository->shouldReceive('update');
- $repository->shouldReceive('find')->andReturn(RuleGroup::first());
-
- $this->be($this->user());
- $response = $this->post(route('rule-groups.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/SearchControllerTest.php b/tests/Feature/Controllers/SearchControllerTest.php
index 5a2888fe83..6c50030354 100644
--- a/tests/Feature/Controllers/SearchControllerTest.php
+++ b/tests/Feature/Controllers/SearchControllerTest.php
@@ -50,11 +50,11 @@ class SearchControllerTest extends TestCase
/**
- * @covers \FireflyIII\Http\Controllers\SearchController
* @covers \FireflyIII\Http\Controllers\SearchController
*/
public function testIndex(): void
{
+ $this->mockDefaultSession();
$search = $this->mock(SearchInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@@ -70,13 +70,12 @@ class SearchControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\SearchController
* @covers \FireflyIII\Http\Controllers\SearchController
*/
public function testSearch(): void
{
+ $this->mockDefaultSession();
$search = $this->mock(SearchInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
$search->shouldReceive('parseQuery')->once();
$search->shouldReceive('setLimit')->withArgs([50])->once();
diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php
index 26b117bbdb..eb50e1caa9 100644
--- a/tests/Feature/Controllers/TagControllerTest.php
+++ b/tests/Feature/Controllers/TagControllerTest.php
@@ -24,7 +24,9 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
@@ -35,6 +37,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
use Mockery;
+use Preferences;
use Tests\TestCase;
/**
@@ -61,11 +64,10 @@ class TagControllerTest extends TestCase
*/
public function testCreate(): void
{
- // mock stuff
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
+ $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@@ -79,12 +81,11 @@ class TagControllerTest extends TestCase
*/
public function testDelete(): void
{
- // mock stuff
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
+ $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@@ -98,13 +99,11 @@ class TagControllerTest extends TestCase
*/
public function testDestroy(): void
{
- // mock stuff
+ $this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('destroy');
+ Preferences::shouldReceive('mark')->atLeast()->once();
$this->be($this->user());
$response = $this->post(route('tags.destroy', [1]));
@@ -117,11 +116,10 @@ class TagControllerTest extends TestCase
*/
public function testEdit(): void
{
- // mock stuff
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $this->mockDefaultSession();
+ $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@@ -136,13 +134,12 @@ class TagControllerTest extends TestCase
*/
public function testIndex(): void
{
- // mock stuff
+ $this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('count')->andReturn(0);
$repository->shouldReceive('tagCloud')->andReturn([]);
$repository->shouldReceive('oldestTag')->andReturn(null)->once();
@@ -161,9 +158,7 @@ class TagControllerTest extends TestCase
*/
public function testShow(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
$amounts = [
TransactionType::WITHDRAWAL => '0',
@@ -171,15 +166,16 @@ class TagControllerTest extends TestCase
TransactionType::DEPOSIT => '0',
];
+ $pref = new Preference;
+ $pref->data = 50;
+ Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
-
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
@@ -209,9 +205,7 @@ class TagControllerTest extends TestCase
*/
public function testShowAll(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
@@ -220,7 +214,7 @@ class TagControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$collector->shouldReceive('removeFilter')->andReturnSelf()->once();
@@ -252,9 +246,7 @@ class TagControllerTest extends TestCase
*/
public function testShowDate(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mockDefaultSession();
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
@@ -267,7 +259,7 @@ class TagControllerTest extends TestCase
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('expenseInPeriod')->andReturn(new Collection)->atLeast()->times(1);
@@ -305,12 +297,12 @@ class TagControllerTest extends TestCase
*/
public function testStore(): void
{
- // mock stuff
+ $this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$repository->shouldReceive('findNull')->andReturn(null);
$repository->shouldReceive('store')->andReturn(new Tag);
@@ -333,11 +325,11 @@ class TagControllerTest extends TestCase
*/
public function testUpdate(): void
{
- // mock stuff
+ $this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+
$this->session(['tags.edit.uri' => 'http://localhost']);
$data = [
diff --git a/tests/Feature/Controllers/Transaction/BulkControllerTest.php b/tests/Feature/Controllers/Transaction/BulkControllerTest.php
index 1b1fa6021a..90c4d9173f 100644
--- a/tests/Feature/Controllers/Transaction/BulkControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/BulkControllerTest.php
@@ -74,6 +74,7 @@ class BulkControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournalIds')->atLeast()->once()->withArgs([[$withdrawal->id]])->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawalArray]);
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 3f00b3e1fa..34a98e8346 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -32,11 +32,16 @@ use FireflyConfig;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
+use FireflyIII\Models\Attachment;
+use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category;
use FireflyIII\Models\Configuration;
+use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Preference;
+use FireflyIII\Models\Rule;
+use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
@@ -58,6 +63,53 @@ use RuntimeException;
*/
abstract class TestCase extends BaseTestCase
{
+ /**
+ * @return PiggyBank
+ */
+ public function getRandomPiggyBank(): PiggyBank
+ {
+ return $this->user()->piggyBanks()->inRandomOrder()->first(['piggy_banks.*']);
+ }
+
+ /**
+ * @return PiggyBank
+ */
+ public function getRandomTag(): Tag
+ {
+ return $this->user()->tags()->inRandomOrder()->first(['tags.*']);
+ }
+
+ /**
+ * @return Rule
+ */
+ public function getRandomRule(): Rule
+ {
+ return $this->user()->rules()->inRandomOrder()->first();
+ }
+
+ /**
+ * @return Bill
+ */
+ public function getRandomBill(): Bill
+ {
+ return $this->user()->bills()->where('active', 1)->inRandomOrder()->first();
+ }
+
+ /**
+ * @return Bill
+ */
+ public function getRandomInactiveBill(): Bill
+ {
+ return $this->user()->bills()->where('active', 0)->inRandomOrder()->first();
+ }
+
+ /**
+ * @return Attachment
+ */
+ public function getRandomAttachment(): Attachment
+ {
+ return $this->user()->attachments()->inRandomOrder()->first();
+ }
/**
* @return TransactionJournalLink
@@ -72,7 +124,7 @@ abstract class TestCase extends BaseTestCase
*/
public function getRandomBudget(): Budget
{
- return $this->user()->budgets()->inRandomOrder()->first();
+ return $this->user()->budgets()->where('active', 1)->inRandomOrder()->first();
}
/**
@@ -102,7 +154,7 @@ abstract class TestCase extends BaseTestCase
$this->mockDefaultConfiguration();
$this->mockDefaultPreferences();
$euro = $this->getEuro();
- Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
+ Amount::shouldReceive('getDefaultCurrency')->andReturn($euro);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journal = new TransactionJournal;
@@ -236,11 +288,11 @@ abstract class TestCase extends BaseTestCase
$list = new Preference;
$list->data = 50;
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['twoFactorAuthEnabled', false])->andReturn($false);
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['twoFactorAuthSecret'])->andReturnNull();
+ Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($false);
+ Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturnNull();
Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view);
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['language', 'en_US'])->andReturn($lang);
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['list-length', 10])->andReturn($list);
+ Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($lang);
+ Preferences::shouldReceive('get')->withArgs(['list-length', 10])->andReturn($list);
}
/**
@@ -539,7 +591,6 @@ abstract class TestCase extends BaseTestCase
if (null !== $group) {
$count = $group->transactionJournals()->count();
}
- Log::debug(sprintf('Count is %d', $count));
} while (1 !== $count);
return $journal->transactionGroup;