Skip to content

Commit

Permalink
Add form type unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Feb 7, 2022
1 parent 23404a1 commit 2c1dfbb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/Form/CollectionJsTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Tienvx\UX\CollectionJs\Tests\Form;

use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Test\TypeTestCase;
use Tienvx\UX\CollectionJs\Form\CollectionJsType;

Expand Down Expand Up @@ -52,4 +54,28 @@ public function testCustomOptions()
$this->assertTrue($view->vars['call_post_add_on_init']);
$this->assertSame('__test__', $view->vars['prototype_name']);
}

public function testDontAllowAdd()
{
$form = $this->factory
->create(static::TESTED_TYPE, null, [
'entry_type' => TextType::class,
'allow_add' => false,
])
;

$view = $form->createView();
$this->assertInstanceOf(FormView::class, $view->vars['prototype']);
}

public function testDisablePrototype()
{
$this->expectExceptionObject(new InvalidConfigurationException(sprintf('You must enable prototype for form type %s.', static::TESTED_TYPE)));
$this->factory
->create(static::TESTED_TYPE, null, [
'entry_type' => TextType::class,
'prototype' => false,
])
;
}
}

0 comments on commit 2c1dfbb

Please sign in to comment.