/** * Triggers a flash drop-down based on the flashes in the user * * @param sfUser $user */ function trigger_flash_from_user($user) { $validTypes = array('info', 'saved', 'error'); foreach ($validTypes as $validType) { if ($user->hasFlash($validType)) { return sprintf(' <script type="text/javascript"> $(document).ready(function(){ $.showFlashMessage("%s", "%s"); }); </script>', $validType, addslashes($user->getFlash($validType))); } } }
$t->diag('->setCulture() ->getCulture()'); $user->setCulture('fr'); $t->is($user->getCulture(), 'fr', '->setCulture() changes the current user culture'); // ->setFlash() ->getFlash() ->hasFlash() $t->diag('->setFlash() ->getFlash() ->hasFlash()'); $user->initialize($dispatcher, $storage, array('use_flash' => true)); $user->setFlash('foo', 'bar'); $t->is($user->getFlash('foo'), 'bar', '->setFlash() sets a flash variable'); $t->is($user->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); user_flush($dispatcher, $user, $storage, array('use_flash' => true)); $userBis = new sfUser($dispatcher, $storage, array('use_flash' => true)); $t->is($userBis->getFlash('foo'), 'bar', '->getFlash() returns a flash previously set'); $t->is($userBis->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); user_flush($dispatcher, $user, $storage, array('use_flash' => true)); $userBis = new sfUser($dispatcher, $storage, array('use_flash' => true)); $t->is($userBis->getFlash('foo'), null, 'Flashes are automatically removed after the next request'); $t->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists'); // array access for user attributes $user->setAttribute('foo', 'foo'); $t->diag('Array access for user attributes'); $t->is(isset($user['foo']), true, '->offsetExists() returns true if user attribute exists'); $t->is(isset($user['foo2']), false, '->offsetExists() returns false if user attribute does not exist'); $t->is($user['foo3'], false, '->offsetGet() returns false if attribute does not exist'); $t->is($user['foo'], 'foo', '->offsetGet() returns attribute by name'); $user['foo2'] = 'foo2'; $t->is($user['foo2'], 'foo2', '->offsetSet() sets attribute by name'); unset($user['foo2']); $t->is(isset($user['foo2']), false, '->offsetUnset() unsets attribute by name'); $user = new sfUser($dispatcher, $storage); // attribute holder proxy require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';