Skip to content

Firefly III: a personal finances manager

Expanded test coverage.

James Colefe66d089ad8f
diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php
index 818c12c2f6..bd83eb13b4 100644
--- a/app/Http/Controllers/Admin/UserController.php
+++ b/app/Http/Controllers/Admin/UserController.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Admin;
@@ -18,6 +18,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\UserFormRequest;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
+use Log;
use Preferences;
use Session;
use View;
@@ -129,29 +130,27 @@ class UserController extends Controller
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
- public function update(UserFormRequest $request, User $user)
+ public function update(UserFormRequest $request, User $user, UserRepositoryInterface $repository)
{
+ Log::debug('Actually here');
$data = $request->getUserData();
// update password
if (strlen($data['password']) > 0) {
- $user->password = bcrypt($data['password']);
- $user->save();
+ $repository->changePassword($user, $data['password']);
}
- // change blocked status and code:
- $user->blocked = $data['blocked'];
- $user->blocked_code = $data['blocked_code'];
- $user->save();
+ $repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email])));
Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) {
- // set value so edit routine will not overwrite URL:
+ // @codeCoverageIgnoreStart
Session::put('users.edit.fromUpdate', true);
return redirect(route('admin.users.edit', [$user->id]))->withInput(['return_to_edit' => 1]);
+ // @codeCoverageIgnoreEnd
}
// redirect to previous URL.
diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php
index 3942c0868b..1f0f162558 100644
--- a/app/Http/Controllers/Auth/ForgotPasswordController.php
+++ b/app/Http/Controllers/Auth/ForgotPasswordController.php
@@ -19,6 +19,8 @@ use Illuminate\Http\Request;
use Password;
/**
+ * @codeCoverageIgnore
+ *
* Class ForgotPasswordController
*
* @package FireflyIII\Http\Controllers\Auth
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 0072229023..655559ba39 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -22,6 +22,8 @@ use Illuminate\Http\Request;
use Lang;
/**
+ * @codeCoverageIgnore
+ *
* Class LoginController
*
* @package FireflyIII\Http\Controllers\Auth
diff --git a/app/Http/Controllers/Auth/PasswordController.php b/app/Http/Controllers/Auth/PasswordController.php
index 06a6fa99b2..2f98b71c3f 100644
--- a/app/Http/Controllers/Auth/PasswordController.php
+++ b/app/Http/Controllers/Auth/PasswordController.php
@@ -22,6 +22,8 @@ use Illuminate\Support\Facades\Password;
/**
+ * @codeCoverageIgnore
+ *
* Class PasswordController
*
* @package FireflyIII\Http\Controllers\Auth
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index cd392a925c..042ea85145 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -24,6 +24,8 @@ use Session;
use Validator;
/**
+ * @codeCoverageIgnore
+ *
* Class RegisterController
*
* @package FireflyIII\Http\Controllers\Auth
diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php
index 1d99a0c179..bc9d48f3a3 100644
--- a/app/Http/Controllers/Auth/ResetPasswordController.php
+++ b/app/Http/Controllers/Auth/ResetPasswordController.php
@@ -16,6 +16,8 @@ use FireflyIII\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
/**
+ * @codeCoverageIgnore
+ *
* Class ResetPasswordController
*
* @package FireflyIII\Http\Controllers\Auth
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index 813183d1cb..325eac42f2 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
@@ -144,7 +144,7 @@ class TagController extends Controller
*
* @return View
*/
- public function edit(Tag $tag)
+ public function edit(Tag $tag, TagRepositoryInterface $repository)
{
$subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]);
$subTitleIcon = 'fa-tag';
@@ -158,8 +158,8 @@ class TagController extends Controller
/*
* Can this tag become another type?
*/
- $allowAdvance = $tag->tagAllowAdvance();
- $allowToBalancingAct = $tag->tagAllowBalancing();
+ $allowAdvance = $repository->tagAllowAdvance($tag);
+ $allowToBalancingAct = $repository->tagAllowBalancing($tag);
// edit tag options:
if ($allowAdvance === false) {
@@ -318,10 +318,11 @@ class TagController extends Controller
Preferences::mark();
if (intval($request->get('create_another')) === 1) {
- // set value so create routine will not overwrite URL:
+ // @codeCoverageIgnoreStart
Session::put('tags.create.fromStore', true);
return redirect(route('tags.create'))->withInput();
+ // @codeCoverageIgnoreEnd
}
return redirect($this->getPreviousUri('tags.create.uri'));
@@ -343,10 +344,11 @@ class TagController extends Controller
Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) {
- // set value so edit routine will not overwrite URL:
+ // @codeCoverageIgnoreStart
Session::put('tags.edit.fromUpdate', true);
return redirect(route('tags.edit', [$tag->id]))->withInput(['return_to_edit' => 1]);
+ // @codeCoverageIgnoreEnd
}
// redirect to previous URL.
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 527b6e84ca..c8369d0a2f 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
@@ -151,10 +151,9 @@ class TransactionController extends Controller
$ids = array_unique($ids);
foreach ($ids as $id) {
$journal = $repository->find(intval($id));
- if ($journal && $journal->date->format('Y-m-d') == $date->format('Y-m-d')) {
- $journal->order = $order;
+ if ($journal && $journal->date->isSameDay($date)) {
+ $repository->setOrder($journal, $order);
$order++;
- $journal->save();
}
}
}
@@ -240,8 +239,6 @@ class TransactionController extends Controller
];
Log::debug(sprintf('What is %s', $what));
switch ($what) {
- default:
- throw new FireflyException(sprintf('Cannot handle "%s"', $what));
case 'withdrawal':
$array['spent'] = $sum;
break;
@@ -250,7 +247,6 @@ class TransactionController extends Controller
break;
case 'transfers':
case 'transfer':
- Log::debug('HERE');
$array['transferred'] = Steam::positive($sum);
break;
diff --git a/app/Http/Requests/UserFormRequest.php b/app/Http/Requests/UserFormRequest.php
index 436e3c9d33..08a7076038 100644
--- a/app/Http/Requests/UserFormRequest.php
+++ b/app/Http/Requests/UserFormRequest.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Http\Requests;
@@ -37,7 +37,7 @@ class UserFormRequest extends Request
{
return [
'email' => $this->string('email'),
- 'blocked' => $this->integer('blocked'),
+ 'blocked' => $this->integer('blocked') === 1,
'blocked_code' => $this->string('blocked_code'),
'password' => $this->string('password'),
];
@@ -50,7 +50,7 @@ class UserFormRequest extends Request
{
return [
'id' => 'required|exists:users,id',
- 'email' => 'required',
+ 'email' => 'email|required',
'password' => 'confirmed',
'blocked_code' => 'between:0,30',
'blocked' => 'between:0,1|numeric',
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index 3ad3178855..30018b5e87 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -9,12 +9,11 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Models;
use Crypt;
-use FireflyIII\Support\Models\TagTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -27,7 +26,7 @@ use Watson\Validating\ValidatingTrait;
*/
class Tag extends Model
{
- use ValidatingTrait, SoftDeletes, TagTrait;
+ use ValidatingTrait, SoftDeletes;
/**
* The attributes that should be casted to native types.
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index 31ac868afa..2fd7811541 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
@@ -135,6 +135,20 @@ class JournalRepository implements JournalRepositoryInterface
return TransactionType::orderBy('type', 'ASC')->get();
}
+ /**
+ * @param TransactionJournal $journal
+ * @param int $order
+ *
+ * @return bool
+ */
+ public function setOrder(TransactionJournal $journal, int $order): bool
+ {
+ $journal->order = $order;
+ $journal->save();
+
+ return true;
+ }
+
/**
* @param User $user
*/
diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php
index f1f5438ad4..c33d47367b 100644
--- a/app/Repositories/Journal/JournalRepositoryInterface.php
+++ b/app/Repositories/Journal/JournalRepositoryInterface.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
@@ -67,6 +67,14 @@ interface JournalRepositoryInterface
*/
public function getTransactionTypes(): Collection;
+ /**
+ * @param TransactionJournal $journal
+ * @param int $order
+ *
+ * @return bool
+ */
+ public function setOrder(TransactionJournal $journal, int $order): bool;
+
/**
* @param User $user
*/
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index 924f0cf77a..ecf0919395 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\Tag;
@@ -246,6 +246,73 @@ class TagRepository implements TagRepositoryInterface
}
+ /**
+ * Can a tag become an advance payment?
+ *
+ * @param Tag $tag
+ *
+ * @return bool
+ */
+ public function tagAllowAdvance(Tag $tag): bool
+ {
+ /*
+ * If this tag is a balancing act, and it contains transfers, it cannot be
+ * changed to an advancePayment.
+ */
+
+ if ($tag->tagMode == 'balancingAct' || $tag->tagMode == 'nothing') {
+ foreach ($tag->transactionjournals as $journal) {
+ if ($journal->isTransfer()) {
+ return false;
+ }
+ }
+ }
+
+ /*
+ * If this tag contains more than one expenses, it cannot become an advance payment.
+ */
+ $count = 0;
+ foreach ($tag->transactionjournals as $journal) {
+ if ($journal->isWithdrawal()) {
+ $count++;
+ }
+ }
+ if ($count > 1) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Can a tag become a balancing act?
+ *
+ * @param Tag $tag
+ *
+ * @return bool
+ */
+ public function tagAllowBalancing(Tag $tag): bool
+ {
+ /*
+ * If has more than two transactions already, cannot become a balancing act:
+ */
+ if ($tag->transactionjournals->count() > 2) {
+ return false;
+ }
+
+ /*
+ * If any transaction is a deposit, cannot become a balancing act.
+ */
+ foreach ($tag->transactionjournals as $journal) {
+ if ($journal->isDeposit()) {
+ return false;
+ }
+ }
+
+ return true;
+
+ }
+
/**
* @param Tag $tag
* @param array $data
diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php
index dc7126d108..fc224d19ce 100644
--- a/app/Repositories/Tag/TagRepositoryInterface.php
+++ b/app/Repositories/Tag/TagRepositoryInterface.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\Tag;
@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
*/
interface TagRepositoryInterface
{
+
/**
* This method will connect a journal with a tag.
*
@@ -125,6 +126,20 @@ interface TagRepositoryInterface
*/
public function store(array $data): Tag;
+ /**
+ * @param Tag $tag
+ *
+ * @return bool
+ */
+ public function tagAllowAdvance(Tag $tag): bool;
+
+ /**
+ * @param Tag $tag
+ *
+ * @return bool
+ */
+ public function tagAllowBalancing(Tag $tag): bool;
+
/**
* Update a tag.
*
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index 8410349efb..ae31df83c9 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\User;
@@ -66,6 +66,23 @@ class UserRepository implements UserRepositoryInterface
return true;
}
+ /**
+ * @param User $user
+ * @param bool $isBlocked
+ * @param string $code
+ *
+ * @return bool
+ */
+ public function changeStatus(User $user, bool $isBlocked, string $code): bool
+ {
+ // change blocked status and code:
+ $user->blocked = $isBlocked;
+ $user->blocked_code = $code;
+ $user->save();
+
+ return true;
+ }
+
/**
* @return int
*/
diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.php
index 3a380f0190..458cad07e8 100644
--- a/app/Repositories/User/UserRepositoryInterface.php
+++ b/app/Repositories/User/UserRepositoryInterface.php
@@ -9,7 +9,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace FireflyIII\Repositories\User;
@@ -50,6 +50,15 @@ interface UserRepositoryInterface
*/
public function changePassword(User $user, string $password);
+ /**
+ * @param User $user
+ * @param bool $isBlocked
+ * @param string $code
+ *
+ * @return bool
+ */
+ public function changeStatus(User $user, bool $isBlocked, string $code): bool;
+
/**
* Returns a count of all users.
*
diff --git a/app/Support/Models/TagTrait.php b/app/Support/Models/TagTrait.php
deleted file mode 100644
index c99a276f92..0000000000
--- a/app/Support/Models/TagTrait.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/**
- * TagTrait.php
- * Copyright (c) 2017 [email protected]
- * This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
- *
- * See the LICENSE file for details.
- */
-
-declare(strict_types = 1);
-
-namespace FireflyIII\Support\Models;
-
-use Illuminate\Support\Collection;
-
-/**
- *
- * @property Collection $transactionjournals
- * @property string $tagMode
- *
- * Class TagSupport
- *
- * @package FireflyIII\Support\Models
- */
-trait TagTrait
-{
- /**
- * Can a tag become an advance payment?
- *
- * @return bool
- */
- public function tagAllowAdvance(): bool
- {
- /*
- * If this tag is a balancing act, and it contains transfers, it cannot be
- * changes to an advancePayment.
- */
-
- if ($this->tagMode == 'balancingAct' || $this->tagMode == 'nothing') {
- foreach ($this->transactionjournals as $journal) {
- if ($journal->isTransfer()) {
- return false;
- }
- }
- }
-
- /*
- * If this tag contains more than one expenses, it cannot become an advance payment.
- */
- $count = 0;
- foreach ($this->transactionjournals as $journal) {
- if ($journal->isWithdrawal()) {
- $count++;
- }
- }
- if ($count > 1) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Can a tag become a balancing act?
- *
- * @return bool
- */
- public function tagAllowBalancing(): bool
- {
- /*
- * If has more than two transactions already, cannot become a balancing act:
- */
- if ($this->transactionjournals->count() > 2) {
- return false;
- }
-
- /*
- * If any transaction is a deposit, cannot become a balancing act.
- */
- foreach ($this->transactionjournals as $journal) {
- if ($journal->isDeposit()) {
- return false;
- }
- }
-
- return true;
-
- }
-
-}
diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php
index f94977460a..d272442aba 100644
--- a/tests/Feature/Controllers/Admin/UserControllerTest.php
+++ b/tests/Feature/Controllers/Admin/UserControllerTest.php
@@ -7,14 +7,12 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace Tests\Feature\Controllers\Admin;
-use FireflyIII\Models\Preference;
use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Support\Facades\Preferences;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -60,14 +58,43 @@ class UserControllerTest extends TestCase
public function testShow()
{
$repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('getUserData')->andReturn([]);
+ $repository->shouldReceive('getUserData')->andReturn(
+ [
+ 'export_jobs_success' => 0,
+ 'import_jobs_success' => 0,
+ 'attachments_size' => 0,
+ ]
+ );
$this->be($this->user());
- $response = $this->get(route('admin.users.edit', [1]));
+ $response = $this->get(route('admin.users.show', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\Admin\UserController::update
+ */
+ public function testUpdate()
+ {
+ $repository = $this->mock(UserRepositoryInterface::class);
+ $repository->shouldReceive('changePassword')->once();
+ $repository->shouldReceive('changeStatus')->once();
+ $data = [
+ 'id' => 1,
+ 'email' => '[email protected]',
+ 'password' => 'james',
+ 'password_confirmation' => 'james',
+ 'blocked_code' => 'blocked',
+ 'blocked' => 1,
+ ];
+
+ $this->be($this->user());
+ $response = $this->post(route('admin.users.update', ['1']), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ }
+
}
diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php
index f6ac686e79..e06e81800c 100644
--- a/tests/Feature/Controllers/TagControllerTest.php
+++ b/tests/Feature/Controllers/TagControllerTest.php
@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace Tests\Feature\Controllers;
@@ -36,6 +36,7 @@ class TagControllerTest extends TestCase
public function testCreate()
{
// mock stuff
+ $repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -51,6 +52,7 @@ class TagControllerTest extends TestCase
public function testDelete()
{
// mock stuff
+ $repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -83,8 +85,11 @@ class TagControllerTest extends TestCase
public function testEdit()
{
// mock stuff
+ $repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('tagAllowAdvance')->once()->andReturn(false);
+ $repository->shouldReceive('tagAllowBalancing')->once()->andReturn(false);
$this->be($this->user());
$response = $this->get(route('tags.edit', [1]));
@@ -124,22 +129,20 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('spentInPeriod')->andReturn('-1');
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
- $repository->shouldReceive('lastUseDate')->andReturn(new Carbon);
- $repository->shouldReceive('earnedInPeriod')->andReturn('1');
- $repository->shouldReceive('find')->andReturn(new Tag);
+ $repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
+ $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
+ $repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
+ $repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
- $collector->shouldReceive('setLimit')->andReturnSelf();
- $collector->shouldReceive('setPage')->andReturnSelf();
- $collector->shouldReceive('setTag')->andReturnSelf();
- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
- $collector->shouldReceive('disableInternalFilter')->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setPage')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setTag')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setRange')->andReturnSelf()->times(3);
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
@@ -148,6 +151,67 @@ class TagControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\TagController::show
+ */
+ public function testShowDate()
+ {
+ // mock stuff
+ $repository = $this->mock(TagRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
+ $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
+ $repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
+ $repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
+
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setPage')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setTag')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setRange')->andReturnSelf()->times(3);
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
+
+
+ $this->be($this->user());
+ $response = $this->get(route('tags.show', [1, '2016-01-01']));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\TagController::show
+ */
+ public function testShowAll()
+ {
+ // mock stuff
+ $repository = $this->mock(TagRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
+
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setPage')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setTag')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
+ $collector->shouldReceive('setRange')->andReturnSelf()->times(3);
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
+
+
+ $this->be($this->user());
+ $response = $this->get(route('tags.show', [1, 'all']));
+ $response->assertStatus(200);
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\TagController::store
*/
diff --git a/tests/Feature/Controllers/TransactionControllerTest.php b/tests/Feature/Controllers/TransactionControllerTest.php
index 1de5eab1e4..ba5a49f93a 100644
--- a/tests/Feature/Controllers/TransactionControllerTest.php
+++ b/tests/Feature/Controllers/TransactionControllerTest.php
@@ -7,10 +7,11 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace Tests\Feature\Controllers;
+use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -23,9 +24,11 @@ use Tests\TestCase;
class TransactionControllerTest extends TestCase
{
+
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
+ * @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndex()
{
@@ -78,7 +81,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user());
- $response = $this->get(route('transactions.index', ['transfer','all']));
+ $response = $this->get(route('transactions.index', ['transfer', 'all']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -86,6 +89,7 @@ class TransactionControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
+ * @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndexByDate()
{
@@ -115,17 +119,84 @@ class TransactionControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\TransactionController::index
+ * @covers \FireflyIII\Http\Controllers\TransactionController::__construct
+ * @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
+ */
+ public function testIndexDeposit()
+ {
+ // mock stuff
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
+
+ $collector->shouldReceive('setTypes')->andReturnSelf();
+ $collector->shouldReceive('setLimit')->andReturnSelf();
+ $collector->shouldReceive('setPage')->andReturnSelf();
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
+ $collector->shouldReceive('setRange')->andReturnSelf();
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf();
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
+ $collector->shouldReceive('disableInternalFilter')->andReturnSelf();
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+ $collector->shouldReceive('getJournals')->andReturn(new Collection);
+
+ $this->be($this->user());
+ $response = $this->get(route('transactions.index', ['deposit']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\TransactionController::index
+ * @covers \FireflyIII\Http\Controllers\TransactionController::__construct
+ * @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
+ */
+ public function testIndexWithdrawal()
+ {
+ // mock stuff
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
+
+ $collector->shouldReceive('setTypes')->andReturnSelf();
+ $collector->shouldReceive('setLimit')->andReturnSelf();
+ $collector->shouldReceive('setPage')->andReturnSelf();
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
+ $collector->shouldReceive('setRange')->andReturnSelf();
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf();
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
+ $collector->shouldReceive('disableInternalFilter')->andReturnSelf();
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+ $collector->shouldReceive('getJournals')->andReturn(new Collection);
+
+ $this->be($this->user());
+ $response = $this->get(route('transactions.index', ['withdrawal']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('<ol class="breadcrumb">');
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::reorder
*/
public function testReorder()
{
// mock stuff
- $repository = $this->mock(JournalRepositoryInterface::class);
+ $journal = factory(TransactionJournal::class)->make();
+ $journal->date = new Carbon('2016-01-01');
+ $repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('find')->once()->andReturn($journal);
+ $repository->shouldReceive('setOrder')->once()->andReturn(true);
$data = [
- 'items' => [],
+ 'date' => '2016-01-01',
+ 'items' => [1],
];
$this->be($this->user());
$response = $this->post(route('transactions.reorder'), $data);