This commit is contained in:
James Cole
2017-03-18 07:46:42 +01:00
parent 68be58c9f2
commit c62e3dcb78
7 changed files with 242 additions and 168 deletions

View File

@@ -234,91 +234,147 @@ class CategoryController extends Controller
* @param Request $request * @param Request $request
* @param JournalCollectorInterface $collector * @param JournalCollectorInterface $collector
* @param Category $category * @param Category $category
* @param string $moment
* *
* @return View * @return View
*/ */
public function show(Request $request, JournalCollectorInterface $collector, Category $category) public function show(Request $request, JournalCollectorInterface $collector, Category $category, string $moment = '')
{ {
$range = Preferences::get('viewRange', '1M')->data; // default values:
$start = session('start', Navigation::startOfPeriod(new Carbon, $range)); /** @var CategoryRepositoryInterface $repository */
$end = session('end', Navigation::endOfPeriod(new Carbon, $range)); $repository = app(CategoryRepositoryInterface::class);
$hideCategory = true; // used in list.
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitle = $category->name; $subTitle = $category->name;
$subTitleIcon = 'fa-bar-chart'; $subTitleIcon = 'fa-bar-chart';
$entries = $this->getGroupedEntries($category); $page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
$method = 'default'; $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$count = 0;
// get journals $loop = 0;
$collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation(); $range = Preferences::get('viewRange', '1M')->data;
$journals = $collector->getPaginatedJournals(); $start = null;
$journals->setPath('categories/show/' . $category->id); $end = null;
$periods = new Collection;
return view('categories.show', compact('category', 'method', 'journals', 'entries', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end')); // prep for "all" view.
} if ($moment === 'all') {
$subTitle = trans('firefly.all_journals_for_category', ['name' => $category->name]);
/** $start = $repository->firstUseDate($category);
* @param Request $request $end = new Carbon;
* @param CategoryRepositoryInterface $repository
* @param Category $category
*
* @return View
*/
public function showAll(Request $request, CategoryRepositoryInterface $repository, Category $category)
{
$range = Preferences::get('viewRange', '1M')->data;
$start = $repository->firstUseDate($category);
if ($start->year == 1900) {
$start = new Carbon;
} }
$end = Navigation::endOfPeriod(new Carbon, $range);
$subTitle = $category->name;
$subTitleIcon = 'fa-bar-chart';
$hideCategory = true; // used in list.
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$method = 'all';
/** @var JournalCollectorInterface $collector */ // prep for "specific date" view.
$collector = app(JournalCollectorInterface::class); if (strlen($moment) > 0 && $moment !== 'all') {
$collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setCategory($category)->withBudgetInformation(); $start = new Carbon($moment);
$journals = $collector->getPaginatedJournals(); $end = Navigation::endOfPeriod($start, $range);
$journals->setPath('categories/show/' . $category->id . '/all'); $subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,
'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
$periods = $this->periodEntries($category);
}
return view('categories.show', compact('category', 'method', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end')); // prep for current period
if (strlen($moment) === 0) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
$periods = $this->periodEntries($category);
$subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
}
// grab journals, but be prepared to jump a period back to get the right ones:
Log::info('Now at transaction loop start.');
while ($count === 0 && $loop < 3) {
$loop++;
Log::info('Count is zero, search for journals.');
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
->setCategory($category)->withBudgetInformation()->withCategoryInformation();
$journals = $collector->getPaginatedJournals();
$journals->setPath('categories/show/' . $category->id);
$count = $journals->getCollection()->count();
if ($count === 0) {
$start->subDay();
$start = Navigation::startOfPeriod($start, $range);
$end = Navigation::endOfPeriod($start, $range);
Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d')));
}
}
// fix title:
if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
$subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
}
return view('categories.show', compact('category', 'moment', 'journals', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
} }
/** // /**
* @param Request $request // * @param Request $request
* @param Category $category // * @param CategoryRepositoryInterface $repository
* @param string $date // * @param Category $category
* // *
* @return View // * @return View
*/ // */
public function showByDate(Request $request, Category $category, string $date) // public function showAll(Request $request, CategoryRepositoryInterface $repository, Category $category)
{ // {
$carbon = new Carbon($date); // $range = Preferences::get('viewRange', '1M')->data;
$range = Preferences::get('viewRange', '1M')->data; // $start = $repository->firstUseDate($category);
$start = Navigation::startOfPeriod($carbon, $range); // if ($start->year == 1900) {
$end = Navigation::endOfPeriod($carbon, $range); // $start = new Carbon;
$subTitle = $category->name; // }
$subTitleIcon = 'fa-bar-chart'; // $end = Navigation::endOfPeriod(new Carbon, $range);
$hideCategory = true; // used in list. // $subTitle = $category->name;
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page')); // $subTitleIcon = 'fa-bar-chart';
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); // $hideCategory = true; // used in list.
$entries = $this->getGroupedEntries($category); // $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$method = 'date'; // $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
// $method = 'all';
/** @var JournalCollectorInterface $collector */ //
$collector = app(JournalCollectorInterface::class); // /** @var JournalCollectorInterface $collector */
$collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation(); // $collector = app(JournalCollectorInterface::class);
$journals = $collector->getPaginatedJournals(); // $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setCategory($category)->withBudgetInformation();
$journals->setPath('categories/show/' . $category->id . '/' . $date); // $journals = $collector->getPaginatedJournals();
// $journals->setPath('categories/show/' . $category->id . '/all');
return view('categories.show', compact('category', 'method', 'entries', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end')); //
} // return view('categories.show', compact('category', 'method', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));
// }
//
// /**
// * @param Request $request
// * @param Category $category
// * @param string $date
// *
// * @return View
// */
// public function showByDate(Request $request, Category $category, string $date)
// {
// $carbon = new Carbon($date);
// $range = Preferences::get('viewRange', '1M')->data;
// $start = Navigation::startOfPeriod($carbon, $range);
// $end = Navigation::endOfPeriod($carbon, $range);
// $subTitle = $category->name;
// $subTitleIcon = 'fa-bar-chart';
// $hideCategory = true; // used in list.
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
// $entries = $this->getGroupedEntries($category);
// $method = 'date';
//
// /** @var JournalCollectorInterface $collector */
// $collector = app(JournalCollectorInterface::class);
// $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation();
// $journals = $collector->getPaginatedJournals();
// $journals->setPath('categories/show/' . $category->id . '/' . $date);
//
// return view('categories.show', compact('category', 'method', 'entries', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));
// }
/** /**
* @param CategoryFormRequest $request * @param CategoryFormRequest $request
@@ -368,53 +424,6 @@ class CategoryController extends Controller
return redirect($this->getPreviousUri('categories.edit.uri')); return redirect($this->getPreviousUri('categories.edit.uri'));
} }
/**
* @param Category $category
*
* @return Collection
*/
private function getGroupedEntries(Category $category): Collection
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$first = $repository->firstUseDate($category);
if ($first->year == 1900) {
$first = new Carbon;
}
$range = Preferences::get('viewRange', '1M')->data;
$first = Navigation::startOfPeriod($first, $range);
$end = Navigation::endOfX(new Carbon, $range);
$entries = new Collection;
// properties for entries with their amounts.
$cache = new CacheProperties();
$cache->addProperty($first);
$cache->addProperty($end);
$cache->addProperty('categories.entries');
$cache->addProperty($category->id);
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
while ($end >= $first) {
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
$entries->push([$dateStr, $dateName, $spent, $earned, clone $end]);
$end = Navigation::subtractPeriod($end, $range, 1);
}
$cache->store($entries);
return $entries;
}
/** /**
* @return Collection * @return Collection
*/ */
@@ -490,4 +499,58 @@ class CategoryController extends Controller
return $entries; return $entries;
} }
/**
* @param Category $category
*
* @return Collection
*/
private function periodEntries(Category $category): Collection
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$first = $repository->firstUseDate($category);
if ($first->year == 1900) {
$first = new Carbon;
}
$range = Preferences::get('viewRange', '1M')->data;
$first = Navigation::startOfPeriod($first, $range);
$end = Navigation::endOfX(new Carbon, $range);
$entries = new Collection;
// properties for entries with their amounts.
$cache = new CacheProperties();
$cache->addProperty($first);
$cache->addProperty($end);
$cache->addProperty('categories.entries');
$cache->addProperty($category->id);
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
while ($end >= $first) {
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
$entries->push(
[
'string' => $dateStr,
'name' => $dateName,
'spent' => $spent,
'earned' => $earned,
'date' => clone $end,
]
);
$end = Navigation::subtractPeriod($end, $range, 1);
}
$cache->store($entries);
return $entries;
}
} }

