Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Singularize filter. #22

Merged
merged 8 commits into from

2 participants

Nikolay Bukarinov Ivan Shumkov
Commits on Dec 4, 2012
  1. Nikolay Bukarinov

    Add Singularize filter.

    Bukarinov authored
    Little refactoring.
Commits on Dec 5, 2012
  1. Nikolay Bukarinov
  2. Nikolay Bukarinov

    Move Roles to library.

    Bukarinov authored
    Move ResourceInterface and AbstractResource to Assertion\Resource namespace.
  3. Nikolay Bukarinov
  4. Nikolay Bukarinov

    Tests for Roles

    Bukarinov authored
  5. Nikolay Bukarinov
  6. Nikolay Bukarinov
  7. Nikolay Bukarinov
This page is out of date. Refresh to see the latest.
Showing with 454 additions and 47 deletions.
  1. +101 −0 library/GeometriaLab/Filter/Singularize.php
  2. +11 −11 library/GeometriaLab/Permissions/Assertion/Assertion.php
  3. +1 −1  library/GeometriaLab/Permissions/Assertion/{ → Resource}/AbstractResource.php
  4. +1 −1  library/GeometriaLab/Permissions/Assertion/{ → Resource}/ResourceInterface.php
  5. +1 −1  library/GeometriaLab/Permissions/Assertion/Service.php
  6. +119 −0 library/GeometriaLab/Permissions/Roles/AbstractRoles.php
  7. +15 −0 library/GeometriaLab/Permissions/Roles/ResourceRoles.php
  8. +14 −14 tests/GeometriaLabTest/Permissions/Assertion/AssertionTest.php
  9. +3 −3 tests/GeometriaLabTest/Permissions/Assertion/{ → Resource}/ResourceTest.php
  10. +0 −10 tests/GeometriaLabTest/Permissions/Assertion/Sample/Bar.php
  11. +10 −0 tests/GeometriaLabTest/Permissions/Assertion/SampleResource/Bar.php
  12. +2 −2 tests/GeometriaLabTest/Permissions/Assertion/{Sample → SampleResource}/Foo.php
  13. +4 −4 tests/GeometriaLabTest/Permissions/Assertion/ServiceTest.php
  14. +115 −0 tests/GeometriaLabTest/Permissions/Roles/RolesTest.php
  15. +11 −0 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Bar.php
  16. +11 −0 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Baz.php
  17. +11 −0 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Foo.php
  18. +11 −0 tests/GeometriaLabTest/Permissions/Roles/SampleModel/ModelWithoutId.php
  19. +13 −0 tests/GeometriaLabTest/Permissions/Roles/SampleRoles/Roles.php
