Skip to content

Commit

Permalink
Fix NativeLabelTranslatorStrategy whitespace bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Jun 5, 2013
1 parent aaee838 commit 312f4af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions Tests/Translator/NativeLabelTranslatorStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,36 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Tests\Translator;

use Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy;

class NativeTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
{
public function testLabel()

/**
* @dataProvider getLabelTests
*/
public function testLabel($expectedLabel, $label)
{
$strategy = new NativeLabelTranslatorStrategy;

$this->assertEquals('Is Valid', $strategy->getLabel('isValid', 'form', 'label'));
$this->assertEquals('Is Valid', $strategy->getLabel('is_Valid', 'form', 'label'));
$this->assertEquals('Is0 Valid', $strategy->getLabel('is0Valid', 'form', 'label'));
$this->assertEquals('Is Valid Super Cool', $strategy->getLabel('isValid_SuperCool', 'form', 'label'));
$this->assertEquals($expectedLabel, $strategy->getLabel($label, 'form', 'label'));
}

public function getLabelTests()
{
return array(
array('Is Valid', 'isValid'),
array('Is Valid', 'is_Valid'),
array('Is0 Valid', 'is0Valid'),
array('Is Valid', '_isValid'),
array('Is Valid', '__isValid'),
array('Is Valid', 'isValid_'),
array('Is Valid', 'isValid__'),
array('Is Valid', '__isValid__'),
array('Is Valid Super Cool', 'isValid_SuperCool'),
);
}
}
2 changes: 1 addition & 1 deletion Translator/NativeLabelTranslatorStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function getLabel($label, $context = '', $type = '')
$label = str_replace(array('_', '.'), ' ', $label);
$label = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label));

return ucwords(str_replace('_', ' ', $label));
return trim(ucwords(str_replace('_', ' ', $label)));
}
}

0 comments on commit 312f4af

Please sign in to comment.