View File

@@ -124,6 +124,7 @@ return [
'journals_in_period_for_account' => 'All transactions for account :name between :start and :end', 'journals_in_period_for_account' => 'All transactions for account :name between :start and :end',
'transferred' => 'Transferred', 'transferred' => 'Transferred',
'all_withdrawal' => 'All expenses', 'all_withdrawal' => 'All expenses',
'all_transactions' => 'All transactions',
'title_withdrawal_between' => 'All expenses between :start and :end', 'title_withdrawal_between' => 'All expenses between :start and :end',
'all_deposit' => 'All revenue', 'all_deposit' => 'All revenue',
'title_deposit_between' => 'All revenue between :start and :end', 'title_deposit_between' => 'All revenue between :start and :end',
@@ -131,6 +132,8 @@ return [
'title_transfers_between' => 'All transfers between :start and :end', 'title_transfers_between' => 'All transfers between :start and :end',
'all_transfer' => 'All transfers', 'all_transfer' => 'All transfers',
'title_transfer_between' => 'All transfers between :start and :end', 'title_transfer_between' => 'All transfers between :start and :end',
'all_journals_for_category' => 'All transactions for category :name',
'journals_in_period_for_category' => 'All transactions for category :name between :start and :end',
// repeat frequencies: // repeat frequencies:

View File

@@ -43,7 +43,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3> <h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{% include 'list.journals-tasker' %} {% include 'list.journals-tasker' with {hideBudgets:true, hideBills:true} %}
</div> </div>
</div> </div>
</div> </div>
@@ -101,8 +101,9 @@
{% block scripts %} {% block scripts %}
<script type="text/javascript"> <script type="text/javascript">
var budgetID = {{ budget.id }}; var budgetID = {{ budget.id }};
var budgetLimitID = 0;
{% if budgetLimit.id %} {% if budgetLimit.id %}
var budgetLimitID = {{ budgetLimit.id }}; budgetLimitID = {{ budgetLimit.id }};
var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, budgetLimit.id] ) }}'; var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, budgetLimit.id] ) }}';
{% else %} {% else %}
var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}'; var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}';

