<?php $app = 'frontend'; $fixtures = 'fixtures/fixtures.yml'; include dirname(__FILE__) . '/../../bootstrap/functional.php'; $t = new lime_test(4); // ->getChoices() $t->diag('->getChoices()'); $validator = new sfWidgetFormDoctrineChoice(array('model' => 'Author')); $author = Doctrine_Core::getTable('Author')->createQuery()->limit(1)->fetchOne(); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage', 2 => 'Fabien POTENCIER'), '->getChoices() returns choices'); $validator->setOption('order_by', array('name', 'asc')); $t->cmp_ok($validator->getChoices(), '===', array(2 => 'Fabien POTENCIER', 1 => 'Jonathan H. Wage'), '->getChoices() returns ordered choices'); $validator->setOption('table_method', 'testTableMethod'); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage', 2 => 'Fabien POTENCIER'), '->getChoices() returns choices for given "table_method" option'); $validator = new sfWidgetFormDoctrineChoice(array('model' => 'Author', 'query' => Doctrine_Core::getTable('Author')->createQuery()->limit(1))); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage'), '->getChoices() returns choices for given "query" option');
public function getChoices() { $choices = parent::getChoices(); $choices['other'] = 'その他'; return $choices; }
$t->is($userCount, 1); $profileCount = Doctrine_Query::create()->from('Profile p')->count(); $t->is($profileCount, 1); $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User')); $t->is($widget->getChoices(), array(1 => 1)); $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'key_method' => 'getUsername', 'method' => 'getPassword')); $t->is($widget->getChoices(), array('jwage' => '4cb9c8a8048fd02294477fcb1a41191a')); $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'key_method' => 'getUsername', 'method' => 'getPassword')); $t->is($widget->getChoices(), array('jwage' => '4cb9c8a8048fd02294477fcb1a41191a')); $methods = array('widgetChoiceTableMethod1', 'widgetChoiceTableMethod2', 'widgetChoiceTableMethod3'); foreach ($methods as $method) { $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => $method)); $t->is($widget->getChoices(), array(1 => 1)); } $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => 'widgetChoiceTableMethod4')); $t->is($widget->getChoices(), array()); $user = new User(); $user->Groups[]->name = 'User Group 1'; $user->Groups[]->name = 'User Group 2'; class UserGroupForm extends GroupForm { public function configure() { parent::configure(); $this->useFields(array('name')); } } $userForm = new UserForm($user); $userForm->embedRelation('Groups', 'UserGroupForm'); $data = array('username' => 'jonwage', 'password' => 'changeme', 'Groups' => array(0 => array('name' => 'New User Group 1 Name'), 1 => array('name' => 'New User Group 2 Name'))); $userForm->bind($data);