summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Cornutt <enygma@phpdeveloper.org>2015-05-30 06:54:22 -0500
committerChris Cornutt <enygma@phpdeveloper.org>2015-05-30 06:54:22 -0500
commit78aeced17030aa931fc052e5c20a576a8e96e6ff (patch)
tree076ce0e9556472547164474f0c2ac106bbffd11b
parent61841c73cabd8cadf2e4783b68a677b1824f9a72 (diff)
downloadgatekeeper-78aeced17030aa931fc052e5c20a576a8e96e6ff.zip
gatekeeper-78aeced17030aa931fc052e5c20a576a8e96e6ff.tar.gz
gatekeeper-78aeced17030aa931fc052e5c20a576a8e96e6ff.tar.bz2
adding the test for using method results in expression evaluation
-rw-r--r--tests/Psecio/Gatekeeper/PolicyModelTest.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/Psecio/Gatekeeper/PolicyModelTest.php b/tests/Psecio/Gatekeeper/PolicyModelTest.php
index 1c4c288..6cca281 100644
--- a/tests/Psecio/Gatekeeper/PolicyModelTest.php
+++ b/tests/Psecio/Gatekeeper/PolicyModelTest.php
@@ -91,4 +91,33 @@ class PolicyModelTest extends \Psecio\Gatekeeper\Base
$this->policy->evaluate([]);
}
+
+ /**
+ * Test the expression matching when a method is involved
+ * In this case, get a User's groups list and return just
+ * the names to see if a group exists/doesn't exist
+ */
+ public function testPolicyEvaluateObjectWithFunction()
+ {
+ $ds = $this->buildMock(true);
+ $groups = new GroupCollection($ds);
+ $group = new GroupModel($ds, ['name' => 'group1']);
+ $groups->add($group);
+
+ $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Stub')
+ ->setConstructorArgs(array(array()))
+ ->getMock();
+ $ds->method('fetch')
+ ->willReturn($groups->toArray(true));
+
+ $user = new UserModel($ds, ['username' => 'ccornutt42']);
+
+ // "group1" does exist
+ $this->policy->load(['expression' => '"group1" in user.groups.getName()']);
+ $this->assertTrue($this->policy->evaluate($user));
+
+ // "group2" does not exist
+ $this->policy->load(['expression' => '"group2" in user.groups.getName()']);
+ $this->assertFalse($this->policy->evaluate($user));
+ }
} \ No newline at end of file