Fixed a lot of tests and associated code.

This commit is contained in:
James Cole 2017-12-17 14:06:14 +01:00
parent 7d348f25ac
commit b08af77c98
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
42 changed files with 579 additions and 442 deletions

View File

@ -37,7 +37,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
use Session; use Session;
@ -150,9 +149,10 @@ class ReconcileController extends Controller
'post_uri' => $route, 'post_uri' => $route,
'html' => view( 'html' => view(
'accounts.reconcile.overview', compact( 'accounts.reconcile.overview', compact(
'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount',
'route', 'countCleared' 'startBalance', 'endBalance', 'amount',
) 'route', 'countCleared'
)
)->render(), )->render(),
]; ];
@ -189,11 +189,11 @@ class ReconcileController extends Controller
// get start and end // get start and end
if (null === $start && null === $end) { if (null === $start && null === $end) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
} }
if (null === $end) { if (null === $end) {
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
} }
$startDate = clone $start; $startDate = clone $start;
@ -210,8 +210,9 @@ class ReconcileController extends Controller
return view( return view(
'accounts.reconcile.index', compact( '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'
)
); );
} }

View File

@ -38,7 +38,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
use Steam; use Steam;
use View; use View;
@ -293,7 +292,7 @@ class AccountController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$fStart = $start->formatLocalized($this->monthAndDayFormat); $fStart = $start->formatLocalized($this->monthAndDayFormat);
$fEnd = $end->formatLocalized($this->monthAndDayFormat); $fEnd = $end->formatLocalized($this->monthAndDayFormat);
$subTitle = trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); $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 // prep for current period view
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$fStart = $start->formatLocalized($this->monthAndDayFormat); $fStart = $start->formatLocalized($this->monthAndDayFormat);
$fEnd = $end->formatLocalized($this->monthAndDayFormat); $fEnd = $end->formatLocalized($this->monthAndDayFormat);
$subTitle = trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); $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); $repository = app(AccountRepositoryInterface::class);
$start = $repository->oldestJournalDate($account); $start = $repository->oldestJournalDate($account);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range, null); $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection; $entries = new Collection;
$count = 0; $count = 0;
// properties for cache // properties for cache
@ -434,8 +433,8 @@ class AccountController extends Controller
Log::debug('Going to get period expenses and incomes.'); Log::debug('Going to get period expenses and incomes.');
while ($end >= $start && $count < 90) { while ($end >= $start && $count < 90) {
$end = Navigation::startOfPeriod($end, $range); $end = app('navigation')->startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range); $currentEnd = app('navigation')->endOfPeriod($end, $range);
// try a collector for income: // try a collector for income:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
@ -449,7 +448,7 @@ class AccountController extends Controller
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount(); $collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
$spent = strval($collector->getJournals()->sum('transaction_amount')); $spent = strval($collector->getJournals()->sum('transaction_amount'));
$dateStr = $end->format('Y-m-d'); $dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range); $dateName = app('navigation')->periodShow($end, $range);
$entries->push( $entries->push(
[ [
'string' => $dateStr, 'string' => $dateStr,
@ -458,7 +457,7 @@ class AccountController extends Controller
'earned' => $earned, 'earned' => $earned,
'date' => clone $end,] 'date' => clone $end,]
); );
$end = Navigation::subtractPeriod($end, $range, 1); $end = app('navigation')->subtractPeriod($end, $range, 1);
++$count; ++$count;
} }
$cache->store($entries); $cache->store($entries);

View File

