Author: oweitman
Date: 2010-04-09 12:14:35 +0200 (Fri, 09 Apr 2010)
New Revision: 29048
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/LICENSE
plugins/sfFormI18nNumberPlugin/tags/0.9.3/README
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/i18n/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/i18n/sfNumberFormatPlus.class.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/i18n/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/i18n/sfValidatorI18nNumber.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/i18n/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/i18n/sfWidgetFormI18nNumber.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/package.xml
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bin/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bin/prove.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/functional.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/unit.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/functional/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/validator/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/validator/sfValidatorI18nNumberTest.php
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/widget/
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/widget/sfWidgetFormI18nNumberTest.php
plugins/sfFormI18nNumberPlugin/trunk/test/unit/widget/
plugins/sfFormI18nNumberPlugin/trunk/test/unit/widget/sfWidgetFormI18nNumberTest.php
Modified:
plugins/sfFormI18nNumberPlugin/trunk/lib/widget/i18n/sfWidgetFormI18nNumber.php
plugins/sfFormI18nNumberPlugin/trunk/package.xml
Log:
correct a problem in the widget
add functional tests for the widget
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/LICENSE
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/LICENSE
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/LICENSE 2010-04-09 10:14:35 UTC
(rev 29048)
@@ -0,0 +1,19 @@
+Copyright (c) 2008 oweitman
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/README
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/README
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/README 2010-04-09 10:14:35 UTC
(rev 29048)
@@ -0,0 +1,80 @@
+sfFormI18nNumberPlugin
+==============
+
+The `sfFormI18nNumberPlugin` is a symfony plugin that provides an widget and
validator for
+internationalized numbers.
+
+Installation
+------------
+
+ * Install the plugin
+
+ $ symfony plugin:install sfFormI18nNumberPlugin
+
+ * Clear you cache
+
+ $ symfony cc
+
+Use of the Validator and Widget
+-----------------------
+
+After you create in your schema a number-field with type double, float or
decimal,
+change your form as follows:
+
+
+before
+
+ [php]
+ public function configure()
+ {
+ // widgets
+ $this->setWidgets(array(
+ 'number' => new sfWidgetFormInput(),
+ ));
+
+ // validators
+ $this->setValidators(array(
+ 'number' => new sfValidatorNumber(),
+ ));
+ }
+
+after
+
+ [php]
+ public function configure()
+ {
+ // widgets
+ $this->setWidgets(array(
+ 'number' => new sfWidgetFormI18nNumber(),
+ ));
+
+ // validators
+ $this->setValidators(array(
+ 'number' => new sfValidatorI18nNumber(),
+ ));
+ }
+
+Configuration
+-----------------------
+
+The widget and the validator takes the culture to recognize, convert and
display numbers
+from the user-session. If this is not possible or you want to use a different
culture than
+the culture of the user session, you can set a option.
+
+ [php]
+ // widgets
+ $this->setWidgets(array(
+ 'number' => new sfWidgetFormI18nNumber(array('culture' => 'fr')),
+ ));
+
+ // validators
+ $this->setValidators(array(
+ 'number' => new sfValidatorI18nNumber(array('culture' => 'fr')),
+ ));
+
+
+TODO
+----
+
+ * tbd
+
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/i18n/sfNumberFormatPlus.class.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/i18n/sfNumberFormatPlus.class.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/i18n/sfNumberFormatPlus.class.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,182 @@
+<?php
+
+/**
+ * sfNumberFormat class file.
+ *
+ * @author oweitman
+ * @package symfony
+ * @subpackage i18n
+ */
+
+/**
+ * sfNumberFormat class.
+ *
+ *
+ */
+class sfNumberFormatPlus extends sfNumberFormat
+{
+ /**
+ * Returns the normalized number from a localized one
+ * Parsing depends on given locale (grouping and decimal)
+ *
+ * Examples for input:
+ * '2345.4356,1234' = 23455456.1234
+ * '+23,3452.123' = 233452.123
+ * '12343 ' = 12343
+ * '-9456' = -9456
+ * '0' = 0
+ *
+ * @param string $input Input string to parse for numbers
+ * @param array $options Options: locale, precision. See {...@link
setOptions()} for details.
+ * @return string Returns the extracted number
+ * @throws Zend_Locale_Exception
+ */
+ public static function getNumber($value, $culture)
+ {
+ if (!is_string($value)) {
+ return $value;
+ }
+
+ if (!self::isNumber($value, $culture)) {
+ throw new sfException('No localized value in ' . $value . '
found, or the given number does not match the localized format');
+ }
+
+ $num_format = sfCultureInfo::getInstance($culture)->getNumberFormat();
+
+ if ((strpos($value, $num_format->getNegativeSign()) !== false) ||
+ (strpos($value, '-') !== false)) {
+ $value = strtr($value, array($num_format->getNegativeSign() => '', '-'
=> ''));
+ $value = '-' . $value;
+ }
+
+ $value = str_replace($num_format->getGroupSeparator(),'', $value);
+ if (strpos($value, $num_format->getDecimalSeparator()) !== false) {
+ if ($num_format->getDecimalSeparator() != '.') {
+ $value = str_replace($num_format->getDecimalSeparator(), ".", $value);
+ }
+ }
+
+ return $value;
+ }
+ /**
+ * Checks if the input contains a normalized or localized number
+ *
+ * @param string $input Localized number string
+ * @param array $options Options: locale. See {...@link setOptions()}
for details.
+ * @return boolean Returns true if a number was found
+ */
+ public static function isNumber($input, $culture)
+ {
+
+ $regexs = self::_getRegexForType(sfNumberFormatInfo::DECIMAL,$culture);
+ foreach ($regexs as $regex) {
+ preg_match($regex, $input, $found);
+ if (isset($found[0])) {
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * Internal method to convert cldr number syntax into regex
+ *
+ * @param string $type
+ * @return string
+ */
+ private static function _getRegexForType($type, $culture)
+ {
+
+ $num_format = sfNumberFormatInfo::getInstance($culture,$type);
+ $pos_pattern = $num_format->getPattern();
+ $decimal = $pos_pattern['positive'];
+ $decimal = preg_replace('/[^#0,;\.\-Ee]/', '',$decimal);
+ $patterns = explode(';', $decimal);
+
+ if (count($patterns) == 1) {
+ $patterns[1] = '-' . $patterns[0];
+ }
+
+ $num_format = sfCultureInfo::getInstance($culture)->getNumberFormat();
+ foreach($patterns as $pkey => $pattern) {
+ $regex[$pkey] = '/^';
+ $rest = 0;
+ $end = null;
+ if (strpos($pattern, '.') !== false) {
+ $end = substr($pattern, strpos($pattern, '.') + 1);
+ $pattern = substr($pattern, 0, -strlen($end) - 1);
+ }
+
+ if (strpos($pattern, ',') !== false) {
+ $parts = explode(',', $pattern);
+ $count = count($parts);
+ foreach($parts as $key => $part) {
+ switch ($part) {
+ case '#':
+ case '-#':
+ if ($part[0] == '-') {
+ $regex[$pkey] .= '[' . $num_format->getNegativeSign() .
'-]{0,1}';
+ } else {
+ $regex[$pkey] .= '[' . $num_format->getPositiveSign() .
'+]{0,1}';
+ }
+
+ if (($parts[$key + 1]) == '##0') {
+ $regex[$pkey] .= '[0-9]{1,3}';
+ } else if (($parts[$key + 1]) == '##') {
+ $regex[$pkey] .= '[0-9]{1,2}';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos
1):"' . $pattern . '"');
+ }
+ break;
+ case '##':
+ if ($parts[$key + 1] == '##0') {
+ $regex[$pkey] .= '(\\' . $num_format->getGroupSeparator() .
'{0,1}[0-9]{2})*';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos
2):"' . $pattern . '"');
+ }
+ break;
+ case '##0':
+ if ($parts[$key - 1] == '##') {
+ $regex[$pkey] .= '[0-9]';
+ } else if (($parts[$key - 1] == '#') || ($parts[$key - 1] ==
'-#')) {
+ $regex[$pkey] .= '(\\' . $num_format->getGroupSeparator() .
'{0,1}[0-9]{3})*';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos
3):"' . $pattern . '"');
+ }
+ break;
+ case '#0':
+ if ($key == 0) {
+ $regex[$pkey] .= '[0-9]*';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos
4):"' . $pattern . '"');
+ }
+ break;
+ }
+ }
+ }
+
+ if (strpos($pattern, 'E') !== false) {
+ if (($pattern == '#E0') || ($pattern == '#E00')) {
+ $regex[$pkey] .= '[' . $num_format->getPositiveSign() .
'+]{0,1}[0-9]{1,}(\\' . $num_format->getDecimalSeparator() . '[0-9]{1,})*[eE]['
. $num_format->getPositiveSign() . '+]{0,1}[0-9]{1,}';
+ } else if (($pattern == '-#E0') || ($pattern == '-#E00')) {
+ $regex[$pkey] .= '[' . $num_format->getNegativeSign() .
'-]{0,1}[0-9]{1,}(\\' . $num_format->getDecimalSeparator() . '[0-9]{1,})*[eE]['
. $num_format->getNegativeSign() . '-]{0,1}[0-9]{1,}';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos 5):"'
. $pattern . '"');
+ }
+ }
+
+ if (!empty($end)) {
+ if ($end == '###') {
+ $regex[$pkey] .= '(\\' . $num_format->getDecimalSeparator() .
'{1}[0-9]{1,}){0,1}';
+ } else if ($end == '###-') {
+ $regex[$pkey] .= '(\\' . $num_format->getDecimalSeparator() .
'{1}[0-9]{1,}){0,1}[' . $num_format->getNegativeSign() . '-]';
+ } else {
+ throw new sfException('Unsupported token for numberformat (Pos 6):"'
. $pattern . '"');
+ }
+ }
+
+ $regex[$pkey] .= '$/';
+ }
+
+ return $regex;
+ }
+}
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/i18n/sfValidatorI18nNumber.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/i18n/sfValidatorI18nNumber.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/validator/i18n/sfValidatorI18nNumber.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,71 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * sfValidatorNumber validates a number (integer or float). It also converts
the input value to a float.
+ *
+ * @package symfony
+ * @subpackage validator
+ * @author oweitman
+ * @version SVN: $Id$
+ */
+class sfValidatorI18nNumber extends sfValidatorNumber
+{
+ /**
+ * Configures the current validator.
+ *
+ * Available options:
+ *
+ * * culture: culture of the number
+ *
+ * @param array $options An array of options
+ * @param array $messages An array of error messages
+ *
+ * @see sfValidatorBase
+ * @see sfValidatorNumber
+ * */
+ protected function configure($options = array(), $messages = array())
+ {
+ parent::configure($options,$messages);
+
+ $this->addOption('culture',$this->_current_language());
+ $this->addMessage('format', 'Input has a wrong format: %value%');
+
+ }
+
+ /**
+ * @see sfValidatorBase
+ */
+ protected function doClean($value)
+ {
+ try
+ {
+ $value = sfNumberFormatPlus::getNumber($value,
$this->getOption('culture'));
+ }
+ catch (Exception $e)
+ {
+ //print_r($e);
+ throw new sfValidatorError($this, 'format', array('value' => $value));
+ }
+ return parent::doClean($value);
+ }
+
+ function _current_language()
+ {
+ try
+ {
+ return sfContext::getInstance()->getUser()->getCulture();
+ }
+ catch (Exception $e)
+ {
+ return sfCultureInfo::getInstance()->getName();
+ }
+ }
+}
\ No newline at end of file
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/i18n/sfWidgetFormI18nNumber.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/i18n/sfWidgetFormI18nNumber.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/tags/0.9.3/lib/widget/i18n/sfWidgetFormI18nNumber.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,73 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * sfWidgetFormInput represents an HTML input tag.
+ *
+ * @package symfony
+ * @subpackage widget
+ * @author oweitman
+ * @version
+ */
+class sfWidgetFormI18nNumber extends sfWidgetFormInput
+{
+ /**
+ * Constructor.
+ *
+ * Available options:
+ *
+ * * type: The widget type (text by default)
+ *
+ * @param array $options An array of options
+ * @param array $attributes An array of default HTML attributes
+ *
+ * @see sfWidgetForm
+ */
+ protected function configure($options = array(), $attributes = array())
+ {
+ parent::configure($options, $attributes);
+
+ $this->addOption('culture', $this->_current_language());
+ }
+
+ /**
+ * @param string $name The element name
+ * @param string $value The value displayed in this widget
+ * @param array $attributes An array of HTML attributes to be merged with
the default HTML attributes
+ * @param array $errors An array of errors for the field
+ *
+ * @return string An HTML tag string
+ *
+ * @see sfWidgetForm
+ */
+ public function render($name, $value = null, $attributes = array(), $errors
= array())
+ {
+
+ if (is_numeric($value) && !is_null($value))
+ {
+ $numberFormat = new sfNumberFormat($this->getOption('culture'));
+ $value = $numberFormat->format($value);
+ }
+ return parent::render($name,$value,$attributes, $errors);
+
+ //return $this->renderTag('input', array_merge(array('type' =>
$this->getOption('type'), 'name' => $name, 'value' => $value), $attributes));
+ }
+ function _current_language()
+ {
+ try
+ {
+ return sfContext::getInstance()->getUser()->getCulture();
+ }
+ catch (Exception $e)
+ {
+ return sfCultureInfo::getInstance()->getName();
+ }
+ }
+}
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/package.xml
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/package.xml
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/package.xml 2010-04-09
10:14:35 UTC (rev 29048)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
+ <name>sfFormI18nNumberPlugin</name>
+ <channel>plugins.symfony-project.org</channel>
+ <summary>I18n-Number validator and widget</summary>
+ <description>I18n-Number validator and widget</description>
+ <lead>
+ <name>oweitman</name>
+ <user>oweitman</user>
+ <email>[email protected]</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-04-09</date>
+ <time>10:06:49</time>
+ <version>
+ <release>0.9.3</release>
+ <api>0.9.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.symfony-project.org/license">MIT license</license>
+ <notes>
+-
+ </notes>
+ <contents>
+ <dir name="/">
+ <file md5sum="d509e893096cd79bf4bf5a64898a9b09"
name="test/unit/widget/sfWidgetFormI18nNumberTest.php" role="data" />
+ <file md5sum="5318bd59e2abe95c72216e4198c1ee0d"
name="test/unit/validator/sfValidatorI18nNumberTest.php" role="data" />
+ <file md5sum="3342e2e00283321c6e02401452886fb9"
name="test/bootstrap/unit.php" role="data" />
+ <file md5sum="604d04fa189f79b6651c20d3234dcd6d"
name="test/bootstrap/functional.php" role="data" />
+ <file md5sum="b84d430d03fce3a229116fb8a7fb0db1"
name="lib/widget/i18n/sfWidgetFormI18nNumber.php" role="data" />
+ <file md5sum="0e5e8155d7a5e6677b200723c53e161f"
name="lib/validator/i18n/sfValidatorI18nNumber.php" role="data" />
+ <file md5sum="27bcd1769dacf95ef717435a10c46754"
name="lib/i18n/sfNumberFormatPlus.class.php" role="data" />
+ <file md5sum="62e8e18f5f7ef8b6575c6631e5ded2d4" name="README" role="data" />
+ <file md5sum="c08e44581c779e68051552222fd7a778" name="LICENSE" role="data"
/>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.4</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.1</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog />
+</package>
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bin/prove.php
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bin/prove.php
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bin/prove.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,8 @@
+<?php
+
+include dirname(__FILE__).'/../bootstrap/unit.php';
+
+$h = new lime_harness(new lime_output_color());
+$h->register(sfFinder::type('file')->name('*Test.php')->in(dirname(__FILE__).'/..'));
+
+exit($h->run() ? 0 : 1);
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/functional.php
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/functional.php
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/functional.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,21 @@
+<?php
+
+if (!isset($app))
+{
+ $app = 'frontend';
+}
+
+require_once $_SERVER['SYMFONY'].'/autoload/sfCoreAutoload.class.php';
+sfCoreAutoload::register();
+
+function sfFormI18nNumberPlugin_cleanup()
+{
+ sfToolkit::clearDirectory(dirname(__FILE__).'/../fixtures/project/cache');
+ sfToolkit::clearDirectory(dirname(__FILE__).'/../fixtures/project/log');
+}
+sfFormI18nNumberPlugin_cleanup();
+register_shutdown_function('sfFormI18nNumberPlugin_cleanup');
+
+require_once
dirname(__FILE__).'/../fixtures/project/config/ProjectConfiguration.class.php';
+$configuration = ProjectConfiguration::getApplicationConfiguration($app,
'test', isset($debug) ? $debug : true);
+sfContext::createInstance($configuration);
Added: plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/unit.php
===================================================================
--- plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/unit.php
(rev 0)
+++ plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/bootstrap/unit.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,6 @@
+<?php
+
+require_once
dirname(__FILE__).'/../../../../config/ProjectConfiguration.class.php';
+
+$configuration = new sfProjectConfiguration();
+require_once $configuration->getSymfonyLibDir().'/vendor/lime/lime.php';
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/validator/sfValidatorI18nNumberTest.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/validator/sfValidatorI18nNumberTest.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/validator/sfValidatorI18nNumberTest.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * 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(13, new lime_output_color());
+
+$v = new sfValidatorI18nNumber();
+
+// ->clean() - no culture
+$t->diag('->clean() - standard culture = en');
+
+$v->setOption('culture','en');
+$t->is($v->clean(12.3), 12.3, '->clean() returns the numbers unmodified');
+$t->is($v->clean('12.3'), 12.3, '->clean() converts strings to numbers');
+
+$t->is($v->clean(12.12345678901234), 12.12345678901234, '->clean() returns the
numbers unmodified');
+$t->is($v->clean('12.12345678901234'), 12.12345678901234, '->clean() converts
strings to numbers');
+
+$t->is($v->clean('123,456.78'), 123456.78, '->clean() convert grouped
numbers');
+
+try
+{
+ $v->clean('123,456.789,012');
+ $t->fail('->clean fails wrong grouped numbers');
+}
+catch (sfValidatorError $e)
+{
+ $t->pass('->clean throws a sfValidatorError if the value is grouped wrong');
+}
+
+try
+{
+ $v->clean('not a float');
+ $t->fail('->clean() throws a sfValidatorError if the value is not a number');
+}
+catch (sfValidatorError $e)
+{
+ $t->pass('->clean() throws a sfValidatorError if the value is not a number');
+}
+
+$t->diag('->clean() - culture = de');
+$v->setOption('culture','de');
+$t->is($v->clean("12,3"),"12.3",'->clean() return the normalized string');
+$t->is($v->clean('12,12345678901234'), 12.12345678901234, '->clean() converts
strings to normalized numbers');
+$t->is($v->clean('123.456,78'), 123456.78, '->clean() convert grouped
numbers');
+$t->is($v->clean('100.000'), 100000, '->clean() convert grouped numbers');
+
+try
+{
+ $v->clean('123.456,789.012');
+ $t->fail('->clean fails wrong grouped numbers');
+}
+catch (sfValidatorError $e)
+{
+ $t->pass('->clean throws a sfValidatorError if the value is grouped wrong');
+}
+
+try
+{
+ $v->clean("12.3");
+ $t->fail('->clean() throws a sfValidatorError if the value is not in
localized format');
+}
+catch (sfValidatorError $e)
+{
+ $t->pass('->clean() throws a sfValidatorError if the value is not in
localized format');
+}
+
Added:
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/widget/sfWidgetFormI18nNumberTest.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/widget/sfWidgetFormI18nNumberTest.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/tags/0.9.3/test/unit/widget/sfWidgetFormI18nNumberTest.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * 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(12, new lime_output_color());
+
+$w = new sfWidgetFormI18nNumber();
+
+$t->diag('->clean() - standard culture = en');
+$w->setOption('culture','en');
+
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12.3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12.1234" id="key" />', '->render() renders the widget as HTML');
+
+$w->setOption('culture','de');
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12,3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12,1234" id="key" />', '->render() renders the widget as HTML');
+
+$w->setOption('culture','pl');
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12,3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12,1234" id="key" />', '->render() renders the widget as HTML');
+
Modified:
plugins/sfFormI18nNumberPlugin/trunk/lib/widget/i18n/sfWidgetFormI18nNumber.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/trunk/lib/widget/i18n/sfWidgetFormI18nNumber.php
2010-04-09 09:00:05 UTC (rev 29047)
+++
plugins/sfFormI18nNumberPlugin/trunk/lib/widget/i18n/sfWidgetFormI18nNumber.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -50,7 +50,7 @@
public function render($name, $value = null, $attributes = array(), $errors
= array())
{
- if (!is_string($value) && !is_null($value))
+ if (is_numeric($value) && !is_null($value))
{
$numberFormat = new sfNumberFormat($this->getOption('culture'));
$value = $numberFormat->format($value);
Modified: plugins/sfFormI18nNumberPlugin/trunk/package.xml
===================================================================
--- plugins/sfFormI18nNumberPlugin/trunk/package.xml 2010-04-09 09:00:05 UTC
(rev 29047)
+++ plugins/sfFormI18nNumberPlugin/trunk/package.xml 2010-04-09 10:14:35 UTC
(rev 29048)
@@ -1,111 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
-<package xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.1"
version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
- <name>sfFormI18nNumberPlugin</name>
- <channel>pear.symfony-project.com</channel>
- <summary>I18n-Number validator and widget</summary>
- <description>I18n-Number validator and widget</description>
- <lead>
- <name>oweitman</name>
- <user>oweitman</user>
- <email>[email protected]</email>
- <active>yes</active>
- </lead>
- <date>2009-08-27</date>
- <version>
- <release>0.9.2</release>
- <api>0.9.2</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.symfony-project.org/license">MIT license</license>
- <notes>-</notes>
+<package packagerversion="1.9.0" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
+ <name>sfFormI18nNumberPlugin</name>
+ <channel>plugins.symfony-project.org</channel>
+ <summary>I18n-Number validator and widget</summary>
+ <description>I18n-Number validator and widget</description>
+ <lead>
+ <name>oweitman</name>
+ <user>oweitman</user>
+ <email>[email protected]</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-04-09</date>
+ <time>10:06:49</time>
+ <version>
+ <release>0.9.3</release>
+ <api>0.9.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.symfony-project.org/license">MIT license</license>
+ <notes>
+-
+ </notes>
<contents>
- <dir name="/">
- <file role="data" name="README" />
- <file role="data" name="LICENSE" />
- <dir name="lib">
- <dir name="i18n">
- <file role="data" name="sfNumberFormatPlus.class.php" />
- </dir>
- <dir name="widget">
- <dir name="i18n">
- <file role="data" name="sfWidgetFormI18nNumber.php" />
- </dir>
- </dir>
- <dir name="validator">
- <dir name="i18n">
- <file role="data" name="sfValidatorI18nNumber.php" />
- </dir>
- </dir>
- </dir>
- <dir name="test">
- <dir name="bootstrap">
- <file role="data" name="unit.php" />
- <file role="data" name="functional.php" />
- </dir>
- <dir name="unit">
- <dir name="widget">
- </dir>
- <dir name="validator">
- <file role="data" name="sfValidatorI18nNumberTest.php" />
- </dir>
- </dir>
- </dir>
- </dir>
+ <dir name="/">
+ <file md5sum="d509e893096cd79bf4bf5a64898a9b09"
name="test/unit/widget/sfWidgetFormI18nNumberTest.php" role="data" />
+ <file md5sum="5318bd59e2abe95c72216e4198c1ee0d"
name="test/unit/validator/sfValidatorI18nNumberTest.php" role="data" />
+ <file md5sum="3342e2e00283321c6e02401452886fb9"
name="test/bootstrap/unit.php" role="data" />
+ <file md5sum="604d04fa189f79b6651c20d3234dcd6d"
name="test/bootstrap/functional.php" role="data" />
+ <file md5sum="b84d430d03fce3a229116fb8a7fb0db1"
name="lib/widget/i18n/sfWidgetFormI18nNumber.php" role="data" />
+ <file md5sum="0e5e8155d7a5e6677b200723c53e161f"
name="lib/validator/i18n/sfValidatorI18nNumber.php" role="data" />
+ <file md5sum="27bcd1769dacf95ef717435a10c46754"
name="lib/i18n/sfNumberFormatPlus.class.php" role="data" />
+ <file md5sum="62e8e18f5f7ef8b6575c6631e5ded2d4" name="README" role="data" />
+ <file md5sum="c08e44581c779e68051552222fd7a778" name="LICENSE" role="data"
/>
+ </dir>
</contents>
- <dependencies>
- <required>
- <php>
- <min>5.2.4</min>
- </php>
- <pearinstaller>
- <min>1.4.1</min>
- </pearinstaller>
- <package>
- <name>symfony</name>
- <channel>pear.symfony-project.com</channel>
- <min>1.2.0</min>
- <max>1.3.0</max>
- <exclude>1.3.0</exclude>
- </package>
- </required>
- </dependencies>
- <phprelease></phprelease>
- <changelog>
- <release>
- <version>
- <release>0.9.2</release>
- <api>0.9.2</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.symfony-project.com/license">MIT
license</license>
- <date>2009-08-27</date>
- <license>MIT</license>
- <notes>
- * Remove forgotten debug-code
- * Changed unit-test integration
- </notes>
- </release>
- <release>
- <version>
- <release>0.9.1</release>
- <api>0.9.1</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.symfony-project.com/license">MIT
license</license>
- <date>2009-08-25</date>
- <license>MIT</license>
- <notes>
- * Initial Release
- </notes>
- </release>
- </changelog>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.4</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.1</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog />
</package>
Added:
plugins/sfFormI18nNumberPlugin/trunk/test/unit/widget/sfWidgetFormI18nNumberTest.php
===================================================================
---
plugins/sfFormI18nNumberPlugin/trunk/test/unit/widget/sfWidgetFormI18nNumberTest.php
(rev 0)
+++
plugins/sfFormI18nNumberPlugin/trunk/test/unit/widget/sfWidgetFormI18nNumberTest.php
2010-04-09 10:14:35 UTC (rev 29048)
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * 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(12, new lime_output_color());
+
+$w = new sfWidgetFormI18nNumber();
+
+$t->diag('->clean() - standard culture = en');
+$w->setOption('culture','en');
+
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12.3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12.1234" id="key" />', '->render() renders the widget as HTML');
+
+$w->setOption('culture','de');
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12,3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12,1234" id="key" />', '->render() renders the widget as HTML');
+
+$w->setOption('culture','pl');
+$t->is($w->render('key',12.3), '<input type="text" name="key" value="12,3"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.0), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12), '<input type="text" name="key" value="12"
id="key" />', '->render() renders the widget as HTML');
+$t->is($w->render('key',12.1234), '<input type="text" name="key"
value="12,1234" id="key" />', '->render() renders the widget as HTML');
+
--
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.