Skip to content

Commit b6fabb5

Browse files
committed
Added issue-8 test
1 parent 13904b7 commit b6fabb5

File tree

7 files changed

+203
-0
lines changed

7 files changed

+203
-0
lines changed

tests/Functional/BasicFormTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,4 +1160,38 @@ public function issue_7_should_not_occur()
11601160
$javascript
11611161
);
11621162
}
1163+
1164+
/**
1165+
* @test
1166+
*/
1167+
public function issue_8_should_not_occur()
1168+
{
1169+
$client = self::createClient();
1170+
1171+
$javascript = $this->fetch_application_page_javascript('/issue/8', $client);
1172+
1173+
$this->assertEqualJs(
1174+
'(function ($) {
1175+
"use strict";
1176+
var form = $("form[name=\"test_range\"]");
1177+
var validator = form.validate({
1178+
rules: {
1179+
"test_range\x5Bsize\x5D\x5Bmin_size\x5D": {"required": true, "min": 400},
1180+
"test_range\x5Bsize\x5D\x5Bmax_size\x5D": {"required": true, "max": 2000}
1181+
},
1182+
messages: {
1183+
"test_range\x5Bsize\x5D\x5Bmin_size\x5D": {
1184+
"required": "This\x20value\x20should\x20not\x20be\x20blank.",
1185+
"min": "This\x20value\x20should\x20be\x20greater\x20than\x20or\x20equal\x20to\x20400."
1186+
},
1187+
"test_range\x5Bsize\x5D\x5Bmax_size\x5D": {
1188+
"required": "This\x20value\x20should\x20not\x20be\x20blank.",
1189+
"max": "This\x20value\x20should\x20be\x20less\x20than\x20or\x20equal\x20to\x202000."
1190+
}
1191+
}
1192+
});
1193+
})(jQuery);',
1194+
$javascript
1195+
);
1196+
}
11631197
}

tests/Functional/TestBundle/Controller/FormController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Type\IncludeSimpleFormType;
1818
use Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Type\ViewTransformRulesFormType;
1919
use Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue7;
20+
use Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue8;
2021

