properly move test methods

This commit is contained in:
Christian Flothmann 2019-02-14 10:40:15 +01:00
parent b5b547d5e4
commit 6bfc5f0901
6 changed files with 304 additions and 152 deletions

View File

@ -293,6 +293,82 @@ 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

@ -179,6 +179,82 @@ 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

@ -193,6 +193,82 @@ 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

@ -71,6 +71,82 @@ 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

@ -931,80 +931,4 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
// foo="foo"
$this->assertContains('<div id="form" foo="foo">', $html);
}
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

@ -533,80 +533,4 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
// foo="foo"
$this->assertContains('<table id="form" foo="foo">', $html);
}
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]"]
'
);
}
}