$context = new sfContext(); $request = new sfWebRequest(); $request->initialize($context); $context->request = $request; $storage = sfStorage::newInstance('sfSessionTestStorage'); $storage->initialize($context); $storage->clear(); $context->storage = $storage; $user = new sfUser(); $user->initialize($context); $context->user = $user; // ->initialize() $t->diag('->initialize()'); $t->is($user->getCulture(), 'en', '->initialize() sets the culture to "en" by default'); sfConfig::set('sf_i18n_default_culture', 'de'); $user->setCulture(null); user_flush($context); $t->is($user->getCulture(), 'de', '->initialize() sets the culture to the value of sf_i18n_default_culture if available'); sfConfig::set('sf_i18n_default_culture', 'fr'); user_flush($context); $t->is($user->getCulture(), 'de', '->initialize() reads the culture from the session data if available'); $userBis = new sfUser(); $userBis->initialize($context); $t->is($userBis->getCulture(), 'de', '->intialize() serializes the culture to the session data'); // ->setCulture() ->getCulture() $t->diag('->setCulture() ->getCulture()'); $user->setCulture('fr'); $t->is($user->getCulture(), 'fr', '->setCulture() changes the current user culture'); // parameter holder proxy require_once $_test_dir . '/unit/sfParameterHolderTest.class.php'; $pht = new sfParameterHolderProxyTest($t);
* (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(32); $_SERVER['session_id'] = 'test'; $dispatcher = new sfEventDispatcher(); $sessionPath = sys_get_temp_dir() . '/sessions_' . rand(11111, 99999); $storage = new sfSessionTestStorage(array('session_path' => $sessionPath)); $user = new sfUser($dispatcher, $storage); // ->initialize() $t->diag('->initialize()'); $t->is($user->getCulture(), 'en', '->initialize() sets the culture to "en" by default'); $user->setCulture(null); $user->initialize($dispatcher, $storage, array('default_culture' => 'de')); user_flush($dispatcher, $user, $storage); $t->is($user->getCulture(), 'de', '->initialize() sets the culture to the value of default_culture if available'); user_flush($dispatcher, $user, $storage); $t->is($user->getCulture(), 'de', '->initialize() reads the culture from the session data if available'); $userBis = new sfUser($dispatcher, $storage); $t->is($userBis->getCulture(), 'de', '->initialize() serializes the culture to the session data'); // ->setCulture() ->getCulture() $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');
/* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../bootstrap.php'; require_once dirname(__FILE__) . '/../../lib/form/sfFormLanguage.class.php'; $t = new lime_test(9, new lime_output_color()); // initialize objects $dispatcher = new sfEventDispatcher(); $sessionPath = sys_get_temp_dir() . '/sessions_' . rand(11111, 99999); $storage = new sfSessionTestStorage(array('session_path' => $sessionPath)); $user = new sfUser($dispatcher, $storage); $user->setCulture('en'); $request = new sfWebRequest($dispatcher); // __construct() $t->diag('__construct()'); try { new sfFormLanguage($user); $t->fail('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } catch (RuntimeException $e) { $t->pass('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } $form = new sfFormLanguage($user, array('languages' => array('en', 'fr'))); $t->is($form->getDefault('language'), 'en', '__construct() sets the default language value to the user language'); $w = $form->getWidgetSchema(); $t->is($w['language']->getOption('languages'), array('en', 'fr'), '__construct() uses the "languages" option for the select form widget'); $v = $form->getValidatorSchema(); $t->is($v['language']->getOption('languages'), array('en', 'fr'), '__construct() uses the "languages" option for the validator');