mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-10-13 17:02:06 -05:00
Expand test coverage.
This commit is contained in:
82 files changed
+1413
-142
No files matched your search
@@ -276,6 +276,9 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('info-income');
|
||||
|
||||
Log::debug(sprintf('infoIncome start is %s', $start->format('Y-m-d')));
|
||||
Log::debug(sprintf('infoIncome end is %s', $end->format('Y-m-d')));
|
||||
|
||||
if ($cache->has()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$result = $cache->get();
|
||||
@@ -292,18 +295,24 @@ class BudgetController extends Controller
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$begin = app('navigation')->subtractPeriod($start, $range, 3);
|
||||
|
||||
Log::debug(sprintf('Range is %s', $range));
|
||||
Log::debug(sprintf('infoIncome begin is %s', $begin->format('Y-m-d')));
|
||||
|
||||
// get average amount available.
|
||||
$total = '0';
|
||||
$count = 0;
|
||||
$currentStart = clone $begin;
|
||||
while ($currentStart < $start) {
|
||||
Log::debug(sprintf('Loop: currentStart is %s', $currentStart->format('Y-m-d')));
|
||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, $range);
|
||||
$total = bcadd($total, $this->repository->getAvailableBudget($currency, $currentStart, $currentEnd));
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $range, 0);
|
||||
++$count;
|
||||
}
|
||||
Log::debug('Loop end');
|
||||
|
||||
if (0 === $count) {
|
||||
$count = 1; // @codeCoverageIgnore
|
||||
$count = 1;
|
||||
}
|
||||
$result['available'] = bcdiv($total, strval($count));
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class IndexController extends Controller
|
||||
public function create(string $bank)
|
||||
{
|
||||
if (true === !(config(sprintf('import.enabled.%s', $bank)))) {
|
||||
throw new FireflyException(sprintf('Cannot import from "%s" at this time.', $bank));
|
||||
throw new FireflyException(sprintf('Cannot import from "%s" at this time.', $bank)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$importJob = $this->repository->create($bank);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
@@ -33,6 +34,25 @@ use Log;
|
||||
*/
|
||||
class PrerequisitesController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', trans('firefly.import_index_title'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
$this->middleware(IsDemoUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once there are no prerequisites, this method will create an importjob object and
|
||||
* redirect the user to a view where this object can be used by a bank specific
|
||||
@@ -47,11 +67,11 @@ class PrerequisitesController extends Controller
|
||||
public function index(string $bank)
|
||||
{
|
||||
if (true === !(config(sprintf('import.enabled.%s', $bank)))) {
|
||||
throw new FireflyException(sprintf('Cannot import from "%s" at this time.', $bank));
|
||||
throw new FireflyException(sprintf('Cannot import from "%s" at this time.', $bank)); // @codeCoverageIgnore
|
||||
}
|
||||
$class = strval(config(sprintf('import.prerequisites.%s', $bank)));
|
||||
if (!class_exists($class)) {
|
||||
throw new FireflyException(sprintf('No class to handle "%s".', $bank));
|
||||
throw new FireflyException(sprintf('No class to handle "%s".', $bank)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var PrerequisitesInterface $object */
|
||||
@@ -61,7 +81,7 @@ class PrerequisitesController extends Controller
|
||||
if ($object->hasPrerequisites()) {
|
||||
$view = $object->getView();
|
||||
$parameters = ['title' => strval(trans('firefly.import_index_title')), 'mainTitleIcon' => 'fa-archive'];
|
||||
$parameters = $object->getViewParameters() + $parameters;
|
||||
$parameters = array_merge($object->getViewParameters(), $parameters);
|
||||
|
||||
return view($view, $parameters);
|
||||
}
|
||||
@@ -88,9 +108,14 @@ class PrerequisitesController extends Controller
|
||||
public function post(Request $request, string $bank)
|
||||
{
|
||||
Log::debug(sprintf('Now in postPrerequisites for %s', $bank));
|
||||
|
||||
if (true === !(config(sprintf('import.enabled.%s', $bank)))) {
|
||||
throw new FireflyException(sprintf('Cannot import from "%s" at this time.', $bank)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$class = strval(config(sprintf('import.prerequisites.%s', $bank)));
|
||||
if (!class_exists($class)) {
|
||||
throw new FireflyException(sprintf('Cannot find class %s', $class));
|
||||
throw new FireflyException(sprintf('Cannot find class %s', $class)); // @codeCoverageIgnore
|
||||
}
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
@@ -106,10 +131,8 @@ class PrerequisitesController extends Controller
|
||||
|
||||
if ($result->count() > 0) {
|
||||
$request->session()->flash('error', $result->first());
|
||||
|
||||
return redirect(route('import.prerequisites', [$bank]));
|
||||
}
|
||||
|
||||
return redirect(route('import.create-job', [$bank]));
|
||||
return redirect(route('import.prerequisites', [$bank]));
|
||||
}
|
||||
}
|
||||
@@ -56,9 +56,9 @@ class StatusController extends Controller
|
||||
*/
|
||||
public function index(ImportJob $job)
|
||||
{
|
||||
$statuses = ['configured', 'running', 'finished', 'errored'];
|
||||
$statuses = ['configured', 'running', 'finished', 'error'];
|
||||
if (!in_array($job->status, $statuses)) {
|
||||
return redirect(route('import.file.configure', [$job->key]));
|
||||
return redirect(route('import.configure', [$job->key]));
|
||||
}
|
||||
$subTitle = trans('import.status_sub_title');
|
||||
$subTitleIcon = 'fa-star';
|
||||
@@ -108,7 +108,7 @@ class StatusController extends Controller
|
||||
$result['running'] = true;
|
||||
}
|
||||
|
||||
// TODO cannot handle 'errored'
|
||||
// TODO cannot handle 'error'
|
||||
|
||||
return Response::json($result);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Log;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
@@ -81,7 +82,7 @@ class AutoCompleteController extends Controller
|
||||
$set = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
||||
$filtered = $set->filter(
|
||||
function (Account $account) {
|
||||
if ($account->active) {
|
||||
if ($account->active === true) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ class AutoCompleteController extends Controller
|
||||
$set = $repository->getAccountsByType([AccountType::REVENUE]);
|
||||
$filtered = $set->filter(
|
||||
function (Account $account) {
|
||||
if ($account->active) {
|
||||
if ($account->active === true) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ use Response;
|
||||
class IntroController
|
||||
{
|
||||
/**
|
||||
* Get the intro steps. There are currently no specific routes with an outro step.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $specificPage
|
||||
*
|
||||
@@ -39,12 +41,15 @@ class IntroController
|
||||
*/
|
||||
public function getIntroSteps(string $route, string $specificPage = '')
|
||||
{
|
||||
Log::debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage));
|
||||
$steps = $this->getBasicSteps($route);
|
||||
$specificSteps = $this->getSpecificSteps($route, $specificPage);
|
||||
if (0 === count($specificSteps)) {
|
||||
Log::debug(sprintf('No specific steps for route "%s" and page "%s"', $route, $specificPage));
|
||||
return Response::json($steps);
|
||||
}
|
||||
if ($this->hasOutroStep($route)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// save last step:
|
||||
$lastStep = $steps[count($steps) - 1];
|
||||
// remove last step:
|
||||
@@ -52,6 +57,7 @@ class IntroController
|
||||
// merge arrays and add last step again
|
||||
$steps = array_merge($steps, $specificSteps);
|
||||
$steps[] = $lastStep;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (!$this->hasOutroStep($route)) {
|
||||
$steps = array_merge($steps, $specificSteps);
|
||||
@@ -68,13 +74,16 @@ class IntroController
|
||||
public function hasOutroStep(string $route): bool
|
||||
{
|
||||
$routeKey = str_replace('.', '_', $route);
|
||||
Log::debug(sprintf('Has outro step for route %s', $routeKey));
|
||||
$elements = config(sprintf('intro.%s', $routeKey));
|
||||
if (!is_array($elements)) {
|
||||
return false;
|
||||
}
|
||||
$keys = array_keys($elements);
|
||||
Log::debug('Elements is array', $elements);
|
||||
Log::debug('Keys is', array_keys($elements));
|
||||
Log::debug(sprintf('Keys has "outro": %s', var_export(in_array('outro', array_keys($elements)), true)));
|
||||
|
||||
return in_array('outro', $keys);
|
||||
return in_array('outro', array_keys($elements));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +144,7 @@ class IntroController
|
||||
$steps[] = $currentStep;
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
|
||||
|
||||
return $steps;
|
||||
}
|
||||
@@ -147,7 +157,8 @@ class IntroController
|
||||
*/
|
||||
private function getSpecificSteps(string $route, string $specificPage): array
|
||||
{
|
||||
$steps = [];
|
||||
$steps = [];
|
||||
$routeKey = '';
|
||||
|
||||
// user is on page with specific instructions:
|
||||
if (strlen($specificPage) > 0) {
|
||||
@@ -165,6 +176,7 @@ class IntroController
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Total specific steps for route "%s" and page "%s" (routeKey is "%s") is %d', $route, $specificPage, $routeKey, count($steps)));
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ class LinkController extends Controller
|
||||
JournalRepositoryInterface $journalRepository,
|
||||
TransactionJournal $journal
|
||||
) {
|
||||
Log::debug('We are here (store)');
|
||||
$linkInfo = $request->getLinkInfo();
|
||||
if (0 === $linkInfo['transaction_journal_id']) {
|
||||
Session::flash('error', trans('firefly.invalid_link_selection'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
$linkType = $repository->find($linkInfo['link_type_id']);
|
||||
$other = $journalRepository->find($linkInfo['transaction_journal_id']);
|
||||
$alreadyLinked = $repository->findLink($journal, $other);
|
||||
if ($alreadyLinked) {
|
||||
@@ -115,22 +115,7 @@ class LinkController extends Controller
|
||||
}
|
||||
Log::debug(sprintf('Journal is %d, opposing is %d', $journal->id, $other->id));
|
||||
|
||||
$journalLink = new TransactionJournalLink;
|
||||
$journalLink->linkType()->associate($linkType);
|
||||
if ('inward' === $linkInfo['direction']) {
|
||||
Log::debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->inward, $other->id, $journal->id));
|
||||
$journalLink->source()->associate($other);
|
||||
$journalLink->destination()->associate($journal);
|
||||
}
|
||||
|
||||
if ('outward' === $linkInfo['direction']) {
|
||||
Log::debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->outward, $journal->id, $other->id));
|
||||
$journalLink->source()->associate($journal);
|
||||
$journalLink->destination()->associate($other);
|
||||
}
|
||||
|
||||
$journalLink->comment = $linkInfo['comments'];
|
||||
$journalLink->save();
|
||||
$repository->storeLink($linkInfo, $other, $journal);
|
||||
Session::flash('success', trans('firefly.journals_linked'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
|
||||
@@ -143,7 +143,7 @@ class SingleController extends Controller
|
||||
];
|
||||
|
||||
/** @var Note $note */
|
||||
$note = $journal->notes()->first();
|
||||
$note = $this->repository->getNote($journal);
|
||||
if (null !== $note) {
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ class SingleController extends Controller
|
||||
'destination_currency' => $foreignCurrency,
|
||||
];
|
||||
/** @var Note $note */
|
||||
$note = $journal->notes()->first();
|
||||
$note = $this->repository->getNote($journal);
|
||||
if (null !== $note) {
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user