Author: bschussek
Date: 2010-04-29 09:41:57 +0200 (Thu, 29 Apr 2010)
New Revision: 29309
Modified:
branches/1.3/lib/widget/sfWidgetFormChoiceBase.class.php
branches/1.3/test/unit/widget/sfWidgetFormChoiceTest.php
branches/1.4/lib/widget/sfWidgetFormChoiceBase.class.php
branches/1.4/test/unit/widget/sfWidgetFormChoiceTest.php
Log:
[1.3, 1.4] fixed: Choices are not always automatically translated. Added option
"translate_choices" that defaults to true (closes #7714)
Modified: branches/1.3/lib/widget/sfWidgetFormChoiceBase.class.php
===================================================================
--- branches/1.3/lib/widget/sfWidgetFormChoiceBase.class.php 2010-04-29
07:24:51 UTC (rev 29308)
+++ branches/1.3/lib/widget/sfWidgetFormChoiceBase.class.php 2010-04-29
07:41:57 UTC (rev 29309)
@@ -33,6 +33,7 @@
protected function configure($options = array(), $attributes = array())
{
$this->addRequiredOption('choices');
+ $this->addOption('translate_choices', true);
}
/**
@@ -49,6 +50,11 @@
$choices = $choices->call();
}
+ if (!$this->getOption('translate_choices'))
+ {
+ return $choices;
+ }
+
$results = array();
foreach ($choices as $key => $choice)
{
Modified: branches/1.3/test/unit/widget/sfWidgetFormChoiceTest.php
===================================================================
--- branches/1.3/test/unit/widget/sfWidgetFormChoiceTest.php 2010-04-29
07:24:51 UTC (rev 29308)
+++ branches/1.3/test/unit/widget/sfWidgetFormChoiceTest.php 2010-04-29
07:41:57 UTC (rev 29309)
@@ -20,7 +20,7 @@
}
}
-$t = new lime_test(17);
+$t = new lime_test(19);
$dom = new DomDocument('1.0', 'utf-8');
$dom->validateOnParse = true;
@@ -88,6 +88,19 @@
$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(),
'translation[bar]', '->render() translates the options');
$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(),
'translation[foo]', '->render() translates the options');
+// choices are not translated if "translate_choices" is set to false
+$t->diag('choices are not translated if "translate_choices" is set to false');
+
+$ws = new sfWidgetFormSchema();
+$ws->addFormFormatter('stub', new FormFormatterStub());
+$ws->setFormFormatterName('stub');
+$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar', 'foobar'
=> 'foo'), 'translate_choices' => false));
+$w->setParent($ws);
+$dom->loadHTML($w->render('foo'));
+$css = new sfDomCssSelector($dom);
+$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(), 'bar',
'->render() translates the options');
+$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'foo',
'->render() translates the options');
+
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormChoice(array('choices' => array()));
Modified: branches/1.4/lib/widget/sfWidgetFormChoiceBase.class.php
===================================================================
--- branches/1.4/lib/widget/sfWidgetFormChoiceBase.class.php 2010-04-29
07:24:51 UTC (rev 29308)
+++ branches/1.4/lib/widget/sfWidgetFormChoiceBase.class.php 2010-04-29
07:41:57 UTC (rev 29309)
@@ -33,6 +33,7 @@
protected function configure($options = array(), $attributes = array())
{
$this->addRequiredOption('choices');
+ $this->addOption('translate_choices', true);
}
/**
@@ -49,6 +50,11 @@
$choices = $choices->call();
}
+ if (!$this->getOption('translate_choices'))
+ {
+ return $choices;
+ }
+
$results = array();
foreach ($choices as $key => $choice)
{
Modified: branches/1.4/test/unit/widget/sfWidgetFormChoiceTest.php
===================================================================
--- branches/1.4/test/unit/widget/sfWidgetFormChoiceTest.php 2010-04-29
07:24:51 UTC (rev 29308)
+++ branches/1.4/test/unit/widget/sfWidgetFormChoiceTest.php 2010-04-29
07:41:57 UTC (rev 29309)
@@ -20,7 +20,7 @@
}
}
-$t = new lime_test(17);
+$t = new lime_test(19);
$dom = new DomDocument('1.0', 'utf-8');
$dom->validateOnParse = true;
@@ -88,6 +88,19 @@
$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(),
'translation[bar]', '->render() translates the options');
$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(),
'translation[foo]', '->render() translates the options');
+// choices are not translated if "translate_choices" is set to false
+$t->diag('choices are not translated if "translate_choices" is set to false');
+
+$ws = new sfWidgetFormSchema();
+$ws->addFormFormatter('stub', new FormFormatterStub());
+$ws->setFormFormatterName('stub');
+$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar', 'foobar'
=> 'foo'), 'translate_choices' => false));
+$w->setParent($ws);
+$dom->loadHTML($w->render('foo'));
+$css = new sfDomCssSelector($dom);
+$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(), 'bar',
'->render() translates the options');
+$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'foo',
'->render() translates the options');
+
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormChoice(array('choices' => array()));
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.