Skip to content

Firefly III: a personal finances manager

Fixed a lot of tests and associated code.

James Coleb08af77c98f4
diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php
index d508927317..5a01279c2c 100644
--- a/app/Http/Controllers/Account/ReconcileController.php
+++ b/app/Http/Controllers/Account/ReconcileController.php
@@ -37,7 +37,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
-use Navigation;
use Preferences;
use Response;
use Session;
@@ -150,9 +149,10 @@ class ReconcileController extends Controller
'post_uri' => $route,
'html' => view(
'accounts.reconcile.overview', compact(
- 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount',
- 'route', 'countCleared'
- )
+ 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount',
+ 'startBalance', 'endBalance', 'amount',
+ 'route', 'countCleared'
+ )
)->render(),
];
@@ -189,11 +189,11 @@ class ReconcileController extends Controller
// get start and end
if (null === $start && null === $end) {
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
}
if (null === $end) {
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
}
$startDate = clone $start;
@@ -210,8 +210,9 @@ class ReconcileController extends Controller
return view(
'accounts.reconcile.index', compact(
- 'account', 'currency', 'subTitleIcon', 'start', 'end', 'subTitle', 'startBalance', 'endBalance', 'transactionsUri', 'overviewUri', 'indexUri'
- )
+ 'account', 'currency', 'subTitleIcon', 'start', 'end', 'subTitle', 'startBalance', 'endBalance', 'transactionsUri',
+ 'overviewUri', 'indexUri'
+ )
);
}
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 0b57e0555c..7f477cb649 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -38,7 +38,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Preferences;
use Steam;
use View;
@@ -293,7 +292,7 @@ class AccountController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$fStart = $start->formatLocalized($this->monthAndDayFormat);
$fEnd = $end->formatLocalized($this->monthAndDayFormat);
$subTitle = trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
@@ -303,8 +302,8 @@ class AccountController extends Controller
// prep for current period view
if (0 === strlen($moment)) {
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$fStart = $start->formatLocalized($this->monthAndDayFormat);
$fEnd = $end->formatLocalized($this->monthAndDayFormat);
$subTitle = trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
@@ -417,8 +416,8 @@ class AccountController extends Controller
$repository = app(AccountRepositoryInterface::class);
$start = $repository->oldestJournalDate($account);
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($start, $range);
- $end = Navigation::endOfX(new Carbon, $range, null);
+ $start = app('navigation')->startOfPeriod($start, $range);
+ $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection;
$count = 0;
// properties for cache
@@ -434,8 +433,8 @@ class AccountController extends Controller
Log::debug('Going to get period expenses and incomes.');
while ($end >= $start && $count < 90) {
- $end = Navigation::startOfPeriod($end, $range);
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $end = app('navigation')->startOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
// try a collector for income:
/** @var JournalCollectorInterface $collector */
@@ -449,7 +448,7 @@ class AccountController extends Controller
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
$spent = strval($collector->getJournals()->sum('transaction_amount'));
$dateStr = $end->format('Y-m-d');
- $dateName = Navigation::periodShow($end, $range);
+ $dateName = app('navigation')->periodShow($end, $range);
$entries->push(
[
'string' => $dateStr,
@@ -458,7 +457,7 @@ class AccountController extends Controller
'earned' => $earned,
'date' => clone $end,]
);
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
++$count;
}
$cache->store($entries);
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 231e216233..23812bd3b1 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -31,6 +31,9 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Schema;
+/**
+ * Class LoginController
+ */
class LoginController extends Controller
{
/*
@@ -68,6 +71,7 @@ class LoginController extends Controller
* @param Request $request
*
* @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response|void
+ * @throws \Illuminate\Validation\ValidationException
*/
public function login(Request $request)
{
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index bffa80b359..64c4d13c07 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -281,7 +281,7 @@ class BillController extends Controller
// flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
- $request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
+ $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
}
if (1 === intval($request->get('create_another'))) {
@@ -317,7 +317,7 @@ class BillController extends Controller
// flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
- $request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
+ $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
}
if (1 === intval($request->get('return_to_edit'))) {
@@ -342,7 +342,7 @@ class BillController extends Controller
private function lastPaidDate(Collection $dates, Carbon $default): Carbon
{
if ($dates->count() === 0) {
- return $default;
+ return $default; // @codeCoverageIgnore
}
$latest = $dates->first();
/** @var Carbon $date */
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index c1a646f55c..a0dc043ae7 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -37,7 +37,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Preferences;
use Response;
use View;
@@ -185,7 +184,7 @@ class BudgetController extends Controller
if (null !== $moment || 0 !== strlen(strval($moment))) {
try {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
} catch (Exception $e) {
// start and end are already defined.
}
@@ -194,7 +193,7 @@ class BudgetController extends Controller
$next->addDay();
$prev = clone $start;
$prev->subDay();
- $prev = Navigation::startOfPeriod($prev, $range);
+ $prev = app('navigation')->startOfPeriod($prev, $range);
$this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets();
$inactive = $this->repository->getInactiveBudgets();
@@ -212,9 +211,9 @@ class BudgetController extends Controller
$count = 0;
while ($count < 12) {
$previousDate->subDay();
- $previousDate = Navigation::startOfPeriod($previousDate, $range);
+ $previousDate = app('navigation')->startOfPeriod($previousDate, $range);
$format = $previousDate->format('Y-m-d');
- $previousLoop[$format] = Navigation::periodShow($previousDate, $range);
+ $previousLoop[$format] = app('navigation')->periodShow($previousDate, $range);
++$count;
}
@@ -226,16 +225,16 @@ class BudgetController extends Controller
while ($count < 12) {
$format = $nextDate->format('Y-m-d');
- $nextLoop[$format] = Navigation::periodShow($nextDate, $range);
- $nextDate = Navigation::endOfPeriod($nextDate, $range);
+ $nextLoop[$format] = app('navigation')->periodShow($nextDate, $range);
+ $nextDate = app('navigation')->endOfPeriod($nextDate, $range);
++$count;
$nextDate->addDay();
}
// display info
- $currentMonth = Navigation::periodShow($start, $range);
- $nextText = Navigation::periodShow($next, $range);
- $prevText = Navigation::periodShow($prev, $range);
+ $currentMonth = app('navigation')->periodShow($start, $range);
+ $nextText = app('navigation')->periodShow($next, $range);
+ $prevText = app('navigation')->periodShow($prev, $range);
return view(
'budgets.index',
@@ -277,9 +276,11 @@ class BudgetController extends Controller
$cache->addProperty('info-income');
if ($cache->has()) {
- $result = $cache->get(); // @codeCoverageIgnore
+ // @codeCoverageIgnoreStart
+ $result = $cache->get();
return view('budgets.info', compact('result', 'begin', 'currentEnd'));
+ // @codeCoverageIgnoreEnd
}
$result = [
'available' => '0',
@@ -288,16 +289,16 @@ class BudgetController extends Controller
];
$currency = app('amount')->getDefaultCurrency();
$range = Preferences::get('viewRange', '1M')->data;
- $begin = Navigation::subtractPeriod($start, $range, 3);
+ $begin = app('navigation')->subtractPeriod($start, $range, 3);
// get average amount available.
$total = '0';
$count = 0;
$currentStart = clone $begin;
while ($currentStart < $start) {
- $currentEnd = Navigation::endOfPeriod($currentStart, $range);
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, $range);
$total = bcadd($total, $this->repository->getAvailableBudget($currency, $currentStart, $currentEnd));
- $currentStart = Navigation::addPeriod($currentStart, $range, 0);
+ $currentStart = app('navigation')->addPeriod($currentStart, $range, 0);
++$count;
}
$result['available'] = bcdiv($total, strval($count));
@@ -354,7 +355,7 @@ class BudgetController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans(
'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -364,8 +365,8 @@ class BudgetController extends Controller
// prep for current period
if (0 === strlen($moment)) {
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview();
$subTitle = trans(
'firefly.without_budget_between',
@@ -577,8 +578,8 @@ class BudgetController extends Controller
$first = $repository->first();
$start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($start, $range);
- $end = Navigation::endOfX(new Carbon, $range, null);
+ $start = app('navigation')->startOfPeriod($start, $range);
+ $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection;
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -591,8 +592,8 @@ class BudgetController extends Controller
Log::debug('Going to get period expenses and incomes.');
while ($end >= $start) {
- $end = Navigation::startOfPeriod($end, $range);
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $end = app('navigation')->startOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutBudget()->withOpposingAccount()->setTypes([TransactionType::WITHDRAWAL]);
@@ -600,9 +601,9 @@ class BudgetController extends Controller
$sum = strval($set->sum('transaction_amount') ?? '0');
$journals = $set->count();
$dateStr = $end->format('Y-m-d');
- $dateName = Navigation::periodShow($end, $range);
+ $dateName = app('navigation')->periodShow($end, $range);
$entries->push(['string' => $dateStr, 'name' => $dateName, 'count' => $journals, 'sum' => $sum, 'date' => clone $end]);
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
}
$cache->store($entries);
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 43259f84fc..29f44cf807 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -36,7 +36,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Preferences;
use Steam;
use View;
@@ -178,7 +177,7 @@ class CategoryController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -188,8 +187,8 @@ class CategoryController extends Controller
// prep for current period
if (0 === strlen($moment)) {
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getNoCategoryPeriodOverview();
$subTitle = trans(
'firefly.without_category_between',
@@ -242,7 +241,7 @@ class CategoryController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,
@@ -255,9 +254,9 @@ class CategoryController extends Controller
// prep for current period
if (0 === strlen($moment)) {
/** @var Carbon $start */
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
/** @var Carbon $end */
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview($category);
$subTitle = trans(
'firefly.journals_in_period_for_category',
@@ -337,8 +336,8 @@ class CategoryController extends Controller
$first = $repository->first();
$start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($start, $range);
- $end = Navigation::endOfX(new Carbon, $range, null);
+ $start = app('navigation')->startOfPeriod($start, $range);
+ $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection;
// properties for cache
@@ -354,8 +353,8 @@ class CategoryController extends Controller
Log::debug(sprintf('Going to get period expenses and incomes between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d')));
while ($end >= $start) {
Log::debug('Loop!');
- $end = Navigation::startOfPeriod($end, $range);
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $end = app('navigation')->startOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
// count journals without category in this period:
/** @var JournalCollectorInterface $collector */
@@ -386,7 +385,7 @@ class CategoryController extends Controller
$earned = $collector->getJournals()->sum('transaction_amount');
$dateStr = $end->format('Y-m-d');
- $dateName = Navigation::periodShow($end, $range);
+ $dateName = app('navigation')->periodShow($end, $range);
$entries->push(
[
'string' => $dateStr,
@@ -398,7 +397,7 @@ class CategoryController extends Controller
'date' => clone $end,
]
);
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
}
Log::debug('End of loops');
$cache->store($entries);
@@ -420,11 +419,11 @@ class CategoryController extends Controller
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$first = $repository->firstUseDate($category);
if (null === $first) {
- $first = new Carbon;
+ $first = new Carbon; // @codeCoverageIgnore
}
$range = Preferences::get('viewRange', '1M')->data;
- $first = Navigation::startOfPeriod($first, $range);
- $end = Navigation::endOfX(new Carbon, $range, null);
+ $first = app('navigation')->startOfPeriod($first, $range);
+ $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection;
$count = 0;
@@ -439,12 +438,12 @@ class CategoryController extends Controller
return $cache->get(); // @codeCoverageIgnore
}
while ($end >= $first && $count < 90) {
- $end = Navigation::startOfPeriod($end, $range);
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $end = app('navigation')->startOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$dateStr = $end->format('Y-m-d');
- $dateName = Navigation::periodShow($end, $range);
+ $dateName = app('navigation')->periodShow($end, $range);
// amount transferred
/** @var JournalCollectorInterface $collector */
@@ -465,7 +464,7 @@ class CategoryController extends Controller
'date' => clone $end,
]
);
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
++$count;
}
$cache->store($entries);
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index a814be6e1b..071fe37649 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -38,7 +38,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Preferences;
use Response;
use Steam;
@@ -348,7 +347,7 @@ class AccountController extends Controller
public function period(Account $account, Carbon $start)
{
$range = Preferences::get('viewRange', '1M')->data;
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 0fbc20571a..6041b778df 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -37,7 +37,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Preferences;
use Response;
use Steam;
@@ -81,7 +80,7 @@ class BudgetController extends Controller
{
$first = $this->repository->firstUseDate($budget);
$range = Preferences::get('viewRange', '1M')->data;
- $currentStart = Navigation::startOfPeriod($first, $range);
+ $currentStart = app('navigation')->startOfPeriod($first, $range);
$last = session('end', new Carbon);
$cache = new CacheProperties();
$cache->addProperty($first);
@@ -95,15 +94,15 @@ class BudgetController extends Controller
$final = clone $last;
$final->addYears(2);
$budgetCollection = new Collection([$budget]);
- $last = Navigation::endOfX($last, $range, $final); // not to overshoot.
+ $last = app('navigation')->endOfX($last, $range, $final); // not to overshoot.
$entries = [];
while ($currentStart < $last) {
// periodspecific dates:
- $currentEnd = Navigation::endOfPeriod($currentStart, $range);
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, $range);
// sub another day because reasons.
$currentEnd->subDay();
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
- $format = Navigation::periodShow($currentStart, $range);
+ $format = app('navigation')->periodShow($currentStart, $range);
$entries[$format] = bcmul($spent, '-1');
$currentStart = clone $currentEnd;
$currentStart->addDays(2);
@@ -374,7 +373,7 @@ class BudgetController extends Controller
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$entries = $this->repository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end); // get the expenses
$budgeted = $this->getBudgetedInPeriod($budget, $start, $end);
@@ -417,7 +416,7 @@ class BudgetController extends Controller
}
// the expenses:
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$entries = $this->repository->getNoBudgetPeriodReport($accounts, $start, $end);
$chartData = [];
@@ -464,13 +463,13 @@ class BudgetController extends Controller
*/
private function getBudgetedInPeriod(Budget $budget, Carbon $start, Carbon $end): array
{
- $key = Navigation::preferredCarbonFormat($start, $end);
- $range = Navigation::preferredRangeFormat($start, $end);
+ $key = app('navigation')->preferredCarbonFormat($start, $end);
+ $range = app('navigation')->preferredRangeFormat($start, $end);
$current = clone $start;
$budgeted = [];
while ($current < $end) {
- $currentStart = Navigation::startOfPeriod($current, $range);
- $currentEnd = Navigation::endOfPeriod($current, $range);
+ $currentStart = app('navigation')->startOfPeriod($current, $range);
+ $currentEnd = app('navigation')->endOfPeriod($current, $range);
$budgetLimits = $this->repository->getBudgetLimits($budget, $currentStart, $currentEnd);
$index = $currentStart->format($key);
$budgeted[$index] = $budgetLimits->sum('amount');
diff --git a/app/Http/Controllers/Chart/BudgetReportController.php b/app/Http/Controllers/Chart/BudgetReportController.php
index 60ee052df1..ab0bf74e3c 100644
--- a/app/Http/Controllers/Chart/BudgetReportController.php
+++ b/app/Http/Controllers/Chart/BudgetReportController.php
@@ -37,7 +37,6 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Response;
/**
@@ -135,8 +134,8 @@ class BudgetReportController extends Controller
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $format = Navigation::preferredCarbonLocalizedFormat($start, $end);
- $function = Navigation::preferredEndOfPeriod($start, $end);
+ $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = [];
$currentStart = clone $start;
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index f354244d2d..17fced12e6 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -31,7 +31,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Preferences;
use Response;
@@ -78,7 +77,7 @@ class CategoryController extends Controller
}
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($start, $range);
+ $start = app('navigation')->startOfPeriod($start, $range);
$end = new Carbon;
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$chartData = [
@@ -101,15 +100,15 @@ class CategoryController extends Controller
];
while ($start <= $end) {
- $currentEnd = Navigation::endOfPeriod($start, $range);
+ $currentEnd = app('navigation')->endOfPeriod($start, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
$sum = bcadd($spent, $earned);
- $label = Navigation::periodShow($start, $range);
+ $label = app('navigation')->periodShow($start, $range);
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12);
$chartData[2]['entries'][$label] = round($sum, 12);
- $start = Navigation::addPeriod($start, $range, 0);
+ $start = app('navigation')->addPeriod($start, $range, 0);
}
$data = $this->generator->multiSet($chartData);
@@ -180,7 +179,7 @@ class CategoryController extends Controller
}
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
$income = $repository->periodIncome(new Collection([$category]), $accounts, $start, $end);
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
[
'label' => strval(trans('firefly.spent')),
@@ -236,7 +235,7 @@ class CategoryController extends Controller
}
$expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
$income = $repository->periodIncomeNoCategory($accounts, $start, $end);
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
[
'label' => strval(trans('firefly.spent')),
@@ -281,8 +280,8 @@ class CategoryController extends Controller
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
{
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($date, $range);
- $end = Navigation::endOfPeriod($date, $range);
+ $start = app('navigation')->startOfPeriod($date, $range);
+ $end = app('navigation')->endOfPeriod($date, $range);
$data = $this->makePeriodChart($repository, $category, $start, $end);
return Response::json($data);
@@ -336,7 +335,7 @@ class CategoryController extends Controller
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start);
$sum = bcadd($spent, $earned);
- $label = trim(Navigation::periodShow($start, '1D'));
+ $label = trim(app('navigation')->periodShow($start, '1D'));
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12);
diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php
index 5c59817706..c384e761b4 100644
--- a/app/Http/Controllers/Chart/CategoryReportController.php
+++ b/app/Http/Controllers/Chart/CategoryReportController.php
@@ -36,7 +36,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Response;
/**
@@ -177,8 +176,8 @@ class CategoryReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $format = Navigation::preferredCarbonLocalizedFormat($start, $end);
- $function = Navigation::preferredEndOfPeriod($start, $end);
+ $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = [];
$currentStart = clone $start;
diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php
index acc7485d1c..2235eecd74 100644
--- a/app/Http/Controllers/Chart/ExpenseReportController.php
+++ b/app/Http/Controllers/Chart/ExpenseReportController.php
@@ -33,7 +33,6 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Response;
/**
@@ -86,8 +85,8 @@ class ExpenseReportController extends Controller
// return Response::json($cache->get()); // @codeCoverageIgnore
}
- $format = Navigation::preferredCarbonLocalizedFormat($start, $end);
- $function = Navigation::preferredEndOfPeriod($start, $end);
+ $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = [];
$currentStart = clone $start;
$combined = $this->combineAccounts($expense);
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index d54697bfa5..f9954986bb 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -29,7 +29,6 @@ use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Response;
use Steam;
@@ -109,7 +108,7 @@ class ReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
- $format = Navigation::preferredCarbonLocalizedFormat($start, $end);
+ $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$source = $this->getChartData($accounts, $start, $end);
$chartData = [
[
@@ -256,7 +255,7 @@ class ReportController extends Controller
$tasker = app(AccountTaskerInterface::class);
while ($currentStart <= $end) {
- $currentEnd = Navigation::endOfPeriod($currentStart, '1M');
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
$earned = strval(
array_sum(
array_map(
@@ -282,7 +281,7 @@ class ReportController extends Controller
$label = $currentStart->format('Y-m') . '-01';
$spentArray[$label] = bcmul($spent, '-1');
$earnedArray[$label] = $earned;
- $currentStart = Navigation::addPeriod($currentStart, '1M', 0);
+ $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
}
$result = [
'spent' => $spentArray,
diff --git a/app/Http/Controllers/Chart/TagReportController.php b/app/Http/Controllers/Chart/TagReportController.php
index de4daf03dc..6528d7511b 100644
--- a/app/Http/Controllers/Chart/TagReportController.php
+++ b/app/Http/Controllers/Chart/TagReportController.php
@@ -36,7 +36,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
use Response;
class TagReportController extends Controller
@@ -168,8 +167,8 @@ class TagReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $format = Navigation::preferredCarbonLocalizedFormat($start, $end);
- $function = Navigation::preferredEndOfPeriod($start, $end);
+ $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = [];
$currentStart = clone $start;
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index 3d08e5d0b0..a327c4fd39 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -126,7 +126,7 @@ class Controller extends BaseController
$uri = $this->redirectUri;
}
if (!(false === strpos($uri, 'jscript'))) {
- $uri = $this->redirectUri;
+ $uri = $this->redirectUri; // @codeCoverageIgnore
}
return $uri;
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 5167168692..3f0427b753 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -239,6 +239,9 @@ class HomeController extends Controller
);
}
+ /**
+ * @return string
+ */
public function routes()
{
$set = RouteFacade::getRoutes();
@@ -249,7 +252,7 @@ class HomeController extends Controller
'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
'two-factor.lost', 'report.options',
];
-
+ $return = '&nbsp;';
/** @var Route $route */
foreach ($set as $route) {
$name = $route->getName();
@@ -261,12 +264,12 @@ class HomeController extends Controller
}
}
if (!$found) {
- echo 'touch ' . $route->getName() . '.md;';
+ $return .= 'touch ' . $route->getName() . '.md;';
}
}
}
- return '&nbsp;';
+ return $return;
}
/**
diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php
index 5706d6bb4e..22e8fb754e 100644
--- a/app/Http/Controllers/JavascriptController.php
+++ b/app/Http/Controllers/JavascriptController.php
@@ -138,13 +138,14 @@ class JavascriptController extends Controller
$end = session('end');
$first = session('first');
$title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
- $isCustom = session('is_custom_range');
+ $isCustom = session('is_custom_range', false) === true;
$today = new Carbon;
$ranges = [
// 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)));
// when current range is a custom range, add the current period as the next range.
if ($isCustom) {
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index a1dbfc93a8..bf487e897c 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -91,30 +91,32 @@ class ProfileController extends Controller
}
/**
- * @param string $token
+ * @param UserRepositoryInterface $repository
+ * @param string $token
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- *
* @throws FireflyException
*/
- public function confirmEmailChange(string $token)
+ public function confirmEmailChange(UserRepositoryInterface $repository, string $token)
{
// find preference with this token value.
$set = Preferences::findByName('email_change_confirm_token');
$user = null;
+ Log::debug(sprintf('Found %d preferences', $set->count()));
/** @var Preference $preference */
foreach ($set as $preference) {
if ($preference->data === $token) {
+ Log::debug('Found user');
$user = $preference->user;
}
}
// update user to clear blocked and blocked_code.
if (null === $user) {
+ Log::debug('Found no user');
throw new FireflyException('Invalid token.');
}
- $user->blocked = 0;
- $user->blocked_code = '';
- $user->save();
+ Log::debug('Will unblock user.');
+ $repository->unblockUser($user);
// return to login.
Session::flash('success', strval(trans('firefly.login_with_new_email')));
@@ -172,7 +174,7 @@ class ProfileController extends Controller
$existing = $repository->findByEmail($newEmail);
if (null !== $existing) {
// force user logout.
- $this->guard()->logout();
+ Auth::guard()->logout();
$request->session()->invalidate();
Session::flash('success', strval(trans('firefly.email_changed')));
@@ -245,7 +247,7 @@ class ProfileController extends Controller
}
/**
- *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function regenerate()
{
@@ -264,7 +266,7 @@ class ProfileController extends Controller
*
* @throws FireflyException
*/
- public function undoEmailChange(string $token, string $hash)
+ public function undoEmailChange(UserRepositoryInterface $repository, string $token, string $hash)
{
// find preference with this token value.
$set = Preferences::findByName('email_change_undo_token');
@@ -282,6 +284,7 @@ class ProfileController extends Controller
// found user.
// which email address to return to?
$set = Preferences::beginsWith($user, 'previous_email_');
+ /** @var string $match */
$match = null;
foreach ($set as $entry) {
$hashed = hash('sha256', $entry->data);
@@ -294,10 +297,9 @@ class ProfileController extends Controller
throw new FireflyException('Invalid token.');
}
// change user back
- $user->email = $match;
- $user->blocked = 0;
- $user->blocked_code = '';
- $user->save();
+ // now actually update user:
+ $repository->changeEmail($user, $match);
+ $repository->unblockUser($user);
// return to login.
Session::flash('success', strval(trans('firefly.login_with_old_email')));
diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php
index 60532b58fc..e1b62ba45a 100644
--- a/app/Http/Controllers/Report/BudgetController.php
+++ b/app/Http/Controllers/Report/BudgetController.php
@@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
/**
* Class BudgetController.
@@ -88,7 +87,7 @@ class BudgetController extends Controller
$data = $repository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
$data[0] = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget"
$report = $this->filterBudgetPeriodReport($data);
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
$cache->store($result);
diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php
index 929b9eb0eb..5cf4507a21 100644
--- a/app/Http/Controllers/Report/CategoryController.php
+++ b/app/Http/Controllers/Report/CategoryController.php
@@ -28,7 +28,6 @@ use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
-use Navigation;
/**
* Class CategoryController.
@@ -58,7 +57,7 @@ class CategoryController extends Controller
$data = $repository->periodExpenses($categories, $accounts, $start, $end);
$data[0] = $repository->periodExpensesNoCategory($accounts, $start, $end);
$report = $this->filterReport($data);
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
$cache->store($result);
@@ -89,7 +88,7 @@ class CategoryController extends Controller
$data = $repository->periodIncome($categories, $accounts, $start, $end);
$data[0] = $repository->periodIncomeNoCategory($accounts, $start, $end);
$report = $this->filterReport($data);
- $periods = Navigation::listOfPeriods($start, $end);
+ $periods = app('navigation')->listOfPeriods($start, $end);
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
$cache->store($result);
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index d7cf237f24..cbcab15618 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -70,6 +70,7 @@ class ReportController extends Controller
/**
* @param Collection $accounts
+ * @param Collection $expense
* @param Carbon $start
* @param Carbon $end
*
@@ -79,7 +80,7 @@ class ReportController extends Controller
public function accountReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)
{
if ($end < $start) {
- return view('error')->with('message', trans('firefly.end_after_start_date'));
+ return view('error')->with('message', trans('firefly.end_after_start_date'));// @codeCoverageIgnore
}
if ($start < session('first')) {
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php
index a4b259cc49..9a29dae03b 100644
--- a/app/Http/Controllers/RuleController.php
+++ b/app/Http/Controllers/RuleController.php
@@ -363,11 +363,11 @@ class RuleController extends Controller
$triggers = $this->getValidTriggerList($request);
if (0 === count($triggers)) {
- return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
+ return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore
}
- $limit = config('firefly.test-triggers.limit');
- $range = config('firefly.test-triggers.range');
+ $limit = intval(config('firefly.test-triggers.limit'));
+ $range = intval(config('firefly.test-triggers.range'));
/** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class);
@@ -379,10 +379,10 @@ class RuleController extends Controller
// Warn the user if only a subset of transactions is returned
$warning = '';
if (count($matchingTransactions) === $limit) {
- $warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]);
+ $warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore
}
if (0 === count($matchingTransactions)) {
- $warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]);
+ $warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore
}
// Return json response
@@ -403,6 +403,7 @@ class RuleController extends Controller
* @param Rule $rule
*
* @return \Illuminate\Http\JsonResponse
+ * @throws \Throwable
*/
public function testTriggersByRule(Rule $rule)
{
@@ -412,8 +413,8 @@ class RuleController extends Controller
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
}
- $limit = config('firefly.test-triggers.limit');
- $range = config('firefly.test-triggers.range');
+ $limit = intval(config('firefly.test-triggers.limit'));
+ $range = intval(config('firefly.test-triggers.range'));
/** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class);
@@ -425,10 +426,10 @@ class RuleController extends Controller
// Warn the user if only a subset of transactions is returned
$warning = '';
if (count($matchingTransactions) === $limit) {
- $warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]);
+ $warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore
}
if (0 === count($matchingTransactions)) {
- $warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]);
+ $warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore
}
// Return json response
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index adf20010fa..28e7cee929 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -31,7 +31,6 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
-use Navigation;
use Preferences;
use Session;
use View;
@@ -216,7 +215,7 @@ class TagController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans(
'firefly.journals_in_period_for_tag',
['tag' => $tag->tag,
@@ -229,9 +228,9 @@ class TagController extends Controller
// prep for current period
if (0 === strlen($moment)) {
/** @var Carbon $start */
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
/** @var Carbon $end */
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview($tag);
$subTitle = trans(
'firefly.journals_in_period_for_tag',
@@ -310,8 +309,8 @@ class TagController extends Controller
{
// get first and last tag date from tag:
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range);
- $end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range);
+ $start = app('navigation')->startOfPeriod($this->repository->firstUseDate($tag), $range);
+ $end = app('navigation')->startOfPeriod($this->repository->lastUseDate($tag), $range);
// properties for entries with their amounts.
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -327,19 +326,19 @@ class TagController extends Controller
// while end larger or equal to start
while ($end >= $start) {
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
// get expenses and what-not in this period and this tag.
$arr = [
'string' => $end->format('Y-m-d'),
- 'name' => Navigation::periodShow($end, $range),
+ 'name' => app('navigation')->periodShow($end, $range),
'date' => clone $end,
'spent' => $this->repository->spentInperiod($tag, $end, $currentEnd),
'earned' => $this->repository->earnedInperiod($tag, $end, $currentEnd),
];
$collection->push($arr);
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
}
$cache->store($collection);
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index bc86d5e35c..37cb63abdf 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -36,7 +36,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Preferences;
use Response;
use View;
@@ -96,7 +95,7 @@ class TransactionController extends Controller
// prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment);
- $end = Navigation::endOfPeriod($start, $range);
+ $end = app('navigation')->endOfPeriod($start, $range);
$path = route('transactions.index', [$what, $moment]);
$subTitle = trans(
'firefly.title_' . $what . '_between',
@@ -107,8 +106,8 @@ class TransactionController extends Controller
// prep for current period
if (0 === strlen($moment)) {
- $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
+ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview($what);
$subTitle = trans(
'firefly.title_' . $what . '_between',
@@ -206,8 +205,8 @@ class TransactionController extends Controller
$first = $repository->first();
$start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data;
- $start = Navigation::startOfPeriod($start, $range);
- $end = Navigation::endOfX(new Carbon, $range, null);
+ $start = app('navigation')->startOfPeriod($start, $range);
+ $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection;
$types = config('firefly.transactionTypesByWhat.' . $what);
@@ -225,8 +224,8 @@ class TransactionController extends Controller
Log::debug(sprintf('Going to get period expenses and incomes between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d')));
while ($end >= $start) {
Log::debug('Loop start!');
- $end = Navigation::startOfPeriod($end, $range);
- $currentEnd = Navigation::endOfPeriod($end, $range);
+ $end = app('navigation')->startOfPeriod($end, $range);
+ $currentEnd = app('navigation')->endOfPeriod($end, $range);
// count journals without budget in this period:
/** @var JournalCollectorInterface $collector */
@@ -239,7 +238,7 @@ class TransactionController extends Controller
// count per currency:
$sums = $this->sumPerCurrency($journals);
$dateStr = $end->format('Y-m-d');
- $dateName = Navigation::periodShow($end, $range);
+ $dateName = app('navigation')->periodShow($end, $range);
$array = [
'string' => $dateStr,
'name' => $dateName,
@@ -251,7 +250,7 @@ class TransactionController extends Controller
if ($journals->count() > 0) {
$entries->push($array);
}
- $end = Navigation::subtractPeriod($end, $range, 1);
+ $end = app('navigation')->subtractPeriod($end, $range, 1);
}
Log::debug('End of loop');
$cache->store($entries);
diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php
index 8f5a9badcc..adc35331a5 100644
--- a/app/Http/Middleware/Range.php
+++ b/app/Http/Middleware/Range.php
@@ -29,7 +29,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
-use Navigation;
use Preferences;
use Session;
use View;
@@ -126,8 +125,8 @@ class Range
if (!Session::has('start') && !Session::has('end')) {
$viewRange = Preferences::get('viewRange', '1M')->data;
$start = new Carbon;
- $start = Navigation::updateStartDate($viewRange, $start);
- $end = Navigation::updateEndDate($viewRange, $start);
+ $start = app('navigation')->updateStartDate($viewRange, $start);
+ $end = app('navigation')->updateEndDate($viewRange, $start);
Session::put('start', $start);
Session::put('end', $end);
diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php
index 78ef0b1e62..f9485b911b 100644
--- a/app/Http/breadcrumbs.php
+++ b/app/Http/breadcrumbs.php
@@ -595,6 +595,15 @@ Breadcrumbs::register(
$breadcrumbs->push(trans('breadcrumbs.changePassword'), route('profile.change-password'));
}
);
+
+Breadcrumbs::register(
+ 'profile.change-email',
+ function (BreadCrumbGenerator $breadcrumbs) {
+ $breadcrumbs->parent('profile.index');
+ $breadcrumbs->push(trans('breadcrumbs.change_email'), route('profile.change-email'));
+ }
+);
+
Breadcrumbs::register(
'profile.delete-account',
function (BreadCrumbGenerator $breadcrumbs) {
@@ -757,22 +766,21 @@ Breadcrumbs::register(
);
Breadcrumbs::register(
- 'rule-groups.select-transactions',
- function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) {
+ 'rules.select-transactions',
+ function (BreadCrumbGenerator $breadcrumbs, Rule $rule) {
$breadcrumbs->parent('rules.index');
$breadcrumbs->push(
- trans('firefly.rule_group_select_transactions', ['title' => $ruleGroup->title]), route('rule-groups.select-transactions', [$ruleGroup])
+ trans('firefly.rule_select_transactions', ['title' => $rule->title]), route('rules.select-transactions', [$rule])
);
}
);
Breadcrumbs::register(
- 'rule-groups.select_transactions',
+ 'rule-groups.select-transactions',
function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) {
$breadcrumbs->parent('rules.index');
$breadcrumbs->push(
- trans('firefly.execute_group_on_existing_transactions', ['title' => $ruleGroup->title]),
- route('rule-groups.select_transactions', [$ruleGroup])
+ trans('firefly.rule_group_select_transactions', ['title' => $ruleGroup->title]), route('rule-groups.select-transactions', [$ruleGroup])
);
}
);
diff --git a/app/Jobs/ExecuteRuleOnExistingTransactions.php b/app/Jobs/ExecuteRuleOnExistingTransactions.php
index 0c7fbd7fd1..45117b37bf 100644
--- a/app/Jobs/ExecuteRuleOnExistingTransactions.php
+++ b/app/Jobs/ExecuteRuleOnExistingTransactions.php
@@ -117,6 +117,15 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
return $this->user;
}
+ /**
+ * @return Rule
+ */
+ public function getRule(): Rule
+ {
+ return $this->rule;
+ }
+
+
/**
* @param User $user
*/
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index 45c567ca2d..e37a7028dc 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -223,6 +223,18 @@ class UserRepository implements UserRepositoryInterface
return $user->hasRole($role);
}
+ /**
+ * @param User $user
+ */
+ public function unblockUser(User $user): void
+ {
+ $user->blocked = 0;
+ $user->blocked_code = '';
+ $user->save();
+
+ return;
+ }
+
/**
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
* The user is NOT blocked.
diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.php
index 8436eee569..2089c6a5c8 100644
--- a/app/Repositories/User/UserRepositoryInterface.php
+++ b/app/Repositories/User/UserRepositoryInterface.php
@@ -122,6 +122,11 @@ interface UserRepositoryInterface
*/
public function hasRole(User $user, string $role): bool;
+ /**
+ * @param User $user
+ */
+ public function unblockUser(User $user): void;
+
/**
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
* The user is NOT blocked.
diff --git a/resources/lang/en_US/breadcrumbs.php b/resources/lang/en_US/breadcrumbs.php
index 6c834d0d02..0f4d2c91ed 100644
--- a/resources/lang/en_US/breadcrumbs.php
+++ b/resources/lang/en_US/breadcrumbs.php
@@ -29,6 +29,7 @@ return [
'preferences' => 'Preferences',
'profile' => 'Profile',
'changePassword' => 'Change your password',
+ 'change_email' => 'Change your email address',
'bills' => 'Bills',
'newBill' => 'New bill',
'edit_bill' => 'Edit bill ":name"',
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index aba14a68b2..65f8d6af4c 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -711,6 +711,8 @@ return [
'deleted_transfer' => 'Successfully deleted transfer ":description"',
'stored_journal' => 'Successfully created new transaction ":description"',
'select_transactions' => 'Select transactions',
+ 'rule_group_select_transactions' => 'Apply ":title" to transactions',
+ 'rule_select_transactions' => 'Apply ":title" to transactions',
'stop_selection' => 'Stop selecting transactions',
'reconcile_selected' => 'Reconcile',
'mass_delete_journals' => 'Delete a number of transactions',
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
index 10e29f1744..d4c96cf7a7 100644
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ b/tests/Feature/Controllers/BillControllerTest.php
@@ -110,6 +110,7 @@ class BillControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\BillController::index
* @covers \FireflyIII\Http\Controllers\BillController::__construct
+ * @covers \FireflyIII\Http\Controllers\BillController::lastPaidDate
*/
public function testIndex()
{
diff --git a/tests/Feature/Controllers/BudgetControllerTest.php b/tests/Feature/Controllers/BudgetControllerTest.php
index 7bfc7d4e73..d9a01de692 100644
--- a/tests/Feature/Controllers/BudgetControllerTest.php
+++ b/tests/Feature/Controllers/BudgetControllerTest.php
@@ -43,6 +43,21 @@ use Tests\TestCase;
*/
class BudgetControllerTest extends TestCase
{
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\BudgetController::infoIncome
+ */
+ public function testInfoIncome() {
+ // mock stuff
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
+
+ $data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
+ $this->be($this->user());
+ $response = $this->get(route('budgets.income.info', ['20170101','20170131']), $data);
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
*/
diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.php
index 9e6edee8c2..4f98f72a96 100644
--- a/tests/Feature/Controllers/CurrencyControllerTest.php
+++ b/tests/Feature/Controllers/CurrencyControllerTest.php
@@ -206,9 +206,11 @@ class CurrencyControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
+ $currencies = factory(TransactionCurrency::class, 3)->make();
+
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
- $repository->shouldReceive('get')->andReturn(new Collection);
+ $repository->shouldReceive('get')->andReturn($currencies);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$this->be($this->user());
diff --git a/tests/Feature/Controllers/HomeControllerTest.php b/tests/Feature/Controllers/HomeControllerTest.php
index 225d40d96b..ab48cec6a4 100644
--- a/tests/Feature/Controllers/HomeControllerTest.php
+++ b/tests/Feature/Controllers/HomeControllerTest.php
@@ -86,6 +86,16 @@ class HomeControllerTest extends TestCase
$response->assertSessionHas('warning', '91 days of data may take a while to load.');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\HomeController::displayDebug()
+ */
+ public function testDisplayDebug()
+ {
+ $this->be($this->user());
+ $response = $this->get(route('debug'));
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\HomeController::displayError
*/
@@ -170,6 +180,16 @@ class HomeControllerTest extends TestCase
$response->assertStatus(302);
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\HomeController::routes()
+ */
+ public function testRoutes()
+ {
+ $this->be($this->user());
+ $response = $this->get(route('routes'));
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\HomeController::testFlash
*/
diff --git a/tests/Feature/Controllers/Import/FileControllerTest.php b/tests/Feature/Controllers/Import/FileControllerTest.php
deleted file mode 100644
index 87bef0d6c2..0000000000
--- a/tests/Feature/Controllers/Import/FileControllerTest.php
+++ /dev/null
@@ -1,225 +0,0 @@
-<?php
-/**
- * FileControllerTest.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\Import;
-
-use FireflyIII\Import\Configurator\CsvConfigurator;
-use FireflyIII\Import\Routine\ImportRoutine;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use Illuminate\Http\UploadedFile;
-use Tests\TestCase;
-
-/**
- * Class FileControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class FileControllerTest extends TestCase
-{
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::__construct
- * @covers \FireflyIII\Http\Controllers\Import\FileController::configure
- * @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator
- */
- public function testConfigure()
- {
- // mock stuff.
- $configurator = $this->mock(CsvConfigurator::class);
- $configurator->shouldReceive('setJob')->once();
- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
- $configurator->shouldReceive('getNextView')->once()->andReturn('import.csv.initial');
- $configurator->shouldReceive('getNextData')->andReturn(['specifics' => [], 'delimiters' => [], 'accounts' => []])->once();
-
- $this->be($this->user());
- $response = $this->get(route('import.file.configure', ['configure']));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::__construct
- * @covers \FireflyIII\Http\Controllers\Import\FileController::configure
- * @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator
- */
- public function testConfigured()
- {
- // mock stuff.
- $configurator = $this->mock(CsvConfigurator::class);
- $configurator->shouldReceive('setJob')->once();
- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('import.file.configure', ['configure']));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.file.status', ['configure']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::download
- */
- public function testDownload()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.download', ['configure']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::initialize
- */
- public function testInitialize()
- {
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $path = resource_path('stubs/csv.csv');
- $file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);
- $configPath = resource_path('stubs/demo-configuration.json');
- $configFile = new UploadedFile($path, 'configuration.json', filesize($configPath), 'application/json', null, true);
- $job = new ImportJob;
- $job->key = 'hello';
-
- $repository->shouldReceive('create')->once()->andReturn($job);
- $repository->shouldReceive('processFile')->once();
- $repository->shouldReceive('processConfiguration')->once();
- $repository->shouldReceive('updateStatus')->once();
-
- $this->be($this->user());
- $response = $this->post(route('import.file.initialize'), ['import_file_type' => 'csv', 'import_file' => $file, 'configuration_file' => $configFile]);
-
- $response->assertStatus(302);
- $response->assertRedirect(route('import.file.configure', ['hello']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::json
- */
- public function testJson()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.json', ['configure']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::json
- */
- public function testJsonFinished()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.json', ['finished']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::json
- */
- public function testJsonRunning()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.json', ['running']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure
- */
- public function testPostConfigure()
- {
- $configurator = $this->mock(CsvConfigurator::class);
- $configurator->shouldReceive('setJob')->once();
- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
- $configurator->shouldReceive('configureJob')->once()->andReturn(false);
- $configurator->shouldReceive('getWarningMessage')->once()->andReturn('');
-
- $this->be($this->user());
- $response = $this->post(route('import.file.process-configuration', ['running']));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.file.configure', ['running']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure
- */
- public function testPostConfigured()
- {
- $configurator = $this->mock(CsvConfigurator::class);
- $configurator->shouldReceive('setJob')->once();
- $configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->post(route('import.file.process-configuration', ['running']));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.file.status', ['running']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::start
- */
- public function testStart()
- {
- $importer = $this->mock(ImportRoutine::class);
- $importer->shouldReceive('setJob')->once();
- $importer->shouldReceive('run')->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->post(route('import.file.start', ['running']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::start
- * @expectedExceptionMessage Job did not complete succesfully.
- */
- public function testStartFailed()
- {
- $importer = $this->mock(ImportRoutine::class);
- $importer->shouldReceive('setJob')->once();
- $importer->shouldReceive('run')->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->post(route('import.file.start', ['running']));
- $response->assertStatus(500);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::status
- */
- public function testStatus()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.status', ['running']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\FileController::status
- */
- public function testStatusNew()
- {
- $this->be($this->user());
- $response = $this->get(route('import.file.status', ['new']));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.file.configure', ['new']));
- }
-}
diff --git a/tests/Feature/Controllers/ImportControllerTest.php b/tests/Feature/Controllers/ImportControllerTest.php
deleted file mode 100644
index f85991ec4c..0000000000
--- a/tests/Feature/Controllers/ImportControllerTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * ImportControllerTest.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 Tests\TestCase;
-
-/**
- * Class ImportControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ImportControllerTest extends TestCase
-{
- /**
- * @covers \FireflyIII\Http\Controllers\ImportController::index
- */
- public function testIndex()
- {
- $this->be($this->user());
- $response = $this->get(route('import.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/JavascriptControllerTest.php b/tests/Feature/Controllers/JavascriptControllerTest.php
index 9085e5a987..cb343cbbae 100644
--- a/tests/Feature/Controllers/JavascriptControllerTest.php
+++ b/tests/Feature/Controllers/JavascriptControllerTest.php
@@ -86,4 +86,21 @@ class JavascriptControllerTest extends TestCase
$response = $this->get(route('javascript.variables'));
$response->assertStatus(200);
}
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\JavascriptController::variables
+ * @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
+ *
+ * @param string $range
+ *
+ * @dataProvider dateRangeProvider
+ */
+ public function testVariablesCustom(string $range)
+ {
+ $this->be($this->user());
+ $this->changeDateRange($this->user(), $range);
+ $this->session(['is_custom_range' => true]);
+ $response = $this->get(route('javascript.variables'));
+ $response->assertStatus(200);
+ }
}
diff --git a/tests/Feature/Controllers/NewUserControllerTest.php b/tests/Feature/Controllers/NewUserControllerTest.php
index 862491ae60..e8c997cfa7 100644
--- a/tests/Feature/Controllers/NewUserControllerTest.php
+++ b/tests/Feature/Controllers/NewUserControllerTest.php
@@ -86,9 +86,10 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->times(2);
$data = [
- 'bank_name' => 'New bank',
- 'savings_balance' => '1000',
- 'bank_balance' => '100',
+ 'bank_name' => 'New bank',
+ 'savings_balance' => '1000',
+ 'bank_balance' => '100',
+ 'amount_currency_id_bank_balance' => 1,
];
$this->be($this->emptyUser());
$response = $this->post(route('new-user.submit'), $data);
@@ -108,8 +109,9 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->twice();
$data = [
- 'bank_name' => 'New bank',
- 'bank_balance' => '100',
+ 'bank_name' => 'New bank',
+ 'bank_balance' => '100',
+ 'amount_currency_id_bank_balance' => 1,
];
$this->be($this->emptyUser());
$response = $this->post(route('new-user.submit'), $data);
diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php
index 072fc73152..de624afad2 100644
--- a/tests/Feature/Controllers/ProfileControllerTest.php
+++ b/tests/Feature/Controllers/ProfileControllerTest.php
@@ -22,9 +22,13 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
+use FireflyIII\User;
+use Illuminate\Support\Collection;
+use Preferences;
use Tests\TestCase;
/**
@@ -36,6 +40,18 @@ use Tests\TestCase;
*/
class ProfileControllerTest extends TestCase
{
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::changeEmail()
+ */
+ public function testChangeEmail()
+ {
+ $this->be($this->user());
+ $response = $this->get(route('profile.change-email'));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::changePassword
*/
@@ -51,6 +67,36 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::confirmEmailChange()
+ * @expectedExceptionMessage Invalid token
+ */
+ public function testConfirmEmailChangeNoToken()
+ {
+ Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());
+ // email_change_confirm_token
+ $response = $this->get(route('profile.confirm-email-change', ['some-fake-token']));
+ $response->assertStatus(500);
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::confirmEmailChange()
+ */
+ public function testConfirmEmailWithToken()
+ {
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('unblockUser');
+ $preference = new Preference;
+ $preference->data = 'existing-token';
+ /** @var \stdClass $preference */
+ $preference->user = $this->user();
+ Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection([$preference]));
+ // email_change_confirm_token
+ $response = $this->get(route('profile.confirm-email-change', ['existing-token']));
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::deleteAccount
*/
@@ -72,6 +118,8 @@ class ProfileControllerTest extends TestCase
*/
public function testIndex()
{
+ // delete access token.
+ Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->delete();
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -82,6 +130,58 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::postChangeEmail
+ */
+ public function testPostChangeEmail()
+ {
+ $data = [
+ 'email' => '[email protected]',
+ ];
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('findByEmail')->once()->andReturn(null);
+ $repository->shouldReceive('changeEmail')->once()->andReturn(true);
+
+ $this->be($this->user());
+ $response = $this->post(route('profile.change-email.post'), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ $response->assertRedirect(route('index'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::postChangeEmail
+ */
+ public function testPostChangeEmailExisting()
+ {
+ $data = [
+ 'email' => '[email protected]',
+ ];
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('findByEmail')->once()->andReturn(new User);
+
+ $this->be($this->user());
+ $response = $this->post(route('profile.change-email.post'), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ $response->assertRedirect(route('index'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::postChangeEmail
+ */
+ public function testPostChangeEmailSame()
+ {
+ $data = [
+ 'email' => $this->user()->email,
+ ];
+ $this->be($this->user());
+ $response = $this->post(route('profile.change-email.post'), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('error');
+ $response->assertRedirect(route('profile.change-email'));
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
@@ -187,4 +287,92 @@ class ProfileControllerTest extends TestCase
$response->assertRedirect(route('profile.delete-account'));
$response->assertSessionHas('error');
}
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::regenerate()
+ */
+ public function testRegenerate()
+ {
+ $token = '';
+ $currentToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
+ if (!is_null($currentToken)) {
+ $token = $currentToken->data;
+ }
+ $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);
+
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::undoEmailChange()
+ */
+ public function testUndoEmailChange()
+ {
+ $hash = hash('sha256', '[email protected]');
+ $tokenPreference = new Preference;
+ $tokenPreference->data = 'token';
+ /** @var \stdClass $tokenPreference */
+ $tokenPreference->user = $this->user();
+
+ $hashPreference = new Preference;
+ $hashPreference->data = '[email protected]';
+ /** @var \stdClass $hashPreference */
+ $hashPreference->user = $this->user();
+
+ Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
+ Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
+
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('changeEmail')->once();
+ $repository->shouldReceive('unblockUser')->once();
+
+ $response = $this->get(route('profile.undo-email-change', ['token', $hash]));
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ $response->assertRedirect(route('login'));
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::undoEmailChange()
+ * @expectedExceptionMessage Invalid token
+ */
+ public function testUndoEmailChangeBadHash()
+ {
+ $hash = hash('sha256', '[email protected]');
+ $tokenPreference = new Preference;
+ $tokenPreference->data = 'token';
+ /** @var \stdClass $tokenPreference */
+ $tokenPreference->user = $this->user();
+
+ $hashPreference = new Preference;
+ $hashPreference->data = '[email protected]';
+ /** @var \stdClass $hashPreference */
+ $hashPreference->user = $this->user();
+
+ Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
+ Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
+
+ $response = $this->get(route('profile.undo-email-change', ['token', $hash]));
+ $response->assertStatus(500);
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\ProfileController::undoEmailChange()
+ * @expectedExceptionMessage Invalid token
+ */
+ public function testUndoEmailChangeBadToken()
+ {
+ Preferences::shouldReceive('findByName')->once()->andReturn(new Collection);
+
+ $response = $this->get(route('profile.undo-email-change', ['token', 'some-hash']));
+ $response->assertStatus(500);
+ }
+
+
}
diff --git a/tests/Feature/Controllers/ReportControllerTest.php b/tests/Feature/Controllers/ReportControllerTest.php
index f0a157dafb..064950fb76 100644
--- a/tests/Feature/Controllers/ReportControllerTest.php
+++ b/tests/Feature/Controllers/ReportControllerTest.php
@@ -22,12 +22,14 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use FireflyIII\Generator\Report\Account\YearReportGenerator as AcYRG;
use FireflyIII\Generator\Report\Audit\YearReportGenerator as AYRG;
use FireflyIII\Generator\Report\Budget\YearReportGenerator as BYRG;
use FireflyIII\Generator\Report\Category\YearReportGenerator as CYRG;
use FireflyIII\Generator\Report\Standard\YearReportGenerator as SYRG;
use FireflyIII\Generator\Report\Tag\YearReportGenerator as TYRG;
use FireflyIII\Helpers\Report\ReportHelperInterface;
+use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
@@ -50,6 +52,26 @@ use Tests\TestCase;
*/
class ReportControllerTest extends TestCase
{
+ /**
+ * @covers \FireflyIII\Http\Controllers\ReportController::accountReport()
+ */
+ public function testAccountReport()
+ {
+ $generator = $this->mock(AcYRG::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $generator->shouldReceive('setStartDate')->once();
+ $generator->shouldReceive('setEndDate')->once();
+ $generator->shouldReceive('setAccounts')->once();
+ $generator->shouldReceive('setExpense')->once();
+ $generator->shouldReceive('generate')->andReturn('here-be-report')->once();
+
+ $this->be($this->user());
+ $response = $this->get(route('reports.report.account', [1, 2, '20160101', '20160131']));
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ReportController::auditReport
*/
@@ -172,6 +194,28 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200);
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\ReportController::options
+ * @covers \FireflyIII\Http\Controllers\ReportController::accountReportOptions()
+ */
+ public function testOptionsAccount()
+ {
+ $account = new Account();
+ $account->name = 'Something';
+ $account->id = 3;
+ $collection = new Collection([$account]);
+
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository = $this->mock(AccountRepositoryInterface::class);
+ $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE]])->once()->andReturn($collection);
+ $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
+
+ $this->be($this->user());
+ $response = $this->get(route('reports.options', ['account']));
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ReportController::options
* @covers \FireflyIII\Http\Controllers\ReportController::budgetReportOptions
@@ -224,6 +268,27 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200);
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\ReportController::postIndex
+ */
+ public function testPostIndexAccountOK()
+ {
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $data = [
+ 'accounts' => ['1'],
+ 'exp_rev' => ['4'],
+ 'daterange' => '2016-01-01 - 2016-01-31',
+ 'report_type' => 'account',
+ ];
+
+ $this->be($this->user());
+ $response = $this->post(route('reports.index.post'), $data);
+ $response->assertStatus(302);
+ $response->assertRedirect(route('reports.report.account', ['1', '4', '20160101', '20160131']));
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
diff --git a/tests/Feature/Controllers/RuleControllerTest.php b/tests/Feature/Controllers/RuleControllerTest.php
index 65888e8a09..607eecc051 100644
--- a/tests/Feature/Controllers/RuleControllerTest.php
+++ b/tests/Feature/Controllers/RuleControllerTest.php
@@ -22,15 +22,19 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
+use FireflyIII\Jobs\Job;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher;
use Illuminate\Support\Collection;
+use Queue;
use Tests\TestCase;
/**
@@ -183,6 +187,31 @@ class RuleControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleController::execute
+ */
+ public function testExecute()
+ {
+ Queue::fake();
+
+ $data = [
+ 'accounts' => [1],
+ 'start_date' => '2017-01-01',
+ 'end_date' => '2017-01-02',
+ ];
+
+ $this->be($this->user());
+ $response = $this->post(route('rules.execute', [1]), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+
+ Queue::assertPushed(
+ ExecuteRuleOnExistingTransactions::class, function (Job $job) {
+ return $job->getRule()->id === 1;
+ }
+ );
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\RuleController::index
* @covers \FireflyIII\Http\Controllers\RuleController::__construct
@@ -245,6 +274,20 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200);
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleController::selectTransactions()
+ */
+ public function testSelectTransactions()
+ {
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
+
+ $this->be($this->user());
+ $response = $this->get(route('rules.select-transactions', [1]));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\RuleController::store
*/
@@ -312,6 +355,25 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200);
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\RuleController::testTriggersByRule()
+ */
+ public function testTestTriggersByRule()
+ {
+
+ $matcher = $this->mock(TransactionMatcher::class);
+
+ $matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
+ $matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
+ $matcher->shouldReceive('setRule')->andReturnSelf()->once();
+ $matcher->shouldReceive('findTransactionsByRule')->andReturn(new Collection);
+
+ $this->be($this->user());
+ $response = $this->get(route('rules.test-triggers-rule', [1]));
+ $response->assertStatus(200);
+
+ }
+
/**
* This actually hits an error and not the actually code but OK.
*