$tableGroup = Doctrine_Core::getTable('sfGuardGroup'); $tableGroup->createQuery()->delete()->where('name = ?', 'test-group')->execute(); $tablePermission = Doctrine_Core::getTable('sfGuardPermission'); $tablePermission->createQuery()->delete()->where('name = ?', 'test-permission')->execute(); $activeUser = new sfGuardUser(); $activeUser->first_name = 'John'; $activeUser->last_name = 'Doe'; $activeUser->email_address = '*****@*****.**'; $activeUser->username = '******'; $activeUser->password = '******'; $activeUser->is_active = true; $activeUser->save(); // ->__toString() $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');
/** * Notify the administrator of the pending user activation. * * @param sfGuardUser $user */ protected function notifyAdministrator(sfGuardUser $user) { $from = $user->getEmailAddress(); $to = $this->getAdminEmail(); $subject = sprintf('[%s] Registration request for: %s', $this->generateUrl('homepage', array(), true), $user->getName()); $body = 'A new user has registered but will need to be activated before they can sign in.' . "\n\n"; $body .= sprintf('The details they entered were: %s (%s)', $user->getName(), $user->getEmailAddress()) . "\n\n"; $body .= 'If you wish to automatically activate this user, you can do so by simply clicking on this link:' . "\n"; $body .= $this->generateUrl('sf_guard_register_confirm', array('id' => $user->getId()), true) . "\n\n"; $body .= 'Please note: you will need to be signed in to complete this action.' . "\n"; $this->getMailer()->composeAndSend($from, $to, $subject, $body); }