View File

@@ -1,12 +1,12 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category, start, end) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category, moment, start, end) }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
{% if method == 'default' %} {% if moment != 'all' and moment != '' %}
{# both charts #} {# both charts #}
<div class="col-lg-6 col-md-6 col-sm-12"> <div class="col-lg-6 col-md-6 col-sm-12">
<div class="box"> <div class="box">
@@ -14,7 +14,7 @@
<h3 class="box-title">{{ 'overview'|_ }} ({{ 'per_period'|_|lower }})</h3> <h3 class="box-title">{{ 'overview'|_ }} ({{ 'per_period'|_|lower }})</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<canvas id="period" style="width:100%" height="350"></canvas> <canvas id="period-specific-period" style="width:100%" height="350"></canvas>
</div> </div>
</div> </div>
</div> </div>
@@ -29,20 +29,20 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if method == 'date' %} {% if moment == '' %}
{# single chart #} {# single chart #}
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'overview'|_ }} ({{ 'current_period'|_|lower }})</h3> <h3 class="box-title">{{ subTitle }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<canvas id="period-specific-period" style="width:100%;height:350px;" height="350"></canvas> <canvas id="period" style="width:100%;height:350px;" height="350"></canvas>
</div> </div>
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if method == 'all' %} {% if moment == 'all' %}
{# all chart #} {# all chart #}
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
<div class="box"> <div class="box">
@@ -56,16 +56,16 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% if entries %} {% if periods.count > 0 %}
<div class="row"> <div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12"> <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('categories.show.all',[category.id]) }}">{{ 'showEverything'|_ }}</a></p> <p class="small text-center"><a href="{{ route('categories.show',[category.id,'all']) }}">{{ 'showEverything'|_ }}</a></p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="row"> <div class="row">
<div class="{% if entries %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}"> <div class="{% if periods.count > 0 %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
@@ -76,7 +76,7 @@
{% if entries %} {% if entries %}
<p> <p>
<i class="fa fa-calendar" aria-hidden="true"></i> <i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('categories.show.all', [category.id]) }}"> <a href="{{ route('categories.show', [category.id,'all']) }}">
{{ 'show_all_no_filter'|_ }} {{ 'show_all_no_filter'|_ }}
</a> </a>
</p> </p>
@@ -91,34 +91,27 @@
</div> </div>
</div> </div>
</div> </div>
{% if entries %} {% if periods.count > 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">
{% for entry in entries %} {% for period in periods %}
{% if entry[2] != 0 or entry[3] != 0 %} <div class="box {% if period.date == start %}box-solid box-primary{% endif %}">
<div class="box {% if entry[4] == start %}box-solid box-primary{% endif %}"> <div class="box-header with-border">
<div class="box-header with-border"> <h3 class="box-title"><a href="{{ route('categories.show',[category.id,period.string]) }}">{{ period.name }}</a>
<h3 class="box-title"><a href="{{ route('categories.show.date',[category.id,entry[0]]) }}">{{ entry[1] }}</a> </h3>
</h3>
</div>
<div class="box-body no-padding">
<table class="table table-hover">
{% if entry[2] != 0 %}
<tr>
<td style="width:33%;">{{ 'spent'|_ }}</td>
<td style="text-align: right;">{{ entry[2]|formatAmount }}</td>
</tr>
{% endif %}
{% if entry[3] != 0 %}
<tr>
<td style="width:33%;">{{ 'earned'|_ }}</td>
<td style="text-align: right;">{{ entry[3]|formatAmount }}</td>
</tr>
{% endif %}
</table>
</div>
</div> </div>
{% endif %} <div class="box-body no-padding">
<table class="table table-hover">
<tr>
<td style="width:33%;">{{ 'spent'|_ }}</td>
<td style="text-align: right;">{{ period.spent|formatAmount }}</td>
</tr>
<tr>
<td style="width:33%;">{{ 'earned'|_ }}</td>
<td style="text-align: right;">{{ period.earned|formatAmount }}</td>
</tr>
</table>
</div>
</div>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}