@ -31,6 +31,9 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Schema; use Schema;
/**
* Class LoginController
*/
class LoginController extends Controller class LoginController extends Controller
{ {
/* /*
@ -68,6 +71,7 @@ class LoginController extends Controller
* @param Request $request * @param Request $request
* *
* @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response|void * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response|void
* @throws \Illuminate\Validation\ValidationException
*/ */
public function login(Request $request) public function login(Request $request)
{ {

View File

@ -281,7 +281,7 @@ class BillController extends Controller
// flash messages // flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) { 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'))) { if (1 === intval($request->get('create_another'))) {
@ -317,7 +317,7 @@ class BillController extends Controller
// flash messages // flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) { 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'))) { if (1 === intval($request->get('return_to_edit'))) {
@ -342,7 +342,7 @@ class BillController extends Controller
private function lastPaidDate(Collection $dates, Carbon $default): Carbon private function lastPaidDate(Collection $dates, Carbon $default): Carbon
{ {
if ($dates->count() === 0) { if ($dates->count() === 0) {
return $default; return $default; // @codeCoverageIgnore
} }
$latest = $dates->first(); $latest = $dates->first();
/** @var Carbon $date */ /** @var Carbon $date */

View File

@ -37,7 +37,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
use View; use View;
@ -185,7 +184,7 @@ class BudgetController extends Controller
if (null !== $moment || 0 !== strlen(strval($moment))) { if (null !== $moment || 0 !== strlen(strval($moment))) {
try { try {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
} catch (Exception $e) { } catch (Exception $e) {
// start and end are already defined. // start and end are already defined.
} }
@ -194,7 +193,7 @@ class BudgetController extends Controller
$next->addDay(); $next->addDay();
$prev = clone $start; $prev = clone $start;
$prev->subDay(); $prev->subDay();
$prev = Navigation::startOfPeriod($prev, $range); $prev = app('navigation')->startOfPeriod($prev, $range);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets(); $budgets = $this->repository->getActiveBudgets();
$inactive = $this->repository->getInactiveBudgets(); $inactive = $this->repository->getInactiveBudgets();
@ -212,9 +211,9 @@ class BudgetController extends Controller
$count = 0; $count = 0;
while ($count < 12) { while ($count < 12) {
$previousDate->subDay(); $previousDate->subDay();
$previousDate = Navigation::startOfPeriod($previousDate, $range); $previousDate = app('navigation')->startOfPeriod($previousDate, $range);
$format = $previousDate->format('Y-m-d'); $format = $previousDate->format('Y-m-d');
$previousLoop[$format] = Navigation::periodShow($previousDate, $range); $previousLoop[$format] = app('navigation')->periodShow($previousDate, $range);
++$count; ++$count;
} }
@ -226,16 +225,16 @@ class BudgetController extends Controller
while ($count < 12) { while ($count < 12) {
$format = $nextDate->format('Y-m-d'); $format = $nextDate->format('Y-m-d');
$nextLoop[$format] = Navigation::periodShow($nextDate, $range); $nextLoop[$format] = app('navigation')->periodShow($nextDate, $range);
$nextDate = Navigation::endOfPeriod($nextDate, $range); $nextDate = app('navigation')->endOfPeriod($nextDate, $range);
++$count; ++$count;
$nextDate->addDay(); $nextDate->addDay();
} }
// display info // display info
$currentMonth = Navigation::periodShow($start, $range); $currentMonth = app('navigation')->periodShow($start, $range);
$nextText = Navigation::periodShow($next, $range); $nextText = app('navigation')->periodShow($next, $range);
$prevText = Navigation::periodShow($prev, $range); $prevText = app('navigation')->periodShow($prev, $range);
return view( return view(
'budgets.index', 'budgets.index',
@ -277,9 +276,11 @@ class BudgetController extends Controller
$cache->addProperty('info-income'); $cache->addProperty('info-income');
if ($cache->has()) { if ($cache->has()) {
$result = $cache->get(); // @codeCoverageIgnore // @codeCoverageIgnoreStart
$result = $cache->get();
return view('budgets.info', compact('result', 'begin', 'currentEnd')); return view('budgets.info', compact('result', 'begin', 'currentEnd'));
// @codeCoverageIgnoreEnd
} }
$result = [ $result = [
'available' => '0', 'available' => '0',
@ -288,16 +289,16 @@ class BudgetController extends Controller
]; ];
$currency = app('amount')->getDefaultCurrency(); $currency = app('amount')->getDefaultCurrency();
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$begin = Navigation::subtractPeriod($start, $range, 3); $begin = app('navigation')->subtractPeriod($start, $range, 3);
// get average amount available. // get average amount available.
$total = '0'; $total = '0';
$count = 0; $count = 0;
$currentStart = clone $begin; $currentStart = clone $begin;
while ($currentStart < $start) { while ($currentStart < $start) {
$currentEnd = Navigation::endOfPeriod($currentStart, $range); $currentEnd = app('navigation')->endOfPeriod($currentStart, $range);
$total = bcadd($total, $this->repository->getAvailableBudget($currency, $currentStart, $currentEnd)); $total = bcadd($total, $this->repository->getAvailableBudget($currency, $currentStart, $currentEnd));
$currentStart = Navigation::addPeriod($currentStart, $range, 0); $currentStart = app('navigation')->addPeriod($currentStart, $range, 0);
++$count; ++$count;
} }
$result['available'] = bcdiv($total, strval($count)); $result['available'] = bcdiv($total, strval($count));
@ -354,7 +355,7 @@ class BudgetController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans( $subTitle = trans(
'firefly.without_budget_between', 'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -364,8 +365,8 @@ class BudgetController extends Controller
// prep for current period // prep for current period
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview(); $periods = $this->getPeriodOverview();
$subTitle = trans( $subTitle = trans(
'firefly.without_budget_between', 'firefly.without_budget_between',
@ -577,8 +578,8 @@ class BudgetController extends Controller
$first = $repository->first(); $first = $repository->first();
$start = $first->date ?? new Carbon; $start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range, null); $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection; $entries = new Collection;
$cache = new CacheProperties; $cache = new CacheProperties;
$cache->addProperty($start); $cache->addProperty($start);
@ -591,8 +592,8 @@ class BudgetController extends Controller
Log::debug('Going to get period expenses and incomes.'); Log::debug('Going to get period expenses and incomes.');
while ($end >= $start) { while ($end >= $start) {
$end = Navigation::startOfPeriod($end, $range); $end = app('navigation')->startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range); $currentEnd = app('navigation')->endOfPeriod($end, $range);
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutBudget()->withOpposingAccount()->setTypes([TransactionType::WITHDRAWAL]); $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'); $sum = strval($set->sum('transaction_amount') ?? '0');
$journals = $set->count(); $journals = $set->count();
$dateStr = $end->format('Y-m-d'); $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]); $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); $cache->store($entries);

View File

@ -36,7 +36,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
use Steam; use Steam;
use View; use View;
@ -178,7 +177,7 @@ class CategoryController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans( $subTitle = trans(
'firefly.without_category_between', 'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -188,8 +187,8 @@ class CategoryController extends Controller
// prep for current period // prep for current period
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getNoCategoryPeriodOverview(); $periods = $this->getNoCategoryPeriodOverview();
$subTitle = trans( $subTitle = trans(
'firefly.without_category_between', 'firefly.without_category_between',
@ -242,7 +241,7 @@ class CategoryController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans( $subTitle = trans(
'firefly.journals_in_period_for_category', 'firefly.journals_in_period_for_category',
['name' => $category->name, ['name' => $category->name,
@ -255,9 +254,9 @@ class CategoryController extends Controller
// prep for current period // prep for current period
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
/** @var Carbon $start */ /** @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 */ /** @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); $periods = $this->getPeriodOverview($category);
$subTitle = trans( $subTitle = trans(
'firefly.journals_in_period_for_category', 'firefly.journals_in_period_for_category',
@ -337,8 +336,8 @@ class CategoryController extends Controller
$first = $repository->first(); $first = $repository->first();
$start = $first->date ?? new Carbon; $start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range, null); $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection; $entries = new Collection;
// properties for cache // 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'))); 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) { while ($end >= $start) {
Log::debug('Loop!'); Log::debug('Loop!');
$end = Navigation::startOfPeriod($end, $range); $end = app('navigation')->startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range); $currentEnd = app('navigation')->endOfPeriod($end, $range);
// count journals without category in this period: // count journals without category in this period:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
@ -386,7 +385,7 @@ class CategoryController extends Controller
$earned = $collector->getJournals()->sum('transaction_amount'); $earned = $collector->getJournals()->sum('transaction_amount');
$dateStr = $end->format('Y-m-d'); $dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range); $dateName = app('navigation')->periodShow($end, $range);
$entries->push( $entries->push(
[ [
'string' => $dateStr, 'string' => $dateStr,
@ -398,7 +397,7 @@ class CategoryController extends Controller
'date' => clone $end, 'date' => clone $end,
] ]
); );
$end = Navigation::subtractPeriod($end, $range, 1); $end = app('navigation')->subtractPeriod($end, $range, 1);
} }
Log::debug('End of loops'); Log::debug('End of loops');
$cache->store($entries); $cache->store($entries);
@ -420,11 +419,11 @@ class CategoryController extends Controller
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$first = $repository->firstUseDate($category); $first = $repository->firstUseDate($category);
if (null === $first) { if (null === $first) {
$first = new Carbon; $first = new Carbon; // @codeCoverageIgnore
} }
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$first = Navigation::startOfPeriod($first, $range); $first = app('navigation')->startOfPeriod($first, $range);
$end = Navigation::endOfX(new Carbon, $range, null); $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection; $entries = new Collection;
$count = 0; $count = 0;
@ -439,12 +438,12 @@ class CategoryController extends Controller
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
while ($end >= $first && $count < 90) { while ($end >= $first && $count < 90) {
$end = Navigation::startOfPeriod($end, $range); $end = app('navigation')->startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range); $currentEnd = app('navigation')->endOfPeriod($end, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd); $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd); $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$dateStr = $end->format('Y-m-d'); $dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range); $dateName = app('navigation')->periodShow($end, $range);
// amount transferred // amount transferred
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
@ -465,7 +464,7 @@ class CategoryController extends Controller
'date' => clone $end, 'date' => clone $end,
] ]
); );
$end = Navigation::subtractPeriod($end, $range, 1); $end = app('navigation')->subtractPeriod($end, $range, 1);
++$count; ++$count;
} }
$cache->store($entries); $cache->store($entries);

View File

@ -38,7 +38,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
use Steam; use Steam;
@ -348,7 +347,7 @@ class AccountController extends Controller
public function period(Account $account, Carbon $start) public function period(Account $account, Carbon $start)
{ {
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($start); $cache->addProperty($start);
$cache->addProperty($end); $cache->addProperty($end);

View File

@ -37,7 +37,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
use Steam; use Steam;
@ -81,7 +80,7 @@ class BudgetController extends Controller
{ {
$first = $this->repository->firstUseDate($budget); $first = $this->repository->firstUseDate($budget);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$currentStart = Navigation::startOfPeriod($first, $range); $currentStart = app('navigation')->startOfPeriod($first, $range);
$last = session('end', new Carbon); $last = session('end', new Carbon);
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($first); $cache->addProperty($first);
@ -95,15 +94,15 @@ class BudgetController extends Controller
$final = clone $last; $final = clone $last;
$final->addYears(2); $final->addYears(2);
$budgetCollection = new Collection([$budget]); $budgetCollection = new Collection([$budget]);
$last = Navigation::endOfX($last, $range, $final); // not to overshoot. $last = app('navigation')->endOfX($last, $range, $final); // not to overshoot.
$entries = []; $entries = [];
while ($currentStart < $last) { while ($currentStart < $last) {
// periodspecific dates: // periodspecific dates:
$currentEnd = Navigation::endOfPeriod($currentStart, $range); $currentEnd = app('navigation')->endOfPeriod($currentStart, $range);
// sub another day because reasons. // sub another day because reasons.
$currentEnd->subDay(); $currentEnd->subDay();
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd); $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'); $entries[$format] = bcmul($spent, '-1');
$currentStart = clone $currentEnd; $currentStart = clone $currentEnd;
$currentStart->addDays(2); $currentStart->addDays(2);
@ -374,7 +373,7 @@ class BudgetController extends Controller
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore 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 $entries = $this->repository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end); // get the expenses
$budgeted = $this->getBudgetedInPeriod($budget, $start, $end); $budgeted = $this->getBudgetedInPeriod($budget, $start, $end);
@ -417,7 +416,7 @@ class BudgetController extends Controller
} }
// the expenses: // the expenses:
$periods = Navigation::listOfPeriods($start, $end); $periods = app('navigation')->listOfPeriods($start, $end);
$entries = $this->repository->getNoBudgetPeriodReport($accounts, $start, $end); $entries = $this->repository->getNoBudgetPeriodReport($accounts, $start, $end);
$chartData = []; $chartData = [];
@ -464,13 +463,13 @@ class BudgetController extends Controller
*/ */
private function getBudgetedInPeriod(Budget $budget, Carbon $start, Carbon $end): array private function getBudgetedInPeriod(Budget $budget, Carbon $start, Carbon $end): array
{ {
$key = Navigation::preferredCarbonFormat($start, $end); $key = app('navigation')->preferredCarbonFormat($start, $end);
$range = Navigation::preferredRangeFormat($start, $end); $range = app('navigation')->preferredRangeFormat($start, $end);
$current = clone $start; $current = clone $start;
$budgeted = []; $budgeted = [];
while ($current < $end) { while ($current < $end) {
$currentStart = Navigation::startOfPeriod($current, $range); $currentStart = app('navigation')->startOfPeriod($current, $range);
$currentEnd = Navigation::endOfPeriod($current, $range); $currentEnd = app('navigation')->endOfPeriod($current, $range);
$budgetLimits = $this->repository->getBudgetLimits($budget, $currentStart, $currentEnd); $budgetLimits = $this->repository->getBudgetLimits($budget, $currentStart, $currentEnd);
$index = $currentStart->format($key); $index = $currentStart->format($key);
$budgeted[$index] = $budgetLimits->sum('amount'); $budgeted[$index] = $budgetLimits->sum('amount');

View File

@ -37,7 +37,6 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Response; use Response;
/** /**
@ -135,8 +134,8 @@ class BudgetReportController extends Controller
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$format = Navigation::preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$function = Navigation::preferredEndOfPeriod($start, $end); $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = []; $chartData = [];
$currentStart = clone $start; $currentStart = clone $start;

View File

@ -31,7 +31,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
@ -78,7 +77,7 @@ class CategoryController extends Controller
} }
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = new Carbon; $end = new Carbon;
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$chartData = [ $chartData = [
@ -101,15 +100,15 @@ class CategoryController extends Controller
]; ];
while ($start <= $end) { while ($start <= $end) {
$currentEnd = Navigation::endOfPeriod($start, $range); $currentEnd = app('navigation')->endOfPeriod($start, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $currentEnd); $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $currentEnd); $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
$sum = bcadd($spent, $earned); $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[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12); $chartData[1]['entries'][$label] = round($earned, 12);
$chartData[2]['entries'][$label] = round($sum, 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); $data = $this->generator->multiSet($chartData);
@ -180,7 +179,7 @@ class CategoryController extends Controller
} }
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end); $expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
$income = $repository->periodIncome(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 = [ $chartData = [
[ [
'label' => strval(trans('firefly.spent')), 'label' => strval(trans('firefly.spent')),
@ -236,7 +235,7 @@ class CategoryController extends Controller
} }
$expenses = $repository->periodExpensesNoCategory($accounts, $start, $end); $expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
$income = $repository->periodIncomeNoCategory($accounts, $start, $end); $income = $repository->periodIncomeNoCategory($accounts, $start, $end);
$periods = Navigation::listOfPeriods($start, $end); $periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [ $chartData = [
[ [
'label' => strval(trans('firefly.spent')), 'label' => strval(trans('firefly.spent')),
@ -281,8 +280,8 @@ class CategoryController extends Controller
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date) public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
{ {
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($date, $range); $start = app('navigation')->startOfPeriod($date, $range);
$end = Navigation::endOfPeriod($date, $range); $end = app('navigation')->endOfPeriod($date, $range);
$data = $this->makePeriodChart($repository, $category, $start, $end); $data = $this->makePeriodChart($repository, $category, $start, $end);
return Response::json($data); return Response::json($data);
@ -336,7 +335,7 @@ class CategoryController extends Controller
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start); $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start); $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start);
$sum = bcadd($spent, $earned); $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[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12); $chartData[1]['entries'][$label] = round($earned, 12);

View File

@ -36,7 +36,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Response; use Response;
/** /**
@ -177,8 +176,8 @@ class CategoryReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$format = Navigation::preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$function = Navigation::preferredEndOfPeriod($start, $end); $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = []; $chartData = [];
$currentStart = clone $start; $currentStart = clone $start;

View File

@ -33,7 +33,6 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Response; use Response;
/** /**
@ -86,8 +85,8 @@ class ExpenseReportController extends Controller
// return Response::json($cache->get()); // @codeCoverageIgnore // return Response::json($cache->get()); // @codeCoverageIgnore
} }
$format = Navigation::preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$function = Navigation::preferredEndOfPeriod($start, $end); $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = []; $chartData = [];
$currentStart = clone $start; $currentStart = clone $start;
$combined = $this->combineAccounts($expense); $combined = $this->combineAccounts($expense);

View File

@ -29,7 +29,6 @@ use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Response; use Response;
use Steam; use Steam;
@ -109,7 +108,7 @@ class ReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray()); 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); $source = $this->getChartData($accounts, $start, $end);
$chartData = [ $chartData = [
[ [
@ -256,7 +255,7 @@ class ReportController extends Controller
$tasker = app(AccountTaskerInterface::class); $tasker = app(AccountTaskerInterface::class);
while ($currentStart <= $end) { while ($currentStart <= $end) {
$currentEnd = Navigation::endOfPeriod($currentStart, '1M'); $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
$earned = strval( $earned = strval(
array_sum( array_sum(
array_map( array_map(
@ -282,7 +281,7 @@ class ReportController extends Controller
$label = $currentStart->format('Y-m') . '-01'; $label = $currentStart->format('Y-m') . '-01';
$spentArray[$label] = bcmul($spent, '-1'); $spentArray[$label] = bcmul($spent, '-1');
$earnedArray[$label] = $earned; $earnedArray[$label] = $earned;
$currentStart = Navigation::addPeriod($currentStart, '1M', 0); $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
} }
$result = [ $result = [
'spent' => $spentArray, 'spent' => $spentArray,

View File

@ -36,7 +36,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Response; use Response;
class TagReportController extends Controller class TagReportController extends Controller
@ -168,8 +167,8 @@ class TagReportController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$format = Navigation::preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$function = Navigation::preferredEndOfPeriod($start, $end); $function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = []; $chartData = [];
$currentStart = clone $start; $currentStart = clone $start;

View File

@ -126,7 +126,7 @@ class Controller extends BaseController
$uri = $this->redirectUri; $uri = $this->redirectUri;
} }
if (!(false === strpos($uri, 'jscript'))) { if (!(false === strpos($uri, 'jscript'))) {
$uri = $this->redirectUri; $uri = $this->redirectUri; // @codeCoverageIgnore
} }
return $uri; return $uri;

View File

@ -239,6 +239,9 @@ class HomeController extends Controller
); );
} }
/**
* @return string
*/
public function routes() public function routes()
{ {
$set = RouteFacade::getRoutes(); $set = RouteFacade::getRoutes();
@ -249,7 +252,7 @@ class HomeController extends Controller
'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch', 'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
'two-factor.lost', 'report.options', 'two-factor.lost', 'report.options',
]; ];
$return = '&nbsp;';
/** @var Route $route */ /** @var Route $route */
foreach ($set as $route) { foreach ($set as $route) {
$name = $route->getName(); $name = $route->getName();
@ -261,12 +264,12 @@ class HomeController extends Controller
} }
} }
if (!$found) { if (!$found) {
echo 'touch ' . $route->getName() . '.md;'; $return .= 'touch ' . $route->getName() . '.md;';
} }
} }
} }
return '&nbsp;'; return $return;
} }
/** /**

View File

@ -138,13 +138,14 @@ class JavascriptController extends Controller
$end = session('end'); $end = session('end');
$first = session('first'); $first = session('first');
$title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat)); $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; $today = new Carbon;
$ranges = [ $ranges = [
// first range is the current range: // first range is the current range:
$title => [$start, $end], $title => [$start, $end],
]; ];
Log::debug(sprintf('viewRange is %s', $viewRange)); 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. // when current range is a custom range, add the current period as the next range.
if ($isCustom) { if ($isCustom) {

View File

@ -91,30 +91,32 @@ class ProfileController extends Controller
} }
/** /**
* @param string $token * @param UserRepositoryInterface $repository
* @param string $token
* *
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*
* @throws FireflyException * @throws FireflyException
*/ */
public function confirmEmailChange(string $token) public function confirmEmailChange(UserRepositoryInterface $repository, string $token)
{ {
// find preference with this token value. // find preference with this token value.
$set = Preferences::findByName('email_change_confirm_token'); $set = Preferences::findByName('email_change_confirm_token');
$user = null; $user = null;
Log::debug(sprintf('Found %d preferences', $set->count()));
/** @var Preference $preference */ /** @var Preference $preference */
foreach ($set as $preference) { foreach ($set as $preference) {
if ($preference->data === $token) { if ($preference->data === $token) {
Log::debug('Found user');
$user = $preference->user; $user = $preference->user;
} }
} }
// update user to clear blocked and blocked_code. // update user to clear blocked and blocked_code.
if (null === $user) { if (null === $user) {
Log::debug('Found no user');
throw new FireflyException('Invalid token.'); throw new FireflyException('Invalid token.');
} }
$user->blocked = 0; Log::debug('Will unblock user.');
$user->blocked_code = ''; $repository->unblockUser($user);
$user->save();
// return to login. // return to login.
Session::flash('success', strval(trans('firefly.login_with_new_email'))); Session::flash('success', strval(trans('firefly.login_with_new_email')));
@ -172,7 +174,7 @@ class ProfileController extends Controller
$existing = $repository->findByEmail($newEmail); $existing = $repository->findByEmail($newEmail);
if (null !== $existing) { if (null !== $existing) {
// force user logout. // force user logout.
$this->guard()->logout(); Auth::guard()->logout();
$request->session()->invalidate(); $request->session()->invalidate();
Session::flash('success', strval(trans('firefly.email_changed'))); 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() public function regenerate()
{ {
@ -264,7 +266,7 @@ class ProfileController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
public function undoEmailChange(string $token, string $hash) public function undoEmailChange(UserRepositoryInterface $repository, string $token, string $hash)
{ {
// find preference with this token value. // find preference with this token value.
$set = Preferences::findByName('email_change_undo_token'); $set = Preferences::findByName('email_change_undo_token');
@ -282,6 +284,7 @@ class ProfileController extends Controller
// found user. // found user.
// which email address to return to? // which email address to return to?
$set = Preferences::beginsWith($user, 'previous_email_'); $set = Preferences::beginsWith($user, 'previous_email_');
/** @var string $match */
$match = null; $match = null;
foreach ($set as $entry) { foreach ($set as $entry) {
$hashed = hash('sha256', $entry->data); $hashed = hash('sha256', $entry->data);
@ -294,10 +297,9 @@ class ProfileController extends Controller
throw new FireflyException('Invalid token.'); throw new FireflyException('Invalid token.');
} }
// change user back // change user back
$user->email = $match; // now actually update user:
$user->blocked = 0; $repository->changeEmail($user, $match);
$user->blocked_code = ''; $repository->unblockUser($user);
$user->save();
// return to login. // return to login.
Session::flash('success', strval(trans('firefly.login_with_old_email'))); Session::flash('success', strval(trans('firefly.login_with_old_email')));

View File

@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
/** /**
* Class BudgetController. * Class BudgetController.
@ -88,7 +87,7 @@ class BudgetController extends Controller
$data = $repository->getBudgetPeriodReport($budgets, $accounts, $start, $end); $data = $repository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
$data[0] = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget" $data[0] = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget"
$report = $this->filterBudgetPeriodReport($data); $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(); $result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
$cache->store($result); $cache->store($result);

View File

@ -28,7 +28,6 @@ use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
/** /**
* Class CategoryController. * Class CategoryController.
@ -58,7 +57,7 @@ class CategoryController extends Controller
$data = $repository->periodExpenses($categories, $accounts, $start, $end); $data = $repository->periodExpenses($categories, $accounts, $start, $end);
$data[0] = $repository->periodExpensesNoCategory($accounts, $start, $end); $data[0] = $repository->periodExpensesNoCategory($accounts, $start, $end);
$report = $this->filterReport($data); $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(); $result = view('reports.partials.category-period', compact('report', 'periods'))->render();
$cache->store($result); $cache->store($result);
@ -89,7 +88,7 @@ class CategoryController extends Controller
$data = $repository->periodIncome($categories, $accounts, $start, $end); $data = $repository->periodIncome($categories, $accounts, $start, $end);
$data[0] = $repository->periodIncomeNoCategory($accounts, $start, $end); $data[0] = $repository->periodIncomeNoCategory($accounts, $start, $end);
$report = $this->filterReport($data); $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(); $result = view('reports.partials.category-period', compact('report', 'periods'))->render();
$cache->store($result); $cache->store($result);

View File

@ -70,6 +70,7 @@ class ReportController extends Controller
/** /**
* @param Collection $accounts * @param Collection $accounts
* @param Collection $expense
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
@ -79,7 +80,7 @@ class ReportController extends Controller
public function accountReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end) public function accountReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)
{ {
if ($end < $start) { 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')) { if ($start < session('first')) {

View File

@ -363,11 +363,11 @@ class RuleController extends Controller
$triggers = $this->getValidTriggerList($request); $triggers = $this->getValidTriggerList($request);
if (0 === count($triggers)) { 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'); $limit = intval(config('firefly.test-triggers.limit'));
$range = config('firefly.test-triggers.range'); $range = intval(config('firefly.test-triggers.range'));
/** @var TransactionMatcher $matcher */ /** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class); $matcher = app(TransactionMatcher::class);
@ -379,10 +379,10 @@ class RuleController extends Controller
// Warn the user if only a subset of transactions is returned // Warn the user if only a subset of transactions is returned
$warning = ''; $warning = '';
if (count($matchingTransactions) === $limit) { 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)) { 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 // Return json response
@ -403,6 +403,7 @@ class RuleController extends Controller
* @param Rule $rule * @param Rule $rule
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* @throws \Throwable
*/ */
public function testTriggersByRule(Rule $rule) public function testTriggersByRule(Rule $rule)
{ {
@ -412,8 +413,8 @@ class RuleController extends Controller
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]); return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
} }
$limit = config('firefly.test-triggers.limit'); $limit = intval(config('firefly.test-triggers.limit'));
$range = config('firefly.test-triggers.range'); $range = intval(config('firefly.test-triggers.range'));
/** @var TransactionMatcher $matcher */ /** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class); $matcher = app(TransactionMatcher::class);
@ -425,10 +426,10 @@ class RuleController extends Controller
// Warn the user if only a subset of transactions is returned // Warn the user if only a subset of transactions is returned
$warning = ''; $warning = '';
if (count($matchingTransactions) === $limit) { 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)) { 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 // Return json response

View File

@ -31,7 +31,6 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Navigation;
use Preferences; use Preferences;
use Session; use Session;
use View; use View;
@ -216,7 +215,7 @@ class TagController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans( $subTitle = trans(
'firefly.journals_in_period_for_tag', 'firefly.journals_in_period_for_tag',
['tag' => $tag->tag, ['tag' => $tag->tag,
@ -229,9 +228,9 @@ class TagController extends Controller
// prep for current period // prep for current period
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
/** @var Carbon $start */ /** @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 */ /** @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); $periods = $this->getPeriodOverview($tag);
$subTitle = trans( $subTitle = trans(
'firefly.journals_in_period_for_tag', 'firefly.journals_in_period_for_tag',
@ -310,8 +309,8 @@ class TagController extends Controller
{ {
// get first and last tag date from tag: // get first and last tag date from tag:
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range); $start = app('navigation')->startOfPeriod($this->repository->firstUseDate($tag), $range);
$end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range); $end = app('navigation')->startOfPeriod($this->repository->lastUseDate($tag), $range);
// properties for entries with their amounts. // properties for entries with their amounts.
$cache = new CacheProperties; $cache = new CacheProperties;
$cache->addProperty($start); $cache->addProperty($start);
@ -327,19 +326,19 @@ class TagController extends Controller
// while end larger or equal to start // while end larger or equal to start
while ($end >= $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. // get expenses and what-not in this period and this tag.
$arr = [ $arr = [
'string' => $end->format('Y-m-d'), 'string' => $end->format('Y-m-d'),
'name' => Navigation::periodShow($end, $range), 'name' => app('navigation')->periodShow($end, $range),
'date' => clone $end, 'date' => clone $end,
'spent' => $this->repository->spentInperiod($tag, $end, $currentEnd), 'spent' => $this->repository->spentInperiod($tag, $end, $currentEnd),
'earned' => $this->repository->earnedInperiod($tag, $end, $currentEnd), 'earned' => $this->repository->earnedInperiod($tag, $end, $currentEnd),
]; ];
$collection->push($arr); $collection->push($arr);
$end = Navigation::subtractPeriod($end, $range, 1); $end = app('navigation')->subtractPeriod($end, $range, 1);
} }
$cache->store($collection); $cache->store($collection);

View File

@ -36,7 +36,6 @@ use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
use Response; use Response;
use View; use View;
@ -96,7 +95,7 @@ class TransactionController extends Controller
// prep for "specific date" view. // prep for "specific date" view.
if (strlen($moment) > 0 && 'all' !== $moment) { if (strlen($moment) > 0 && 'all' !== $moment) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$path = route('transactions.index', [$what, $moment]); $path = route('transactions.index', [$what, $moment]);
$subTitle = trans( $subTitle = trans(
'firefly.title_' . $what . '_between', 'firefly.title_' . $what . '_between',
@ -107,8 +106,8 @@ class TransactionController extends Controller
// prep for current period // prep for current period
if (0 === strlen($moment)) { if (0 === strlen($moment)) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview($what); $periods = $this->getPeriodOverview($what);
$subTitle = trans( $subTitle = trans(
'firefly.title_' . $what . '_between', 'firefly.title_' . $what . '_between',
@ -206,8 +205,8 @@ class TransactionController extends Controller
$first = $repository->first(); $first = $repository->first();
$start = $first->date ?? new Carbon; $start = $first->date ?? new Carbon;
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range, null); $end = app('navigation')->endOfX(new Carbon, $range, null);
$entries = new Collection; $entries = new Collection;
$types = config('firefly.transactionTypesByWhat.' . $what); $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'))); 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) { while ($end >= $start) {
Log::debug('Loop start!'); Log::debug('Loop start!');
$end = Navigation::startOfPeriod($end, $range); $end = app('navigation')->startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range); $currentEnd = app('navigation')->endOfPeriod($end, $range);
// count journals without budget in this period: // count journals without budget in this period:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
@ -239,7 +238,7 @@ class TransactionController extends Controller
// count per currency: // count per currency:
$sums = $this->sumPerCurrency($journals); $sums = $this->sumPerCurrency($journals);
$dateStr = $end->format('Y-m-d'); $dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range); $dateName = app('navigation')->periodShow($end, $range);
$array = [ $array = [
'string' => $dateStr, 'string' => $dateStr,
'name' => $dateName, 'name' => $dateName,
@ -251,7 +250,7 @@ class TransactionController extends Controller
if ($journals->count() > 0) { if ($journals->count() > 0) {
$entries->push($array); $entries->push($array);
} }
$end = Navigation::subtractPeriod($end, $range, 1); $end = app('navigation')->subtractPeriod($end, $range, 1);
} }
Log::debug('End of loop'); Log::debug('End of loop');
$cache->store($entries); $cache->store($entries);

View File

@ -29,7 +29,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Navigation;
use Preferences; use Preferences;
use Session; use Session;
use View; use View;
@ -126,8 +125,8 @@ class Range
if (!Session::has('start') && !Session::has('end')) { if (!Session::has('start') && !Session::has('end')) {
$viewRange = Preferences::get('viewRange', '1M')->data; $viewRange = Preferences::get('viewRange', '1M')->data;
$start = new Carbon; $start = new Carbon;
$start = Navigation::updateStartDate($viewRange, $start); $start = app('navigation')->updateStartDate($viewRange, $start);
$end = Navigation::updateEndDate($viewRange, $start); $end = app('navigation')->updateEndDate($viewRange, $start);
Session::put('start', $start); Session::put('start', $start);
Session::put('end', $end); Session::put('end', $end);

View File

@ -595,6 +595,15 @@ Breadcrumbs::register(
$breadcrumbs->push(trans('breadcrumbs.changePassword'), route('profile.change-password')); $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( Breadcrumbs::register(
'profile.delete-account', 'profile.delete-account',
function (BreadCrumbGenerator $breadcrumbs) { function (BreadCrumbGenerator $breadcrumbs) {
@ -757,22 +766,21 @@ Breadcrumbs::register(
); );
Breadcrumbs::register( Breadcrumbs::register(
'rule-groups.select-transactions', 'rules.select-transactions',
function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) { function (BreadCrumbGenerator $breadcrumbs, Rule $rule) {
$breadcrumbs->parent('rules.index'); $breadcrumbs->parent('rules.index');
$breadcrumbs->push( $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( Breadcrumbs::register(
'rule-groups.select_transactions', 'rule-groups.select-transactions',
function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) { function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) {
$breadcrumbs->parent('rules.index'); $breadcrumbs->parent('rules.index');
$breadcrumbs->push( $breadcrumbs->push(
trans('firefly.execute_group_on_existing_transactions', ['title' => $ruleGroup->title]), trans('firefly.rule_group_select_transactions', ['title' => $ruleGroup->title]), route('rule-groups.select-transactions', [$ruleGroup])
route('rule-groups.select_transactions', [$ruleGroup])
); );
} }
); );

View File

@ -117,6 +117,15 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
return $this->user; return $this->user;
} }
/**
* @return Rule
*/
public function getRule(): Rule
{
return $this->rule;
}
/** /**
* @param User $user * @param User $user
*/ */

View File

@ -223,6 +223,18 @@ class UserRepository implements UserRepositoryInterface
return $user->hasRole($role); 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. * 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. * The user is NOT blocked.

View File

@ -122,6 +122,11 @@ interface UserRepositoryInterface
*/ */
public function hasRole(User $user, string $role): bool; 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. * 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. * The user is NOT blocked.

View File

@ -29,6 +29,7 @@ return [
'preferences' => 'Preferences', 'preferences' => 'Preferences',
'profile' => 'Profile', 'profile' => 'Profile',
'changePassword' => 'Change your password', 'changePassword' => 'Change your password',
'change_email' => 'Change your email address',
'bills' => 'Bills', 'bills' => 'Bills',
'newBill' => 'New bill', 'newBill' => 'New bill',
'edit_bill' => 'Edit bill ":name"', 'edit_bill' => 'Edit bill ":name"',

View File

@ -711,6 +711,8 @@ return [
'deleted_transfer' => 'Successfully deleted transfer ":description"', 'deleted_transfer' => 'Successfully deleted transfer ":description"',
'stored_journal' => 'Successfully created new transaction ":description"', 'stored_journal' => 'Successfully created new transaction ":description"',
'select_transactions' => 'Select transactions', 'select_transactions' => 'Select transactions',
'rule_group_select_transactions' => 'Apply ":title" to transactions',
'rule_select_transactions' => 'Apply ":title" to transactions',
'stop_selection' => 'Stop selecting transactions', 'stop_selection' => 'Stop selecting transactions',
'reconcile_selected' => 'Reconcile', 'reconcile_selected' => 'Reconcile',
'mass_delete_journals' => 'Delete a number of transactions', 'mass_delete_journals' => 'Delete a number of transactions',

View File

@ -110,6 +110,7 @@ class BillControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\BillController::index * @covers \FireflyIII\Http\Controllers\BillController::index
* @covers \FireflyIII\Http\Controllers\BillController::__construct * @covers \FireflyIII\Http\Controllers\BillController::__construct
* @covers \FireflyIII\Http\Controllers\BillController::lastPaidDate
*/ */
public function testIndex() public function testIndex()
{ {

View File

@ -43,6 +43,21 @@ use Tests\TestCase;
*/ */
class BudgetControllerTest extends 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 * @covers \FireflyIII\Http\Controllers\BudgetController::amount
*/ */

View File

@ -206,9 +206,11 @@ class CurrencyControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class);
$currencies = factory(TransactionCurrency::class, 3)->make();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency); $repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
$repository->shouldReceive('get')->andReturn(new Collection); $repository->shouldReceive('get')->andReturn($currencies);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true); $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$this->be($this->user()); $this->be($this->user());

View File

@ -86,6 +86,16 @@ class HomeControllerTest extends TestCase
$response->assertSessionHas('warning', '91 days of data may take a while to load.'); $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 * @covers \FireflyIII\Http\Controllers\HomeController::displayError
*/ */
@ -170,6 +180,16 @@ class HomeControllerTest extends TestCase
$response->assertStatus(302); $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 * @covers \FireflyIII\Http\Controllers\HomeController::testFlash
*/ */

View File

@ -1,225 +0,0 @@
<?php
/**
* FileControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\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']));
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* ImportControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers;
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">');
}
}

View File

@ -86,4 +86,21 @@ class JavascriptControllerTest extends TestCase
$response = $this->get(route('javascript.variables')); $response = $this->get(route('javascript.variables'));
$response->assertStatus(200); $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);
}
} }

View File

@ -86,9 +86,10 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->times(2); $accountRepos->shouldReceive('store')->times(2);
$data = [ $data = [
'bank_name' => 'New bank', 'bank_name' => 'New bank',
'savings_balance' => '1000', 'savings_balance' => '1000',
'bank_balance' => '100', 'bank_balance' => '100',
'amount_currency_id_bank_balance' => 1,
]; ];
$this->be($this->emptyUser()); $this->be($this->emptyUser());
$response = $this->post(route('new-user.submit'), $data); $response = $this->post(route('new-user.submit'), $data);
@ -108,8 +109,9 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->twice(); $accountRepos->shouldReceive('store')->twice();
$data = [ $data = [
'bank_name' => 'New bank', 'bank_name' => 'New bank',
'bank_balance' => '100', 'bank_balance' => '100',
'amount_currency_id_bank_balance' => 1,
]; ];
$this->be($this->emptyUser()); $this->be($this->emptyUser());
$response = $this->post(route('new-user.submit'), $data); $response = $this->post(route('new-user.submit'), $data);

View File

@ -22,9 +22,13 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@ -36,6 +40,18 @@ use Tests\TestCase;
*/ */
class ProfileControllerTest extends 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 * @covers \FireflyIII\Http\Controllers\ProfileController::changePassword
*/ */
@ -51,6 +67,36 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $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 * @covers \FireflyIII\Http\Controllers\ProfileController::deleteAccount
*/ */
@ -72,6 +118,8 @@ class ProfileControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
// delete access token.
Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->delete();
// mock stuff // mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -82,6 +130,58 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $response->assertSee('<ol class="breadcrumb">');
} }
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangeEmail
*/
public function testPostChangeEmail()
{
$data = [
'email' => 'new@example.com',
];
$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' => 'existing@example.com',
];
$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::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword * @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
@ -187,4 +287,92 @@ class ProfileControllerTest extends TestCase
$response->assertRedirect(route('profile.delete-account')); $response->assertRedirect(route('profile.delete-account'));
$response->assertSessionHas('error'); $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', 'previous@example.com');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @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', 'previous@example.comX');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @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);
}
} }

View File

@ -22,12 +22,14 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use FireflyIII\Generator\Report\Account\YearReportGenerator as AcYRG;
use FireflyIII\Generator\Report\Audit\YearReportGenerator as AYRG; use FireflyIII\Generator\Report\Audit\YearReportGenerator as AYRG;
use FireflyIII\Generator\Report\Budget\YearReportGenerator as BYRG; use FireflyIII\Generator\Report\Budget\YearReportGenerator as BYRG;
use FireflyIII\Generator\Report\Category\YearReportGenerator as CYRG; use FireflyIII\Generator\Report\Category\YearReportGenerator as CYRG;
use FireflyIII\Generator\Report\Standard\YearReportGenerator as SYRG; use FireflyIII\Generator\Report\Standard\YearReportGenerator as SYRG;
use FireflyIII\Generator\Report\Tag\YearReportGenerator as TYRG; use FireflyIII\Generator\Report\Tag\YearReportGenerator as TYRG;
use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
@ -50,6 +52,26 @@ use Tests\TestCase;
*/ */
class ReportControllerTest extends 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 * @covers \FireflyIII\Http\Controllers\ReportController::auditReport
*/ */
@ -172,6 +194,28 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200); $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::options
* @covers \FireflyIII\Http\Controllers\ReportController::budgetReportOptions * @covers \FireflyIII\Http\Controllers\ReportController::budgetReportOptions
@ -224,6 +268,27 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200); $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 * @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/ */

View File

@ -22,15 +22,19 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Jobs\Job;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher; use FireflyIII\TransactionRules\TransactionMatcher;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Queue;
use Tests\TestCase; use Tests\TestCase;
/** /**
@ -183,6 +187,31 @@ class RuleControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $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::index
* @covers \FireflyIII\Http\Controllers\RuleController::__construct * @covers \FireflyIII\Http\Controllers\RuleController::__construct
@ -245,6 +274,20 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200); $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 * @covers \FireflyIII\Http\Controllers\RuleController::store
*/ */
@ -312,6 +355,25 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200); $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. * This actually hits an error and not the actually code but OK.
* *