UrlFieldTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Symfony\Tests\Component\Form;
  3. require_once __DIR__ . '/LocalizedTestCase.php';
  4. use Symfony\Component\Form\UrlField;
  5. class UrlFieldTest extends LocalizedTestCase
  6. {
  7. public function testBindAddsDefaultProtocolIfNoneIsIncluded()
  8. {
  9. $field = new UrlField('name');
  10. $field->bind('www.domain.com');
  11. $this->assertSame('http://www.domain.com', $field->getData());
  12. $this->assertSame('http://www.domain.com', $field->getDisplayedData());
  13. }
  14. public function testBindAddsNoDefaultProtocolIfAlreadyIncluded()
  15. {
  16. $field = new UrlField('name', array(
  17. 'default_protocol' => 'http',
  18. ));
  19. $field->bind('ftp://www.domain.com');
  20. $this->assertSame('ftp://www.domain.com', $field->getData());
  21. $this->assertSame('ftp://www.domain.com', $field->getDisplayedData());
  22. }
  23. public function testBindAddsNoDefaultProtocolIfEmpty()
  24. {
  25. $field = new UrlField('name', array(
  26. 'default_protocol' => 'http',
  27. ));
  28. $field->bind('');
  29. $this->assertSame(null, $field->getData());
  30. $this->assertSame('', $field->getDisplayedData());
  31. }
  32. public function testBindAddsNoDefaultProtocolIfSetToNull()
  33. {
  34. $field = new UrlField('name', array(
  35. 'default_protocol' => null,
  36. ));
  37. $field->bind('www.domain.com');
  38. $this->assertSame('www.domain.com', $field->getData());
  39. $this->assertSame('www.domain.com', $field->getDisplayedData());
  40. }
  41. }