static testmethod void usertest() { User pu = getPortalUser(PortalType.PowerCustomerSuccess, null, true); System.assert([select isPortalEnabled from user where id = :pu.id].isPortalEnabled, 'User was not flagged as portal enabled.');
System.RunAs(pu) { System.assert([select isPortalEnabled from user where id = :UserInfo.getUserId()].isPortalEnabled, 'User wasnt portal enabled within the runas block. '); } }
public static User getPortalUser(PortalType portalType, User userWithRole, Boolean doInsert) {
/* Make sure the running user has a role otherwise an exception will be thrown. */ if(userWithRole == null) {
if(UserInfo.getUserRoleId() == null) {
UserRole r = new UserRole(name = 'TEST ROLE'); Database.insert(r);
System.assert(userWithRole.userRoleId != null, 'This test requires the target org to have at least one UserRole created. Please create a user role in this organization and try again.'); }