2012-05-16 18:25:27 +01:00
|
|
|
<?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\Component\Form\Tests;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
2012-07-28 09:59:23 +01:00
|
|
|
use Symfony\Component\Form\FormConfigBuilder;
|
2012-05-16 18:25:27 +01:00
|
|
|
|
|
|
|
class FormConfigTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function getHtml4Ids()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('a0', true),
|
|
|
|
array('a9', true),
|
|
|
|
array('z0', true),
|
|
|
|
array('A0', true),
|
|
|
|
array('A9', true),
|
|
|
|
array('Z0', true),
|
|
|
|
array('#', false),
|
|
|
|
array('a#', false),
|
|
|
|
array('a$', false),
|
|
|
|
array('a%', false),
|
|
|
|
array('a ', false),
|
|
|
|
array("a\t", false),
|
|
|
|
array("a\n", false),
|
|
|
|
array('a-', true),
|
|
|
|
array('a_', true),
|
|
|
|
array('a:', true),
|
|
|
|
// Periods are allowed by the HTML4 spec, but disallowed by us
|
|
|
|
// because they break the generated property paths
|
|
|
|
array('a.', false),
|
|
|
|
// Contrary to the HTML4 spec, we allow names starting with a
|
|
|
|
// number, otherwise naming fields by collection indices is not
|
|
|
|
// possible.
|
|
|
|
// For root forms, leading digits will be stripped from the
|
|
|
|
// "id" attribute to produce valid HTML4.
|
|
|
|
array('0', true),
|
|
|
|
array('9', true),
|
|
|
|
// Contrary to the HTML4 spec, we allow names starting with an
|
|
|
|
// underscore, since this is already a widely used practice in
|
|
|
|
// Symfony2.
|
|
|
|
// For root forms, leading underscores will be stripped from the
|
|
|
|
// "id" attribute to produce valid HTML4.
|
|
|
|
array('_', true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getHtml4Ids
|
|
|
|
*/
|
2012-05-20 10:18:31 +01:00
|
|
|
public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $accepted)
|
2012-05-16 18:25:27 +01:00
|
|
|
{
|
|
|
|
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
|
|
|
|
|
|
|
try {
|
2012-07-28 09:59:23 +01:00
|
|
|
new FormConfigBuilder($name, null, $dispatcher);
|
2012-05-16 18:25:27 +01:00
|
|
|
if (!$accepted) {
|
|
|
|
$this->fail(sprintf('The value "%s" should not be accepted', $name));
|
|
|
|
}
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
// if the value was not accepted, but should be, rethrow exception
|
|
|
|
if ($accepted) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|