[Form] Improved regular expression in AbstractType::getName() and added unit tests
This commit is contained in:
parent
4905bfd285
commit
be5738564f
@ -47,10 +47,8 @@ abstract class AbstractType implements FormTypeInterface
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (preg_match('/\\\\([a-z]+)(?:Form|Type)$/im', get_class($this), $matches)) {
|
||||
$name = strtolower($matches[1]);
|
||||
}
|
||||
preg_match('/\\\\(\w+?)(Form)?(Type)?$/i', get_class($this), $matches);
|
||||
|
||||
return $name;
|
||||
return strtolower($matches[1]);
|
||||
}
|
||||
}
|
||||
|
53
tests/Symfony/Tests/Component/Form/Type/AbstractTypeTest.php
Normal file
53
tests/Symfony/Tests/Component/Form/Type/AbstractTypeTest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Tests\Component\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\Type\AbstractType;
|
||||
|
||||
class AbstractTypeTest extends TestCase
|
||||
{
|
||||
public function testGetNameWithNoSuffix()
|
||||
{
|
||||
$type = new MyTest();
|
||||
|
||||
$this->assertEquals('mytest', $type->getName());
|
||||
}
|
||||
|
||||
public function testGetNameWithTypeSuffix()
|
||||
{
|
||||
$type = new MyTestType();
|
||||
|
||||
$this->assertEquals('mytest', $type->getName());
|
||||
}
|
||||
|
||||
public function testGetNameWithFormSuffix()
|
||||
{
|
||||
$type = new MyTestForm();
|
||||
|
||||
$this->assertEquals('mytest', $type->getName());
|
||||
}
|
||||
|
||||
public function testGetNameWithFormTypeSuffix()
|
||||
{
|
||||
$type = new MyTestFormType();
|
||||
|
||||
$this->assertEquals('mytest', $type->getName());
|
||||
}
|
||||
}
|
||||
|
||||
class MyTest extends AbstractType {}
|
||||
|
||||
class MyTestType extends AbstractType {}
|
||||
|
||||
class MyTestForm extends AbstractType {}
|
||||
|
||||
class MyTestFormType extends AbstractType {}
|
Reference in New Issue
Block a user