API CHANGE: Added SapphireTest::logInWithPermission() (merged from r89209)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@91034 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-09 04:47:19 +00:00 committed by Sam Minnee
parent 15f1905889
commit 4443df7b0a

View File

@ -249,6 +249,39 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
return $dbname;
}
/**
* 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();
}
?>