本文整理汇总了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');