* * 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'); class FormFormatterStub extends sfWidgetFormSchemaFormatter { public function __construct() {} public function translate($subject, $parameters = array()) { return sprintf('translation[%s]', $subject); } } $t = new lime_test(19); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->getRenderer() $t->diag('->getRenderer()'); $w = new sfWidgetFormChoice(array('choices' => array())); $t->is(get_class($w->getRenderer()), 'sfWidgetFormSelect', '->getRenderer() guesses the renderer class to use'); $w->setOption('multiple', true); $t->is(get_class($w->getRenderer()), 'sfWidgetFormSelect', '->getRenderer() guesses the renderer class to use'); $w->setOption('expanded', true); $t->is(get_class($w->getRenderer()), 'sfWidgetFormSelectCheckbox', '->getRenderer() guesses the renderer class to use'); $w->setOption('multiple', false); $t->is(get_class($w->getRenderer()), 'sfWidgetFormSelectRadio', '->getRenderer() guesses the renderer class to use'); class MyWidget extends sfWidgetFormChoice { public function render($name, $value = null, $attributes = array(), $errors = array()) { return null; } public function getJavaScripts() { return array('/path/to/a/file.js'); } public function getStylesheets() { return array('/path/to/a/file.css' => 'all'); } } $w->setOption('renderer_class', 'MyWidget'); $t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer_class as the widget class if provided'); $w->setOption('renderer_class', null); $w->setOption('renderer', new MyWidget(array('choices' => array()))); $t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer as the widget if provided'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar'))); $t->like($w->render('foo'), '//', '->render() uses the id format specified'); $w->setIdFormat('%s'); $w->setOption('multiple', true); $t->like($w->render('foo'), '/