Skip to content

Commit

Permalink
[Form]fixed FormRenderer::humanize() to humanize camel cased label
Browse files Browse the repository at this point in the history
  • Loading branch information
77web authored and fabpot committed Feb 11, 2013
1 parent eb2bcc5 commit 8adb0e3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
@@ -1,6 +1,12 @@
CHANGELOG
=========


2.3.0
------

* changed FormRenderer::humanize() to humanize also camel cased field name

2.2.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormRenderer.php
Expand Up @@ -280,6 +280,6 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
*/
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))));
}
}
18 changes: 18 additions & 0 deletions src/Symfony/Component/Form/Tests/FormRendererTest.php
@@ -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'));
}
}

0 comments on commit 8adb0e3

Please sign in to comment.