Code cleanup for #595

This commit is contained in:
James Cole 2017-03-18 11:02:02 +01:00
parent 3215c4ee4b
commit 282ce041e1
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
14 changed files with 187 additions and 164 deletions

View File

@ -307,8 +307,7 @@ class AccountController extends Controller
}
}
// fix title:
if ((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -478,7 +477,7 @@ class AccountController extends Controller
$opposingTransaction = $journal->transactions()->where('transactions.id', '!=', $transaction->id)->first();
if (is_null($opposingTransaction)) {
throw new FireflyException('Expected an opposing transaction. This account has none. BEEP, error.');
throw new FireflyException('Expected an opposing transaction. This account has none. BEEP, error.'); // @codeCoverageIgnore
}
return redirect(route('accounts.show', [$opposingTransaction->account_id]));

View File

@ -176,10 +176,11 @@ class AttachmentController extends Controller
Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
// @codeCoverageIgnoreStart
$request->session()->put('attachments.edit.fromUpdate', true);
return redirect(route('attachments.edit', [$attachment->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
}
// redirect to previous URL.

View File

@ -240,10 +240,11 @@ class BillController extends Controller
Preferences::mark();
if (intval($request->get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
// @codeCoverageIgnoreStart
$request->session()->put('bills.create.fromStore', true);
return redirect(route('bills.create'))->withInput();
// @codeCoverageIgnoreEnd
}
// redirect to previous URL.
@ -267,10 +268,11 @@ class BillController extends Controller
Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
// @codeCoverageIgnoreStart
$request->session()->put('bills.edit.fromUpdate', true);
return redirect(route('bills.edit', [$bill->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
}
return redirect($this->getPreviousUri('bills.edit.uri'));

View File

@ -259,8 +259,7 @@ class BudgetController extends Controller
}
}
// fix title:
if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]

View File

@ -219,8 +219,7 @@ class CategoryController extends Controller
}
}
// fix title:
if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -302,8 +301,7 @@ class CategoryController extends Controller
}
}
// fix title:
if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -313,66 +311,6 @@ class CategoryController extends Controller
return view('categories.show', compact('category', 'moment', 'journals', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
}
// /**
// * @param Request $request
// * @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 */
// $collector = app(JournalCollectorInterface::class);
// $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setCategory($category)->withBudgetInformation();
// $journals = $collector->getPaginatedJournals();
// $journals->setPath('categories/show/' . $category->id . '/all');
//
// 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

View File

@ -221,9 +221,10 @@ class TagController extends Controller
}
/**
* @param Request $request
* @param JournalCollectorInterface $collector
* @param Tag $tag
* @param Request $request
* @param TagRepositoryInterface $repository
* @param Tag $tag
* @param string $moment
*
* @return View
*/
@ -290,9 +291,8 @@ class TagController extends Controller
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) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.journals_in_period_for_tag',
['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -303,68 +303,6 @@ class TagController extends Controller
return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end', 'moment'));
}
// /**
// * @param Request $request
// * @param JournalCollectorInterface $collector
// * @param Tag $tag
// *
// * @return View
// */
// public function showAll(Request $request, JournalCollectorInterface $collector, Tag $tag)
// {
// $subTitle = $tag->tag;
// $subTitleIcon = 'fa-tag';
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
// $collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page)->setTag($tag)
// ->withOpposingAccount()->disableInternalFilter()
// ->withBudgetInformation()->withCategoryInformation();
// $journals = $collector->getPaginatedJournals();
// $journals->setPath('tags/show/' . $tag->id . '/all');
//
// $sum = $journals->sum(
// function (Transaction $transaction) {
// return $transaction->transaction_amount;
// }
// );
//
// return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end'));
//
// }
//
// public function showByDate(Request $request, JournalCollectorInterface $collector, Tag $tag, string $date)
// {
// $range = Preferences::get('viewRange', '1M')->data;
//
// try {
// $start = new Carbon($date);
// $end = Navigation::endOfPeriod($start, $range);
// } catch (Exception $e) {
// $start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range);
// $end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range);
// }
//
// $subTitle = $tag->tag;
// $subTitleIcon = 'fa-tag';
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
// $periods = $this->getPeriodOverview($tag);
//
// // use collector:
// $collector->setAllAssetAccounts()
// ->setLimit($pageSize)->setPage($page)->setTag($tag)->withOpposingAccount()->disableInternalFilter()
// ->withBudgetInformation()->withCategoryInformation()->setRange($start, $end);
// $journals = $collector->getPaginatedJournals();
// $journals->setPath('tags/show/' . $tag->id);
//
// $sum = $journals->sum(
// function (Transaction $transaction) {
// return $transaction->transaction_amount;
// }
// );
//
// return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end'));
// }
/**
* @param TagFormRequest $request

View File

@ -125,8 +125,7 @@ class TransactionController extends Controller
}
}
// fix title:
if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
if ($moment != 'all' && $loop > 1) {
$subTitle = trans(
'firefly.title_' . $what . '_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]

View File

@ -33,6 +33,47 @@ $factory->define(
}
);
$factory->define(
FireflyIII\Models\TransactionJournal::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'user_id' => 1,
'transaction_type_id' => 1,
'bill_id' => null,
'transaction_currency_id' => 1,
'description' => $faker->words(3, true),
'date' => '2017-01-01',
'interest_date' => null,
'book_date' => null,
'process_date' => null,
'order' => 0,
'tag_count' => 0,
'encrypted' => 0,
'completed' => 1,
];
}
);
$factory->define(
FireflyIII\Models\Bill::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'user_id' => 1,
'name' => $faker->words(3, true),
'match' => $faker->words(3, true),
'amount_min' => '100.00',
'amount_max' => '100.00',
'date' => '2017-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 1,
'name_encrypted' => 0,
'match_encrypted' => 0,
];
}
);
$factory->define(
FireflyIII\Models\PiggyBank::class, function (Faker\Generator $faker) {
return [

View File

@ -1,4 +1,4 @@
<!-- SUCCESS MESSAGE (ALWAYS SINGULAR) -->
{# SUCCESS MESSAGE (ALWAYS SINGULAR) #}
{% if Session.has('success') %}
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
@ -8,14 +8,14 @@
</div>
{% endif %}
<!-- INFO MESSAGE (CAN BE MULTIPLE) -->
{# INFO MESSAGE (CAN BE MULTIPLE) #}
{% if Session.has('info') %}
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">&times;</span><span class="sr-only">{{ 'close'|_ }}</span>
</button>
<!-- MULTIPLE INFO MESSAGE -->
{# MULTIPLE INFO MESSAGE #}
{% if session('info') is iterable and session('info')|length > 1 %}
<strong>
{{ Lang.choice('firefly.flash_info_multiple', session('info')|length, {count: session('info')|length}) }}:</strong>
@ -25,11 +25,11 @@
{% endfor %}
</ul>
{% endif %}
<!-- SET OF MULTIPLE INFO MESSAGES, BUT THERE IS JUST ONE -->
{# SET OF MULTIPLE INFO MESSAGES, BUT THERE IS JUST ONE #}
{% if session('info') is iterable and session('info')|length == 1 %}
<strong>{{ 'flash_info'|_ }}:</strong> {{ session('info')[0]|raw }}
{% endif %}
<!-- SINGLE INFO MESSAGE -->
{# SINGLE INFO MESSAGE #}
{% if session('info') is not iterable %}
<strong>{{ 'flash_info'|_ }}:</strong> {{ session('info')|raw }}
{% endif %}
@ -38,7 +38,7 @@
{% endif %}
<!-- WARNING MESSAGE (ALWAYS SINGULAR) -->
{# WARNING MESSAGE (ALWAYS SINGULAR) #}
{% if Session.has('warning') %}
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
@ -48,14 +48,14 @@
</div>
{% endif %}
<!-- ERROR MESSAGE (CAN BE MULTIPLE) -->
{# ERROR MESSAGE (CAN BE MULTIPLE) #}
{% if Session.has('error') %}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">&times;</span><span class="sr-only">{{ 'close'|_ }}</span>
</button>
<!-- MULTIPLE ERRORS (BAD) -->
{# MULTIPLE ERRORS (BAD) #}
{% if session('error') is iterable and session('error')|length > 1 %}
<strong>
{{ Lang.choice('firefly.flash_error_multiple', session('error')|length, {count: session('error')|length}) }}:
@ -67,13 +67,13 @@
</ul>
{% endif %}
<!-- SET OF MULTIPLE ERRORS, BUT THERE IS JUST ONE -->
{# SET OF MULTIPLE ERRORS, BUT THERE IS JUST ONE #}
{% if session('error') is iterable and session('error')|length == 1 %}
<strong>{{ 'flash_error'|_ }}</strong>
{{ session('error')[0]|raw }}
{% endif %}
<!-- SINGLE ERROR -->
{# SINGLE ERROR #}
{% if session('error') is not iterable %}
<strong>{{ 'flash_error'|_ }}</strong> {{ session('error')|raw }}
{% endif %}

View File

@ -15,7 +15,6 @@ use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -24,7 +23,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Preferences;
use Steam;
use Tests\TestCase;
@ -129,7 +127,7 @@ class AccountControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
Steam::shouldReceive('balancesById')->andReturn([]);
Steam::shouldReceive('balancesById')->andReturn([$account->id => '100']);
Steam::shouldReceive('getLastActivities')->andReturn([]);
$this->be($this->user());
@ -322,8 +320,8 @@ class AccountControllerTest extends TestCase
public function testStore()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -340,6 +338,31 @@ class AccountControllerTest extends TestCase
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::store
*/
public function testStoreAnother()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['accounts.create.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'name' => 'new account ' . rand(1000, 9999),
'what' => 'asset',
'create_another' => 1,
];
$response = $this->post(route('accounts.store', ['asset']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::update
*/
@ -364,4 +387,30 @@ class AccountControllerTest extends TestCase
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::update
*/
public function testUpdateAgain()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['accounts.edit.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'name' => 'updated account ' . rand(1000, 9999),
'active' => 1,
'what' => 'asset',
'return_to_edit' => '1',
];
$response = $this->post(route('accounts.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
}

View File

@ -71,6 +71,24 @@ class AttachmentControllerTest extends TestCase
$response->assertSee('This is attachment number one.');
}
/**
* @covers \FireflyIII\Http\Controllers\AttachmentController::download
* @expectedExceptionMessage Could not find the indicated attachment
*/
public function testDownloadFail()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(false);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.download', [1]));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\AttachmentController::edit
*/
@ -94,7 +112,7 @@ class AttachmentControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.preview', [1]));
$response = $this->get(route('attachments.preview', [3]));
$response->assertStatus(200);
}

View File

@ -97,10 +97,14 @@ class BillControllerTest extends TestCase
public function testIndex()
{
// mock stuff
$bill = factory(Bill::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getBills')->andReturn(new Collection);
$repository->shouldReceive('getBills')->andReturn(new Collection([$bill]));
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPaidDatesInRange')->once()->andReturn(new Collection([1, 2, 3]));
$repository->shouldReceive('getPayDatesInRange')->once()->andReturn(new Collection([1, 2]));
$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
$this->be($this->user());
$response = $this->get(route('bills.index'));
@ -115,9 +119,11 @@ class BillControllerTest extends TestCase
public function testRescan()
{
// mock stuff
$journal = factory(TransactionJournal::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection);
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection([$journal]));
$repository->shouldReceive('scan')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@ -126,6 +132,22 @@ class BillControllerTest extends TestCase
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\BillController::rescan
*/
public function testRescanInactive()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('bills.rescan', [3]));
$response->assertStatus(302);
$response->assertSessionHas('warning');
}
/**
* @covers \FireflyIII\Http\Controllers\BillController::show
*/

View File

@ -42,6 +42,23 @@ class BudgetControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
*/
public function testAmountZero()
{
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$data = ['amount' => 0,];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::create
*/

View File

@ -222,7 +222,7 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
* @covers \FireflyIII\Http\Controllers\CategoryController::getPeriodOverview
*
* @dataProvider dateRangeProvider
*
@ -263,7 +263,7 @@ class CategoryControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::showAll
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @dataProvider dateRangeProvider
*
* @param string $range
@ -298,8 +298,8 @@ class CategoryControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
* @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @covers \FireflyIII\Http\Controllers\CategoryController::getPeriodOverview
* @dataProvider dateRangeProvider
*
* @param string $range