mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expanded test coverage.
This commit is contained in:
parent
222b3008d5
commit
fe66d089ad
@ -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.
|
||||
|
@ -19,6 +19,8 @@ use Illuminate\Http\Request;
|
||||
use Password;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Class ForgotPasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
|
@ -22,6 +22,8 @@ use Illuminate\Http\Request;
|
||||
use Lang;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Class LoginController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
|
@ -22,6 +22,8 @@ use Illuminate\Support\Facades\Password;
|
||||
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Class PasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
|
@ -24,6 +24,8 @@ use Session;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Class RegisterController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
|
@ -16,6 +16,8 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Class ResetPasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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' => '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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user