(finally) fix version dependent Form tests

This commit is contained in:
Christian Flothmann 2019-02-14 16:46:28 +01:00
parent b09761778a
commit d42e054d2c
7 changed files with 105 additions and 385 deletions

View File

@ -16,7 +16,7 @@ use Symfony\Component\Form\Tests\AbstractLayoutTest;
abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
{
protected static $supportedFeatureSetVersion = 304;
protected static $supportedFeatureSetVersion = 403;
public function testLabelOnForm()
{
@ -2672,82 +2672,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
[@name="name"]
[@class="my&class form-control"]
[@value="#0000ff"]
'
);
}
public function testLabelWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}

View File

@ -31,7 +31,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
*/
private $renderer;
protected static $supportedFeatureSetVersion = 304;
protected static $supportedFeatureSetVersion = 403;
protected function setUp()
{
@ -295,82 +295,6 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
);
}
public function testLabelWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}
protected function renderForm(FormView $view, array $vars = [])
{
return (string) $this->renderer->renderBlock($view, 'form', $vars);

View File

@ -30,7 +30,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
*/
private $renderer;
protected static $supportedFeatureSetVersion = 304;
protected static $supportedFeatureSetVersion = 403;
protected function setUp()
{
@ -181,82 +181,6 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
);
}
public function testLabelWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}
protected function renderForm(FormView $view, array $vars = [])
{
return (string) $this->renderer->renderBlock($view, 'form', $vars);

View File

@ -27,7 +27,7 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
*/
protected $engine;
protected static $supportedFeatureSetVersion = 304;
protected static $supportedFeatureSetVersion = 403;
protected function getExtensions()
{
@ -195,82 +195,6 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
);
}
public function testLabelWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}
protected function renderForm(FormView $view, array $vars = [])
{
return (string) $this->engine->get('form')->form($view, $vars);

View File

@ -27,7 +27,7 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
*/
protected $engine;
protected static $supportedFeatureSetVersion = 304;
protected static $supportedFeatureSetVersion = 403;
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
@ -73,82 +73,6 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
);
}
public function testLabelWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}
protected function getExtensions()
{
// should be moved to the Form component once absolute file paths are supported

View File

@ -2589,6 +2589,90 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@type="color"]
[@name="name"]
[@value="#0000ff"]
'
);
}
public function testLabelWithTranslationParameters()
{
$this->requiresFeatureSet(403);
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
'%address%' => 'Paris, rue de la Paix',
],
]);
$this->assertMatchesXpath($html,
'/label
[@for="name"]
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
'
);
}
public function testHelpWithTranslationParameters()
{
$this->requiresFeatureSet(403);
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderHelp($form->createView());
$this->assertMatchesXpath($html,
'/*
[@id="name_help"]
[.="[trans]for company ACME Ltd.[/trans]"]
'
);
}
public function testAttributesWithTranslationParameters()
{
$this->requiresFeatureSet(403);
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
'placeholder' => 'Enter a message to %company%',
],
'attr_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
]);
$html = $this->renderWidget($form->createView());
$this->assertMatchesXpath($html,
'/input
[@title="[trans]Message to ACME Ltd.[/trans]"]
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
'
);
}
public function testButtonWithTranslationParameters()
{
$this->requiresFeatureSet(403);
$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
'label_translation_parameters' => [
'%company%' => 'ACME Ltd.',
],
])
->getForm();
$view = $form->get('mybutton')->createView();
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
$this->assertMatchesXpath($html,
'/button
[.="[trans]Submit to ACME Ltd.[/trans]"]
'
);
}

View File

@ -124,6 +124,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testPassLabelTranslationParametersToView()
{
$this->requiresFeatureSet(403);
$view = $this->factory->create($this->getTestedType(), null, [
'label_translation_parameters' => ['%param%' => 'value'],
])
@ -134,6 +136,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testPassAttrTranslationParametersToView()
{
$this->requiresFeatureSet(403);
$view = $this->factory->create($this->getTestedType(), null, [
'attr_translation_parameters' => ['%param%' => 'value'],
])
@ -144,6 +148,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testInheritLabelTranslationParametersFromParent()
{
$this->requiresFeatureSet(403);
$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'label_translation_parameters' => ['%param%' => 'value'],
@ -157,6 +163,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testInheritAttrTranslationParametersFromParent()
{
$this->requiresFeatureSet(403);
$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'attr_translation_parameters' => ['%param%' => 'value'],
@ -170,6 +178,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testPreferOwnLabelTranslationParameters()
{
$this->requiresFeatureSet(403);
$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'label_translation_parameters' => ['%parent_param%' => 'parent_value', '%override_param%' => 'parent_override_value'],
@ -185,6 +195,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testPreferOwnAttrTranslationParameters()
{
$this->requiresFeatureSet(403);
$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'attr_translation_parameters' => ['%parent_param%' => 'parent_value', '%override_param%' => 'parent_override_value'],
@ -200,6 +212,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testDefaultLabelTranslationParameters()
{
$this->requiresFeatureSet(403);
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
->add('child', $this->getTestedType())
->getForm()
@ -210,6 +224,8 @@ abstract class BaseTypeTest extends TypeTestCase
public function testDefaultAttrTranslationParameters()
{
$this->requiresFeatureSet(403);
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
->add('child', $this->getTestedType())
->getForm()