/** * Returns whether or not inline editing should be enabled. * * This method can be called "in general" (no $obj passed) or answered * for a very specific object being modified. * * @param Object $object The Object being edited - could be a Doctrine_Record, Doctrine_Collection * @return boolean */ public function shouldShowEditor($obj = null, $forceRefresh = false) { $key = $obj === null ? 'generic' : spl_object_hash($obj); if (!isset($this->_shouldShowEditor[$key]) || $forceRefresh) { $credential = $this->getOption('admin_credential'); if ($credential) { $shouldShow = $this->_user->hasCredential($credential); } else { // even if no credential were passed, still require a login at least $shouldShow = $this->_user->isAuthenticated(); } $event = new sfEvent($this, 'editable_content.should_show_editor', array('user' => $this->_user, 'object' => $obj)); $this->_dispatcher->filter($event, $shouldShow); $this->_shouldShowEditor[$key] = $event->getReturnValue(); } return $this->_shouldShowEditor[$key]; }
} $dispatcher = new sfEventDispatcher(); $sessionPath = sfToolkit::getTmpDir() . '/sessions_' . rand(11111, 99999); $storage = new MySessionStorage(array('session_path' => $sessionPath)); $user = new sfBasicSecurityUser($dispatcher, $storage); // ->initialize() $t->diag('->initialize()'); $t->todo('->initialize() times out the user if no request made for a long time'); // ->listCredentials() $t->diag('->listCredentials()'); $user->clearCredentials(); $user->addCredential('user'); $t->is($user->listCredentials(), array('user'), '->listCredentials() returns user credentials as an array'); // ->setAuthenticated() ->isAuthenticated() $t->diag('->setAuthenticated() ->isAuthenticated()'); $t->is($user->isAuthenticated(), false, '->isAuthenticated() returns false by default'); $user->setAuthenticated(true); $t->is($user->isAuthenticated(), true, '->isAuthenticated() returns true if the user is authenticated'); $user->setAuthenticated(false); $t->is($user->isAuthenticated(), false, '->setAuthenticated() accepts a boolean as its first parameter'); // session id regeneration $user->setAuthenticated(false); $id = $storage->getSessionId(); $user->setAuthenticated(true); $t->isnt($id, $id = $storage->getSessionId(), '->setAuthenticated() regenerates the session id if the authentication changes'); $user->setAuthenticated(true); $t->is($storage->getSessionId(), $id, '->setAuthenticated() does not regenerate the session id if the authentication does not change'); $user->addCredential('foo'); $t->isnt($id, $id = $storage->getSessionId(), '->addCredential() regenerates the session id if a new credential is added'); $t->is($id, $storage->getSessionId(), '->addCredential() does not regenerate the session id if the credential already exists'); $user->removeCredential('foo');