UrlFieldTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form;
  11. require_once __DIR__ . '/LocalizedTestCase.php';
  12. use Symfony\Component\Form\UrlField;
  13. class UrlFieldTest extends LocalizedTestCase
  14. {
  15. public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
  16. {
  17. $field = new UrlField('name');
  18. $field->submit('www.domain.com');
  19. $this->assertSame('http://www.domain.com', $field->getData());
  20. $this->assertSame('http://www.domain.com', $field->getDisplayedData());
  21. }
  22. public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
  23. {
  24. $field = new UrlField('name', array(
  25. 'default_protocol' => 'http',
  26. ));
  27. $field->submit('ftp://www.domain.com');
  28. $this->assertSame('ftp://www.domain.com', $field->getData());
  29. $this->assertSame('ftp://www.domain.com', $field->getDisplayedData());
  30. }
  31. public function testSubmitAddsNoDefaultProtocolIfEmpty()
  32. {
  33. $field = new UrlField('name', array(
  34. 'default_protocol' => 'http',
  35. ));
  36. $field->submit('');
  37. $this->assertSame(null, $field->getData());
  38. $this->assertSame('', $field->getDisplayedData());
  39. }
  40. public function testSubmitAddsNoDefaultProtocolIfSetToNull()
  41. {
  42. $field = new UrlField('name', array(
  43. 'default_protocol' => null,
  44. ));
  45. $field->submit('www.domain.com');
  46. $this->assertSame('www.domain.com', $field->getData());
  47. $this->assertSame('www.domain.com', $field->getDisplayedData());
  48. }
  49. }