Skip to content

Commit 3c43ca5

Browse files
committed
Adds test for FormType
1 parent 06df934 commit 3c43ca5

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\LiveComponent\Tests\Unit\Form\Type;
13+
14+
use Symfony\Component\Form\Extension\Core\Type\TextType;
15+
use Symfony\Component\Form\FormBuilderInterface;
16+
use Symfony\Component\Form\Test\TypeTestCase;
17+
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
18+
use Symfony\UX\LiveComponent\Form\Type\MultiStepType;
19+
20+
/**
21+
* @author Silas Joisten <[email protected]>
22+
*/
23+
final class MultiStepTypeTest extends TypeTestCase
24+
{
25+
public function testConfigureOptionsWithoutStepsThrowsException(): void
26+
{
27+
self::expectException(MissingOptionsException::class);
28+
29+
$this->factory->create(MultiStepType::class);
30+
}
31+
32+
public function testConfigureOptionsWithStepsSetsDefaultForCurrentStepName(): void
33+
{
34+
$form = $this->factory->create(MultiStepType::class, [], [
35+
'steps' => [
36+
'general' => static function (): void {},
37+
'contact' => static function (): void {},
38+
'newsletter' => static function (): void {},
39+
],
40+
]);
41+
42+
self::assertSame('general', $form->createView()->vars['current_step_name']);
43+
}
44+
45+
public function testBuildViewHasStepNames(): void
46+
{
47+
$form = $this->factory->create(MultiStepType::class, [], [
48+
'steps' => [
49+
'general' => static function (): void {},
50+
'contact' => static function (): void {},
51+
'newsletter' => static function (): void {},
52+
],
53+
]);
54+
55+
self::assertSame(['general', 'contact', 'newsletter'], $form->createView()->vars['steps_names']);
56+
}
57+
58+
public function testFormOnlyHasCurrentStepForm(): void
59+
{
60+
$form = $this->factory->create(MultiStepType::class, [], [
61+
'steps' => [
62+
'general' => static function (FormBuilderInterface $builder): void {
63+
$builder
64+
->add('firstName', TextType::class)
65+
->add('lastName', TextType::class);
66+
},
67+
'contact' => static function (FormBuilderInterface $builder): void {
68+
$builder
69+
->add('address', TextType::class)
70+
->add('city', TextType::class);
71+
},
72+
'newsletter' => static function (): void {},
73+
],
74+
]);
75+
76+
self::assertArrayHasKey('firstName', $form->createView()->children);
77+
self::assertArrayHasKey('lastName', $form->createView()->children);
78+
self::assertArrayNotHasKey('address', $form->createView()->children);
79+
self::assertArrayNotHasKey('city', $form->createView()->children);
80+
}
81+
}

0 commit comments

Comments
 (0)