Expanded test coverage.

This commit is contained in:
James Cole
2017-03-24 11:07:38 +01:00
parent 398cf0b312
commit 222b3008d5
14 changed files with 651 additions and 121 deletions

View File

@@ -9,13 +9,16 @@
* 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;
use FireflyIII\Http\Requests\TokenFormRequest; use FireflyIII\Http\Requests\TokenFormRequest;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Log;
use PragmaRX\Google2FA\Contracts\Google2FA; use PragmaRX\Google2FA\Contracts\Google2FA;
use Preferences; use Preferences;
use Session; use Session;
@@ -131,7 +134,7 @@ class PreferencesController extends Controller
* *
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/ */
public function postIndex(Request $request) public function postIndex(Request $request, UserRepositoryInterface $repository)
{ {
// front page accounts // front page accounts
$frontPageAccounts = []; $frontPageAccounts = [];
@@ -168,7 +171,7 @@ class PreferencesController extends Controller
$twoFactorAuthEnabled = false; $twoFactorAuthEnabled = false;
$hasTwoFactorAuthSecret = false; $hasTwoFactorAuthSecret = false;
if (!auth()->user()->hasRole('demo')) { if (!$repository->hasRole(auth()->user(), 'demo')) {
// two factor auth // two factor auth
$twoFactorAuthEnabled = intval($request->get('twoFactorAuthEnabled')); $twoFactorAuthEnabled = intval($request->get('twoFactorAuthEnabled'));
$hasTwoFactorAuthSecret = !is_null(Preferences::get('twoFactorAuthSecret')); $hasTwoFactorAuthSecret = !is_null(Preferences::get('twoFactorAuthSecret'));

View File

@@ -9,14 +9,16 @@
* 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;
use FireflyIII\Exceptions\ValidationException; use FireflyIII\Exceptions\ValidationException;
use FireflyIII\Http\Middleware\IsLimitedUser;
use FireflyIII\Http\Requests\DeleteAccountFormRequest; use FireflyIII\Http\Requests\DeleteAccountFormRequest;
use FireflyIII\Http\Requests\ProfileFormRequest; use FireflyIII\Http\Requests\ProfileFormRequest;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Hash; use Hash;
use Log; use Log;
use Session; use Session;
@@ -45,6 +47,8 @@ class ProfileController extends Controller
return $next($request); return $next($request);
} }
); );
$this->middleware(IsLimitedUser::class);
} }
/** /**
@@ -52,16 +56,6 @@ class ProfileController extends Controller
*/ */
public function changePassword() public function changePassword()
{ {
if (intval(getenv('SANDSTORM')) === 1) {
return view('error')->with('message', strval(trans('firefly.sandstorm_not_available')));
}
if (auth()->user()->hasRole('demo')) {
Session::flash('info', strval(trans('firefly.cannot_change_demo')));
return redirect(route('profile.index'));
}
$title = auth()->user()->email; $title = auth()->user()->email;
$subTitle = strval(trans('firefly.change_your_password')); $subTitle = strval(trans('firefly.change_your_password'));
$subTitleIcon = 'fa-key'; $subTitleIcon = 'fa-key';
@@ -74,16 +68,6 @@ class ProfileController extends Controller
*/ */
public function deleteAccount() public function deleteAccount()
{ {
if (intval(getenv('SANDSTORM')) === 1) {
return view('error')->with('message', strval(trans('firefly.sandstorm_not_available')));
}
if (auth()->user()->hasRole('demo')) {
Session::flash('info', strval(trans('firefly.cannot_delete_demo')));
return redirect(route('profile.index'));
}
$title = auth()->user()->email; $title = auth()->user()->email;
$subTitle = strval(trans('firefly.delete_account')); $subTitle = strval(trans('firefly.delete_account'));
$subTitleIcon = 'fa-trash'; $subTitleIcon = 'fa-trash';
@@ -111,32 +95,18 @@ class ProfileController extends Controller
*/ */
public function postChangePassword(ProfileFormRequest $request, UserRepositoryInterface $repository) public function postChangePassword(ProfileFormRequest $request, UserRepositoryInterface $repository)
{ {
if (intval(getenv('SANDSTORM')) === 1) { // the request has already validated both new passwords must be equal.
return view('error')->with('message', strval(trans('firefly.sandstorm_not_available'))); $current = $request->get('current_password');
} $new = $request->get('new_password');
if (auth()->user()->hasRole('demo')) {
Session::flash('info', strval(trans('firefly.cannot_change_demo')));
return redirect(route('profile.index'));
}
// old, new1, new2
if (!Hash::check($request->get('current_password'), auth()->user()->password)) {
Session::flash('error', strval(trans('firefly.invalid_current_password')));
return redirect(route('profile.change-password'));
}
try { try {
$this->validatePassword($request->get('current_password'), $request->get('new_password')); $this->validatePassword(auth()->user(), $current, $new);
} catch (ValidationException $e) { } catch (ValidationException $e) {
Session::flash('error', $e->getMessage()); Session::flash('error', $e->getMessage());
return redirect(route('profile.change-password')); return redirect(route('profile.change-password'));
} }
// update the user with the new password.
$repository->changePassword(auth()->user(), $request->get('new_password')); $repository->changePassword(auth()->user(), $request->get('new_password'));
Session::flash('success', strval(trans('firefly.password_changed'))); Session::flash('success', strval(trans('firefly.password_changed')));
@@ -151,17 +121,6 @@ class ProfileController extends Controller
*/ */
public function postDeleteAccount(UserRepositoryInterface $repository, DeleteAccountFormRequest $request) public function postDeleteAccount(UserRepositoryInterface $repository, DeleteAccountFormRequest $request)
{ {
if (intval(getenv('SANDSTORM')) === 1) {
return view('error')->with('message', strval(trans('firefly.sandstorm_not_available')));
}
if (auth()->user()->hasRole('demo')) {
Session::flash('info', strval(trans('firefly.cannot_delete_demo')));
return redirect(route('profile.index'));
}
// old, new1, new2
if (!Hash::check($request->get('password'), auth()->user()->password)) { if (!Hash::check($request->get('password'), auth()->user()->password)) {
Session::flash('error', strval(trans('firefly.invalid_password'))); Session::flash('error', strval(trans('firefly.invalid_password')));
@@ -182,15 +141,21 @@ class ProfileController extends Controller
} }
/** /**
* @param string $old * @param User $user
* @param string $current
* @param string $new * @param string $new
* @param string $newConfirmation
* *
* @return bool * @return bool
* @throws ValidationException * @throws ValidationException
*/ */
protected function validatePassword(string $old, string $new): bool protected function validatePassword(User $user, string $current, string $new): bool
{ {
if ($new === $old) { if (!Hash::check($current, auth()->user()->password)) {
throw new ValidationException(strval(trans('firefly.invalid_current_password')));
}
if ($current === $new) {
throw new ValidationException(strval(trans('firefly.should_change'))); throw new ValidationException(strval(trans('firefly.should_change')));
} }

View File

@@ -26,6 +26,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log;
use Preferences; use Preferences;
use Response; use Response;
use Session; use Session;
@@ -73,7 +74,7 @@ class ReportController extends Controller
public function auditReport(Collection $accounts, Carbon $start, Carbon $end) public function auditReport(Collection $accounts, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', trans('firefly.end_after_start_date')); return view('error')->with('message', trans('firefly.end_after_start_date')); // @codeCoverageIgnore
} }
if ($start < session('first')) { if ($start < session('first')) {
$start = session('first'); $start = session('first');
@@ -109,7 +110,7 @@ class ReportController extends Controller
public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end) public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', trans('firefly.end_after_start_date')); return view('error')->with('message', trans('firefly.end_after_start_date')); // @codeCoverageIgnore
} }
if ($start < session('first')) { if ($start < session('first')) {
$start = session('first'); $start = session('first');
@@ -145,7 +146,7 @@ class ReportController extends Controller
public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end) public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', trans('firefly.end_after_start_date')); return view('error')->with('message', trans('firefly.end_after_start_date')); // @codeCoverageIgnore
} }
if ($start < session('first')) { if ($start < session('first')) {
$start = session('first'); $start = session('first');
@@ -251,10 +252,9 @@ class ReportController extends Controller
/** /**
* @param ReportFormRequest $request * @param ReportFormRequest $request
* *
* @return RedirectResponse * @return RedirectResponse|\Illuminate\Routing\Redirector
* @throws FireflyException
*/ */
public function postIndex(ReportFormRequest $request): RedirectResponse public function postIndex(ReportFormRequest $request)
{ {
// report type: // report type:
$reportType = $request->get('report_type'); $reportType = $request->get('report_type');
@@ -266,6 +266,7 @@ class ReportController extends Controller
$tags = join(',', $request->getTagList()->pluck('tag')->toArray()); $tags = join(',', $request->getTagList()->pluck('tag')->toArray());
if ($request->getAccountList()->count() === 0) { if ($request->getAccountList()->count() === 0) {
Log::debug('Account count is zero');
Session::flash('error', trans('firefly.select_more_than_one_account')); Session::flash('error', trans('firefly.select_more_than_one_account'));
return redirect(route('reports.index')); return redirect(route('reports.index'));
@@ -293,14 +294,7 @@ class ReportController extends Controller
return view('error')->with('message', trans('firefly.end_after_start_date')); return view('error')->with('message', trans('firefly.end_after_start_date'));
} }
// lower threshold
if ($start < session('first')) {
$start = session('first');
}
switch ($reportType) { switch ($reportType) {
default:
throw new FireflyException(sprintf('Firefly does not support the "%s"-report yet.', $reportType));
case 'category': case 'category':
$uri = route('reports.report.category', [$accounts, $categories, $start, $end]); $uri = route('reports.report.category', [$accounts, $categories, $start, $end]);
break; break;
@@ -332,7 +326,7 @@ class ReportController extends Controller
public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', trans('firefly.end_after_start_date')); return view('error')->with('message', trans('firefly.end_after_start_date')); // @codeCoverageIgnore
} }
if ($start < session('first')) { if ($start < session('first')) {
$start = session('first'); $start = session('first');

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;
@@ -255,10 +255,11 @@ class RuleController 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('rules.create.fromStore', true); Session::put('rules.create.fromStore', true);
return redirect(route('rules.create', [$ruleGroup]))->withInput(); return redirect(route('rules.create', [$ruleGroup]))->withInput();
// @codeCoverageIgnoreEnd
} }
return redirect($this->getPreviousUri('rules.create.uri')); return redirect($this->getPreviousUri('rules.create.uri'));
@@ -340,10 +341,11 @@ class RuleController 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('rules.edit.fromUpdate', true); Session::put('rules.edit.fromUpdate', true);
return redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]); return redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
} }
return redirect($this->getPreviousUri('rules.edit.uri')); return redirect($this->getPreviousUri('rules.edit.uri'));
@@ -473,7 +475,7 @@ class RuleController extends Controller
$actions[] = view( $actions[] = view(
'rules.partials.action', 'rules.partials.action',
[ [
'oldTrigger' => $entry, 'oldAction' => $entry,
'oldValue' => $request->old('rule-action-value')[$index], 'oldValue' => $request->old('rule-action-value')[$index],
'oldChecked' => $checked, 'oldChecked' => $checked,
'count' => $count, 'count' => $count,
@@ -531,7 +533,7 @@ class RuleController extends Controller
if (is_array($data['rule-triggers'])) { if (is_array($data['rule-triggers'])) {
foreach ($data['rule-triggers'] as $index => $triggerType) { foreach ($data['rule-triggers'] as $index => $triggerType) {
$data['rule-trigger-stop'][$index] = $data['rule-trigger-stop'][$index] ?? 0; $data['rule-trigger-stop'][$index] = $data['rule-trigger-stop'][$index] ?? 0;
$triggers[] = [ $triggers[] = [
'type' => $triggerType, 'type' => $triggerType,
'value' => $data['rule-trigger-values'][$index], 'value' => $data['rule-trigger-values'][$index],
'stopProcessing' => intval($data['rule-trigger-stop'][$index]) === 1 ? true : false, 'stopProcessing' => intval($data['rule-trigger-stop'][$index]) === 1 ? true : false,

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;
@@ -217,10 +217,11 @@ class RuleGroupController 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('rule-groups.create.fromStore', true); Session::put('rule-groups.create.fromStore', true);
return redirect(route('rule-groups.create'))->withInput(); return redirect(route('rule-groups.create'))->withInput();
// @codeCoverageIgnoreEnd
} }
return redirect($this->getPreviousUri('rule-groups.create.uri')); return redirect($this->getPreviousUri('rule-groups.create.uri'));
@@ -261,10 +262,11 @@ class RuleGroupController 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('rule-groups.edit.fromUpdate', true); Session::put('rule-groups.edit.fromUpdate', true);
return redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]); return redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]);
// @codeCoverageIgnoreEnd
} }
// redirect to previous URL. // redirect to previous URL.

View File

@@ -0,0 +1,61 @@
<?php
/**
* IsLimitedUser.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\Http\Middleware;
use Closure;
use FireflyIII\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Session;
/**
* Class IsAdmin
*
* @package FireflyIII\Http\Middleware
*/
class IsLimitedUser
{
/**
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
return redirect()->guest('login');
}
/** @var User $user */
$user = auth()->user();
if ($user->hasRole('demo')) {
Session::flash('warning', strval(trans('firefly.not_available_demo_user')));
return redirect(route('index'));
}
if (intval(getenv('SANDSTORM')) === 1) {
Session::flash('warning', strval(trans('firefly.sandstorm_not_available')));
return redirect(route('index'));
}
return $next($request);
}
}

View File

@@ -29,6 +29,7 @@ use Google2FA;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Translation\Translator;
use Illuminate\Validation\Validator; use Illuminate\Validation\Validator;
use Log;
use Session; use Session;
/** /**

View File

@@ -124,7 +124,7 @@ return [
'journals_in_period_for_account' => 'All transactions for account :name between :start and :end', 'journals_in_period_for_account' => 'All transactions for account :name between :start and :end',
'transferred' => 'Transferred', 'transferred' => 'Transferred',
'all_withdrawal' => 'All expenses', 'all_withdrawal' => 'All expenses',
'all_transactions' => 'All transactions', 'all_transactions' => 'All transactions',
'title_withdrawal_between' => 'All expenses between :start and :end', 'title_withdrawal_between' => 'All expenses between :start and :end',
'all_deposit' => 'All revenue', 'all_deposit' => 'All revenue',
'title_deposit_between' => 'All revenue between :start and :end', 'title_deposit_between' => 'All revenue between :start and :end',
@@ -134,6 +134,7 @@ return [
'title_transfer_between' => 'All transfers between :start and :end', 'title_transfer_between' => 'All transfers between :start and :end',
'all_journals_for_category' => 'All transactions for category :name', 'all_journals_for_category' => 'All transactions for category :name',
'journals_in_period_for_category' => 'All transactions for category :name between :start and :end', 'journals_in_period_for_category' => 'All transactions for category :name between :start and :end',
'not_available_demo_user' => 'The feature you try to access is not available to demo users.',
// repeat frequencies: // repeat frequencies:

View File

@@ -10,11 +10,7 @@
<select name="rule-action[{{ count }}]" class="form-control"> <select name="rule-action[{{ count }}]" class="form-control">
{% for key,name in allRuleActions() %} {% for key,name in allRuleActions() %}
<option value="{{ key }}" label="{{ name }}" <option value="{{ key }}" label="{{ name }}" {% if key == oldAction %} selected{% endif %}>{{ name }}</option>
{% if key == oldTrigger %}
selected
{% endif %}
>{{ name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>

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;
@@ -15,8 +15,10 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use PragmaRX\Google2FA\Contracts\Google2FA; use PragmaRX\Google2FA\Contracts\Google2FA;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -81,6 +83,34 @@ class PreferencesControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">'); $response->assertSee('<ol class="breadcrumb">');
} }
/**
*
*/
public function testPostCode()
{
$secret = '0123456789abcde';
$key = '123456';
$google = $this->mock(Google2FA::class);
$this->withoutMiddleware();
$this->session(['two-factor-secret' => $secret]);
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthEnabled', 1])->once();
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthSecret', $secret])->once();
Preferences::shouldReceive('mark')->once();
$google->shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
$data = [
'code' => $key,
];
$this->be($this->user());
$response = $this->post(route('preferences.code.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/** /**
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex * @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/ */
@@ -88,11 +118,13 @@ class PreferencesControllerTest extends TestCase
{ {
// mock stuff // mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->andReturn(false);
$data = [ $data = [
'fiscalYearStart' => '2016-01-01', 'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [], 'frontPageAccounts' => [1],
'viewRange' => '1M', 'viewRange' => '1M',
'customFiscalYear' => 0, 'customFiscalYear' => 0,
'showDepositsFrontpage' => 0, 'showDepositsFrontpage' => 0,
@@ -109,4 +141,80 @@ class PreferencesControllerTest extends TestCase
$response->assertRedirect(route('preferences.index')); $response->assertRedirect(route('preferences.index'));
} }
/**
* User wants 2FA and has secret already.
*
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
public function testPostIndexWith2FA()
{
$this->withoutMiddleware();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->andReturn(false);
// mock preferences (in a useful way?)
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn('12345');
Preferences::shouldReceive('set');
Preferences::shouldReceive('mark');
$data = [
'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [1],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
'transactionPageSize' => 100,
'twoFactorAuthEnabled' => 1,
'language' => 'en_US',
'tj' => [],
];
$this->be($this->user());
$response = $this->post(route('preferences.update'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// go to code to get a secret.
$response->assertRedirect(route('preferences.index'));
}
/**
* User wants 2FA and has no secret.
*
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
public function testPostIndexWithEmpty2FA()
{
$this->withoutMiddleware();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->andReturn(false);
// mock preferences (in a useful way?)
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);
Preferences::shouldReceive('set');
Preferences::shouldReceive('mark');
$data = [
'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [1],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
'transactionPageSize' => 100,
'twoFactorAuthEnabled' => 1,
'language' => 'en_US',
'tj' => [],
];
$this->be($this->user());
$response = $this->post(route('preferences.update'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// go to code to get a secret.
$response->assertRedirect(route('preferences.code'));
}
} }

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;
@@ -72,6 +72,7 @@ class ProfileControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword * @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/ */
public function testPostChangePassword() public function testPostChangePassword()
{ {
@@ -92,6 +93,52 @@ class ProfileControllerTest extends TestCase
$response->assertSessionHas('success'); $response->assertSessionHas('success');
} }
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordNotCorrect()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$data = [
'current_password' => 'james3',
'new_password' => 'james2',
'new_password_confirmation' => 'james2',
];
$this->be($this->user());
$response = $this->post(route('profile.change-password.post'), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordSameNew()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$data = [
'current_password' => 'james',
'new_password' => 'james',
'new_password_confirmation' => 'james',
];
$this->be($this->user());
$response = $this->post(route('profile.change-password.post'), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/** /**
* @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount * @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
*/ */
@@ -101,7 +148,7 @@ class ProfileControllerTest extends TestCase
$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 = $this->mock(UserRepositoryInterface::class); $repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('destroy'); $repository->shouldReceive('destroy')->once();
$data = [ $data = [
'password' => 'james', 'password' => 'james',
]; ];
@@ -111,4 +158,23 @@ class ProfileControllerTest extends TestCase
$response->assertRedirect(route('index')); $response->assertRedirect(route('index'));
} }
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
*/
public function testPostDeleteAccountWrong()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$data = [
'password' => 'james2',
];
$this->be($this->user());
$response = $this->post(route('profile.delete-account.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('profile.delete-account'));
$response->assertSessionHas('error');
}
} }

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;
@@ -51,7 +51,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setStartDate')->once(); $generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once(); $generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once(); $generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report'); $generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user()); $this->be($this->user());
@@ -71,7 +71,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setEndDate')->once(); $generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once(); $generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('setBudgets')->once(); $generator->shouldReceive('setBudgets')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report'); $generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('reports.report.budget', [1, 1, '20160101', '20160131'])); $response = $this->get(route('reports.report.budget', [1, 1, '20160101', '20160131']));
@@ -90,7 +90,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setEndDate')->once(); $generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once(); $generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('setCategories')->once(); $generator->shouldReceive('setCategories')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report'); $generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('reports.report.category', [1, 1, '20160101', '20160131'])); $response = $this->get(route('reports.report.category', [1, 1, '20160101', '20160131']));
@@ -108,13 +108,28 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setStartDate')->once(); $generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once(); $generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once(); $generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report'); $generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('reports.report.default', [1, '20160101', '20160131'])); $response = $this->get(route('reports.report.default', [1, '20160101', '20160131']));
$response->assertStatus(200); $response->assertStatus(200);
} }
/**
* @covers \FireflyIII\Http\Controllers\ReportController::defaultReport
*/
public function testDefaultReportBadDate()
{
$generator = $this->mock(SYRG::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('reports.report.default', [1, '20160101', '20150131']));
$response->assertStatus(200);
$response->assertSee('End date of report must be after start date.');
}
/** /**
* @covers \FireflyIII\Http\Controllers\ReportController::index * @covers \FireflyIII\Http\Controllers\ReportController::index
* @covers \FireflyIII\Http\Controllers\ReportController::__construct * @covers \FireflyIII\Http\Controllers\ReportController::__construct
@@ -204,14 +219,211 @@ class ReportControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex * @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/ */
public function testPostIndex() public function testPostIndexAuditOK()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'audit',
];
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('reports.index.post')); $response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302); $response->assertStatus(302);
$response->assertRedirect(route('reports.report.audit', ['1', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexBudgetError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'budget' => [],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'budget',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.index'));
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexBudgetOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'budget' => ['1'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'budget',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.report.budget', ['1', '1', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexCategoryError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'category' => [],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'category',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.index'));
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexCategoryOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'category' => ['1'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'category',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.report.category', ['1', '1', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexDefaultOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'default',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.report.default', ['1', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexDefaultStartEnd()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'daterange' => '2016-01-01 - 2015-01-31',
'report_type' => 'default',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(200);
$response->assertSee('End date of report must be after start date.');
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexTagError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'tag' => [],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'tag',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.index'));
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexTagOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'tag' => ['housing'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'tag',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.report.tag', ['1', 'housing', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexZeroAccounts()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => [],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'default',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.index'));
$response->assertSessionHas('error');
} }
/** /**

View File

@@ -7,16 +7,18 @@
* 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 FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Rules\TransactionMatcher;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
@@ -30,13 +32,39 @@ class RuleControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::create * @covers \FireflyIII\Http\Controllers\RuleController::create
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
*/ */
public function testCreate() public function testCreate()
{ {
// mock stuff // mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('rules.create', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::create
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
*/
public function testCreatePreviousInput()
{
$old = [
'rule-trigger' => ['description_is'],
'rule-trigger-stop' => ['1'],
'rule-trigger-value' => ['X'],
'rule-action' => ['set_category'],
'rule-action-stop' => ['1'],
'rule-action-value' => ['x'],
];
$this->session(['_old_input' => $old]);
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
@@ -51,7 +79,7 @@ class RuleControllerTest extends TestCase
public function testDelete() public function testDelete()
{ {
// mock stuff // mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
@@ -66,8 +94,8 @@ class RuleControllerTest extends TestCase
public function testDestroy() public function testDestroy()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::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('destroy'); $repository->shouldReceive('destroy');
@@ -85,8 +113,8 @@ class RuleControllerTest extends TestCase
public function testDown() public function testDown()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::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('moveDown'); $repository->shouldReceive('moveDown');
@@ -98,12 +126,43 @@ class RuleControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::edit * @covers \FireflyIII\Http\Controllers\RuleController::edit
* @covers \FireflyIII\Http\Controllers\RuleController::getCurrentActions
* @covers \FireflyIII\Http\Controllers\RuleController::getCurrentTriggers
*/ */
public function testEdit() public function testEdit()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
$this->be($this->user());
$response = $this->get(route('rules.edit', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::edit
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
*/
public function testEditPreviousInput()
{
$old = [
'rule-trigger' => ['description_is'],
'rule-trigger-stop' => ['1'],
'rule-trigger-value' => ['X'],
'rule-action' => ['set_category'],
'rule-action-stop' => ['1'],
'rule-action-value' => ['x'],
];
$this->session(['_old_input' => $old]);
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule); $repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
@@ -116,6 +175,8 @@ class RuleControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::index * @covers \FireflyIII\Http\Controllers\RuleController::index
* @covers \FireflyIII\Http\Controllers\RuleController::__construct * @covers \FireflyIII\Http\Controllers\RuleController::__construct
* @covers \FireflyIII\Http\Controllers\RuleController::createDefaultRule
* @covers \FireflyIII\Http\Controllers\RuleController::createDefaultRuleGroup
*/ */
public function testIndex() public function testIndex()
{ {
@@ -143,12 +204,12 @@ class RuleControllerTest extends TestCase
public function testReorderRuleActions() public function testReorderRuleActions()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::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);
$data = ['triggers' => [1, 2, 3],]; $data = ['actions' => [1, 2, 3],];
$repository->shouldReceive('reorderRuleActions'); $repository->shouldReceive('reorderRuleActions')->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('rules.reorder-actions', [1]), $data); $response = $this->post(route('rules.reorder-actions', [1]), $data);
@@ -161,12 +222,12 @@ class RuleControllerTest extends TestCase
public function testReorderRuleTriggers() public function testReorderRuleTriggers()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::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);
$data = ['triggers' => [1, 2, 3],]; $data = ['triggers' => [1, 2, 3],];
$repository->shouldReceive('reorderRuleTriggers'); $repository->shouldReceive('reorderRuleTriggers')->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('rules.reorder-triggers', [1]), $data); $response = $this->post(route('rules.reorder-triggers', [1]), $data);
@@ -179,8 +240,8 @@ class RuleControllerTest extends TestCase
public function testStore() public function testStore()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -217,15 +278,73 @@ class RuleControllerTest extends TestCase
* This actually hits an error and not the actually code but OK. * This actually hits an error and not the actually code but OK.
* *
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers * @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/ */
public function testTestTriggers() public function testTestTriggersError()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('rules.test-triggers', [1])); $uri = route('rules.test-triggers');
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
*
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/
public function testTestTriggers()
{
$data = [
'rule-trigger' => ['description_is'],
'rule-trigger-value' => ['Bla bla'],
'rule-trigger-stop' => ['1'],
];
// mock stuff
$matcher = $this->mock(TransactionMatcher::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
$matcher->shouldReceive('findMatchingTransactions')->andReturn(new Collection);
$this->be($this->user());
$uri = route('rules.test-triggers') . '?' . http_build_query($data);
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/
public function testTestTriggersMax()
{
$data = [
'rule-trigger' => ['description_is'],
'rule-trigger-value' => ['Bla bla'],
'rule-trigger-stop' => ['1'],
];
$set = factory(Transaction::class, 10)->make();
// mock stuff
$matcher = $this->mock(TransactionMatcher::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
$matcher->shouldReceive('findMatchingTransactions')->andReturn($set);
$this->be($this->user());
$uri = route('rules.test-triggers') . '?' . http_build_query($data);
$response = $this->get($uri);
$response->assertStatus(200); $response->assertStatus(200);
} }
@@ -252,8 +371,8 @@ class RuleControllerTest extends TestCase
public function testUpdate() public function testUpdate()
{ {
// mock stuff // mock stuff
$repository = $this->mock(RuleRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@@ -25,7 +25,7 @@ class SearchControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\SearchController::index * @covers \FireflyIII\Http\Controllers\SearchController::index
* Implement testIndex(). * @covers \FireflyIII\Http\Controllers\SearchController::__construct
*/ */
public function testIndex() public function testIndex()
{ {