Skip to content

Commit

Permalink
qa: adds test for laminas#2
Browse files Browse the repository at this point in the history
Adds an assertion class to the test suite, and a unit test that
exercises it to demonstrate the scenario presented in laminas#2.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
  • Loading branch information
weierophinney committed Sep 21, 2020
1 parent 3a81215 commit 0db3d53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/AclTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1462,4 +1462,22 @@ public function testAllowNullPermissionAfterResourcesExistShouldAllowAllPermissi
$this->acl->allow('admin');
$this->assertTrue($this->acl->isAllowed('admin'));
}

/**
* @see https://github.com/laminas/laminas-permissions-acl/issues/2
*/
public function testWhenAssertionReturnsFalseTheInversionOfItsTypeShouldBeUsed()
{
$assertAllow = new TestAsset\ChildBooleanAssertion(true);
$assertDeny = new TestAsset\ChildBooleanAssertion(false);

$this->acl->addRole('staff');
$this->acl->addResource('base');
$this->acl->allow('staff', 'base', 'update', $assertAllow);

$this->acl->addResource('user', 'base');
$this->acl->allow('staff', 'user', 'update', $assertDeny);

$this->assertFalse($this->acl->isAllowed('staff', 'user', 'update'));
}
}
33 changes: 33 additions & 0 deletions test/TestAsset/ChildBooleanAssertion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* @see https://github.com/laminas/laminas-permissions-acl for the canonical source repository
* @copyright https://github.com/laminas/laminas-permissions-acl/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-permissions-acl/blob/master/LICENSE.md New BSD License
*/

namespace LaminasTest\Permissions\Acl\TestAsset;

use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Assertion\AssertionInterface;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Laminas\Permissions\Acl\Role\RoleInterface;

/**
* @see https://github.com/laminas/laminas-permissions-acl/issues/2
*/
class ChildBooleanAssertion implements AssertionInterface
{
/** @var bool */
private $value;

public function __construct($value)
{
$this->value = (bool) $value;
}

public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
{
return $this->value;
}
}

0 comments on commit 0db3d53

Please sign in to comment.