Expand tests and fix various small issues in strict comparison.

This commit is contained in:
James Cole
2017-07-15 22:17:24 +02:00
parent aac1338bdd
commit fa00ba2edd
12 changed files with 37 additions and 13 deletions

View File

@@ -23,10 +23,10 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController; use Illuminate\Routing\Controller as BaseController;
use Route;
use Session; use Session;
use URL; use URL;
use View; use View;
use Route;
/** /**
* Class Controller * Class Controller
@@ -66,10 +66,12 @@ class Controller extends BaseController
$this->dateTimeFormat = (string)trans('config.date_time'); $this->dateTimeFormat = (string)trans('config.date_time');
// get shown-intro-preference: // get shown-intro-preference:
$key = 'shown_demo_' . Route::currentRouteName(); if (auth()->check()) {
$shownDemo = Preferences::get($key, false)->data; $key = 'shown_demo_' . Route::currentRouteName();
View::share('shownDemo', $shownDemo); $shownDemo = Preferences::get($key, false)->data;
View::share('current_route_name', Route::currentRouteName()); View::share('shownDemo', $shownDemo);
View::share('current_route_name', Route::currentRouteName());
}
return $next($request); return $next($request);
} }

View File

@@ -116,7 +116,7 @@ class Account extends Model
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -55,7 +55,7 @@ class Attachment extends Model
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -62,7 +62,7 @@ class Bill extends Model
public static function routeBinder(Bill $value) public static function routeBinder(Bill $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -85,7 +85,7 @@ class Budget extends Model
public static function routeBinder(Budget $value) public static function routeBinder(Budget $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -86,7 +86,7 @@ class Category extends Model
public static function routeBinder(Category $value) public static function routeBinder(Category $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -51,7 +51,7 @@ class Rule extends Model
public static function routeBinder(Rule $value) public static function routeBinder(Rule $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -52,7 +52,7 @@ class RuleGroup extends Model
public static function routeBinder(RuleGroup $value) public static function routeBinder(RuleGroup $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -87,7 +87,7 @@ class Tag extends Model
public static function routeBinder(Tag $value) public static function routeBinder(Tag $value)
{ {
if (auth()->check()) { if (auth()->check()) {
if ($value->user_id === auth()->user()->id) { if (intval($value->user_id) === auth()->user()->id) {
return $value; return $value;
} }
} }

View File

@@ -156,6 +156,7 @@ return [
'Preferences', 'Preferences',
'URL', 'URL',
'Config', 'Config',
'Request',
'ExpandedForm' => [ 'ExpandedForm' => [
'is_safe' => [ 'is_safe' => [
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',

View File

@@ -30,6 +30,8 @@
<p class="text-danger"> <p class="text-danger">
The page you have requested does not exist. Please check that you have not entered The page you have requested does not exist. Please check that you have not entered
the wrong URL. Did you make a typo perhaps? the wrong URL. Did you make a typo perhaps?
<!-- {{ Request.url() }} -->
</p> </p>
</div> </div>
</div> </div>

View File

@@ -35,9 +35,16 @@ class TwoFactorControllerTest extends TestCase
$truePref->data = true; $truePref->data = true;
$secretPreference = new Preference; $secretPreference = new Preference;
$secretPreference->data = 'BlablaSeecret'; $secretPreference->data = 'BlablaSeecret';
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
$falsePref = new Preference;
$falsePref->data = false;
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once();
$response = $this->get(route('two-factor.index')); $response = $this->get(route('two-factor.index'));
$response->assertStatus(200); $response->assertStatus(200);
} }
@@ -54,6 +61,8 @@ class TwoFactorControllerTest extends TestCase
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once();
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePreference)->once();
$response = $this->get(route('two-factor.index')); $response = $this->get(route('two-factor.index'));
$response->assertStatus(302); $response->assertStatus(302);
$response->assertRedirect(route('index')); $response->assertRedirect(route('index'));
@@ -74,6 +83,11 @@ class TwoFactorControllerTest extends TestCase
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
$falsePref = new Preference;
$falsePref->data = false;
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once();
$response = $this->get(route('two-factor.index')); $response = $this->get(route('two-factor.index'));
$response->assertStatus(500); $response->assertStatus(500);
} }
@@ -92,6 +106,11 @@ class TwoFactorControllerTest extends TestCase
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePreference); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
$falsePref = new Preference;
$falsePref->data = false;
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.lost', false])->andReturn($falsePref)->once();
$response = $this->get(route('two-factor.lost')); $response = $this->get(route('two-factor.lost'));
$response->assertStatus(200); $response->assertStatus(200);
} }