[Form]fixed FormRenderer::humanize() to humanize camel cased label

This commit is contained in:
77web 2013-02-07 18:53:06 +09:00 committed by Fabien Potencier
parent eb2bcc5db9
commit 8adb0e3673
3 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
2.3.0
------
* changed FormRenderer::humanize() to humanize also camel cased field name
2.2.0
-----

View File

@ -280,6 +280,6 @@ class FormRenderer implements FormRendererInterface
*/
public function humanize($text)
{
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
return ucfirst(trim(strtolower(preg_replace(array('/([A-Z])/', '/[_\s]+/'), array('_$1', ' '), $text))));
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Symfony\Component\Form\Test;
class FormRendererTest extends \PHPUnit_Framework_TestCase
{
public function testHumanize()
{
$renderer = $this->getMockBuilder('Symfony\Component\Form\FormRenderer')
->setMethods(null)
->disableOriginalConstructor()
->getMock()
;
$this->assertEquals('Is active', $renderer->humanize('is_active'));
$this->assertEquals('Is active', $renderer->humanize('isActive'));
}
}