2122
/**
2223
* @author Warnar Boekkooi <warnar@boekkooi.net>
@@ -137,6 +138,18 @@ public function issue7Action(Request $request)
137138
return $this->render('::form.html.twig', array('form' => $form->createView()));
138139
}
139140

141+
public function issue8Action(Request $request)
142+
{
143+
$resource = new Issue8\Model\TestRangeEntity();
144+
145+
$form = $this->createForm(new Issue8\Type\TestRangeType());
146+
$form->setData($resource);
147+
$this->handleForm($request, $form);
148+
149+
return $this->render('::form.html.twig', array('form' => $form->createView()));
150+
}
151+
152+
140153
private function handleForm(Request $request, FormInterface $form)
141154
{
142155
$form->handleRequest($request);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
namespace Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue8\Model;
3+
4+
use Symfony\Component\Validator\Constraints as Assert;
5+
6+
/**
7+
* @author Warnar Boekkooi <warnar@boekkooi.net>
8+
*/
9+
class TestRangeEntity
10+
{
11+
/**
12+
* @var int
13+
*
14+
* @Assert\NotBlank()
15+
* @Assert\GreaterThanOrEqual(value=400)
16+
*/
17+
private $minSize = 400;
18+
19+
/**
20+
* @var int
21+
*
22+
* @Assert\NotBlank()
23+
* @Assert\LessThanOrEqual(value=2000)
24+
*/
25+
private $maxSize = 700;
26+
27+
/**
28+
* @return int
29+
*/
30+
public function getMinSize()
31+
{
32+
return $this->minSize;
33+
}
34+
35+
/**
36+
* @param int $minSize
37+
*/
38+
public function setMinSize($minSize)
39+
{
40+
$this->minSize = $minSize;
41+
}
42+
43+
/**
44+
* @return int
45+
*/
46+
public function getMaxSize()
47+
{
48+
return $this->maxSize;
49+
}
50+
51+
/**
52+
* @param int $maxSize
53+
*/
54+
public function setMaxSize($maxSize)
55+
{
56+
$this->maxSize = $maxSize;
57+
}
58+
59+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue8\Type;
3+
4+
use Symfony\Component\Form\AbstractType;
5+
use Symfony\Component\Form\FormBuilderInterface;
6+
use Symfony\Component\Form\FormInterface;
7+
use Symfony\Component\Form\FormView;
8+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
9+
10+
/**
11+
* @author Warnar Boekkooi <warnar@boekkooi.net>
12+
*/
13+
class RangeType extends AbstractType
14+
{
15+
public function buildForm(FormBuilderInterface $builder, array $options)
16+
{
17+
$builder->add($options['min_name'], $options['type'], array_merge($options['options'], $options['min_options']));
18+
$builder->add($options['max_name'], $options['type'], array_merge($options['options'], $options['max_options']));
19+
}
20+
21+
public function buildView(FormView $view, FormInterface $form, array $options)
22+
{
23+
$view->vars['min_name'] = $options['min_name'];
24+
$view->vars['max_name'] = $options['max_name'];
25+
}
26+
27+
public function setDefaultOptions(OptionsResolverInterface $resolver)
28+
{
29+
$resolver->setDefaults(array(
30+
'type' => 'text',
31+
'options' => array(),
32+
'min_options' => array(),
33+
'max_options' => array(),
34+
'min_name' => 'min',
35+
'max_name' => 'max',
36+
'error_bubbling' => false,
37+
));
38+
39+
$resolver->setAllowedTypes(array(
40+
'options' => 'array',
41+
'min_options' => 'array',
42+
'max_options' => 'array',
43+
));
44+
}
45+
46+
public function getName()
47+
{
48+
return 'range';
49+
}
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue8\Type;
3+
4+
use Symfony\Component\Form\AbstractType;
5+
use Symfony\Component\Form\FormBuilderInterface;
6+
use Symfony\Component\Form\FormInterface;
7+
use Symfony\Component\Form\FormView;
8+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
9+
10+
/**
11+
* @author Warnar Boekkooi <warnar@boekkooi.net>
12+
*/
13+
class TestRangeType extends AbstractType
14+
{
15+
public function buildForm(FormBuilderInterface $builder, array $options)
16+
{
17+
// $builder->add('size', 'range', array(
18+
// 'virtual' => true, // <- VIRTUAL OPTION
19+
// 'min_name' => 'min_size',
20+
// 'max_name' => 'max_size'
21+
// ));
22+
$builder->add('size', new RangeType(), array(
23+
'virtual' => true,
24+
// 'inherit_data' => true,
25+
'min_name' => 'min_size',
26+
'max_name' => 'max_size'
27+
));
28+
}
29+
30+
public function setDefaultOptions(OptionsResolverInterface $resolver)
31+
{
32+
$resolver->setDefaults(array(
33+
'data_class' => 'Tests\Boekkooi\Bundle\JqueryValidationBundle\Functional\TestBundle\Form\Issue8\Model\TestRangeEntity'
34+
));
35+
}
36+
37+
public function getName()
38+
{
39+
return 'test_range';
40+
}
41+
}

tests/Functional/app/Resources/views/form.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<li><a href="{{ path('form_collection_datetime') }}">Collection DateTime Form</a></li>
8989
<li><a href="{{ path('form_additional_rules') }}">Additional Rules</a></li>
9090
<li><a href="{{ path('form_issue_7') }}">Issue 7</a></li>
91+
<li><a href="{{ path('form_issue_8') }}">Issue 8</a></li>
9192
</ul>
9293
<div class="col-xs-7 col-sm-9">
9394
{% for flashMessage in app.session.flashbag.get('notice') %}

tests/Functional/app/config/routing.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ form_issue_7:
6262
path: '/issue/7'
6363
defaults:
6464
_controller: TestBundle:Form:issue7
65+
66+
form_issue_8:
67+
path: '/issue/8'
68+
defaults:
69+
_controller: TestBundle:Form:issue8

0 commit comments

Comments
 (0)