Expanded test coverage.

This commit is contained in:
James Cole
2017-03-24 15:01:53 +01:00
parent 222b3008d5
commit fe66d089ad
20 changed files with 357 additions and 149 deletions

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Admin; namespace FireflyIII\Http\Controllers\Admin;
@@ -18,6 +18,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\UserFormRequest; use FireflyIII\Http\Requests\UserFormRequest;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Log;
use Preferences; use Preferences;
use Session; use Session;
use View; use View;
@@ -129,29 +130,27 @@ class UserController extends Controller
* *
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @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(); $data = $request->getUserData();
// update password // update password
if (strlen($data['password']) > 0) { if (strlen($data['password']) > 0) {
$user->password = bcrypt($data['password']); $repository->changePassword($user, $data['password']);
$user->save();
} }
// change blocked status and code: $repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
$user->blocked = $data['blocked'];
$user->blocked_code = $data['blocked_code'];
$user->save();
Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email]))); Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email])));
Preferences::mark(); Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) { if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL: // @codeCoverageIgnoreStart
Session::put('users.edit.fromUpdate', true); Session::put('users.edit.fromUpdate', true);
return redirect(route('admin.users.edit', [$user->id]))->withInput(['return_to_edit' => 1]); return redirect(route('admin.users.edit', [$user->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
} }
// redirect to previous URL. // redirect to previous URL.

View File

@@ -19,6 +19,8 @@ use Illuminate\Http\Request;
use Password; use Password;
/** /**
* @codeCoverageIgnore
*
* Class ForgotPasswordController * Class ForgotPasswordController
* *
* @package FireflyIII\Http\Controllers\Auth * @package FireflyIII\Http\Controllers\Auth

View File

@@ -22,6 +22,8 @@ use Illuminate\Http\Request;
use Lang; use Lang;
/** /**
* @codeCoverageIgnore
*
* Class LoginController * Class LoginController
* *
* @package FireflyIII\Http\Controllers\Auth * @package FireflyIII\Http\Controllers\Auth

View File

@@ -22,6 +22,8 @@ use Illuminate\Support\Facades\Password;
/** /**
* @codeCoverageIgnore
*
* Class PasswordController * Class PasswordController
* *
* @package FireflyIII\Http\Controllers\Auth * @package FireflyIII\Http\Controllers\Auth

View File

@@ -24,6 +24,8 @@ use Session;
use Validator; use Validator;
/** /**
* @codeCoverageIgnore
*
* Class RegisterController * Class RegisterController
* *
* @package FireflyIII\Http\Controllers\Auth * @package FireflyIII\Http\Controllers\Auth

View File

@@ -16,6 +16,8 @@ use FireflyIII\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Foundation\Auth\ResetsPasswords;
/** /**
* @codeCoverageIgnore
*
* Class ResetPasswordController * Class ResetPasswordController
* *
* @package FireflyIII\Http\Controllers\Auth * @package FireflyIII\Http\Controllers\Auth

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
@@ -144,7 +144,7 @@ class TagController extends Controller
* *
* @return View * @return View
*/ */
public function edit(Tag $tag) public function edit(Tag $tag, TagRepositoryInterface $repository)
{ {
$subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]); $subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]);
$subTitleIcon = 'fa-tag'; $subTitleIcon = 'fa-tag';
@@ -158,8 +158,8 @@ class TagController extends Controller
/* /*
* Can this tag become another type? * Can this tag become another type?
*/ */
$allowAdvance = $tag->tagAllowAdvance(); $allowAdvance = $repository->tagAllowAdvance($tag);
$allowToBalancingAct = $tag->tagAllowBalancing(); $allowToBalancingAct = $repository->tagAllowBalancing($tag);
// edit tag options: // edit tag options:
if ($allowAdvance === false) { if ($allowAdvance === false) {
@@ -318,10 +318,11 @@ class TagController extends Controller
Preferences::mark(); Preferences::mark();
if (intval($request->get('create_another')) === 1) { if (intval($request->get('create_another')) === 1) {
// set value so create routine will not overwrite URL: // @codeCoverageIgnoreStart
Session::put('tags.create.fromStore', true); Session::put('tags.create.fromStore', true);
return redirect(route('tags.create'))->withInput(); return redirect(route('tags.create'))->withInput();
// @codeCoverageIgnoreEnd
} }
return redirect($this->getPreviousUri('tags.create.uri')); return redirect($this->getPreviousUri('tags.create.uri'));
@@ -343,10 +344,11 @@ class TagController extends Controller
Preferences::mark(); Preferences::mark();
if (intval($request->get('return_to_edit')) === 1) { if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL: // @codeCoverageIgnoreStart
Session::put('tags.edit.fromUpdate', true); Session::put('tags.edit.fromUpdate', true);
return redirect(route('tags.edit', [$tag->id]))->withInput(['return_to_edit' => 1]); return redirect(route('tags.edit', [$tag->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
} }
// redirect to previous URL. // redirect to previous URL.

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
@@ -151,10 +151,9 @@ class TransactionController extends Controller
$ids = array_unique($ids); $ids = array_unique($ids);
foreach ($ids as $id) { foreach ($ids as $id) {
$journal = $repository->find(intval($id)); $journal = $repository->find(intval($id));
if ($journal && $journal->date->format('Y-m-d') == $date->format('Y-m-d')) { if ($journal && $journal->date->isSameDay($date)) {
$journal->order = $order; $repository->setOrder($journal, $order);
$order++; $order++;
$journal->save();
} }
} }
} }
@@ -240,8 +239,6 @@ class TransactionController extends Controller
]; ];
Log::debug(sprintf('What is %s', $what)); Log::debug(sprintf('What is %s', $what));
switch ($what) { switch ($what) {
default:
throw new FireflyException(sprintf('Cannot handle "%s"', $what));
case 'withdrawal': case 'withdrawal':
$array['spent'] = $sum; $array['spent'] = $sum;
break; break;
@@ -250,7 +247,6 @@ class TransactionController extends Controller
break; break;
case 'transfers': case 'transfers':
case 'transfer': case 'transfer':
Log::debug('HERE');
$array['transferred'] = Steam::positive($sum); $array['transferred'] = Steam::positive($sum);
break; break;

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Http\Requests; namespace FireflyIII\Http\Requests;
@@ -37,7 +37,7 @@ class UserFormRequest extends Request
{ {
return [ return [
'email' => $this->string('email'), 'email' => $this->string('email'),
'blocked' => $this->integer('blocked'), 'blocked' => $this->integer('blocked') === 1,
'blocked_code' => $this->string('blocked_code'), 'blocked_code' => $this->string('blocked_code'),
'password' => $this->string('password'), 'password' => $this->string('password'),
]; ];
@@ -50,7 +50,7 @@ class UserFormRequest extends Request
{ {
return [ return [
'id' => 'required|exists:users,id', 'id' => 'required|exists:users,id',
'email' => 'required', 'email' => 'email|required',
'password' => 'confirmed', 'password' => 'confirmed',
'blocked_code' => 'between:0,30', 'blocked_code' => 'between:0,30',
'blocked' => 'between:0,1|numeric', 'blocked' => 'between:0,1|numeric',

View File

@@ -9,12 +9,11 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use Crypt; use Crypt;
use FireflyIII\Support\Models\TagTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -27,7 +26,7 @@ use Watson\Validating\ValidatingTrait;
*/ */
class Tag extends Model class Tag extends Model
{ {
use ValidatingTrait, SoftDeletes, TagTrait; use ValidatingTrait, SoftDeletes;
/** /**
* The attributes that should be casted to native types. * The attributes that should be casted to native types.

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\Journal; namespace FireflyIII\Repositories\Journal;
@@ -135,6 +135,20 @@ class JournalRepository implements JournalRepositoryInterface
return TransactionType::orderBy('type', 'ASC')->get(); 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 * @param User $user
*/ */

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\Journal; namespace FireflyIII\Repositories\Journal;
@@ -67,6 +67,14 @@ interface JournalRepositoryInterface
*/ */
public function getTransactionTypes(): Collection; public function getTransactionTypes(): Collection;
/**
* @param TransactionJournal $journal
* @param int $order
*
* @return bool
*/
public function setOrder(TransactionJournal $journal, int $order): bool;
/** /**
* @param User $user * @param User $user
*/ */

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\Tag; 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 Tag $tag
* @param array $data * @param array $data

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\Tag; namespace FireflyIII\Repositories\Tag;
@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
*/ */
interface TagRepositoryInterface interface TagRepositoryInterface
{ {
/** /**
* This method will connect a journal with a tag. * This method will connect a journal with a tag.
* *
@@ -125,6 +126,20 @@ interface TagRepositoryInterface
*/ */
public function store(array $data): Tag; 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. * Update a tag.
* *

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\User; namespace FireflyIII\Repositories\User;
@@ -66,6 +66,23 @@ class UserRepository implements UserRepositoryInterface
return true; 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 * @return int
*/ */

View File

@@ -9,7 +9,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace FireflyIII\Repositories\User; namespace FireflyIII\Repositories\User;
@@ -50,6 +50,15 @@ interface UserRepositoryInterface
*/ */
public function changePassword(User $user, string $password); 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. * Returns a count of all users.
* *

View File

@@ -1,90 +0,0 @@
<?php
/**
* TagTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* 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;
}
}

View File

@@ -7,14 +7,12 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace Tests\Feature\Controllers\Admin; namespace Tests\Feature\Controllers\Admin;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Facades\Preferences;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
@@ -60,14 +58,43 @@ class UserControllerTest extends TestCase
public function testShow() public function testShow()
{ {
$repository = $this->mock(UserRepositoryInterface::class); $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()); $this->be($this->user());
$response = $this->get(route('admin.users.edit', [1])); $response = $this->get(route('admin.users.show', [1]));
$response->assertStatus(200); $response->assertStatus(200);
// has bread crumb // has bread crumb
$response->assertSee('<ol class="breadcrumb">'); $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' => 'test@example.com',
'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');
}
} }

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
@@ -36,6 +36,7 @@ class TagControllerTest extends TestCase
public function testCreate() public function testCreate()
{ {
// mock stuff // mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -51,6 +52,7 @@ class TagControllerTest extends TestCase
public function testDelete() public function testDelete()
{ {
// mock stuff // mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -83,8 +85,11 @@ class TagControllerTest extends TestCase
public function testEdit() public function testEdit()
{ {
// mock stuff // mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('tagAllowAdvance')->once()->andReturn(false);
$repository->shouldReceive('tagAllowBalancing')->once()->andReturn(false);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('tags.edit', [1])); $response = $this->get(route('tags.edit', [1]));
@@ -124,22 +129,20 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class); $collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1'); $repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon); $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon); $repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1'); $repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
$repository->shouldReceive('find')->andReturn(new Tag);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setPage')->andReturnSelf(); $collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setTag')->andReturnSelf(); $collector->shouldReceive('setTag')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf(); $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('disableInternalFilter')->andReturnSelf(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$this->be($this->user()); $this->be($this->user());
@@ -148,6 +151,67 @@ class TagControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $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 * @covers \FireflyIII\Http\Controllers\TagController::store
*/ */

View File

@@ -7,10 +7,11 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
declare(strict_types = 1); declare(strict_types=1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -23,9 +24,11 @@ use Tests\TestCase;
class TransactionControllerTest extends TestCase class TransactionControllerTest extends TestCase
{ {
/** /**
* @covers \FireflyIII\Http\Controllers\TransactionController::index * @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct * @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/ */
public function testIndex() public function testIndex()
{ {
@@ -78,7 +81,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('getJournals')->andReturn(new Collection); $collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('transactions.index', ['transfer','all'])); $response = $this->get(route('transactions.index', ['transfer', 'all']));
$response->assertStatus(200); $response->assertStatus(200);
// has bread crumb // has bread crumb
$response->assertSee('<ol class="breadcrumb">'); $response->assertSee('<ol class="breadcrumb">');
@@ -86,6 +89,7 @@ class TransactionControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\TransactionController::index * @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/ */
public function testIndexByDate() public function testIndexByDate()
{ {
@@ -115,17 +119,84 @@ class TransactionControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $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 * @covers \FireflyIII\Http\Controllers\TransactionController::reorder
*/ */
public function testReorder() public function testReorder()
{ {
// mock stuff // 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('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->once()->andReturn($journal);
$repository->shouldReceive('setOrder')->once()->andReturn(true);
$data = [ $data = [
'items' => [], 'date' => '2016-01-01',
'items' => [1],
]; ];
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('transactions.reorder'), $data); $response = $this->post(route('transactions.reorder'), $data);