-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssue15606Test.php
78 lines (67 loc) · 2.76 KB
/
Issue15606Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace AppBundle\Tests\Form;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormBuilder;
class Issue15606Test extends WebTestCase
{
private $arrayWithDuplicateContent = [
2 => "Category A",
3 => " ... Category A.1",
4 => " ... Category A.2",
5 => "Category B",
6 => " ... Category B.1",
7 => " ... ... inactive",
8 => " ... ... active",
9 => " ... Category B.2",
10 => " ... ... inactive",
11 => " ... ... active",
12 => " ... Category B.3",
13 => " ... ... Category B.3.1",
14 => " ... ... Category B.3.2",
15 => " ... Category B.4",
16 => " ... ... Category B.4.1",
17 => " ... ... Category B.4.2",
18 => " ... Category B.5",
19 => " ... ... Category B.5.1",
20 => " ... ... Category B.5.2",
];
private function createFormView($options)
{
$client = static::createClient();
$container = $client->getContainer();
/** @var FormBuilder $formBuilder */
$formBuilder = $container->get('form.factory')->createBuilder('form');
$form = $formBuilder->add('category', 'choice', $options)->getForm();
return $form->createView();
}
public function testBigArrayChoicesAsValues()
{
$formView = $this->createFormView(['choices' => $this->arrayWithDuplicateContent, 'choices_as_values' => true]);
$convertedChoices = $formView->offsetGet('category')->vars['choices'];
$this->assertCount(count($this->arrayWithDuplicateContent), $convertedChoices, 'Choices missing!');
$counter = 0;
foreach (array_keys($this->arrayWithDuplicateContent) as $key) {
/** @var ChoiceView $choice */
$choice = $convertedChoices[$counter];
$this->assertEquals($key, $choice->label);
$counter++;
}
}
public function testBigArrayChoices()
{
$formView = $this->createFormView(['choices' => $this->arrayWithDuplicateContent, 'choices_as_values' => false]);
$convertedChoices = $formView->offsetGet('category')->vars['choices'];
var_dump($convertedChoices);
$this->assertCount(count($this->arrayWithDuplicateContent), $convertedChoices, 'Choices missing!');
$counter = 0;
foreach ($this->arrayWithDuplicateContent as $key => $value) {
/** @var ChoiceView $choice */
$choice = $convertedChoices[$counter];
$this->assertEquals($key, $choice->data);
$this->assertEquals((string) $key, $choice->value);
$this->assertEquals($value, $choice->label);
$counter++;
}
}
}