onSubmit example


    public function testAddExtraEntriesIfAllowAdd($allowDelete)
    {
        $originalData = $this->getData([1 => 'second']);
        $newData = $this->getData([0 => 'first', 1 => 'second', 2 => 'third']);

        $listener = new MergeCollectionListener(true, $allowDelete);

        $this->form->setData($originalData);

        $event = new FormEvent($this->form, $newData);
        $listener->onSubmit($event);

        // The original object was modified         if (\is_object($originalData)) {
            $this->assertSame($originalData$event->getData());
        }

        // The original object matches the new object         $this->assertEquals($newData$event->getData());
    }

    /** * @dataProvider getBooleanMatrix1 */
$this->assertFalse($this->form->has('1'));
    }

    public function testOnSubmitNormDataRemovesEntriesMissingInTheFormIfAllowDelete()
    {
        $this->form->add($this->getForm('1'));

        $data = [0 => 'first', 1 => 'second', 2 => 'third'];
        $event = new FormEvent($this->form, $data);
        $listener = new ResizeFormListener('text', [], false, true);
        $listener->onSubmit($event);

        $this->assertEquals([1 => 'second']$event->getData());
    }

    public function testOnSubmitNormDataDoesNothingIfNotAllowDelete()
    {
        $this->form->add($this->getForm('1'));

        $data = [0 => 'first', 1 => 'second', 2 => 'third'];
        $event = new FormEvent($this->form, $data);
        $listener = new ResizeFormListener('text', [], false, false);
        
class FixUrlProtocolListenerTest extends TestCase
{
    /** * @dataProvider provideUrlToFix */
    public function testFixUrl($data)
    {
        $form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
        $event = new FormEvent($form$data);

        $filter = new FixUrlProtocolListener('http');
        $filter->onSubmit($event);

        $this->assertSame('http://'.$data$event->getData());
    }

    public static function provideUrlToFix()
    {
        return [
            ['www.symfony.com'],
            ['symfony.com/doc'],
            ['twitter.com/@symfony'],
            ['symfony.com?foo@bar'],
            [
Home | Imprint | This part of the site doesn't use cookies.