View File

@@ -162,9 +162,7 @@ Route::group(
Route::get('edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'edit']); Route::get('edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'edit']);
Route::get('delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'delete']); Route::get('delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'delete']);
Route::get('show/{category}', ['uses' => 'CategoryController@show', 'as' => 'show']); Route::get('show/{category}/{moment?}', ['uses' => 'CategoryController@show', 'as' => 'show']);
Route::get('show/{category}/all', ['uses' => 'CategoryController@showAll', 'as' => 'show.all']);
Route::get('show/{category}/{date}', ['uses' => 'CategoryController@showByDate', 'as' => 'show.date']);
Route::get('list/no-category/{moment?}', ['uses' => 'CategoryController@noCategory', 'as' => 'no-category']); Route::get('list/no-category/{moment?}', ['uses' => 'CategoryController@noCategory', 'as' => 'no-category']);
Route::post('store', ['uses' => 'CategoryController@store', 'as' => 'store']); Route::post('store', ['uses' => 'CategoryController@store', 'as' => 'store']);

View File

@@ -15,6 +15,7 @@ use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -23,6 +24,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences;
use Steam; use Steam;
use Tests\TestCase; use Tests\TestCase;
@@ -320,8 +322,8 @@ class AccountControllerTest extends TestCase
public function testStore() public function testStore()
{ {
// mock stuff // mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once(); $repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make()); $repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@@ -14,6 +14,7 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -229,6 +230,7 @@ class CategoryControllerTest extends TestCase
*/ */
public function testShow(string $range) public function testShow(string $range)
{ {
$transaction = factory(Transaction::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -247,8 +249,11 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->once(); $collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once(); $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
@@ -266,22 +271,28 @@ class CategoryControllerTest extends TestCase
public function testShowAll(string $range) public function testShowAll(string $range)
{ {
// mock stuff // mock stuff
$transaction = factory(Transaction::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CategoryRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class); $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setPage')->andReturnSelf()->once(); $collector->shouldReceive('setPage')->andReturnSelf()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->once(); $collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->once(); $collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once(); $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon); $repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.show.all', [1])); $response = $this->get(route('categories.show', [1, 'all']));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">'); $response->assertSee('<ol class="breadcrumb">');
} }
@@ -296,6 +307,7 @@ class CategoryControllerTest extends TestCase
public function testShowByDate(string $range) public function testShowByDate(string $range)
{ {
// mock stuff // mock stuff
$transaction = factory(Transaction::class)->make();
$repository = $this->mock(CategoryRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class); $collector = $this->mock(JournalCollectorInterface::class);
@@ -309,8 +321,10 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->once(); $collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once(); $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon); $repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
$repository->shouldReceive('spentInPeriod')->andReturn('-1'); $repository->shouldReceive('spentInPeriod')->andReturn('-1');
@@ -319,7 +333,7 @@ class CategoryControllerTest extends TestCase
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.show.date', [1, '2015-01-01'])); $response = $this->get(route('categories.show', [1, '2015-01-01']));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">'); $response->assertSee('<ol class="breadcrumb">');
} }