Skip to content

Commit

Permalink
[Form] Improved labels generated by default from form names
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Apr 6, 2012
1 parent 6e0b03a commit 6584721
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ public function getName()

private function humanize($text)
{
return ucfirst(strtolower(str_replace('_', ' ', $text)));
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ public function testPassTranslationDomainToView()
$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');
Expand Down

0 comments on commit 6584721

Please sign in to comment.