[Form] Fixed failing layout tests
This commit is contained in:
parent
1d89922782
commit
7e0960d716
@ -17,8 +17,8 @@ use Symfony\Bridge\Twig\Form\TwigRendererEngine;
|
||||
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
|
||||
|
||||
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
@ -132,7 +132,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
*/
|
||||
public function testIsChoiceSelected($expected, $choice, $value)
|
||||
{
|
||||
$choice = new ChoiceView($choice, $choice, $choice.' label');
|
||||
$choice = new ChoiceView($choice.' label', $choice, $choice);
|
||||
|
||||
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
|
||||
}
|
||||
|
@ -231,6 +231,29 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
|
||||
'/select
|
||||
[@name="name"]
|
||||
[@class="my&class form-control"]
|
||||
[not(@required)]
|
||||
[
|
||||
./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
|
||||
/following-sibling::option[@value="&b"][@class="foo&bar"][not(@selected)][.="[trans]Choice&B[/trans]"]
|
||||
]
|
||||
[count(./option)=2]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceWithPreferred()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -496,6 +519,31 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a'), array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
|
||||
'/select
|
||||
[@name="name[]"]
|
||||
[@class="my&class form-control"]
|
||||
[@required="required"]
|
||||
[@multiple="multiple"]
|
||||
[
|
||||
./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
|
||||
/following-sibling::option[@value="&b"][@class="foo&bar"][not(@selected)][.="[trans]Choice&B[/trans]"]
|
||||
]
|
||||
[count(./option)=2]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceSkipsPlaceholder()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a'), array(
|
||||
@ -577,6 +625,42 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./div
|
||||
[@class="radio"]
|
||||
[
|
||||
./label
|
||||
[.="[trans]Choice&A[/trans]"]
|
||||
[
|
||||
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="radio"]
|
||||
[
|
||||
./label
|
||||
[.="[trans]Choice&B[/trans]"]
|
||||
[
|
||||
./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)][@class="foo&bar"]
|
||||
]
|
||||
]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
|
||||
]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedWithPlaceholder()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -702,6 +786,52 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'),
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="[trans]Choice&A[/trans]"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="[trans]Choice&B[/trans]"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)][@class="foo&bar"]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="[trans]Choice&C[/trans]"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
|
||||
]
|
||||
]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
|
||||
]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountry()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'country', 'AT');
|
||||
|
Reference in New Issue
Block a user