This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/Form/UrlFieldTest.php
2011-03-17 14:55:26 +01:00

65 lines
1.8 KiB
PHP

<?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;
require_once __DIR__ . '/LocalizedTestCase.php';
use Symfony\Component\Form\UrlField;
class UrlFieldTest extends LocalizedTestCase
{
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
{
$field = $this->factory->getInstance('url', 'name');
$field->bind('www.domain.com');
$this->assertSame('http://www.domain.com', $field->getData());
$this->assertSame('http://www.domain.com', $field->getTransformedData());
}
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
{
$field = $this->factory->getInstance('url', 'name', array(
'default_protocol' => 'http',
));
$field->bind('ftp://www.domain.com');
$this->assertSame('ftp://www.domain.com', $field->getData());
$this->assertSame('ftp://www.domain.com', $field->getTransformedData());
}
public function testSubmitAddsNoDefaultProtocolIfEmpty()
{
$field = $this->factory->getInstance('url', 'name', array(
'default_protocol' => 'http',
));
$field->bind('');
$this->assertSame(null, $field->getData());
$this->assertSame('', $field->getTransformedData());
}
public function testSubmitAddsNoDefaultProtocolIfSetToNull()
{
$field = $this->factory->getInstance('url', 'name', array(
'default_protocol' => null,
));
$field->bind('www.domain.com');
$this->assertSame('www.domain.com', $field->getData());
$this->assertSame('www.domain.com', $field->getTransformedData());
}
}