當前位置: 首頁>>代碼示例>>PHP>>正文


PHP sfGuardUser::hasGroup方法代碼示例

本文整理匯總了PHP中sfGuardUser::hasGroup方法的典型用法代碼示例。如果您正苦於以下問題:PHP sfGuardUser::hasGroup方法的具體用法?PHP sfGuardUser::hasGroup怎麽用?PHP sfGuardUser::hasGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sfGuardUser的用法示例。


在下文中一共展示了sfGuardUser::hasGroup方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: Doe

$t->diag('output functions');
$t->is((string) $activeUser, 'John Doe (active_user)', '->__toString() returns the full name and the username');
$t->is($activeUser->getName(), 'John Doe', '->getName() returns the full name of the user');
// group managment
$t->diag('group managment');
$t->is($activeUser->getGroupNames(), array(), '->getGroupNames() return empty array if no group is set');
try {
    $activeUser->addGroupByName('test-group');
    $t->fail('->addGroupByName() does throw an exception if group not exist');
} catch (Exception $e) {
    $t->pass('->addGroupByName() does throw an exception if group not exist');
}
$group = new sfGuardGroup();
$group->name = 'test-group';
$group->save();
$t->is($activeUser->hasGroup('test-group'), false, '->hasGroup() return false if user hasn\'t this group');
try {
    $activeUser->addGroupByName('test-group');
    $t->pass('->addGroupByName() does not throw an exception if group exist');
} catch (Exception $e) {
    $t->diag($e->getMessage());
    $t->fail('->addGroupByName() does not throw an exception if group exist');
}
$t->is($activeUser->getGroupNames(), array('test-group'), '->getGroupNames() return array with group names');
$t->is($activeUser->hasGroup('test-group'), true, '->hasGroup() return true if user has this group');
// permission managment
$t->diag('permission managment');
$t->is($activeUser->getPermissionNames(), array(), '->getPermissionNames() return empty array if no permission is set');
try {
    $activeUser->addPermissionByName('test-permission');
    $t->fail('->addPermissionByName() does throw an exception if group not exist');
開發者ID:limitium,項目名稱:uberlov,代碼行數:31,代碼來源:PluginsfGuardUserTest.php


注:本文中的sfGuardUser::hasGroup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。