Skip to content

Commit

Permalink
Merge branch 'policy-method-guess' of https://github.com/alepeino/fra…
Browse files Browse the repository at this point in the history
…mework into alepeino-policy-method-guess
  • Loading branch information
taylorotwell committed Dec 15, 2016
2 parents dc2ce4f + e0e3220 commit 83f6aba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function authorizeForUser($user, $ability, $arguments = [])
*/
protected function parseAbilityAndArguments($ability, $arguments)
{
if (is_string($ability)) {
if (is_string($ability) && (! class_exists($ability))) {
return [$ability, $arguments];
}

Expand Down
35 changes: 28 additions & 7 deletions tests/Foundation/FoundationAuthorizesRequestsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public function test_basic_gate_check()

$gate = $this->getBasicGate();

$gate->define('foo', function () {
$gate->define('baz', function () {
$_SERVER['_test.authorizes.trait'] = true;

return true;
});

$response = (new FoundationTestAuthorizeTraitClass)->authorize('foo');
$response = (new FoundationTestAuthorizeTraitClass)->authorize('baz');

$this->assertInstanceOf(Response::class, $response);
$this->assertTrue($_SERVER['_test.authorizes.trait']);
Expand All @@ -33,11 +33,11 @@ public function test_exception_is_thrown_if_gate_check_fails()
{
$gate = $this->getBasicGate();

$gate->define('foo', function () {
$gate->define('baz', function () {
return false;
});

(new FoundationTestAuthorizeTraitClass)->authorize('foo');
(new FoundationTestAuthorizeTraitClass)->authorize('baz');
}

public function test_policies_may_be_called()
Expand All @@ -54,15 +54,29 @@ public function test_policies_may_be_called()
$this->assertTrue($_SERVER['_test.authorizes.trait.policy']);
}

public function test_policy_method_may_be_guessed()
public function test_policy_method_may_be_guessed_passing_model_instance()
{
unset($_SERVER['_test.authorizes.trait.policy']);

$gate = $this->getBasicGate();

$gate->policy(FoundationAuthorizesRequestTestClass::class, FoundationAuthorizesRequestTestPolicy::class);

$response = (new FoundationTestAuthorizeTraitClass)->authorize([new FoundationAuthorizesRequestTestClass]);
$response = (new FoundationTestAuthorizeTraitClass)->authorize(new FoundationAuthorizesRequestTestClass);

$this->assertInstanceOf(Response::class, $response);
$this->assertTrue($_SERVER['_test.authorizes.trait.policy']);
}

public function test_policy_method_may_be_guessed_passing_class_name()
{
unset($_SERVER['_test.authorizes.trait.policy']);

$gate = $this->getBasicGate();

$gate->policy(FoundationAuthorizesRequestTestClass::class, FoundationAuthorizesRequestTestPolicy::class);

$response = (new FoundationTestAuthorizeTraitClass)->authorize(FoundationAuthorizesRequestTestClass::class);

$this->assertInstanceOf(Response::class, $response);
$this->assertTrue($_SERVER['_test.authorizes.trait.policy']);
Expand Down Expand Up @@ -115,7 +129,14 @@ public function update()
return true;
}

public function test_policy_method_may_be_guessed()
public function test_policy_method_may_be_guessed_passing_model_instance()
{
$_SERVER['_test.authorizes.trait.policy'] = true;

return true;
}

public function test_policy_method_may_be_guessed_passing_class_name()
{
$_SERVER['_test.authorizes.trait.policy'] = true;

Expand Down

0 comments on commit 83f6aba

Please sign in to comment.