101 library/GeometriaLab/Filter/Singularize.php
View
@@ -0,0 +1,101 @@
+<?php
+
+namespace GeometriaLab\Filter;
+
+use \Zend\Filter\FilterInterface as ZendFilterInterface;
+
+class Singularize implements ZendFilterInterface
+{
+ /**
+ * @var array
+ */
+ protected $singular = array (
+ '/(quiz)zes$/i' => '\1',
+ '/(matr)ices$/i' => '\1ix',
+ '/(vert|ind)ices$/i' => '\1ex',
+ '/^(ox)en/i' => '\1',
+ '/(alias|status)es$/i' => '\1',
+ '/([octop|vir])i$/i' => '\1us',
+ '/(cris|ax|test)es$/i' => '\1is',
+ '/(shoe)s$/i' => '\1',
+ '/(o)es$/i' => '\1',
+ '/(bus)es$/i' => '\1',
+ '/([m|l])ice$/i' => '\1ouse',
+ '/(x|ch|ss|sh)es$/i' => '\1',
+ '/(m)ovies$/i' => '\1ovie',
+ '/(s)eries$/i' => '\1eries',
+ '/([^aeiouy]|qu)ies$/i' => '\1y',
+ '/([lr])ves$/i' => '\1f',
+ '/(tive)s$/i' => '\1',
+ '/(hive)s$/i' => '\1',
+ '/([^f])ves$/i' => '\1fe',
+ '/(^analy)ses$/i' => '\1sis',
+ '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
+ '/([ti])a$/i' => '\1um',
+ '/(n)ews$/i' => '\1ews',
+ '/status/i' => 'status',
+ '/s$/i' => '',
+ );
+ /**
+ * @var array
+ */
+ protected $uncountable = array(
+ 'equipment',
+ 'information',
+ 'rice',
+ 'money',
+ 'species',
+ 'series',
+ 'fish',
+ 'sheep'
+ );
+ /**
+ * @var array
+ */
+ protected $irregular = array(
+ 'person' => 'people',
+ 'man' => 'men',
+ 'child' => 'children',
+ 'sex' => 'sexes',
+ 'move' => 'moves'
+ );
+ /**
+ * @var array
+ */
+ protected static $cachedWords = array();
+
+ /**
+ * Returns the result of filtering $value
+ *
+ * @param string $word
+ * @return string
+ */
+ function filter($word)
+ {
+ if (isset(static::$cachedWords[$word])) {
+ return static::$cachedWords[$word];
+ }
+
+ $lowercaseWord = strtolower($word);
+ foreach ($this->uncountable as $uncountable){
+ if (substr($lowercaseWord,(-1 * strlen($uncountable))) == $uncountable) {
+ return static::$cachedWords[$word] = $word;
+ }
+ }
+
+ foreach ($this->irregular as $plural=> $singular) {
+ $arr = array();
+ if (preg_match('/(' . $singular . ')$/i', $word, $arr)) {
+ return static::$cachedWords[$word] = preg_replace('/(' . $singular . ')$/i', substr($arr[0], 0, 1) . substr($plural, 1), $word);
+ }
+ }
+
+ foreach ($this->singular as $rule => $replacement) {
+ if (preg_match($rule, $word)) {
+ return static::$cachedWords[$word] = preg_replace($rule, $replacement, $word);
+ }
+ }
+
+ return static::$cachedWords[$word] = $word;
+ }
+}
22 library/GeometriaLab/Permissions/Assertion/Assertion.php
View
@@ -9,14 +9,14 @@ class Assertion
/**
* Resource tree
*
- * @var ResourceInterface[]
+ * @var Resource\ResourceInterface[]
*/
protected $resources = array();
/**
* Get all resources
*
- * @return ResourceInterface[]
+ * @return Resource\ResourceInterface[]
*/
public function getResources()
{
@@ -26,11 +26,11 @@ public function getResources()
/**
* Adds a Resource having an identifier unique to the Assertion
*
- * @param ResourceInterface $resource
+ * @param Resource\ResourceInterface $resource
* @throws Exception\InvalidArgumentException
* @return Assertion
*/
- public function addResource(ResourceInterface $resource)
+ public function addResource(Resource\ResourceInterface $resource)
{
$resourceName = $resource->getName();
@@ -48,7 +48,7 @@ public function addResource(ResourceInterface $resource)
*
* The $resource parameter can either be a Resource or a Resource identifier.
*
- * @param ResourceInterface|string $resource
+ * @param Resource\ResourceInterface|string $resource
* @return boolean
*/
public function hasResource($resource)
@@ -63,9 +63,9 @@ public function hasResource($resource)
*
* The $resource parameter can either be a Resource or a Resource identifier.
*
- * @param ResourceInterface|string $resource
+ * @param Resource\ResourceInterface|string $resource
* @throws Exception\InvalidArgumentException
- * @return ResourceInterface
+ * @return Resource\ResourceInterface
*/
public function getResource($resource)
{
@@ -83,7 +83,7 @@ public function getResource($resource)
*
* The $resource parameter can either be a Resource or a Resource identifier.
*
- * @param ResourceInterface|string $resource
+ * @param Resource\ResourceInterface|string $resource
* @throws Exception\InvalidArgumentException
* @return Assertion
*/
@@ -103,7 +103,7 @@ public function removeResource($resource)
/**
* Returns false if and only if the Resource has deny to the $privilege
*
- * @param ResourceInterface|string $resource
+ * @param Resource\ResourceInterface|string $resource
* @param string $privilege
* @param mixed $arg1 [optional]
* @param mixed $arg2 [optional]
@@ -133,12 +133,12 @@ public function assert($resource, $privilege, $arg1 = null, $arg2 = null, $argN
* Get Resource name
* The $resource parameter can either be a Resource or a Resource identifier.
*
- * @param ResourceInterface|string $resource
+ * @param Resource\ResourceInterface|string $resource
* @return string
*/
protected static function getResourceName($resource)
{
- if ($resource instanceof ResourceInterface) {
+ if ($resource instanceof Resource\ResourceInterface) {
return $resource->getName();
}
2  ...riaLab/Permissions/Assertion/AbstractResource.php → ...rmissions/Assertion/Resource/AbstractResource.php
View
@@ -1,6 +1,6 @@
<?php
-namespace GeometriaLab\Permissions\Assertion;
+namespace GeometriaLab\Permissions\Assertion\Resource;
abstract class AbstractResource implements ResourceInterface
{
2  ...iaLab/Permissions/Assertion/ResourceInterface.php → ...missions/Assertion/Resource/ResourceInterface.php
View
@@ -1,6 +1,6 @@
<?php
-namespace GeometriaLab\Permissions\Assertion;
+namespace GeometriaLab\Permissions\Assertion\Resource;
interface ResourceInterface
{
2  library/GeometriaLab/Permissions/Assertion/Service.php
View
@@ -97,7 +97,7 @@ private function addResources()
$pathPattern = $this->getResourcesPath() . '*';
foreach (ZendGlob::glob($pathPattern, ZendGlob::GLOB_BRACE) as $file) {
- /* @var \GeometriaLab\Permissions\Assertion\ResourceInterface $resource */
+ /* @var \GeometriaLab\Permissions\Assertion\Resource\ResourceInterface $resource */
$resourceName = ucfirst(pathinfo($file, PATHINFO_FILENAME));
$resourceClassName = $namespace . '\\' . $resourceName;
119 library/GeometriaLab/Permissions/Roles/AbstractRoles.php
View
@@ -0,0 +1,119 @@
+<?php
+
+namespace GeometriaLab\Permissions\Roles;
+
+use GeometriaLab\Model\AbstractModel,
+ GeometriaLab\Model\Persistent\AbstractModel as PersistentAbstractModel,
+ GeometriaLab\Permissions\Assertion\Resource\ResourceInterface;
+
+/**
+ * @property \GeometriaLab\Permissions\Roles\ResourceRoles[] $resourceRoles
+ */
+abstract class AbstractRoles extends PersistentAbstractModel
+{
+ /**
+ * Resource roles map
+ *
+ * @var array
+ */
+ protected $resourceRolesMap;
+
+ /**
+ * Has role for Model
+ *
+ * @param string $role
+ * @param AbstractModel $model
+ * @return bool
+ * @throws \RuntimeException
+ */
+ public function hasRole($role, AbstractModel $model)
+ {
+ if (!isset($model->id)) {
+ $modelClassName = get_class($model);
+ throw new \RuntimeException("Need 'id' property in model '{$modelClassName}'");
+ }
+
+ $parts = explode('\\', get_class($model));
+ $resourceName = array_pop($parts);
+ return $this->hasRoleForProperty('resourcesRoles', $role, $resourceName, $model->id);
+ }
+
+ /**
+ * Has role for Resource in City
+ *
+ * @param string $role
+ * @param string $cityId
+ * @param ResourceInterface|string $resource
+ * @return bool
+ */
+ public function hasRoleInCity($role, $cityId, $resource)
+ {
+ return $this->hasRoleForProperty('citiesRoles', $role, $resource, $cityId);
+ }
+
+ /**
+ * Has Role for resource in property
+ *
+ * @param string $property
+ * @param string $role
+ * @param string $resourceName
+ * @param string $objectId
+ * @return bool
+ * @throws \InvalidArgumentException
+ */
+ protected function hasRoleForProperty($property, $role, $resourceName, $objectId)
+ {
+ $permission = $this->getPermissionByResourceName($resourceName);
+
+ if ($permission === null) {
+ return false;
+ }
+
+ if (!isset($permission->{$property})) {
+ throw new \InvalidArgumentException("Property '{$property}' doesn't exist");
+ }
+
+ // @TODO Hack for super manager
+ if (isset($permission->{$property}[0]) && $permission->{$property}[0] === $role) {
+ return true;
+ }
+
+ if (!isset($permission->{$property}[$objectId])) {
+ return false;
+ }
+
+ return $permission->{$property}[$objectId] === $role;
+ }
+
+ /**
+ * Get Role by name
+ *
+ * @param string $resourceName
+ * @return ResourceRoles|null
+ * @throws \RuntimeException
+ */
+ protected function getPermissionByResourceName($resourceName)
+ {
+ if ($this->resourceRoles === null) {
+ return null;
+ }
+
+ if ($this->resourceRolesMap === null) {
+ // @TODO Add feature getting Model from array by id
+ foreach ($this->resourceRoles as $index => $resourceRole) {
+ $this->resourceRolesMap[$resourceRole->resourceName] = $index;
+ }
+ }
+
+ if (isset($this->resourceRolesMap[$resourceName])) {
+ $index = $this->resourceRolesMap[$resourceName];
+ if (!isset($this->resourceRoles[$index])) {
+ throw new \RuntimeException("Can't find '{$resourceName}' resourceRoles. ResourceRolesMap is broken.");
+ }
+
+ return $this->resourceRoles[$index];
+ }
+
+ return null;
+ }
+}
15 library/GeometriaLab/Permissions/Roles/ResourceRoles.php
View
@@ -0,0 +1,15 @@
+<?php
+
+namespace GeometriaLab\Permissions\Roles;
+
+use GeometriaLab\Model\AbstractModel;
+
+/**
+ * @property string $resourceName
+ * @property array $resourcesRoles
+ * @property array $citiesRoles
+ */
+class ResourceRoles extends AbstractModel
+{
+
+}
28 tests/GeometriaLabTest/Permissions/Assertion/AssertionTest.php
View
@@ -9,20 +9,20 @@ class AssertionTest extends \PHPUnit_Framework_TestCase
public function testAddResource()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
- $this->assertInstanceOf('\\GeometriaLab\\Permissions\\Assertion\\ResourceInterface', $assertion->getResource('Foo'));
+ $this->assertInstanceOf('\\GeometriaLab\\Permissions\\Assertion\\Resource\\ResourceInterface', $assertion->getResource('Foo'));
$this->assertEquals($fooResource, $assertion->getResource('Foo'));
}
public function testAddResources()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
- $barResource = new Sample\Bar('Bar');
+ $barResource = new SampleResource\Bar('Bar');
$assertion->addResource($barResource);
$expected = array(
@@ -37,7 +37,7 @@ public function testAddExistingResource()
{
$this->setExpectedException('\\GeometriaLab\\Permissions\\Assertion\\Exception\\InvalidArgumentException');
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$assertion->addResource($fooResource);
}
@@ -45,7 +45,7 @@ public function testAddExistingResource()
public function testHasResourceByName()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertTrue($assertion->hasResource('Foo'));
@@ -54,7 +54,7 @@ public function testHasResourceByName()
public function testHasResourceByObject()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertTrue($assertion->hasResource($fooResource));
@@ -63,7 +63,7 @@ public function testHasResourceByObject()
public function testHasNotExistingResource()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertFalse($assertion->hasResource('Bar'));
@@ -72,7 +72,7 @@ public function testHasNotExistingResource()
public function testGetResourceByName()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertEquals($fooResource, $assertion->getResource('Foo'));
@@ -81,7 +81,7 @@ public function testGetResourceByName()
public function testGetResourceByObject()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertEquals($fooResource, $assertion->getResource($fooResource));
@@ -92,7 +92,7 @@ public function testGetNotExistingResource()
$this->setExpectedException('\\GeometriaLab\\Permissions\\Assertion\\Exception\\InvalidArgumentException');
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$assertion->getResource('Bar');
@@ -101,7 +101,7 @@ public function testGetNotExistingResource()
public function testRemoveResourceByName()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$this->assertEquals($fooResource, $assertion->getResource('Foo'));
@@ -125,7 +125,7 @@ public function testAssertWithoutPrivilege()
$this->setExpectedException('\\GeometriaLab\\Permissions\\Assertion\\Exception\\RuntimeException');
$assertion = new Assertion();
- $barResource = new Sample\Bar('Bar');
+ $barResource = new SampleResource\Bar('Bar');
$assertion->addResource($barResource);
$assertion->assert('Bar', 'privilege');
@@ -134,7 +134,7 @@ public function testAssertWithoutPrivilege()
public function testWithDynamicAssert()
{
$assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
+ $fooResource = new SampleResource\Foo('Foo');
$assertion->addResource($fooResource);
$obj = new \stdClass();
6 ...riaLabTest/Permissions/Assertion/ResourceTest.php → ...t/Permissions/Assertion/Resource/ResourceTest.php
View
@@ -1,14 +1,14 @@
<?php
-namespace GeometriaLabTest\Permissions\Assertion;
+namespace GeometriaLabTest\Permissions\Assertion\Resource;
-use GeometriaLab\Permissions\Assertion\Assertion;
+use GeometriaLabTest\Permissions\Assertion\SampleResource\Foo;
class ResourceTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
- $resource = new Sample\Foo('Foo');
+ $resource = new Foo('Foo');
$this->assertEquals('Foo', $resource->getName());
}
10 tests/GeometriaLabTest/Permissions/Assertion/Sample/Bar.php
View
@@ -1,10 +0,0 @@
-<?php
-
-namespace GeometriaLabTest\Permissions\Assertion\Sample;
-
-use GeometriaLab\Permissions\Assertion\AbstractResource;
-
-class Bar extends AbstractResource
-{
-
-}
10 tests/GeometriaLabTest/Permissions/Assertion/SampleResource/Bar.php
View
@@ -0,0 +1,10 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Assertion\SampleResource;
+
+use GeometriaLab\Permissions\Assertion\Resource\AbstractResource;
+
+class Bar extends AbstractResource
+{
+
+}
4 ...etriaLabTest/Permissions/Assertion/Sample/Foo.php → ...Test/Permissions/Assertion/SampleResource/Foo.php
View
@@ -1,9 +1,9 @@
<?php
-namespace GeometriaLabTest\Permissions\Assertion\Sample;
+namespace GeometriaLabTest\Permissions\Assertion\SampleResource;
use GeometriaLab\Permissions\Assertion\Assertion,
- GeometriaLab\Permissions\Assertion\AbstractResource;
+ GeometriaLab\Permissions\Assertion\Resource\AbstractResource;
class Foo extends AbstractResource
{
8 tests/GeometriaLabTest/Permissions/Assertion/ServiceTest.php
View
@@ -41,8 +41,8 @@ static public function setUpBeforeClass()
'Config' => function($e){
return array(
'assertion' => array(
- 'base_dir' => __DIR__ . '/Sample',
- '__NAMESPACE__' => 'GeometriaLabTest\Permissions\Assertion\Sample',
+ 'base_dir' => __DIR__ . '/SampleResource',
+ '__NAMESPACE__' => 'GeometriaLabTest\Permissions\Assertion\SampleResource',
),
);
},
@@ -71,8 +71,8 @@ public function testCreateService()
public function testAddResources()
{
$expected = array(
- 'Foo' => new Sample\Foo('Foo'),
- 'Bar' => new Sample\Bar('Bar'),
+ 'Foo' => new SampleResource\Foo('Foo'),
+ 'Bar' => new SampleResource\Bar('Bar'),
);
$this->assertEquals($expected, static::$assertion->getResources());
115 tests/GeometriaLabTest/Permissions/Roles/RolesTest.php
View
@@ -0,0 +1,115 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles;
+
+use GeometriaLab\Permissions\Roles\ResourceRoles;
+
+class RolesTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var SampleRoles\Roles
+ */
+ protected static $roles;
+
+ public static function setUpBeforeClass()
+ {
+ static::$roles = new SampleRoles\Roles(array(
+ 'id' => 1,
+ 'resourceRoles' => array(
+ new ResourceRoles(array(
+ 'resourceName' => 'Foo',
+ 'resourcesRoles' => array(
+ 1 => 'manager',
+ 2 => 'admin',
+ ),
+ 'citiesRoles' => array(
+ 0 => 'admin',
+ ),
+ )),
+ new ResourceRoles(array(
+ 'resourceName' => 'Bar',
+ 'resourcesRoles' => array(
+ 0 => 'admin',
+ ),
+ 'citiesRoles' => array(
+ 1 => 'manager',
+ 2 => 'admin',
+ ),
+ )),
+ ),
+ ));
+ static::$roles->save();
+ }
+
+ public function testHasRolesForResource()
+ {
+ $foo1 = new SampleModel\Foo(array('id' => 1));
+ $foo2 = new SampleModel\Foo(array('id' => 2));
+
+ $this->assertTrue(static::$roles->hasRole('manager', $foo1));
+ $this->assertTrue(static::$roles->hasRole('admin', $foo2));
+ }
+
+ public function testHasNonExistentRoleForResource()
+ {
+ $foo = new SampleModel\Foo(array('id' => 1));
+
+ $this->assertFalse(static::$roles->hasRole('badRole', $foo));
+ }
+
+ public function testHasRoleForNonExistentResource()
+ {
+ $baz = new SampleModel\Baz(array('id' => 1));
+
+ $this->assertFalse(static::$roles->hasRole('admin', $baz));
+ }
+
+ public function testHasRoleForResourceWithNonExistentId()
+ {
+ $foo = new SampleModel\Foo(array('id' => 3));
+
+ $this->assertFalse(static::$roles->hasRole('admin', $foo));
+ }
+
+ public function testHasRoleForBadResource()
+ {
+ $this->setExpectedException('\\RuntimeException');
+
+ $badModel = new SampleModel\ModelWithoutId();
+
+ static::$roles->hasRole('admin', $badModel);
+ }
+
+ public function testHasSuperManagerRoleForResource()
+ {
+ $bar = new SampleModel\Bar(array('id' => 1));
+
+ $this->assertTrue(static::$roles->hasRole('admin', $bar));
+ }
+
+ public function testHasRolesForResourceInCity()
+ {
+ $this->assertTrue(static::$roles->hasRoleInCity('manager', 1, 'Bar'));
+ $this->assertTrue(static::$roles->hasRoleInCity('admin', 2, 'Bar'));
+ }
+
+ public function testHasNonExistentRoleForResourceInCity()
+ {
+ $this->assertFalse(static::$roles->hasRoleInCity('badRole', 1, 'Bar'));
+ }
+
+ public function testHasRoleForNonExistentResourceInCity()
+ {
+ $this->assertFalse(static::$roles->hasRoleInCity('admin', 1, 'Baz'));
+ }
+
+ public function testHasRoleForResourceWithNonExistentCityIdInCity()
+ {
+ $this->assertFalse(static::$roles->hasRoleInCity('admin', 3, 'Bar'));
+ }
+
+ public function testHasSuperManagerRoleForResourceInCity()
+ {
+ $this->assertTrue(static::$roles->hasRoleInCity('admin', 1, 'Foo'));
+ }
+}
11 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Bar.php
View
@@ -0,0 +1,11 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles\SampleModel;
+
+/**
+ * @property integer $id
+ */
+class Bar extends \GeometriaLab\Model\AbstractModel
+{
+
+}
11 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Baz.php
View
@@ -0,0 +1,11 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles\SampleModel;
+
+/**
+ * @property integer $id
+ */
+class Baz extends \GeometriaLab\Model\AbstractModel
+{
+
+}
11 tests/GeometriaLabTest/Permissions/Roles/SampleModel/Foo.php
View
@@ -0,0 +1,11 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles\SampleModel;
+
+/**
+ * @property integer $id
+ */
+class Foo extends \GeometriaLab\Model\AbstractModel
+{
+
+}
11 tests/GeometriaLabTest/Permissions/Roles/SampleModel/ModelWithoutId.php
View
@@ -0,0 +1,11 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles\SampleModel;
+
+/**
+ *
+ */
+class ModelWithoutId extends \GeometriaLab\Model\AbstractModel
+{
+
+}
13 tests/GeometriaLabTest/Permissions/Roles/SampleRoles/Roles.php
View
@@ -0,0 +1,13 @@
+<?php
+
+namespace GeometriaLabTest\Permissions\Roles\SampleRoles;
+
+/**
+ * @property integer $id {"primary": true}
+ *
+ * @method static \GeometriaLab\Model\Persistent\Mapper\Mock getMapper()
+ */
+class Roles extends \GeometriaLab\Permissions\Roles\AbstractRoles
+{
+
+}
Something went wrong with that request. Please try again.