Skip to content

Commit 8f37f55

Browse files
committed
properly move test methods
1 parent 922ef9d commit 8f37f55

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,82 @@ public function testHelpHtmlIsTrue()
293293
);
294294
}
295295

296+
public function testLabelWithTranslationParameters()
297+
{
298+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
299+
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
300+
'label_translation_parameters' => [
301+
'%address%' => 'Paris, rue de la Paix',
302+
],
303+
]);
304+
305+
$this->assertMatchesXpath($html,
306+
'/label
307+
[@for="name"]
308+
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
309+
'
310+
);
311+
}
312+
313+
public function testHelpWithTranslationParameters()
314+
{
315+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
316+
'help' => 'for company %company%',
317+
'help_translation_parameters' => [
318+
'%company%' => 'ACME Ltd.',
319+
],
320+
]);
321+
$html = $this->renderHelp($form->createView());
322+
323+
$this->assertMatchesXpath($html,
324+
'/*
325+
[@id="name_help"]
326+
[.="[trans]for company ACME Ltd.[/trans]"]
327+
'
328+
);
329+
}
330+
331+
public function testAttributesWithTranslationParameters()
332+
{
333+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
334+
'attr' => [
335+
'title' => 'Message to %company%',
336+
'placeholder' => 'Enter a message to %company%',
337+
],
338+
'attr_translation_parameters' => [
339+
'%company%' => 'ACME Ltd.',
340+
],
341+
]);
342+
$html = $this->renderWidget($form->createView());
343+
344+
$this->assertMatchesXpath($html,
345+
'/input
346+
[@title="[trans]Message to ACME Ltd.[/trans]"]
347+
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
348+
'
349+
);
350+
}
351+
352+
public function testButtonWithTranslationParameters()
353+
{
354+
$form = $this->factory->createNamedBuilder('myform')
355+
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
356+
'label' => 'Submit to %company%',
357+
'label_translation_parameters' => [
358+
'%company%' => 'ACME Ltd.',
359+
],
360+
])
361+
->getForm();
362+
$view = $form->get('mybutton')->createView();
363+
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
364+
365+
$this->assertMatchesXpath($html,
366+
'/button
367+
[.="[trans]Submit to ACME Ltd.[/trans]"]
368+
'
369+
);
370+
}
371+
296372
protected function renderForm(FormView $view, array $vars = [])
297373
{
298374
return (string) $this->renderer->renderBlock($view, 'form', $vars);

Tests/Extension/FormExtensionTableLayoutTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,82 @@ public function testHelpHtmlIsTrue()
179179
);
180180
}
181181

182+
public function testLabelWithTranslationParameters()
183+
{
184+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
185+
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
186+
'label_translation_parameters' => [
187+
'%address%' => 'Paris, rue de la Paix',
188+
],
189+
]);
190+
191+
$this->assertMatchesXpath($html,
192+
'/label
193+
[@for="name"]
194+
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
195+
'
196+
);
197+
}
198+
199+
public function testHelpWithTranslationParameters()
200+
{
201+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
202+
'help' => 'for company %company%',
203+
'help_translation_parameters' => [
204+
'%company%' => 'ACME Ltd.',
205+
],
206+
]);
207+
$html = $this->renderHelp($form->createView());
208+
209+
$this->assertMatchesXpath($html,
210+
'/*
211+
[@id="name_help"]
212+
[.="[trans]for company ACME Ltd.[/trans]"]
213+
'
214+
);
215+
}
216+
217+
public function testAttributesWithTranslationParameters()
218+
{
219+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
220+
'attr' => [
221+
'title' => 'Message to %company%',
222+
'placeholder' => 'Enter a message to %company%',
223+
],
224+
'attr_translation_parameters' => [
225+
'%company%' => 'ACME Ltd.',
226+
],
227+
]);
228+
$html = $this->renderWidget($form->createView());
229+
230+
$this->assertMatchesXpath($html,
231+
'/input
232+
[@title="[trans]Message to ACME Ltd.[/trans]"]
233+
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
234+
'
235+
);
236+
}
237+
238+
public function testButtonWithTranslationParameters()
239+
{
240+
$form = $this->factory->createNamedBuilder('myform')
241+
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
242+
'label' => 'Submit to %company%',
243+
'label_translation_parameters' => [
244+
'%company%' => 'ACME Ltd.',
245+
],
246+
])
247+
->getForm();
248+
$view = $form->get('mybutton')->createView();
249+
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
250+
251+
$this->assertMatchesXpath($html,
252+
'/button
253+
[.="[trans]Submit to ACME Ltd.[/trans]"]
254+
'
255+
);
256+
}
257+
182258
protected function renderForm(FormView $view, array $vars = [])
183259
{
184260
return (string) $this->renderer->renderBlock($view, 'form', $vars);

0 commit comments

Comments
 (0)