4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\EventListener
;
14 use Symfony\Component\Form\FormEvent
;
15 use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener
;
17 class FixUrlProtocolListenerTest
extends \PHPUnit_Framework_TestCase
19 protected function setUp()
21 if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
22 $this->markTestSkipped('The "EventDispatcher" component is not available');
26 public function testFixHttpUrl()
28 $data = "www.symfony.com";
29 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
30 $event = new FormEvent($form, $data);
32 $filter = new FixUrlProtocolListener('http');
33 $filter->onSubmit($event);
35 $this->assertEquals('http://www.symfony.com', $event->getData());
38 public function testSkipKnownUrl()
40 $data = "http://www.symfony.com";
41 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
42 $event = new FormEvent($form, $data);
44 $filter = new FixUrlProtocolListener('http');
45 $filter->onSubmit($event);
47 $this->assertEquals('http://www.symfony.com', $event->getData());
50 public function testSkipOtherProtocol()
52 $data = "ftp://www.symfony.com";
53 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
54 $event = new FormEvent($form, $data);
56 $filter = new FixUrlProtocolListener('http');
57 $filter->onSubmit($event);
59 $this->assertEquals('ftp://www.symfony.com', $event->getData());