mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve test coverage and efficiency for accounts and budgets.
This commit is contained in:
parent
8f25562923
commit
43d753e5bd
@ -319,11 +319,13 @@ class TransferCurrenciesCorrections extends Command
|
|||||||
// both accounts must have currency preference:
|
// both accounts must have currency preference:
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
if ($this->isNoCurrencyPresent()) {
|
if ($this->isNoCurrencyPresent()) {
|
||||||
|
$this->error(
|
||||||
|
sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
|
||||||
// fix source transaction having no currency.
|
// fix source transaction having no currency.
|
||||||
$this->fixSourceNoCurrency();
|
$this->fixSourceNoCurrency();
|
||||||
|
|
||||||
@ -397,8 +399,6 @@ class TransferCurrenciesCorrections extends Command
|
|||||||
null === $this->sourceTransaction->foreign_amount &&
|
null === $this->sourceTransaction->foreign_amount &&
|
||||||
(int)$this->sourceTransaction->transaction_currency_id !== (int)$this->sourceCurrency->id
|
(int)$this->sourceTransaction->transaction_currency_id !== (int)$this->sourceCurrency->id
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
||||||
$this->sourceTransaction->id,
|
$this->sourceTransaction->id,
|
||||||
|
@ -24,7 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Controllers\Account;
|
namespace FireflyIII\Http\Controllers\Account;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use Exception;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
@ -36,7 +36,6 @@ use FireflyIII\Support\Http\Controllers\UserNavigation;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use View;
|
use View;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ShowController
|
* Class ShowController
|
||||||
@ -101,17 +100,18 @@ class ShowController extends Controller
|
|||||||
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
|
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
||||||
$today = new Carbon;
|
$today = new Carbon;
|
||||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
||||||
$page = (int)$request->get('page');
|
$page = (int)$request->get('page');
|
||||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||||
$fStart = $start->formatLocalized($this->monthAndDayFormat);
|
$fStart = $start->formatLocalized($this->monthAndDayFormat);
|
||||||
$fEnd = $end->formatLocalized($this->monthAndDayFormat);
|
$fEnd = $end->formatLocalized($this->monthAndDayFormat);
|
||||||
$subTitle = (string)trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
|
$subTitle = (string)trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
|
||||||
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||||
$periods = $this->getAccountPeriodOverview($account, $end);
|
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
|
||||||
|
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
@ -138,10 +138,10 @@ class ShowController extends Controller
|
|||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @throws Exception
|
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function showAll(Request $request, Account $account)
|
public function showAll(Request $request, Account $account)
|
||||||
{
|
{
|
||||||
|
@ -37,13 +37,14 @@ class ConfigurationController extends Controller
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ConfigurationController constructor.
|
* ConfigurationController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
static function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.administration'));
|
app('view')->share('title', (string)trans('firefly.administration'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class HomeController extends Controller
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ConfigurationController constructor.
|
* ConfigurationController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -36,8 +36,13 @@ use View;
|
|||||||
*/
|
*/
|
||||||
class LinkController extends Controller
|
class LinkController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var LinkTypeRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LinkController constructor.
|
* LinkController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -47,6 +52,7 @@ class LinkController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.administration'));
|
app('view')->share('title', (string)trans('firefly.administration'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||||
|
$this->repository = app(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@ -61,11 +67,11 @@ class LinkController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
Log::channel('audit')->info('User visits link index.');
|
||||||
|
|
||||||
$subTitle = (string)trans('firefly.create_new_link_type');
|
$subTitle = (string)trans('firefly.create_new_link_type');
|
||||||
$subTitleIcon = 'fa-link';
|
$subTitleIcon = 'fa-link';
|
||||||
|
|
||||||
Log::channel('audit')->info('User visits link index.');
|
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "create another").
|
// put previous url in session if not redirect from store (not "create another").
|
||||||
if (true !== session('link-types.create.fromStore')) {
|
if (true !== session('link-types.create.fromStore')) {
|
||||||
$this->rememberPreviousUri('link-types.create.uri');
|
$this->rememberPreviousUri('link-types.create.uri');
|
||||||
@ -77,13 +83,12 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Delete a link form.
|
* Delete a link form.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param LinkTypeRepositoryInterface $repository
|
* @param LinkType $linkType
|
||||||
* @param LinkType $linkType
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||||
*/
|
*/
|
||||||
public function delete(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
public function delete(Request $request, LinkType $linkType)
|
||||||
{
|
{
|
||||||
if (!$linkType->editable) {
|
if (!$linkType->editable) {
|
||||||
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
||||||
@ -92,18 +97,19 @@ class LinkController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id));
|
Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id));
|
||||||
|
|
||||||
$subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]);
|
$subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]);
|
||||||
$otherTypes = $repository->get();
|
$otherTypes = $this->repository->get();
|
||||||
$count = $repository->countJournals($linkType);
|
$count = $this->repository->countJournals($linkType);
|
||||||
$moveTo = [];
|
$moveTo = [];
|
||||||
$moveTo[0] = (string)trans('firefly.do_not_save_connection');
|
$moveTo[0] = (string)trans('firefly.do_not_save_connection');
|
||||||
|
|
||||||
/** @var LinkType $otherType */
|
/** @var LinkType $otherType */
|
||||||
foreach ($otherTypes as $otherType) {
|
foreach ($otherTypes as $otherType) {
|
||||||
if ($otherType->id !== $linkType->id) {
|
if ($otherType->id !== $linkType->id) {
|
||||||
$moveTo[$otherType->id] = sprintf('%s (%s / %s)', $otherType->name, $otherType->inward, $otherType->outward);
|
$moveTo[$otherType->id] = sprintf('%s (%s / %s)', $otherType->name, $otherType->inward, $otherType->outward);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// put previous url in session
|
// put previous url in session
|
||||||
$this->rememberPreviousUri('link-types.delete.uri');
|
$this->rememberPreviousUri('link-types.delete.uri');
|
||||||
|
|
||||||
@ -113,18 +119,17 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Actually destroy the link.
|
* Actually destroy the link.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param LinkTypeRepositoryInterface $repository
|
* @param LinkType $linkType
|
||||||
* @param LinkType $linkType
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function destroy(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
public function destroy(Request $request, LinkType $linkType)
|
||||||
{
|
{
|
||||||
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
|
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
|
||||||
$name = $linkType->name;
|
$name = $linkType->name;
|
||||||
$moveTo = $repository->findNull((int)$request->get('move_link_type_before_delete'));
|
$moveTo = $this->repository->findNull((int)$request->get('move_link_type_before_delete'));
|
||||||
$repository->destroy($linkType, $moveTo);
|
$this->repository->destroy($linkType, $moveTo);
|
||||||
|
|
||||||
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name]));
|
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name]));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
@ -135,7 +140,7 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Edit a link form.
|
* Edit a link form.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param LinkType $linkType
|
* @param LinkType $linkType
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||||
@ -164,20 +169,18 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show index of all links.
|
* Show index of all links.
|
||||||
*
|
*
|
||||||
* @param LinkTypeRepositoryInterface $repository
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index(LinkTypeRepositoryInterface $repository)
|
public function index()
|
||||||
{
|
{
|
||||||
$subTitle = (string)trans('firefly.journal_link_configuration');
|
$subTitle = (string)trans('firefly.journal_link_configuration');
|
||||||
$subTitleIcon = 'fa-link';
|
$subTitleIcon = 'fa-link';
|
||||||
$linkTypes = $repository->get();
|
$linkTypes = $this->repository->get();
|
||||||
|
|
||||||
Log::channel('audit')->info('User on index of link types in admin.');
|
Log::channel('audit')->info('User on index of link types in admin.');
|
||||||
$linkTypes->each(
|
$linkTypes->each(
|
||||||
function (LinkType $linkType) use ($repository) {
|
function (LinkType $linkType) {
|
||||||
$linkType->journalCount = $repository->countJournals($linkType);
|
$linkType->journalCount = $this->repository->countJournals($linkType);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -195,7 +198,7 @@ class LinkController extends Controller
|
|||||||
{
|
{
|
||||||
$subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]);
|
$subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]);
|
||||||
$subTitleIcon = 'fa-link';
|
$subTitleIcon = 'fa-link';
|
||||||
$links = $linkType->transactionJournalLinks()->get();
|
$links = $this->repository->getJournalLinks($linkType);
|
||||||
|
|
||||||
Log::channel('audit')->info(sprintf('User viewing link type #%d', $linkType->id));
|
Log::channel('audit')->info(sprintf('User viewing link type #%d', $linkType->id));
|
||||||
|
|
||||||
@ -205,19 +208,18 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Store the new link.
|
* Store the new link.
|
||||||
*
|
*
|
||||||
* @param LinkTypeFormRequest $request
|
* @param LinkTypeFormRequest $request
|
||||||
* @param LinkTypeRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function store(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository)
|
public function store(LinkTypeFormRequest $request)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $request->string('name'),
|
'name' => $request->string('name'),
|
||||||
'inward' => $request->string('inward'),
|
'inward' => $request->string('inward'),
|
||||||
'outward' => $request->string('outward'),
|
'outward' => $request->string('outward'),
|
||||||
];
|
];
|
||||||
$linkType = $repository->store($data);
|
$linkType = $this->repository->store($data);
|
||||||
|
|
||||||
Log::channel('audit')->info('User stored new link type.', $linkType->toArray());
|
Log::channel('audit')->info('User stored new link type.', $linkType->toArray());
|
||||||
|
|
||||||
@ -237,13 +239,12 @@ class LinkController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Update an existing link.
|
* Update an existing link.
|
||||||
*
|
*
|
||||||
* @param LinkTypeFormRequest $request
|
* @param LinkTypeFormRequest $request
|
||||||
* @param LinkTypeRepositoryInterface $repository
|
* @param LinkType $linkType
|
||||||
* @param LinkType $linkType
|
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
public function update(LinkTypeFormRequest $request, LinkType $linkType)
|
||||||
{
|
{
|
||||||
if (!$linkType->editable) {
|
if (!$linkType->editable) {
|
||||||
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
||||||
@ -256,7 +257,7 @@ class LinkController extends Controller
|
|||||||
'inward' => $request->string('inward'),
|
'inward' => $request->string('inward'),
|
||||||
'outward' => $request->string('outward'),
|
'outward' => $request->string('outward'),
|
||||||
];
|
];
|
||||||
$repository->update($linkType, $data);
|
$this->repository->update($linkType, $data);
|
||||||
|
|
||||||
Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data);
|
Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data);
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var UserRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserController constructor.
|
* UserController constructor.
|
||||||
*/
|
*/
|
||||||
@ -46,7 +49,7 @@ class UserController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.administration'));
|
app('view')->share('title', (string)trans('firefly.administration'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||||
|
$this->repository = app(UserRepositoryInterface::class);
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -72,13 +75,12 @@ class UserController extends Controller
|
|||||||
* Destroy a user.
|
* Destroy a user.
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param UserRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function destroy(User $user, UserRepositoryInterface $repository)
|
public function destroy(User $user)
|
||||||
{
|
{
|
||||||
$repository->destroy($user);
|
$this->repository->destroy($user);
|
||||||
session()->flash('success', (string)trans('firefly.user_deleted'));
|
session()->flash('success', (string)trans('firefly.user_deleted'));
|
||||||
|
|
||||||
return redirect(route('admin.users'));
|
return redirect(route('admin.users'));
|
||||||
@ -114,22 +116,20 @@ class UserController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show index of user manager.
|
* Show index of user manager.
|
||||||
*
|
*
|
||||||
* @param UserRepositoryInterface $repository
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index(UserRepositoryInterface $repository)
|
public function index()
|
||||||
{
|
{
|
||||||
$subTitle = (string)trans('firefly.user_administration');
|
$subTitle = (string)trans('firefly.user_administration');
|
||||||
$subTitleIcon = 'fa-users';
|
$subTitleIcon = 'fa-users';
|
||||||
$users = $repository->all();
|
$users = $this->repository->all();
|
||||||
|
|
||||||
// add meta stuff.
|
// add meta stuff.
|
||||||
$users->each(
|
$users->each(
|
||||||
function (User $user) use ($repository) {
|
function (User $user) {
|
||||||
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
|
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
|
||||||
$preferences = app('preferences')->getArrayForUser($user, $list);
|
$preferences = app('preferences')->getArrayForUser($user, $list);
|
||||||
$user->isAdmin = $repository->hasRole($user, 'owner');
|
$user->isAdmin = $this->repository->hasRole($user, 'owner');
|
||||||
$is2faEnabled = 1 === $preferences['twoFactorAuthEnabled'];
|
$is2faEnabled = 1 === $preferences['twoFactorAuthEnabled'];
|
||||||
$has2faSecret = null !== $preferences['twoFactorAuthSecret'];
|
$has2faSecret = null !== $preferences['twoFactorAuthSecret'];
|
||||||
$user->has2FA = ($is2faEnabled && $has2faSecret);
|
$user->has2FA = ($is2faEnabled && $has2faSecret);
|
||||||
@ -143,18 +143,17 @@ class UserController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show single user.
|
* Show single user.
|
||||||
*
|
*
|
||||||
* @param UserRepositoryInterface $repository
|
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function show(UserRepositoryInterface $repository, User $user)
|
public function show(User $user)
|
||||||
{
|
{
|
||||||
$title = (string)trans('firefly.administration');
|
$title = (string)trans('firefly.administration');
|
||||||
$mainTitleIcon = 'fa-hand-spock-o';
|
$mainTitleIcon = 'fa-hand-spock-o';
|
||||||
$subTitle = (string)trans('firefly.single_user_administration', ['email' => $user->email]);
|
$subTitle = (string)trans('firefly.single_user_administration', ['email' => $user->email]);
|
||||||
$subTitleIcon = 'fa-user';
|
$subTitleIcon = 'fa-user';
|
||||||
$information = $repository->getUserData($user);
|
$information = $this->repository->getUserData($user);
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'admin.users.show', compact(
|
'admin.users.show', compact(
|
||||||
@ -168,22 +167,21 @@ class UserController extends Controller
|
|||||||
*
|
*
|
||||||
* @param UserFormRequest $request
|
* @param UserFormRequest $request
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param UserRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(UserFormRequest $request, User $user, UserRepositoryInterface $repository)
|
public function update(UserFormRequest $request, User $user)
|
||||||
{
|
{
|
||||||
Log::debug('Actually here');
|
Log::debug('Actually here');
|
||||||
$data = $request->getUserData();
|
$data = $request->getUserData();
|
||||||
|
|
||||||
// update password
|
// update password
|
||||||
if ('' !== $data['password']) {
|
if ('' !== $data['password']) {
|
||||||
$repository->changePassword($user, $data['password']);
|
$this->repository->changePassword($user, $data['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
|
$this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
|
||||||
$repository->updateEmail($user, $data['email']);
|
$this->repository->updateEmail($user, $data['email']);
|
||||||
|
|
||||||
session()->flash('success', (string)trans('firefly.updated_user', ['email' => $user->email]));
|
session()->flash('success', (string)trans('firefly.updated_user', ['email' => $user->email]));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
@ -33,6 +33,7 @@ use Log;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ForgotPasswordController
|
* Class ForgotPasswordController
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class ForgotPasswordController extends Controller
|
class ForgotPasswordController extends Controller
|
||||||
{
|
{
|
||||||
@ -72,6 +73,7 @@ class ForgotPasswordController extends Controller
|
|||||||
$this->validateEmail($request);
|
$this->validateEmail($request);
|
||||||
|
|
||||||
// verify if the user is not a demo user. If so, we give him back an error.
|
// verify if the user is not a demo user. If so, we give him back an error.
|
||||||
|
/** @var User $user */
|
||||||
$user = User::where('email', $request->get('email'))->first();
|
$user = User::where('email', $request->get('email'))->first();
|
||||||
|
|
||||||
if (null !== $user && $repository->hasRole($user, 'demo')) {
|
if (null !== $user && $repository->hasRole($user, 'demo')) {
|
||||||
|
@ -69,22 +69,25 @@ class AmountController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the amount for a single budget in a specific period. Shows a waring when its a lot.
|
* Set the amount for a single budget in a specific period.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param BudgetRepositoryInterface $repository
|
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function amount(Request $request, BudgetRepositoryInterface $repository, Budget $budget): JsonResponse
|
public function amount(Request $request, Budget $budget): JsonResponse
|
||||||
{
|
{
|
||||||
// grab vars from URI
|
// grab vars from URI
|
||||||
$amount = (string)$request->get('amount');
|
$amount = (string)$request->get('amount');
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
/** @var Carbon $start */
|
||||||
|
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||||
|
|
||||||
|
/** @var Carbon $end */
|
||||||
|
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||||
|
|
||||||
// grab other useful vars
|
// grab other useful vars
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
@ -95,11 +98,11 @@ class AmountController extends Controller
|
|||||||
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
||||||
|
|
||||||
// calculate what the user has spent in current period.
|
// calculate what the user has spent in current period.
|
||||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
$spent = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||||
|
|
||||||
// given the new budget, this is what they have left (and left per day?)
|
// given the new budget, this is what they have left (and left per day?)
|
||||||
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
||||||
$leftPerDay = null; //
|
$leftPerDay = null;
|
||||||
|
|
||||||
// If the user budgets ANY amount per day for this budget (anything but zero) Firefly III calculates how much he could spend per day.
|
// If the user budgets ANY amount per day for this budget (anything but zero) Firefly III calculates how much he could spend per day.
|
||||||
if (1 === bccomp(bcadd($amount, $spent), '0')) {
|
if (1 === bccomp(bcadd($amount, $spent), '0')) {
|
||||||
@ -113,7 +116,7 @@ class AmountController extends Controller
|
|||||||
// If the difference is very large, give the user a notification.
|
// If the difference is very large, give the user a notification.
|
||||||
$average = $this->repository->budgetedPerDay($budget);
|
$average = $this->repository->budgetedPerDay($budget);
|
||||||
$current = bcdiv($amount, (string)$periodLength);
|
$current = bcdiv($amount, (string)$periodLength);
|
||||||
if (bccomp(bcmul('1.1', $average), $current) === -1) {
|
if (bccomp(bcmul('1.3', $average), $current) === -1) {
|
||||||
$largeDiff = true;
|
$largeDiff = true;
|
||||||
$warnText = (string)trans(
|
$warnText = (string)trans(
|
||||||
'firefly.over_budget_warn',
|
'firefly.over_budget_warn',
|
||||||
@ -141,68 +144,6 @@ class AmountController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows some basic info about the income and the suggested budget.
|
|
||||||
*
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
* TODO remove this feature
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
*/
|
|
||||||
public function infoIncome(Carbon $start, Carbon $end)
|
|
||||||
{
|
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
|
||||||
/** @var Carbon $searchBegin */
|
|
||||||
$searchBegin = app('navigation')->subtractPeriod($start, $range, 3);
|
|
||||||
$searchEnd = app('navigation')->addPeriod($end, $range, 3);
|
|
||||||
$daysInPeriod = $start->diffInDays($end);
|
|
||||||
$daysInSearchPeriod = $searchBegin->diffInDays($searchEnd);
|
|
||||||
$average = $this->repository->getAverageAvailable($start, $end);
|
|
||||||
$available = bcmul($average, (string)$daysInPeriod);
|
|
||||||
|
|
||||||
Log::debug(sprintf('Average is %s, so total available is %s because days is %d.', $average, $available, $daysInPeriod));
|
|
||||||
|
|
||||||
// amount earned in this period:
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::DEPOSIT]);
|
|
||||||
$earned = $collector->getSum();
|
|
||||||
// Total amount earned divided by the number of days in the whole search period is the average amount earned per day.
|
|
||||||
// This is multiplied by the number of days in the current period, showing you the average.
|
|
||||||
$earnedAverage = bcmul(bcdiv($earned, (string)$daysInSearchPeriod), (string)$daysInPeriod);
|
|
||||||
|
|
||||||
Log::debug(sprintf('Earned is %s, earned average is %s', $earned, $earnedAverage));
|
|
||||||
|
|
||||||
// amount spent in period
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::WITHDRAWAL]);
|
|
||||||
$spent = $collector->getSum();
|
|
||||||
$spentAverage = app('steam')->positive(bcmul(bcdiv($spent, (string)$daysInSearchPeriod), (string)$daysInPeriod));
|
|
||||||
|
|
||||||
Log::debug(sprintf('Spent is %s, spent average is %s', $earned, $earnedAverage));
|
|
||||||
|
|
||||||
// the default suggestion is the money the user has spent, on average, over this period.
|
|
||||||
$suggested = $spentAverage;
|
|
||||||
|
|
||||||
Log::debug(sprintf('Suggested is now %s (spent average)', $suggested));
|
|
||||||
|
|
||||||
// if the user makes less per period, suggest that amount instead.
|
|
||||||
if (1 === bccomp($spentAverage, $earnedAverage)) {
|
|
||||||
Log::debug(
|
|
||||||
sprintf('Because earned average (%s) is less than spent average (%s) will suggest earned average instead.', $earnedAverage, $spentAverage)
|
|
||||||
);
|
|
||||||
$suggested = $earnedAverage;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = ['available' => $available, 'earned' => $earnedAverage, 'spent' => $spentAverage, 'suggested' => $suggested,];
|
|
||||||
|
|
||||||
return view('budgets.info', compact('result', 'searchBegin', 'searchEnd', 'start', 'end'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an available budget for the current period.
|
* Store an available budget for the current period.
|
||||||
*
|
*
|
||||||
@ -212,7 +153,9 @@ class AmountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postUpdateIncome(BudgetIncomeRequest $request): RedirectResponse
|
public function postUpdateIncome(BudgetIncomeRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
|
/** @var Carbon $start */
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $request->string('start'));
|
$start = Carbon::createFromFormat('Y-m-d', $request->string('start'));
|
||||||
|
/** @var Carbon $end */
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $request->string('end'));
|
$end = Carbon::createFromFormat('Y-m-d', $request->string('end'));
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
$amount = $request->get('amount');
|
$amount = $request->get('amount');
|
||||||
@ -240,6 +183,6 @@ class AmountController extends Controller
|
|||||||
$available = round($available, $defaultCurrency->decimal_places);
|
$available = round($available, $defaultCurrency->decimal_places);
|
||||||
$page = (int)$request->get('page');
|
$page = (int)$request->get('page');
|
||||||
|
|
||||||
return view('budgets.income', compact('available', 'start', 'end', 'page'));
|
return view('budgets.income', compact('available', 'start', 'end', 'page','defaultCurrency'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ class CreateController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateController constructor.
|
* CreateController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,7 @@ class DeleteController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DeleteController constructor.
|
* DeleteController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* EditController constructor.
|
* EditController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@ class IndexController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* IndexController constructor.
|
* IndexController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -43,20 +43,22 @@ use Illuminate\Http\Request;
|
|||||||
class ShowController extends Controller
|
class ShowController extends Controller
|
||||||
{
|
{
|
||||||
use PeriodOverview, AugumentData;
|
use PeriodOverview, AugumentData;
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $journalRepos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ShowController constructor.
|
* ShowController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
app('view')->share('hideBudgets', true);
|
|
||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.budgets'));
|
app('view')->share('title', (string)trans('firefly.budgets'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-tasks');
|
app('view')->share('mainTitleIcon', 'fa-tasks');
|
||||||
|
$this->journalRepos = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@ -82,9 +84,13 @@ class ShowController extends Controller
|
|||||||
'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)]
|
||||||
);
|
);
|
||||||
$periods = $this->getNoBudgetPeriodOverview($end);
|
|
||||||
$page = (int)$request->get('page');
|
// get first journal ever to set off the budget period overview.
|
||||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
$first = $this->journalRepos->firstNull();
|
||||||
|
$firstDate = null !== $first ? $first->date : $start;
|
||||||
|
$periods = $this->getNoBudgetPeriodOverview($firstDate, $end);
|
||||||
|
$page = (int)$request->get('page');
|
||||||
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
@ -100,16 +106,13 @@ class ShowController extends Controller
|
|||||||
* Shows ALL transactions without a budget.
|
* Shows ALL transactions without a budget.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
|
||||||
*/
|
*/
|
||||||
public function noBudgetAll(Request $request, JournalRepositoryInterface $repository)
|
public function noBudgetAll(Request $request)
|
||||||
{
|
{
|
||||||
$subTitle = (string)trans('firefly.all_journals_without_budget');
|
$subTitle = (string)trans('firefly.all_journals_without_budget');
|
||||||
$first = $repository->firstNull();
|
$first = $this->journalRepos->firstNull();
|
||||||
$start = null === $first ? new Carbon : $first->date;
|
$start = null === $first ? new Carbon : $first->date;
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
$page = (int)$request->get('page');
|
$page = (int)$request->get('page');
|
||||||
@ -169,7 +172,7 @@ class ShowController extends Controller
|
|||||||
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
||||||
{
|
{
|
||||||
if ($budgetLimit->budget->id !== $budget->id) {
|
if ($budgetLimit->budget->id !== $budget->id) {
|
||||||
throw new FireflyException('This budget limit is not part of this budget.');
|
throw new FireflyException('This budget limit is not part of this budget.'); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = (int)$request->get('page');
|
$page = (int)$request->get('page');
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Models\Budget;
|
|||||||
* Class BudgetFormRequest.
|
* Class BudgetFormRequest.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
|
* TODO after 4.8.0, split for update/store
|
||||||
*/
|
*/
|
||||||
class BudgetFormRequest extends Request
|
class BudgetFormRequest extends Request
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BillFormRequest.
|
* Class LinkTypeFormRequest.
|
||||||
*/
|
*/
|
||||||
class LinkTypeFormRequest extends Request
|
class LinkTypeFormRequest extends Request
|
||||||
{
|
{
|
||||||
|
@ -29,9 +29,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
@ -44,15 +42,26 @@ use Log;
|
|||||||
*
|
*
|
||||||
* TODO verify this all works as expected.
|
* TODO verify this all works as expected.
|
||||||
*
|
*
|
||||||
|
* - Always request start date and end date.
|
||||||
* - Group expenses, income, etc. under this period.
|
* - Group expenses, income, etc. under this period.
|
||||||
* - Returns collection of arrays. Possible fields are:
|
* - Returns collection of arrays. Fields
|
||||||
* - start (string),
|
|
||||||
* end (string),
|
|
||||||
* title (string),
|
* title (string),
|
||||||
* spent (string),
|
* route (string)
|
||||||
* earned (string),
|
* total_transactions (int)
|
||||||
* transferred (string)
|
* spent (array),
|
||||||
|
* earned (array),
|
||||||
|
* transferred_away (array)
|
||||||
|
* transferred_in (array)
|
||||||
*
|
*
|
||||||
|
* each array has the following format:
|
||||||
|
* currency_id => [
|
||||||
|
* currency_id : 1, (int)
|
||||||
|
* currency_symbol : X (str)
|
||||||
|
* currency_name: Euro (str)
|
||||||
|
* currency_code: EUR (str)
|
||||||
|
* amount: -1234 (str)
|
||||||
|
* count: 23
|
||||||
|
* ]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
trait PeriodOverview
|
trait PeriodOverview
|
||||||
@ -63,20 +72,15 @@ trait PeriodOverview
|
|||||||
* and for each period, the amount of money spent and earned. This is a complex operation which is cached for
|
* and for each period, the amount of money spent and earned. This is a complex operation which is cached for
|
||||||
* performance reasons.
|
* performance reasons.
|
||||||
*
|
*
|
||||||
* The method has been refactored recently for better performance.
|
|
||||||
*
|
|
||||||
* @param Account $account The account involved
|
* @param Account $account The account involved
|
||||||
* @param Carbon $date The start date.
|
* @param Carbon $date The start date.
|
||||||
|
* @param Carbon $end The end date.
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getAccountPeriodOverview(Account $account, Carbon $date): Collection
|
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $repository */
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
|
||||||
$end = $repository->oldestJournalDate($account) ?? Carbon::now()->subMonth()->startOfMonth();
|
|
||||||
$start = clone $date;
|
|
||||||
|
|
||||||
if ($end < $start) {
|
if ($end < $start) {
|
||||||
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
|
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
|
||||||
@ -93,43 +97,54 @@ trait PeriodOverview
|
|||||||
}
|
}
|
||||||
/** @var array $dates */
|
/** @var array $dates */
|
||||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||||
$entries = new Collection;
|
$entries = [];
|
||||||
|
|
||||||
|
// collect all expenses in this period:
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setAccounts(new Collection([$account]));
|
||||||
|
$collector->setRange($start, $end);
|
||||||
|
$collector->setTypes([TransactionType::DEPOSIT]);
|
||||||
|
$earnedSet = $collector->getExtractedJournals();
|
||||||
|
|
||||||
|
// collect all income in this period:
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setAccounts(new Collection([$account]));
|
||||||
|
$collector->setRange($start, $end);
|
||||||
|
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
|
$spentSet = $collector->getExtractedJournals();
|
||||||
|
|
||||||
|
// collect all transfers in this period:
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setAccounts(new Collection([$account]));
|
||||||
|
$collector->setRange($start, $end);
|
||||||
|
$collector->setTypes([TransactionType::TRANSFER]);
|
||||||
|
$transferSet = $collector->getExtractedJournals();
|
||||||
|
|
||||||
// loop dates
|
// loop dates
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
|
|
||||||
// collect from start to end:
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setAccounts(new Collection([$account]));
|
|
||||||
$collector->setRange($currentDate['start'], $currentDate['end']);
|
|
||||||
$collector->setTypes([TransactionType::DEPOSIT]);
|
|
||||||
$earnedSet = $collector->getExtractedJournals();
|
|
||||||
|
|
||||||
$earned = $this->groupByCurrency($earnedSet);
|
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setAccounts(new Collection([$account]));
|
|
||||||
$collector->setRange($currentDate['start'], $currentDate['end']);
|
|
||||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
|
||||||
$spentSet = $collector->getExtractedJournals();
|
|
||||||
$spent = $this->groupByCurrency($spentSet);
|
|
||||||
|
|
||||||
$title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
|
$title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
|
||||||
/** @noinspection PhpUndefinedMethodInspection */
|
|
||||||
$entries->push(
|
|
||||||
[
|
|
||||||
'transactions' => count($spentSet) + count($earnedSet),
|
|
||||||
'title' => $title,
|
|
||||||
'spent' => $spent,
|
|
||||||
'earned' => $earned,
|
|
||||||
'transferred' => '0',
|
|
||||||
'route' => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//$cache->store($entries);
|
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
|
||||||
|
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
|
||||||
|
$transferredAway = $this->filterTransferredAway($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||||
|
$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||||
|
$entries[] =
|
||||||
|
[
|
||||||
|
'title' => $title,
|
||||||
|
'route' =>
|
||||||
|
route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||||
|
|
||||||
|
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||||
|
'spent' => $this->groupByCurrency($spent),
|
||||||
|
'earned' => $this->groupByCurrency($earned),
|
||||||
|
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||||
|
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$cache->store($entries);
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
@ -144,6 +159,7 @@ trait PeriodOverview
|
|||||||
*/
|
*/
|
||||||
protected function getCategoryPeriodOverview(Category $category, Carbon $date): Collection
|
protected function getCategoryPeriodOverview(Category $category, Carbon $date): Collection
|
||||||
{
|
{
|
||||||
|
die('not yet complete');
|
||||||
/** @var JournalRepositoryInterface $journalRepository */
|
/** @var JournalRepositoryInterface $journalRepository */
|
||||||
$journalRepository = app(JournalRepositoryInterface::class);
|
$journalRepository = app(JournalRepositoryInterface::class);
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
@ -208,17 +224,13 @@ trait PeriodOverview
|
|||||||
*
|
*
|
||||||
* This method has been refactored recently.
|
* This method has been refactored recently.
|
||||||
*
|
*
|
||||||
|
* @param Carbon $start
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getNoBudgetPeriodOverview(Carbon $date): Collection
|
protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var JournalRepositoryInterface $repository */
|
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
|
||||||
$first = $repository->firstNull();
|
|
||||||
$end = null === $first ? new Carbon : $first->date;
|
|
||||||
$start = clone $date;
|
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
|
|
||||||
if ($end < $start) {
|
if ($end < $start) {
|
||||||
@ -231,32 +243,33 @@ trait PeriodOverview
|
|||||||
$cache->addProperty('no-budget-period-entries');
|
$cache->addProperty('no-budget-period-entries');
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
//return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array $dates */
|
/** @var array $dates */
|
||||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||||
$entries = new Collection;
|
$entries = [];
|
||||||
|
|
||||||
|
|
||||||
|
// get all expenses without a budget.
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setRange($start, $end)->withoutBudget()->withAccountInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
|
$journals = $collector->getExtractedJournals();
|
||||||
|
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
/** @var GroupCollectorInterface $collector */
|
$set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setRange($currentDate['start'], $currentDate['end'])->withoutBudget()->withAccountInformation()->setTypes(
|
|
||||||
[TransactionType::WITHDRAWAL]
|
|
||||||
);
|
|
||||||
$journals = $collector->getExtractedJournals();
|
|
||||||
$count = count($journals);
|
|
||||||
$spent = $this->groupByCurrency($journals);
|
|
||||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||||
$entries->push(
|
$entries[] =
|
||||||
[
|
[
|
||||||
'transactions' => $count,
|
'title' => $title,
|
||||||
'title' => $title,
|
|
||||||
'spent' => $spent,
|
|
||||||
'earned' => '0',
|
|
||||||
'transferred' => '0',
|
|
||||||
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||||
]
|
'total_transactions' => count($set),
|
||||||
);
|
'spent' => $this->groupByCurrency($set),
|
||||||
|
'earned' => [],
|
||||||
|
'transferred_away' => [],
|
||||||
|
'transferred_in' => [],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$cache->store($entries);
|
$cache->store($entries);
|
||||||
|
|
||||||
@ -275,6 +288,7 @@ trait PeriodOverview
|
|||||||
*/
|
*/
|
||||||
protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.
|
protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.
|
||||||
{
|
{
|
||||||
|
die('not yet complete');
|
||||||
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
$first = $this->journalRepos->firstNull();
|
$first = $this->journalRepos->firstNull();
|
||||||
@ -361,6 +375,7 @@ trait PeriodOverview
|
|||||||
*/
|
*/
|
||||||
protected function getTagPeriodOverview(Tag $tag, Carbon $date): Collection // period overview for tags.
|
protected function getTagPeriodOverview(Tag $tag, Carbon $date): Collection // period overview for tags.
|
||||||
{
|
{
|
||||||
|
die('not yet complete');
|
||||||
/** @var TagRepositoryInterface $repository */
|
/** @var TagRepositoryInterface $repository */
|
||||||
$repository = app(TagRepositoryInterface::class);
|
$repository = app(TagRepositoryInterface::class);
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
@ -423,6 +438,7 @@ trait PeriodOverview
|
|||||||
*/
|
*/
|
||||||
protected function getTransactionPeriodOverview(string $transactionType, Carbon $endDate): Collection
|
protected function getTransactionPeriodOverview(string $transactionType, Carbon $endDate): Collection
|
||||||
{
|
{
|
||||||
|
die('not yet complete');
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
@ -519,6 +535,65 @@ trait PeriodOverview
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return only transactions where $account is the source.
|
||||||
|
* @param Account $account
|
||||||
|
* @param array $journals
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function filterTransferredAway(Account $account, array $journals): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
if ($account->id === (int)$journal['source_account_id']) {
|
||||||
|
$return[] = $journal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return only transactions where $account is the source.
|
||||||
|
* @param Account $account
|
||||||
|
* @param array $journals
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function filterTransferredIn(Account $account, array $journals): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
if ($account->id === (int)$journal['destination_account_id']) {
|
||||||
|
$return[] = $journal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter a list of journals by a set of dates, and then group them by currency.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function filterJournalsByDate(array $array, Carbon $start, Carbon $end): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($array as $journal) {
|
||||||
|
if ($journal['date'] <= $end && $journal['date'] >= $start) {
|
||||||
|
$result[] = $journal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $journals
|
* @param array $journals
|
||||||
*
|
*
|
||||||
@ -529,19 +604,40 @@ trait PeriodOverview
|
|||||||
$return = [];
|
$return = [];
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$currencyId = (int)$journal['currency_id'];
|
$currencyId = (int)$journal['currency_id'];
|
||||||
|
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||||
if (!isset($return[$currencyId])) {
|
if (!isset($return[$currencyId])) {
|
||||||
$currency = new TransactionCurrency;
|
$return[$currencyId] = [
|
||||||
$currency->symbol = $journal['currency_symbol'];
|
'amount' => '0',
|
||||||
$currency->decimal_places = $journal['currency_decimal_places'];
|
'count' => 0,
|
||||||
$currency->name = $journal['currency_name'];
|
'currency_id' => $currencyId,
|
||||||
$return[$currencyId] = [
|
'currency_name' => $journal['currency_name'],
|
||||||
'amount' => '0',
|
'currency_code' => $journal['currency_code'],
|
||||||
'currency' => $currency,
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
//'currency' => 'x',//$currency,
|
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);
|
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);
|
||||||
|
$return[$currencyId]['count']++;
|
||||||
|
|
||||||
|
|
||||||
|
if (null !== $foreignCurrencyId) {
|
||||||
|
if (!isset($return[$foreignCurrencyId])) {
|
||||||
|
$return[$foreignCurrencyId] = [
|
||||||
|
'amount' => '0',
|
||||||
|
'count' => 0,
|
||||||
|
'currency_id' => (int)$foreignCurrencyId,
|
||||||
|
'currency_name' => $journal['foreign_currency_name'],
|
||||||
|
'currency_code' => $journal['foreign_currency_code'],
|
||||||
|
'currency_symbol' => $journal['foreign_currency_symbol'],
|
||||||
|
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
$return[$foreignCurrencyId]['count']++;
|
||||||
|
$return[$foreignCurrencyId]['amount'] = bcadd($return[$foreignCurrencyId]['amount'], $journal['foreign_amount']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -25,6 +25,8 @@ namespace FireflyIII\Support\Twig\Extension;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Log;
|
use Log;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
@ -43,7 +45,8 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->transactionAmount(),
|
$this->journalArrayAmount(),
|
||||||
|
$this->journalObjectAmount(),
|
||||||
$this->groupAmount(),
|
$this->groupAmount(),
|
||||||
$this->journalHasMeta(),
|
$this->journalHasMeta(),
|
||||||
$this->journalGetMetaDate(),
|
$this->journalGetMetaDate(),
|
||||||
@ -160,18 +163,44 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Shows the amount for a single journal array.
|
||||||
|
*
|
||||||
* @return Twig_SimpleFunction
|
* @return Twig_SimpleFunction
|
||||||
*/
|
*/
|
||||||
public function transactionAmount(): Twig_SimpleFunction
|
public function journalArrayAmount(): Twig_SimpleFunction
|
||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'transactionAmount',
|
'journalArrayAmount',
|
||||||
function (array $array): string {
|
function (array $array): string {
|
||||||
// if is not a withdrawal, amount positive.
|
// if is not a withdrawal, amount positive.
|
||||||
$result = $this->normalAmount($array);
|
$result = $this->normalJournalArrayAmount($array);
|
||||||
// now append foreign amount, if any.
|
// now append foreign amount, if any.
|
||||||
if (null !== $array['foreign_amount']) {
|
if (null !== $array['foreign_amount']) {
|
||||||
$foreign = $this->foreignAmount($array);
|
$foreign = $this->foreignJournalArrayAmount($array);
|
||||||
|
$result = sprintf('%s (%s)', $result, $foreign);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
},
|
||||||
|
['is_safe' => ['html']]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the amount for a single journal object.
|
||||||
|
*
|
||||||
|
* @return Twig_SimpleFunction
|
||||||
|
*/
|
||||||
|
public function journalObjectAmount(): Twig_SimpleFunction
|
||||||
|
{
|
||||||
|
return new Twig_SimpleFunction(
|
||||||
|
'journalObjectAmount',
|
||||||
|
function (TransactionJournal $journal): string {
|
||||||
|
// if is not a withdrawal, amount positive.
|
||||||
|
$result = $this->normalJournalObjectAmount($journal);
|
||||||
|
// now append foreign amount, if any.
|
||||||
|
if ($this->journalObjectHasForeign($journal)) {
|
||||||
|
$foreign = $this->foreignJournalObjectAmount($journal);
|
||||||
$result = sprintf('%s (%s)', $result, $foreign);
|
$result = sprintf('%s (%s)', $result, $foreign);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +217,7 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function foreignAmount(array $array): string
|
private function foreignJournalArrayAmount(array $array): string
|
||||||
{
|
{
|
||||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||||
$amount = $array['foreign_amount'] ?? '0';
|
$amount = $array['foreign_amount'] ?? '0';
|
||||||
@ -207,6 +236,35 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate foreign amount for journal from a transaction group.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function foreignJournalObjectAmount(TransactionJournal $journal): string
|
||||||
|
{
|
||||||
|
$type = $journal->transactionType->type;
|
||||||
|
/** @var Transaction $first */
|
||||||
|
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
|
$currency = $first->foreignCurrency;
|
||||||
|
$amount = $first->foreign_amount ?? '0';
|
||||||
|
$colored = true;
|
||||||
|
if ($type !== TransactionType::WITHDRAWAL) {
|
||||||
|
$amount = bcmul($amount, '-1');
|
||||||
|
}
|
||||||
|
if ($type === TransactionType::TRANSFER) {
|
||||||
|
$colored = false;
|
||||||
|
}
|
||||||
|
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||||
|
if ($type === TransactionType::TRANSFER) {
|
||||||
|
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate normal amount for transaction from a transaction group.
|
* Generate normal amount for transaction from a transaction group.
|
||||||
*
|
*
|
||||||
@ -214,7 +272,7 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function normalAmount(array $array): string
|
private function normalJournalArrayAmount(array $array): string
|
||||||
{
|
{
|
||||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||||
$amount = $array['amount'] ?? '0';
|
$amount = $array['amount'] ?? '0';
|
||||||
@ -232,4 +290,44 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate normal amount for transaction from a transaction group.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function normalJournalObjectAmount(TransactionJournal $journal): string
|
||||||
|
{
|
||||||
|
$type = $journal->transactionType->type;
|
||||||
|
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
|
$currency = $journal->transactionCurrency;
|
||||||
|
$amount = $first->amount ?? '0';
|
||||||
|
$colored = true;
|
||||||
|
if ($type !== TransactionType::WITHDRAWAL) {
|
||||||
|
$amount = bcmul($amount, '-1');
|
||||||
|
}
|
||||||
|
if ($type === TransactionType::TRANSFER) {
|
||||||
|
$colored = false;
|
||||||
|
}
|
||||||
|
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||||
|
if ($type === TransactionType::TRANSFER) {
|
||||||
|
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function journalObjectHasForeign(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
/** @var Transaction $first */
|
||||||
|
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
|
|
||||||
|
return null !== $first->foreign_amount;
|
||||||
|
}
|
||||||
}
|
}
|
@ -48,4 +48,34 @@ class Translation extends Twig_Extension
|
|||||||
|
|
||||||
return $filters;
|
return $filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->journalLinkTranslation(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Twig_SimpleFunction
|
||||||
|
*/
|
||||||
|
public function journalLinkTranslation(): Twig_SimpleFunction
|
||||||
|
{
|
||||||
|
return new Twig_SimpleFunction(
|
||||||
|
'journalLinkTranslation',
|
||||||
|
function (string $direction, string $original) {
|
||||||
|
$key = sprintf('firefly.%s_%s', $original, $direction);
|
||||||
|
$translation = trans($key);
|
||||||
|
if ($key === $translation) {
|
||||||
|
return $original;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $translation;
|
||||||
|
},
|
||||||
|
['is_safe' => ['html']]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
9
public/v1/js/ff/budgets/index.js
vendored
9
public/v1/js/ff/budgets/index.js
vendored
@ -26,7 +26,6 @@ $(function () {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$('.updateIncome').on('click', updateIncome);
|
$('.updateIncome').on('click', updateIncome);
|
||||||
$('.infoIncome').on('click', infoIncome);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
On start, fill the "spent"-bar using the content from the page.
|
On start, fill the "spent"-bar using the content from the page.
|
||||||
@ -239,11 +238,3 @@ function updateIncome() {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function infoIncome() {
|
|
||||||
$('#defaultModal').empty().load(infoIncomeUri, function () {
|
|
||||||
$('#defaultModal').modal('show');
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
@ -101,7 +101,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="{% if periods.count > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
<div class="{% if periods|length > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
||||||
@ -116,7 +116,7 @@
|
|||||||
{% include 'list.groups' %}
|
{% include 'list.groups' %}
|
||||||
<p>
|
<p>
|
||||||
<i class="fa fa-calendar"></i>
|
<i class="fa fa-calendar"></i>
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
<a href="{{ route('accounts.show.all', [account.id]) }}">
|
<a href="{{ route('accounts.show.all', [account.id]) }}">
|
||||||
{{ 'show_all_no_filter'|_ }}
|
{{ 'show_all_no_filter'|_ }}
|
||||||
</a>
|
</a>
|
||||||
@ -129,7 +129,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">
|
<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">
|
||||||
{% include 'list.periods' %}
|
{% include 'list.periods' %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,14 +35,15 @@
|
|||||||
<td data-value="{{ link.source.description }}">
|
<td data-value="{{ link.source.description }}">
|
||||||
<a href="{{ route('transactions.show', [link.source_id]) }}">{{ link.source.description }}</a>
|
<a href="{{ route('transactions.show', [link.source_id]) }}">{{ link.source.description }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ link.source|journalTXotalAmount }}</td>
|
<td>
|
||||||
|
{{ journalObjectAmount(link.source) }}
|
||||||
|
</td>
|
||||||
<td>{{ journalLinkTranslation('outward', linkType.outward) }}</td>
|
<td>{{ journalLinkTranslation('outward', linkType.outward) }}</td>
|
||||||
<td data-value="{{ link.destination.description }}">
|
<td data-value="{{ link.destination.description }}">
|
||||||
<a href="{{ route('transactions.show', [link.destination_id]) }}">{{ link.destination.description }}</a>
|
<a href="{{ route('transactions.show', [link.destination_id]) }}">{{ link.destination.description }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ link.destination|journalTotalAmount }}
|
{{ journalObjectAmount(link.destination) }}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<input type="hidden" name="page" value="{{ page }}" />
|
<input type="hidden" name="page" value="{{ page }}" />
|
||||||
|
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>
|
<div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div>
|
||||||
<input step="any" class="form-control" id="amount" value="{{ available }}" autocomplete="off" name="amount" type="number"/>
|
<input step="any" class="form-control" id="amount" value="{{ available }}" autocomplete="off" name="amount" type="number"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
:
|
:
|
||||||
<span id="available" data-value="{{ available }}">{{ available|formatAmountPlain }}</span>
|
<span id="available" data-value="{{ available }}">{{ available|formatAmountPlain }}</span>
|
||||||
<a href="#" class="updateIncome btn btn-default btn-xs"><i class="fa fa-pencil"></i></a>
|
<a href="#" class="updateIncome btn btn-default btn-xs"><i class="fa fa-pencil"></i></a>
|
||||||
<a href="#" class="infoIncome btn btn-info btn-xs"><i class="fa fa-info-circle"></i></a>
|
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -252,7 +251,6 @@
|
|||||||
var budgetIndexUri = "{{ route('budgets.index','REPLACE') }}";
|
var budgetIndexUri = "{{ route('budgets.index','REPLACE') }}";
|
||||||
var budgetAmountUri = "{{ route('budgets.amount','REPLACE') }}";
|
var budgetAmountUri = "{{ route('budgets.amount','REPLACE') }}";
|
||||||
var updateIncomeUri = "{{ route('budgets.income',[start.format('Y-m-d'),end.format('Y-m-d')]) }}?page={{ page }}";
|
var updateIncomeUri = "{{ route('budgets.income',[start.format('Y-m-d'),end.format('Y-m-d')]) }}?page={{ page }}";
|
||||||
var infoIncomeUri = "{{ route('budgets.income.info',[start.format('Y-m-d'),end.format('Y-m-d')]) }}";
|
|
||||||
var periodStart = "{{ start.format('Y-m-d') }}";
|
var periodStart = "{{ start.format('Y-m-d') }}";
|
||||||
var periodEnd = "{{ end.format('Y-m-d') }}";
|
var periodEnd = "{{ end.format('Y-m-d') }}";
|
||||||
</script>
|
</script>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{# upper show-all instruction #}
|
{# upper show-all instruction #}
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-offset-9 col-lg-3 col-md-offset-9 col-md-3 col-sm-12 col-xs-12">
|
<div class="col-lg-offset-9 col-lg-3 col-md-offset-9 col-md-3 col-sm-12 col-xs-12">
|
||||||
<p class="small text-center"><a href="{{ route('budgets.no-budget',['all']) }}">{{ 'showEverything'|_ }}</a></p>
|
<p class="small text-center"><a href="{{ route('budgets.no-budget',['all']) }}">{{ 'showEverything'|_ }}</a></p>
|
||||||
@ -16,14 +16,14 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="{% if periods.count > 0 %}col-lg-9 col-md-9 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
<div class="{% if periods|length > 0 %}col-lg-9 col-md-9 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ subTitle }}</h3>
|
<h3 class="box-title">{{ subTitle }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body ">
|
<div class="box-body ">
|
||||||
|
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
{% include 'list.groups' %}
|
{% include 'list.groups' %}
|
||||||
<p>
|
<p>
|
||||||
<i class="fa fa-calendar"></i>
|
<i class="fa fa-calendar"></i>
|
||||||
@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
|
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
|
||||||
{% include 'list.periods' %}
|
{% include 'list.periods' %}
|
||||||
</div>
|
</div>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# lower show-all instruction #}
|
{# lower show-all instruction #}
|
||||||
{% if periods.count > 0 %}
|
{% if periods|length > 0 %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-offset-9 col-lg-3 col-md-offset-9 col-md-3 col-sm-12 col-xs-12">
|
<div class="col-lg-offset-9 col-lg-3 col-md-offset-9 col-md-3 col-sm-12 col-xs-12">
|
||||||
<p class="small text-center"><a href="{{ route('budgets.no-budget-all') }}">{{ 'showEverything'|_ }}</a></p>
|
<p class="small text-center"><a href="{{ route('budgets.no-budget-all') }}">{{ 'showEverything'|_ }}</a></p>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% for transaction in group.transactions %}
|
{% for transaction in group.transactions %}
|
||||||
{{ transaction.description }}
|
{{ transaction.description }}
|
||||||
<span class="pull-right small">
|
<span class="pull-right small">
|
||||||
{{ transactionAmount(transaction) }}
|
{{ journalArrayAmount(transaction) }}
|
||||||
</span>
|
</span>
|
||||||
<br/>
|
<br/>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -6,42 +6,60 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box-body no-padding">
|
<div class="box-body no-padding">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
{% if period.transactions > 0 %}
|
{% if period.total_transactions > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:33%;">{{ 'transactions'|_ }}</td>
|
<td style="width:33%;">{{ 'transactions'|_ }}</td>
|
||||||
<td style="text-align: right;">{{ period.transactions }}</td>
|
<td style="text-align: right;">{{ period.total_transactions }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# loop all spent amounts #}
|
|
||||||
|
|
||||||
{% for entry in period.spent %}
|
{% for entry in period.spent %}
|
||||||
{# actually spent anything: #}
|
{% if entry.amount != 0 %}
|
||||||
{% if entry.amount !=0 %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:33%;">{{ 'spent'|_ }}</td>
|
<td style="width:33%;">{{ 'spent'|_ }}</td>
|
||||||
<td style="text-align: right;">
|
<td style="text-align: right;">
|
||||||
{{ formatAmountBySymbol(entry.amount * -1, entry.currency.symbol, entry.currency.decimal_places) }}
|
<span title="{{ entry.count }}">
|
||||||
|
{{ formatAmountBySymbol(entry.amount, entry.currency_symbol, entry.currency_decimal_places) }}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
{% for entry in period.earned %}
|
{% for entry in period.earned %}
|
||||||
{% if entry.amount !=0 %}
|
{% if entry.amount != 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:33%;">{{ 'earned'|_ }}</td>
|
<td style="width:33%;">{{ 'earned'|_ }}</td>
|
||||||
<td style="text-align: right;">{{ formatAmountBySymbol(entry.amount, entry.currency.symbol, entry.currency.decimal_places) }}</td>
|
<td style="text-align: right;">
|
||||||
|
<span title="{{ entry.count }}">
|
||||||
|
{{ formatAmountBySymbol(entry.amount*-1, entry.currency_symbol, entry.currency_decimal_places) }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for array in period.transferred.sums %}
|
{% for entry in period.transferred_away %}
|
||||||
{% if array.sum !=0 %}
|
{% if entry.amount != 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:33%;">{{ 'transferred'|_ }}</td>
|
<td style="width:33%;">{{ 'transferred_away'|_ }}</td>
|
||||||
<td style="text-align: right;"><span
|
<td style="text-align: right;">
|
||||||
class="text-info">{{ formatAmountBySymbol(array.sum, array.currency_symbol, array.currency_decimal_places, false) }}</span>
|
<span title="{{ entry.count }}">
|
||||||
|
{{ formatAmountBySymbol(entry.amount*-1, entry.currency_symbol, entry.currency_decimal_places) }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for entry in period.transferred_in %}
|
||||||
|
{% if entry.amount != 0 %}
|
||||||
|
<tr>
|
||||||
|
<td style="width:33%;">{{ 'transferred_in'|_ }}</td>
|
||||||
|
<td style="text-align: right;">
|
||||||
|
<span title="{{ entry.count }}">
|
||||||
|
{{ formatAmountBySymbol(entry.amount*-1, entry.currency_symbol, entry.currency_decimal_places) }}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<td data-value="{{ transaction.description }}">{{ transaction.description }}</td>
|
<td data-value="{{ transaction.description }}">{{ transaction.description }}</td>
|
||||||
<td data-value="{{ transaction.date.format('Y-m-d') }}">
|
<td data-value="{{ transaction.date.format('Y-m-d') }}">
|
||||||
{{ transaction.date.formatLocalized(monthAndDayFormat) }}
|
{{ transaction.date.formatLocalized(monthAndDayFormat) }}
|
||||||
</td>
|
</td><!-- TODO i dont think transactionAmount will work -->
|
||||||
<td style="text-align: right;" data-value="{{ transaction.transaction_amount }}"><span
|
<td style="text-align: right;" data-value="{{ transaction.transaction_amount }}"><span
|
||||||
style="margin-right:5px;">{{ transaction|transactionAmount }}</span></td>
|
style="margin-right:5px;">{{ transaction|transactionAmount }}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -219,7 +219,6 @@ Route::group(
|
|||||||
|
|
||||||
// update budget amount and income amount
|
// update budget amount and income amount
|
||||||
Route::get('income/{start_date}/{end_date}', ['uses' => 'Budget\AmountController@updateIncome', 'as' => 'income']);
|
Route::get('income/{start_date}/{end_date}', ['uses' => 'Budget\AmountController@updateIncome', 'as' => 'income']);
|
||||||
Route::get('info/{start_date}/{end_date}', ['uses' => 'Budget\AmountController@infoIncome', 'as' => 'income.info']);
|
|
||||||
Route::post('income', ['uses' => 'Budget\AmountController@postUpdateIncome', 'as' => 'income.post']);
|
Route::post('income', ['uses' => 'Budget\AmountController@postUpdateIncome', 'as' => 'income.post']);
|
||||||
Route::post('amount/{budget}', ['uses' => 'Budget\AmountController@amount', 'as' => 'amount']);
|
Route::post('amount/{budget}', ['uses' => 'Budget\AmountController@amount', 'as' => 'amount']);
|
||||||
|
|
||||||
|
@ -63,28 +63,19 @@ class CreateControllerTest extends TestCase
|
|||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$euro = $this->getEuro();
|
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// mock hasRole for user repository:
|
// mock hasRole for user repository:
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
// mock default calls
|
||||||
|
$this->mockDefaultSession();
|
||||||
// mock default calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
||||||
|
|
||||||
// mock default calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
// get all types:
|
// get all types:
|
||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||||
@ -105,31 +96,22 @@ class CreateControllerTest extends TestCase
|
|||||||
public function testStore(): void
|
public function testStore(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
|
||||||
$repository->shouldReceive('store')->once()->andReturn($asset);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// mock default calls to Configuration:
|
$repository->shouldReceive('store')->once()->andReturn($asset);
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// change the preference:
|
// change the preference:
|
||||||
$emptyPref = new Preference;
|
$emptyPref = new Preference;
|
||||||
$emptyPref->data = [];
|
$emptyPref->data = [];
|
||||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||||
|
|
||||||
// mock default calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->session(['accounts.create.uri' => 'http://localhost/x']);
|
$this->session(['accounts.create.uri' => 'http://localhost/x']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$data = [
|
$data = [
|
||||||
@ -151,28 +133,20 @@ class CreateControllerTest extends TestCase
|
|||||||
public function testStoreAnother(): void
|
public function testStoreAnother(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
|
||||||
|
|
||||||
$repository->shouldReceive('store')->once()->andReturn($asset);
|
$repository->shouldReceive('store')->once()->andReturn($asset);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// change the preference:
|
// change the preference:
|
||||||
$emptyPref = new Preference;
|
$emptyPref = new Preference;
|
||||||
$emptyPref->data = [];
|
$emptyPref->data = [];
|
||||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
|
|
||||||
// mock default calls to Preferences:
|
// mock default session stuff
|
||||||
$this->mockDefaultPreferences();
|
$this->mockDefaultSession();
|
||||||
//$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
|
||||||
|
|
||||||
// mock default calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -201,28 +175,18 @@ class CreateControllerTest extends TestCase
|
|||||||
public function testStoreLiability(): void
|
public function testStoreLiability(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$liability = $this->getRandomLoan();
|
$liability = $this->getRandomLoan();
|
||||||
$loan = AccountType::where('type', AccountType::LOAN)->first();
|
$loan = AccountType::where('type', AccountType::LOAN)->first();
|
||||||
$euro = $this->getEuro();
|
|
||||||
$repository->shouldReceive('store')->once()->andReturn($liability);
|
$repository->shouldReceive('store')->once()->andReturn($liability);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// change the preference:
|
// change the preference:
|
||||||
$emptyPref = new Preference;
|
$emptyPref = new Preference;
|
||||||
$emptyPref->data = [];
|
$emptyPref->data = [];
|
||||||
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
|
||||||
|
|
||||||
// mock default calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
//$this->mockIntroPreference('shown_demo_accounts_create_asset');
|
|
||||||
|
|
||||||
// mock default calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
|
||||||
|
|
||||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||||
|
@ -62,25 +62,15 @@ class DeleteControllerTest extends TestCase
|
|||||||
public function testDelete(): void
|
public function testDelete(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// mock hasRole for user repository:
|
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
// mock Amount
|
// mock default session stuff
|
||||||
$euro = $this->getEuro();
|
$this->mockDefaultSession();
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
// mock calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('accounts.delete', [$asset->id]));
|
$response = $this->get(route('accounts.delete', [$asset->id]));
|
||||||
@ -96,25 +86,16 @@ class DeleteControllerTest extends TestCase
|
|||||||
public function testDestroy(): void
|
public function testDestroy(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
|
||||||
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
|
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// mock calls to Preferences:
|
// mock default session stuff
|
||||||
$this->mockDefaultPreferences();
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
// mock Amount
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
$this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
|
$this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
|
@ -62,25 +62,20 @@ class EditControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit(): void
|
public function testEdit(): void
|
||||||
{
|
{
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// mock preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
//$repository->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->atLeast()->once();
|
|
||||||
|
|
||||||
// mock hasRole for user repository:
|
// mock hasRole for user repository:
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection)->atLeast()->once();
|
$repository->shouldReceive('get')->andReturn(new Collection)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
||||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull()->atLeast()->once();
|
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull()->atLeast()->once();
|
||||||
@ -100,12 +95,6 @@ class EditControllerTest extends TestCase
|
|||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
||||||
|
|
||||||
// mock calls to Preferences:
|
|
||||||
//$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('accounts.edit', [$asset->id]));
|
$response = $this->get(route('accounts.edit', [$asset->id]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -120,7 +109,6 @@ class EditControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEditLiability(): void
|
public function testEditLiability(): void
|
||||||
{
|
{
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
@ -131,7 +119,7 @@ class EditControllerTest extends TestCase
|
|||||||
|
|
||||||
//$repository->shouldReceive('findNull')->once()->andReturn($euro);
|
//$repository->shouldReceive('findNull')->once()->andReturn($euro);
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||||
@ -151,16 +139,8 @@ class EditControllerTest extends TestCase
|
|||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
|
||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
|
||||||
|
|
||||||
// mock Amount
|
// mock default session stuff
|
||||||
$euro = $this->getEuro();
|
$this->mockDefaultSession();
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
// mock calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('accounts.edit', [$loan->id]));
|
$response = $this->get(route('accounts.edit', [$loan->id]));
|
||||||
@ -177,7 +157,6 @@ class EditControllerTest extends TestCase
|
|||||||
public function testEditNull(): void
|
public function testEditNull(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
@ -185,10 +164,7 @@ class EditControllerTest extends TestCase
|
|||||||
// mock hasRole for user repository:
|
// mock hasRole for user repository:
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(2));
|
|
||||||
//$repository->shouldReceive('findNull')->once()->andReturn(null);
|
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
|
||||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
|
||||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
|
||||||
@ -203,11 +179,8 @@ class EditControllerTest extends TestCase
|
|||||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
||||||
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
|
||||||
|
|
||||||
// mock calls to Preferences:
|
// mock default session stuff
|
||||||
$this->mockDefaultPreferences();
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
// get all types:
|
// get all types:
|
||||||
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
|
||||||
@ -232,18 +205,15 @@ class EditControllerTest extends TestCase
|
|||||||
public function testUpdate(): void
|
public function testUpdate(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$this->mock(CurrencyRepositoryInterface::class);
|
$this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
$repository->shouldReceive('update')->once();
|
$repository->shouldReceive('update')->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
|
|
||||||
$euro = $this->getEuro();
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
|
$this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$data = [
|
$data = [
|
||||||
@ -252,12 +222,6 @@ class EditControllerTest extends TestCase
|
|||||||
'what' => 'asset',
|
'what' => 'asset',
|
||||||
];
|
];
|
||||||
|
|
||||||
// mock calls to Preferences:
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
$response = $this->post(route('accounts.update', [1]), $data);
|
$response = $this->post(route('accounts.update', [1]), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
@ -271,11 +235,9 @@ class EditControllerTest extends TestCase
|
|||||||
public function testUpdateAgain(): void
|
public function testUpdateAgain(): void
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$this->mock(CurrencyRepositoryInterface::class);
|
$this->mock(CurrencyRepositoryInterface::class);
|
||||||
$repository->shouldReceive('update')->once();
|
$repository->shouldReceive('update')->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
$this->session(['accounts.edit.uri' => 'http://localhost']);
|
$this->session(['accounts.edit.uri' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -286,15 +248,10 @@ class EditControllerTest extends TestCase
|
|||||||
'return_to_edit' => '1',
|
'return_to_edit' => '1',
|
||||||
];
|
];
|
||||||
|
|
||||||
$euro = $this->getEuro();
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
// mock calls to Preferences:
|
// mock default session stuff
|
||||||
$this->mockDefaultPreferences();
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
$response = $this->post(route('accounts.update', [1]), $data);
|
$response = $this->post(route('accounts.update', [1]), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
|
@ -67,7 +67,6 @@ class IndexControllerTest extends TestCase
|
|||||||
// mock stuff
|
// mock stuff
|
||||||
$account = $this->getRandomAsset();
|
$account = $this->getRandomAsset();
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
@ -76,17 +75,12 @@ class IndexControllerTest extends TestCase
|
|||||||
|
|
||||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
|
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
|
||||||
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
|
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
|
||||||
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
// mock calls to Preferences:
|
$this->mockDefaultSession();
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// mock calls to Configuration:
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
// list size
|
// list size
|
||||||
$pref = new Preference;
|
$pref = new Preference;
|
||||||
@ -94,7 +88,6 @@ class IndexControllerTest extends TestCase
|
|||||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
|
||||||
Amount::shouldReceive('formatAnything')->andReturn('123');
|
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
|
||||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
||||||
|
@ -23,16 +23,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Feature\Controllers\Account;
|
namespace Tests\Feature\Controllers\Account;
|
||||||
|
|
||||||
use Amount;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\TransactionGroupFactory;
|
use FireflyIII\Factory\TransactionGroupFactory;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
@ -67,24 +64,21 @@ class ReconcileControllerTest extends TestCase
|
|||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$this->mock(GroupCollectorInterface::class);
|
$this->mock(GroupCollectorInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$euro = $this->getEuro();
|
||||||
$euro = $this->getEuro();
|
$asset = $this->getRandomAsset();
|
||||||
$asset = $this->getRandomAsset();
|
$date = new Carbon;
|
||||||
$date = new Carbon;
|
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturnTrue();
|
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturnTrue();
|
||||||
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
|
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
|
||||||
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('accounts.reconcile', [$asset->id, '20170101', '20170131']));
|
$response = $this->get(route('accounts.reconcile', [$asset->id, '20170101', '20170131']));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -103,7 +97,7 @@ class ReconcileControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mockDefaultSession();
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
@ -112,16 +106,9 @@ class ReconcileControllerTest extends TestCase
|
|||||||
$this->mock(CurrencyRepositoryInterface::class);
|
$this->mock(CurrencyRepositoryInterface::class);
|
||||||
$this->mock(GroupCollectorInterface::class);
|
$this->mock(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$journalRepos->shouldReceive('reconcileById')->times(3);
|
$journalRepos->shouldReceive('reconcileById')->times(3);
|
||||||
@ -130,6 +117,7 @@ class ReconcileControllerTest extends TestCase
|
|||||||
$factory->shouldReceive('setUser')->atLeast()->once();
|
$factory->shouldReceive('setUser')->atLeast()->once();
|
||||||
$factory->shouldReceive('create')->andReturn($group);
|
$factory->shouldReceive('create')->andReturn($group);
|
||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'journals' => [1, 2, 3],
|
'journals' => [1, 2, 3],
|
||||||
'reconcile' => 'create',
|
'reconcile' => 'create',
|
||||||
@ -154,23 +142,14 @@ class ReconcileControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mockDefaultSession();
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$factory = $this->mock(TransactionGroupFactory::class);
|
$factory = $this->mock(TransactionGroupFactory::class);
|
||||||
$group = $this->getRandomWithdrawalGroup();
|
|
||||||
$this->mock(CurrencyRepositoryInterface::class);
|
$this->mock(CurrencyRepositoryInterface::class);
|
||||||
$this->mock(GroupCollectorInterface::class);
|
$this->mock(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
@ -27,11 +27,9 @@ use Amount;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Log;
|
use Log;
|
||||||
@ -68,12 +66,10 @@ class ShowControllerTest extends TestCase
|
|||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
|
//$tasker = $this->mock(AccountTaskerInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$this->mock(CurrencyRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
//$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$collector = $this->mock(GroupCollectorInterface::class);
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$journal = $this->getRandomWithdrawalAsArray();
|
$journal = $this->getRandomWithdrawalAsArray();
|
||||||
@ -81,26 +77,19 @@ class ShowControllerTest extends TestCase
|
|||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
// mock stuff
|
$this->mockDefaultSession();
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// amount mocks:
|
// amount mocks:
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||||
|
|
||||||
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
||||||
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
||||||
|
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// list size
|
// list size
|
||||||
$pref = new Preference;
|
$pref = new Preference;
|
||||||
$pref->data = 50;
|
$pref->data = 50;
|
||||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
Preferences::shouldReceive('lastActivity')->atLeast()->once();
|
$this->mockLastActivity();
|
||||||
// mock hasRole for user repository:
|
// mock hasRole for user repository:
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
@ -132,8 +121,6 @@ class ShowControllerTest extends TestCase
|
|||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
@ -145,22 +132,12 @@ class ShowControllerTest extends TestCase
|
|||||||
$euro = $this->getEuro();
|
$euro = $this->getEuro();
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
|
|
||||||
// mock stuff
|
$this->mockDefaultSession();
|
||||||
$this->mockDefaultConfiguration();
|
|
||||||
$this->mockDefaultPreferences();
|
|
||||||
|
|
||||||
// amount mocks:
|
|
||||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
|
||||||
// Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
|
||||||
|
|
||||||
$repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
|
$repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
|
||||||
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
$repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
|
||||||
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
||||||
|
|
||||||
|
|
||||||
// used for session range.
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
// list size
|
// list size
|
||||||
$pref = new Preference;
|
$pref = new Preference;
|
||||||
$pref->data = 50;
|
$pref->data = 50;
|
||||||
|
@ -22,11 +22,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Feature\Controllers\Admin;
|
namespace Tests\Feature\Controllers\Admin;
|
||||||
|
|
||||||
|
use Amount;
|
||||||
use FireflyConfig;
|
use FireflyConfig;
|
||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,14 +48,19 @@ class ConfigurationControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||||
*/
|
*/
|
||||||
public function testIndex(): void
|
public function testIndex(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
|
// for session
|
||||||
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
$this->mockDefaultPreferences();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$falseConfig = new Configuration;
|
$falseConfig = new Configuration;
|
||||||
@ -72,10 +81,19 @@ class ConfigurationControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||||
|
* @covers \FireflyIII\Http\Requests\ConfigurationRequest
|
||||||
*/
|
*/
|
||||||
public function testPostIndex(): void
|
public function testPostIndex(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
|
// for session
|
||||||
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
$this->mockDefaultPreferences();
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
@ -86,6 +104,7 @@ class ConfigurationControllerTest extends TestCase
|
|||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['single_user_mode', false])->once();
|
FireflyConfig::shouldReceive('set')->withArgs(['single_user_mode', false])->once();
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['is_demo_site', false])->once();
|
FireflyConfig::shouldReceive('set')->withArgs(['is_demo_site', false])->once();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('admin.configuration.index.post'));
|
$response = $this->post(route('admin.configuration.index.post'));
|
||||||
|
@ -22,8 +22,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Feature\Controllers\Admin;
|
namespace Tests\Feature\Controllers\Admin;
|
||||||
|
|
||||||
|
use Amount;
|
||||||
use Event;
|
use Event;
|
||||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
@ -49,6 +52,14 @@ class HomeControllerTest extends TestCase
|
|||||||
public function testIndex(): void
|
public function testIndex(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
|
// default for session
|
||||||
|
$this->mockDefaultPreferences();
|
||||||
|
$this->mockDefaultConfiguration();
|
||||||
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
@ -65,6 +76,13 @@ class HomeControllerTest extends TestCase
|
|||||||
public function testTestMessage(): void
|
public function testTestMessage(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
|
||||||
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
$this->mockDefaultPreferences();
|
||||||
|
$this->mockDefaultConfiguration();
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
@ -29,6 +29,7 @@ use Illuminate\Support\Collection;
|
|||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LinkControllerTest
|
* Class LinkControllerTest
|
||||||
@ -50,6 +51,11 @@ class LinkControllerTest extends TestCase
|
|||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
@ -66,17 +72,23 @@ class LinkControllerTest extends TestCase
|
|||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
// create editable link type just in case:
|
// create editable link type just in case:
|
||||||
LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
$newType = LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
$linkType = LinkType::where('editable', 1)->first();
|
$linkType = LinkType::where('editable', 1)->first();
|
||||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType]));
|
$another= LinkType::where('editable', 0)->first();
|
||||||
|
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType, $another]));
|
||||||
$repository->shouldReceive('countJournals')->andReturn(2);
|
$repository->shouldReceive('countJournals')->andReturn(2);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$newType->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,6 +100,9 @@ class LinkControllerTest extends TestCase
|
|||||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
$linkType = LinkType::where('editable', 0)->first();
|
$linkType = LinkType::where('editable', 0)->first();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -107,6 +122,10 @@ class LinkControllerTest extends TestCase
|
|||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
// create editable link type just in case:
|
// create editable link type just in case:
|
||||||
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
||||||
|
|
||||||
@ -126,10 +145,14 @@ class LinkControllerTest extends TestCase
|
|||||||
public function testEditEditable(): void
|
public function testEditEditable(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
// create editable link type just in case:
|
// create editable link type just in case:
|
||||||
LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
|
LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
|
||||||
|
|
||||||
@ -145,10 +168,15 @@ class LinkControllerTest extends TestCase
|
|||||||
public function testEditNonEditable(): void
|
public function testEditNonEditable(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
$linkType = LinkType::where('editable', 0)->first();
|
$linkType = LinkType::where('editable', 0)->first();
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
||||||
@ -162,9 +190,13 @@ class LinkControllerTest extends TestCase
|
|||||||
public function testIndex(): void
|
public function testIndex(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
//Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$linkTypes = LinkType::inRandomOrder()->take(3)->get();
|
$linkTypes = LinkType::inRandomOrder()->take(3)->get();
|
||||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
@ -181,8 +213,11 @@ class LinkControllerTest extends TestCase
|
|||||||
public function testShow(): void
|
public function testShow(): void
|
||||||
{
|
{
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getJournalLinks')->andReturn(new Collection);
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
$linkType = LinkType::first();
|
$linkType = LinkType::first();
|
||||||
@ -203,10 +238,13 @@ class LinkControllerTest extends TestCase
|
|||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'test ' . random_int(1, 10000),
|
'name' => sprintf('test %d', $this->randomInt()),
|
||||||
'inward' => 'test inward' . random_int(1, 10000),
|
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||||
'outward' => 'test outward' . random_int(1, 10000),
|
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||||
];
|
];
|
||||||
$repository->shouldReceive('store')->once()->andReturn(LinkType::first());
|
$repository->shouldReceive('store')->once()->andReturn(LinkType::first());
|
||||||
$repository->shouldReceive('findNull')->andReturn(LinkType::first());
|
$repository->shouldReceive('findNull')->andReturn(LinkType::first());
|
||||||
@ -230,10 +268,13 @@ class LinkControllerTest extends TestCase
|
|||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'test ' . random_int(1, 10000),
|
'name' => sprintf('test %d', $this->randomInt()),
|
||||||
'inward' => 'test inward' . random_int(1, 10000),
|
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||||
'outward' => 'test outward' . random_int(1, 10000),
|
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||||
'create_another' => '1',
|
'create_another' => '1',
|
||||||
];
|
];
|
||||||
$repository->shouldReceive('store')->once()->andReturn(new LinkType);
|
$repository->shouldReceive('store')->once()->andReturn(new LinkType);
|
||||||
@ -260,10 +301,14 @@ class LinkControllerTest extends TestCase
|
|||||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
$linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'test ' . random_int(1, 10000),
|
'name' => sprintf('test %d', $this->randomInt()),
|
||||||
'inward' => 'test inward' . random_int(1, 10000),
|
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||||
'outward' => 'test outward' . random_int(1, 10000),
|
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||||
];
|
];
|
||||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -284,12 +329,14 @@ class LinkControllerTest extends TestCase
|
|||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
$linkType = LinkType::where('editable', 0)->first();
|
$linkType = LinkType::where('editable', 0)->first();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'test ' . random_int(1, 10000),
|
'name' => sprintf('test %d', $this->randomInt()),
|
||||||
'inward' => 'test inward' . random_int(1, 10000),
|
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||||
'outward' => 'test outward' . random_int(1, 10000),
|
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||||
'return_to_edit' => '1',
|
'return_to_edit' => '1',
|
||||||
];
|
];
|
||||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||||
@ -314,10 +361,14 @@ class LinkControllerTest extends TestCase
|
|||||||
// create editable link type just in case:
|
// create editable link type just in case:
|
||||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
||||||
|
|
||||||
|
// mock default session stuff
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'test ' . random_int(1, 10000),
|
'name' => sprintf('test %d', $this->randomInt()),
|
||||||
'inward' => 'test inward' . random_int(1, 10000),
|
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||||
'outward' => 'test outward' . random_int(1, 10000),
|
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||||
'return_to_edit' => '1',
|
'return_to_edit' => '1',
|
||||||
];
|
];
|
||||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||||
|
@ -52,25 +52,22 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex(): void
|
public function testIndex(): void
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
// mock calls
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
// mock update calls.
|
||||||
|
$config = new Configuration;
|
||||||
$config = new Configuration;
|
$config->data = -1;
|
||||||
$config->data = -1;
|
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
|
||||||
$falseConfig->data = false;
|
|
||||||
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
|
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
|
|
||||||
|
// call service
|
||||||
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.update-check'));
|
$response = $this->get(route('admin.update-check'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
// has bread crumb
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +76,19 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testPost(): void
|
public function testPost(): void
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
// mock calls
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
// mock update calls
|
||||||
$falseConfig->data = false;
|
|
||||||
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||||
|
|
||||||
|
// call service
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
|
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
@ -103,16 +102,16 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdateCheck(): void
|
public function testUpdateCheck(): void
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
// mock calls
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
|
||||||
$falseConfig->data = false;
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
// set some data
|
||||||
$version = config('firefly.version');
|
$version = config('firefly.version');
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$date->subDays(5);
|
$date->subDays(5);
|
||||||
@ -138,14 +137,13 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdateCheckCurrent(): void
|
public function testUpdateCheckCurrent(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
|
||||||
$falseConfig->data = false;
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||||
|
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
@ -175,13 +173,10 @@ class UpdateControllerTest extends TestCase
|
|||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
|
||||||
$falseConfig->data = false;
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||||
|
|
||||||
$version = config('firefly.version') . '-alpha';
|
|
||||||
$releases = [];
|
$releases = [];
|
||||||
$updater = $this->mock(UpdateRequest::class);
|
$updater = $this->mock(UpdateRequest::class);
|
||||||
$updater->shouldReceive('call')->andThrow(FireflyException::class, 'Something broke.');
|
$updater->shouldReceive('call')->andThrow(FireflyException::class, 'Something broke.');
|
||||||
@ -203,10 +198,8 @@ class UpdateControllerTest extends TestCase
|
|||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$falseConfig = new Configuration;
|
|
||||||
$falseConfig->data = false;
|
|
||||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
|
||||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||||
|
|
||||||
$version = config('firefly.version') . '-alpha';
|
$version = config('firefly.version') . '-alpha';
|
||||||
|
@ -26,6 +26,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +51,9 @@ class UserControllerTest extends TestCase
|
|||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.users.delete', [1]));
|
$response = $this->get(route('admin.users.delete', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -67,6 +71,8 @@ class UserControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('admin.users.destroy', ['2']));
|
$response = $this->post(route('admin.users.destroy', ['2']));
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -81,6 +87,9 @@ class UserControllerTest extends TestCase
|
|||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.users.edit', [1]));
|
$response = $this->get(route('admin.users.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -98,6 +107,15 @@ class UserControllerTest extends TestCase
|
|||||||
$user = $this->user();
|
$user = $this->user();
|
||||||
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
|
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
|
||||||
|
|
||||||
|
Preferences::shouldReceive('getArrayForUser')->atLeast()->once()->andReturn(
|
||||||
|
[
|
||||||
|
'twoFactorAuthEnabled' => false,
|
||||||
|
'twoFactorAuthSecret' => null,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($user);
|
$this->be($user);
|
||||||
$response = $this->get(route('admin.users'));
|
$response = $this->get(route('admin.users'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -120,6 +138,8 @@ class UserControllerTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('admin.users.show', [1]));
|
$response = $this->get(route('admin.users.show', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -129,6 +149,7 @@ class UserControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Admin\UserController
|
* @covers \FireflyIII\Http\Controllers\Admin\UserController
|
||||||
|
* @covers \FireflyIII\Http\Requests\UserFormRequest
|
||||||
*/
|
*/
|
||||||
public function testUpdate(): void
|
public function testUpdate(): void
|
||||||
{
|
{
|
||||||
@ -138,6 +159,10 @@ class UserControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('updateEmail')->once();
|
$repository->shouldReceive('updateEmail')->once();
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark');
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
|
@ -24,17 +24,15 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Feature\Controllers\Budget;
|
namespace Tests\Feature\Controllers\Budget;
|
||||||
|
|
||||||
|
|
||||||
|
use Amount;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Log;
|
use Log;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,24 +55,24 @@ class AmountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAmount(): void
|
public function testAmount(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info('Now in testAmount()');
|
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$budget = $this->getRandomBudget();
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
// assert some reactions:
|
||||||
|
$response->assertSee($budget->name);
|
||||||
|
$response->assertSee('"amount":"200"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,211 +81,23 @@ class AmountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAmountLargeDiff(): void
|
public function testAmountLargeDiff(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$budget = $this->getRandomBudget();
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info('Now in testAmountLargeDiff()');
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
$data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
|
||||||
$response->assertStatus(200);
|
|
||||||
$response->assertSee('Normally you budget about \u20ac10.00 per day.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
|
||||||
*/
|
|
||||||
public function testAmountOutOfRange(): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info('Now in testAmountOutOfRange()');
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
||||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
|
||||||
|
|
||||||
$today = new Carbon;
|
|
||||||
$start = $today->startOfMonth()->format('Y-m-d');
|
|
||||||
$end = $today->endOfMonth()->format('Y-m-d');
|
|
||||||
$data = ['amount' => 200, 'start' => $start, 'end' => $end];
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
|
||||||
*/
|
|
||||||
public function testAmountZero(): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info('Now in testAmountZero()');
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
||||||
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
|
|
||||||
|
|
||||||
$data = ['amount' => 0, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
|
||||||
*/
|
|
||||||
public function testInfoIncome(): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info('Now in testInfoIncome()');
|
|
||||||
// mock stuff
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
||||||
$date = new Carbon;
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
|
||||||
|
|
||||||
// collect transactions to return. First an expense, then income.
|
|
||||||
$income = new Transaction;
|
|
||||||
$income->transaction_amount = '150';
|
|
||||||
$incomeCollection = new Collection([$income]);
|
|
||||||
$expense = new Transaction;
|
|
||||||
$expense->transaction_amount = '100';
|
|
||||||
$expenseCollection = new Collection([$expense]);
|
|
||||||
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
|
||||||
|
|
||||||
|
|
||||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
|
||||||
$accountRepos->shouldReceive('setUser');
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
||||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
|
||||||
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
|
||||||
* @dataProvider dateRangeProvider
|
|
||||||
*
|
|
||||||
* @param string $range
|
|
||||||
*/
|
|
||||||
public function testInfoIncomeExpanded(string $range): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info(sprintf('Now in testInfoIncomeExpanded(%s)', $range));
|
|
||||||
// mock stuff
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
||||||
$date = new Carbon;
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
|
|
||||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
|
||||||
$accountRepos->shouldReceive('setUser');
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
||||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
|
||||||
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
|
||||||
|
|
||||||
// collect transactions to return. First an expense, then income.
|
|
||||||
$income = new Transaction;
|
|
||||||
$income->transaction_amount = '150';
|
|
||||||
$incomeCollection = new Collection([$income]);
|
|
||||||
$expense = new Transaction;
|
|
||||||
$expense->transaction_amount = '100';
|
|
||||||
$expenseCollection = new Collection([$expense]);
|
|
||||||
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
|
||||||
|
|
||||||
$this->be($this->user());
|
|
||||||
$this->changeDateRange($this->user(), $range);
|
|
||||||
$response = $this->get(route('budgets.income.info', ['20170301', '20170430']));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
|
|
||||||
*/
|
|
||||||
public function testInfoIncomeInversed(): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
Log::info('Now in testInfoIncomeInversed()');
|
|
||||||
// mock stuff
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
||||||
$date = new Carbon;
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
|
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
|
|
||||||
|
|
||||||
// collect transactions to return. First an expense, then income.
|
|
||||||
$income = new Transaction;
|
|
||||||
$income->transaction_amount = '100';
|
|
||||||
$incomeCollection = new Collection([$income]);
|
|
||||||
$expense = new Transaction;
|
|
||||||
$expense->transaction_amount = '150';
|
|
||||||
$expenseCollection = new Collection([$expense]);
|
|
||||||
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
|
|
||||||
|
|
||||||
|
|
||||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
|
||||||
$accountRepos->shouldReceive('setUser');
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
||||||
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
|
|
||||||
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('Usually you budget about 200 per day.');
|
||||||
|
$response->assertSee($budget->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,23 +105,13 @@ class AmountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testPostUpdateIncome(): void
|
public function testPostUpdateIncome(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
Log::info('Now in testPostUpdateIncome()');
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
||||||
$date = new Carbon;
|
|
||||||
//$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
//$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('setAvailableBudget');
|
$repository->shouldReceive('setAvailableBudget');
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.income.post'), $data);
|
$response = $this->post(route('budgets.income.post'), $data);
|
||||||
@ -324,26 +124,19 @@ class AmountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdateIncome(): void
|
public function testUpdateIncome(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
Log::info('Now in testUpdateIncome()');
|
|
||||||
// must be in list
|
|
||||||
$this->be($this->user());
|
|
||||||
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
|
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,11 @@ namespace Tests\Feature\Controllers\Budget;
|
|||||||
|
|
||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,14 +53,13 @@ class CreateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
Log::debug('Now in testCreate()');
|
$this->mock(BudgetRepositoryInterface::class);
|
||||||
// mock stuff
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.create'));
|
$response = $this->get(route('budgets.create'));
|
||||||
@ -78,20 +76,20 @@ class CreateControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
Log::debug('Now in testStore()');
|
Log::debug('Now in testStore()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$budget = factory(Budget::class)->make();
|
$budget = $this->getRandomBudget();
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||||
$repository->shouldReceive('store')->andReturn($budget);
|
$repository->shouldReceive('store')->andReturn($budget);
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$this->session(['budgets.create.uri' => 'http://localhost']);
|
$this->session(['budgets.create.uri' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'New Budget ' . $this->randomInt(),
|
'name' => sprintf('New Budget %s', $this->randomInt()),
|
||||||
];
|
];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.store'), $data);
|
$response = $this->post(route('budgets.store'), $data);
|
||||||
|
@ -29,6 +29,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,12 +55,13 @@ class DeleteControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
Log::debug('Now in testDelete()');
|
Log::debug('Now in testDelete()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.delete', [1]));
|
$response = $this->get(route('budgets.delete', [1]));
|
||||||
@ -75,11 +77,11 @@ class DeleteControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
Log::debug('Now in testDestroy()');
|
Log::debug('Now in testDestroy()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,13 +56,11 @@ class EditControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
Log::debug('Now in testEdit()');
|
Log::debug('Now in testEdit()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.edit', [1]));
|
$response = $this->get(route('budgets.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -77,16 +76,17 @@ class EditControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
Log::debug('Now in testUpdate()');
|
Log::debug('Now in testUpdate()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$budget = factory(Budget::class)->make();
|
$budget = $this->getRandomBudget();
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$this->mock(UserRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||||
$repository->shouldReceive('update');
|
$repository->shouldReceive('update');
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||||
|
|
||||||
$this->session(['budgets.edit.uri' => 'http://localhost']);
|
$this->session(['budgets.edit.uri' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -24,9 +24,9 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Feature\Controllers\Budget;
|
namespace Tests\Feature\Controllers\Budget;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
@ -35,6 +35,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
|
use Amount;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,14 +62,9 @@ class IndexControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex(string $range): void
|
public function testIndex(string $range): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
Log::info(sprintf('Now in testIndex(%s)', $range));
|
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$budget = factory(Budget::class)->make();
|
$budget = $this->getRandomBudget();
|
||||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
$budgetLimit = $this->getRandomBudgetLimit();
|
||||||
|
|
||||||
// set budget limit to current month:
|
|
||||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||||
$budgetInfo = [
|
$budgetInfo = [
|
||||||
@ -80,11 +77,9 @@ class IndexControllerTest extends TestCase
|
|||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
@ -95,6 +90,14 @@ class IndexControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||||
|
// list size
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('budgets.index'));
|
$response = $this->get(route('budgets.index'));
|
||||||
@ -111,10 +114,8 @@ class IndexControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndexOutOfRange(string $range): void
|
public function testIndexOutOfRange(string $range): void
|
||||||
{
|
{
|
||||||
Log::info(sprintf('Now in testIndexOutOfRange(%s)', $range));
|
$budget = $this->getRandomBudget();
|
||||||
// mock stuff
|
$budgetLimit = $this->getRandomBudgetLimit();
|
||||||
$budget = factory(Budget::class)->make();
|
|
||||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
||||||
$budgetInfo = [
|
$budgetInfo = [
|
||||||
$budget->id => [
|
$budget->id => [
|
||||||
'spent' => '0',
|
'spent' => '0',
|
||||||
@ -129,7 +130,6 @@ class IndexControllerTest extends TestCase
|
|||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
@ -137,7 +137,6 @@ class IndexControllerTest extends TestCase
|
|||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
@ -148,6 +147,14 @@ class IndexControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||||
|
// list size
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$today = new Carbon;
|
$today = new Carbon;
|
||||||
$today->startOfMonth();
|
$today->startOfMonth();
|
||||||
@ -166,10 +173,8 @@ class IndexControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndexWithDate(string $range): void
|
public function testIndexWithDate(string $range): void
|
||||||
{
|
{
|
||||||
Log::info(sprintf('Now in testIndexWithDate(%s)', $range));
|
$budget = $this->getRandomBudget();
|
||||||
// mock stuff
|
$budgetLimit = $this->getRandomBudgetLimit();
|
||||||
$budget = factory(Budget::class)->make();
|
|
||||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
||||||
$budgetInfo = [
|
$budgetInfo = [
|
||||||
$budget->id => [
|
$budget->id => [
|
||||||
'spent' => '0',
|
'spent' => '0',
|
||||||
@ -184,17 +189,13 @@ class IndexControllerTest extends TestCase
|
|||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||||
@ -203,6 +204,14 @@ class IndexControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
$this->mockIntroPreference('shown_demo_budgets_index');
|
||||||
|
// list size
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('budgets.index', ['2017-01-01']));
|
$response = $this->get(route('budgets.index', ['2017-01-01']));
|
||||||
@ -219,36 +228,24 @@ class IndexControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndexWithInvalidDate(string $range): void
|
public function testIndexWithInvalidDate(string $range): void
|
||||||
{
|
{
|
||||||
Log::info(sprintf('Now in testIndexWithInvalidDate(%s)', $range));
|
$budgetLimit = $this->getRandomBudgetLimit();
|
||||||
// mock stuff
|
|
||||||
$budget = factory(Budget::class)->make();
|
|
||||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
||||||
|
|
||||||
// set budget limit to current month:
|
// set budget limit to current month:
|
||||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||||
$budgetInfo = [
|
|
||||||
$budget->id => [
|
|
||||||
'spent' => '0',
|
|
||||||
'budgeted' => '0',
|
|
||||||
'currentRep' => false,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$this->mock(UserRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
Amount::shouldReceive('formatAnything')->andReturn('123');
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('budgets.index', ['Hello-there']));
|
$response = $this->get(route('budgets.index', ['Hello-there']));
|
||||||
|
@ -23,10 +23,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Feature\Controllers\Budget;
|
namespace Tests\Feature\Controllers\Budget;
|
||||||
|
|
||||||
|
use Amount;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use Exception;
|
||||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
@ -36,11 +38,13 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Class ShowControllerTest
|
* Class ShowControllerTest
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
class ShowControllerTest extends TestCase
|
class ShowControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -63,36 +67,41 @@ class ShowControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoBudget(string $range): void
|
public function testNoBudget(string $range): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
$this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
return;
|
|
||||||
|
|
||||||
Log::info(sprintf('Now in testNoBudget(%s)', $range));
|
|
||||||
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
try {
|
||||||
|
$date = new Carbon;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
|
|
||||||
|
// mock calls
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||||
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||||
|
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
||||||
|
|
||||||
$date = new Carbon();
|
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('budgets.no-budget'));
|
$response = $this->get(route('budgets.no-budget', ['2019-01-01', '2019-01-31']));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
// has bread crumb
|
// has bread crumb
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
@ -106,30 +115,35 @@ class ShowControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoBudgetAll(string $range): void
|
public function testNoBudgetAll(string $range): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
$this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
try {
|
||||||
|
$date = new Carbon;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
// mock calls
|
||||||
Log::info(sprintf('Now in testNoBudgetAll(%s)', $range));
|
$pref = new Preference;
|
||||||
// mock stuff
|
$pref->data = 50;
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
|
||||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
||||||
|
|
||||||
$date = new Carbon();
|
try {
|
||||||
|
$date = new Carbon;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
}
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -140,53 +154,6 @@ class ShowControllerTest extends TestCase
|
|||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
|
||||||
* @dataProvider dateRangeProvider
|
|
||||||
*
|
|
||||||
* @param string $range
|
|
||||||
*/
|
|
||||||
public function testNoBudgetDate(string $range): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info(sprintf('Now in testNoBudgetDate(%s)', $range));
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
|
||||||
$date = new Carbon;
|
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
|
||||||
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
||||||
|
|
||||||
$date = new Carbon();
|
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
|
||||||
|
|
||||||
$this->be($this->user());
|
|
||||||
$this->changeDateRange($this->user(), $range);
|
|
||||||
$response = $this->get(route('budgets.no-budget', ['2016-01-01']));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
// has bread crumb
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||||
* @dataProvider dateRangeProvider
|
* @dataProvider dateRangeProvider
|
||||||
@ -195,31 +162,29 @@ class ShowControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow(string $range): void
|
public function testShow(string $range): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
$budgetLimit = $this->getRandomBudgetLimit();
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info(sprintf('Now in testShow(%s)', $range));
|
|
||||||
// mock stuff
|
|
||||||
|
|
||||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
|
||||||
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
// mock calls
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||||
|
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
||||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
|
||||||
|
|
||||||
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
@ -228,9 +193,14 @@ class ShowControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||||
|
|
||||||
$date = new Carbon();
|
try {
|
||||||
$date->subDay();
|
$date = new Carbon;
|
||||||
$this->session(['first' => $date]);
|
$date->subDay();
|
||||||
|
$this->session(['first' => $date]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
@ -239,24 +209,6 @@ class ShowControllerTest extends TestCase
|
|||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
|
||||||
*/
|
|
||||||
public function testShowByBadBudgetLimit(): void
|
|
||||||
{
|
|
||||||
Log::info('Now in testShowByBadBudgetLimit()');
|
|
||||||
// mock stuff
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('budgets.show.limit', [1, 8]));
|
|
||||||
$response->assertStatus(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
|
||||||
* @dataProvider dateRangeProvider
|
* @dataProvider dateRangeProvider
|
||||||
@ -265,29 +217,32 @@ class ShowControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowByBudgetLimit(string $range): void
|
public function testShowByBudgetLimit(string $range): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
||||||
|
|
||||||
return;
|
|
||||||
Log::info(sprintf('Now in testShowByBudgetLimit(%s)', $range));
|
|
||||||
// mock stuff
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
|
||||||
|
$this->mockDefaultSession();
|
||||||
|
|
||||||
|
|
||||||
|
// mock calls
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data = 50;
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||||
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||||
|
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
||||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||||
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
|
||||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
|
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use Amount;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Closure;
|
use Closure;
|
||||||
use DB;
|
use DB;
|
||||||
@ -33,12 +34,14 @@ use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Transformers\TransactionTransformer;
|
use FireflyIII\Transformers\TransactionTransformer;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
@ -54,6 +57,45 @@ use RuntimeException;
|
|||||||
*/
|
*/
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Budget
|
||||||
|
*/
|
||||||
|
public function getRandomBudget(): Budget
|
||||||
|
{
|
||||||
|
return $this->user()->budgets()->inRandomOrder()->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BudgetLimit
|
||||||
|
*/
|
||||||
|
public function getRandomBudgetLimit(): BudgetLimit
|
||||||
|
{
|
||||||
|
return BudgetLimit
|
||||||
|
::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||||
|
->where('budgets.user_id', $this->user()->id)
|
||||||
|
->inRandomOrder()->first(['budget_limits.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function mockDefaultSession()
|
||||||
|
{
|
||||||
|
$this->mockDefaultConfiguration();
|
||||||
|
$this->mockDefaultPreferences();
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
|
$journal = new TransactionJournal;
|
||||||
|
$journal->date = new Carbon;
|
||||||
|
|
||||||
|
$journalRepos->shouldReceive('firstNull')->andReturn($journal);
|
||||||
|
|
||||||
|
return $journalRepos;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock the Preferences call that checks if the user has seen the introduction popups already.
|
* Mock the Preferences call that checks if the user has seen the introduction popups already.
|
||||||
*
|
*
|
||||||
@ -94,7 +136,12 @@ abstract class TestCase extends BaseTestCase
|
|||||||
return [
|
return [
|
||||||
'transaction_journal_id' => $withdrawal->id,
|
'transaction_journal_id' => $withdrawal->id,
|
||||||
'currency_id' => $euro->id,
|
'currency_id' => $euro->id,
|
||||||
|
'foreign_currency_id' => null,
|
||||||
|
'date' => new Carbon,
|
||||||
|
'source_account_id' => 1,
|
||||||
|
'destination_account_id' => 4,
|
||||||
'currency_name' => $euro->name,
|
'currency_name' => $euro->name,
|
||||||
|
'currency_code' => $euro->code,
|
||||||
'currency_symbol' => $euro->symbol,
|
'currency_symbol' => $euro->symbol,
|
||||||
'currency_decimal_places' => $euro->decimal_places,
|
'currency_decimal_places' => $euro->decimal_places,
|
||||||
'amount' => '-30',
|
'amount' => '-30',
|
||||||
|
@ -298,11 +298,11 @@ class TransferCurrenciesCorrectionsTest extends TestCase
|
|||||||
$dollar = $this->getDollar();
|
$dollar = $this->getDollar();
|
||||||
|
|
||||||
// make sure that source and destination have the right currencies beforehand
|
// make sure that source and destination have the right currencies beforehand
|
||||||
$source = $transfer->transactions()->where('amount', '<', 0)->first();
|
$source = $transfer->transactions()->where('amount', '<', 0)->first();
|
||||||
$source->transaction_currency_id = $euro->id;
|
$source->transaction_currency_id = $euro->id;
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
||||||
$dest= $transfer->transactions()->where('amount', '>', 0)->first();
|
$dest = $transfer->transactions()->where('amount', '>', 0)->first();
|
||||||
$dest->transaction_currency_id = $dollar->id;
|
$dest->transaction_currency_id = $dollar->id;
|
||||||
$dest->save();
|
$dest->save();
|
||||||
|
|
||||||
@ -448,7 +448,6 @@ class TransferCurrenciesCorrectionsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHandleTransferBadSourceCurrency(): void
|
public function testHandleTransferBadSourceCurrency(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
@ -459,6 +458,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
|
|||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $transfer->transactions()->where('amount', '<', 0)->first();
|
$source = $transfer->transactions()->where('amount', '<', 0)->first();
|
||||||
$source->transaction_currency_id = 2;
|
$source->transaction_currency_id = 2;
|
||||||
|
$source->foreign_amount = null;
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
|
Loading…
Reference in New Issue
Block a user