[pLog-svn] r6661 - plog/branches/lifetype-1.2/class/test/helpers
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Mon Jun 23 16:24:01 EDT 2008
Author: jondaley
Date: 2008-06-23 16:24:01 -0400 (Mon, 23 Jun 2008)
New Revision: 6661
Modified:
plog/branches/lifetype-1.2/class/test/helpers/testtools.class.php
Log:
create permissions by default in testtools, so they don't have to be added in every test
Modified: plog/branches/lifetype-1.2/class/test/helpers/testtools.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/helpers/testtools.class.php 2008-06-23 19:50:43 UTC (rev 6660)
+++ plog/branches/lifetype-1.2/class/test/helpers/testtools.class.php 2008-06-23 20:24:01 UTC (rev 6661)
@@ -8,6 +8,8 @@
lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
/**
* \ingroup Test
@@ -39,7 +41,7 @@
}
/**
- * Creates a temporary user
+ * Creates a temporary user with minimal (login only) permissions
*
* @return A UserInfo object if successful or false otherwise
*/
@@ -52,35 +54,69 @@
"About test user",
"Test User"
);
-
+
$users = new Users();
- if( $users->addUser( $user ))
- return( $user );
- else
- return( false );
+ if(!$users->addUser($user))
+ return false;
+
+ $userPerms = new UserPermissions();
+
+ $perms = new Permissions();
+ $loginAccess = $perms->getPermissionByName( "login_perm" );
+ if($loginAccess === false){
+ print "Error getting login permission id";
+ return false;
+ }
+
+ // Give user login privileges
+ $userPerm = new UserPermission( $user->getId(), 0, $loginAccess->getId() );
+ if(!$userPerm){
+ print "Error creating UserPermission(login) for user";
+ return false;
+ }
+ if(!$userPerms->grantPermission( $userPerm )){
+ print "Error granting login permissions to user";
+ return false;
+ }
+
+ return $user;
}
/**
- * Creates a temporary admin user
+ * Creates a temporary admin user, with default admin privileges
*
* @return A UserInfo object if successful or false otherwise
*/
function createAdminUser()
{
- $user = new UserInfo(
- TestTools::getRandomWord( 15, false, false ),
- "password",
- "test at user.com",
- "About test user",
- "Test User"
- );
+ $user = TestTools::createUser();
+ if(!$user)
+ return false;
+
$user->setSiteAdmin( true );
-
+ $userPerms = new UserPermissions();
+
+ $perms = new Permissions();
+ $allPerms = $perms->getAllPermissions();
+ foreach($allPerms as $perm){
+ if($perm->isAdminOnlyPermission()){
+ $userPerm = new UserPermission( $user->getId(), 0, $perm->getId() );
+ if(!$userPerm){
+ print "Error creating UserPermission(".$perm->getId().") for user";
+ }
+ if(!$userPerms->grantPermission($userPerm)){
+ print "Error granting UserPermission(".$perm->getId().") for user";
+ }
+ }
+ }
+
+ // save user
$users = new Users();
- if( $users->addUser( $user ))
- return( $user );
- else
- return( false );
+ if(!$users->updateUser($user)){
+ print "Couldn't update admin privileges for user";
+ return $user; // return a user, since he has already been created
+ }
+ return $user;
}
/**
More information about the pLog-svn
mailing list