[Form] Improved labels generated by default from form names

This commit is contained in:
Bernhard Schussek 2012-04-06 19:50:06 +02:00
parent 6e0b03a6e2
commit 658472193d
2 changed files with 17 additions and 1 deletions

View File

@ -200,6 +200,6 @@ class FieldType extends AbstractType
private function humanize($text)
{
return ucfirst(strtolower(str_replace('_', ' ', $text)));
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
}
}

View File

@ -188,6 +188,22 @@ class FieldTypeTest extends TypeTestCase
$this->assertSame('test', $view->get('translation_domain'));
}
public function testPassDefaultLabelToView()
{
$form = $this->factory->createNamed('field', '__test___field');
$view = $form->createView();
$this->assertSame('Test field', $view->get('label'));
}
public function testPassLabelToView()
{
$form = $this->factory->createNamed('field', '__test___field', null, array('label' => 'My label'));
$view = $form->createView();
$this->assertSame('My label', $view->get('label'));
}
public function testDefaultTranslationDomain()
{
$form = $this->factory->create('field');