Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 401cf87

Browse files
committed
minor #30238 properly move test methods (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- properly move test methods | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 6bfc5f0 properly move test methods
2 parents b5b547d + 6bfc5f0 commit 401cf87

File tree

6 files changed

+304
-152
lines changed

6 files changed

+304
-152
lines changed

src/Symfony/Bridge/Twig/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);

src/Symfony/Bridge/Twig/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);

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,82 @@ public function testHelpHtmlIsTrue()
193193
);
194194
}
195195

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

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,82 @@ public function testHelpAttr()
7171
);
7272
}
7373

74+
public function testLabelWithTranslationParameters()
75+
{
76+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
77+
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
78+
'label_translation_parameters' => [
79+
'%address%' => 'Paris, rue de la Paix',
80+
],
81+
]);
82+
83+
$this->assertMatchesXpath($html,
84+
'/label
85+
[@for="name"]
86+
[.="[trans]Address is Paris, rue de la Paix[/trans]"]
87+
'
88+
);
89+
}
90+
91+
public function testHelpWithTranslationParameters()
92+
{
93+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
94+
'help' => 'for company %company%',
95+
'help_translation_parameters' => [
96+
'%company%' => 'ACME Ltd.',
97+
],
98+
]);
99+
$html = $this->renderHelp($form->createView());
100+
101+
$this->assertMatchesXpath($html,
102+
'/*
103+
[@id="name_help"]
104+
[.="[trans]for company ACME Ltd.[/trans]"]
105+
'
106+
);
107+
}
108+
109+
public function testAttributesWithTranslationParameters()
110+
{
111+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
112+
'attr' => [
113+
'title' => 'Message to %company%',
114+
'placeholder' => 'Enter a message to %company%',
115+
],
116+
'attr_translation_parameters' => [
117+
'%company%' => 'ACME Ltd.',
118+
],
119+
]);
120+
$html = $this->renderWidget($form->createView());
121+
122+
$this->assertMatchesXpath($html,
123+
'/input
124+
[@title="[trans]Message to ACME Ltd.[/trans]"]
125+
[@placeholder="[trans]Enter a message to ACME Ltd.[/trans]"]
126+
'
127+
);
128+
}
129+
130+
public function testButtonWithTranslationParameters()
131+
{
132+
$form = $this->factory->createNamedBuilder('myform')
133+
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
134+
'label' => 'Submit to %company%',
135+
'label_translation_parameters' => [
136+
'%company%' => 'ACME Ltd.',
137+
],
138+
])
139+
->getForm();
140+
$view = $form->get('mybutton')->createView();
141+
$html = $this->renderWidget($view, ['label_format' => 'form.%name%']);
142+
143+
$this->assertMatchesXpath($html,
144+
'/button
145+
[.="[trans]Submit to ACME Ltd.[/trans]"]
146+
'
147+
);
148+
}
149+
74150
protected function getExtensions()
75151
{
76152
// should be moved to the Form component once absolute file paths are supported

0 commit comments

Comments
 (0)