From bc6b3804b6de33780568b79549bc3e93fda06d13 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 15 Oct 2009 22:40:17 +0000 Subject: [PATCH] API CHANGE: Added SapphireTest::logInWithPermission() (from r89012) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89209 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/SapphireTest.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 501e43795..5bafa5de3 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -492,6 +492,39 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } } } + + /** + * Create a member and group with the given permission code, and log in with it. + * Returns the member ID. + */ + function logInWithPermssion($permCode = "ADMIN") { + if(!isset($this->cache_generatedMembers[$permCode])) { + $group = new Group(); + $group->Title = "$permCode group"; + $group->write(); + + $permission = new Permission(); + $permission->Code = $permCode; + $permission->write(); + $group->Permissions()->add($permission); + + $member = new Member(); + $member->FirstName = $permCode; + $member->Surname = "User"; + $member->Email = "$permCode@example.org"; + $member->write(); + $group->Members()->add($member); + + $this->cache_generatedMembers[$permCode] = $member; + } + + $this->cache_generatedMembers[$permCode]->logIn(); + } + + /** + * Cache for logInWithPermission() + */ + protected $cache_generatedMembers = array(); } ?>