fix test for not configured form action attribute

This commit is contained in:
Christian Flothmann 2015-09-30 23:19:51 +02:00
parent dbb099dad6
commit 54c63fabf0
7 changed files with 62 additions and 2 deletions

View File

@ -274,7 +274,7 @@
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
<form name="{{ name }}" method="{{ form_method|lower }}"{% if action %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
<form name="{{ name }}" method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}

View File

@ -74,6 +74,18 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
$this->assertSame('<form name="form" method="get">', $html);
}
public function testStartTagHasActionAttributeWhenActionIsZero()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '0',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -153,6 +153,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame('<form name="form" method="get">', $html);
}
public function testStartTagHasActionAttributeWhenActionIsZero()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '0',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -75,6 +75,18 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
$this->assertSame('<form name="form" method="get">', $html);
}
public function testStartTagHasActionAttributeWhenActionIsZero()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '0',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -1,6 +1,6 @@
<?php $method = strtoupper($method) ?>
<?php $form_method = $method === 'GET' || $method === 'POST' ? $method : 'POST' ?>
<form name="<?php echo $name ?>" method="<?php echo strtolower($form_method) ?>"<?php if ($action): ?> action="<?php echo $action ?>"<?php endif ?><?php foreach ($attr as $k => $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?><?php if ($multipart): ?> enctype="multipart/form-data"<?php endif ?>>
<form name="<?php echo $name ?>" method="<?php echo strtolower($form_method) ?>"<?php if ($action !== ''): ?> action="<?php echo $action ?>"<?php endif ?><?php foreach ($attr as $k => $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?><?php if ($multipart): ?> enctype="multipart/form-data"<?php endif ?>>
<?php if ($form_method !== $method): ?>
<input type="hidden" name="_method" value="<?php echo $method ?>" />
<?php endif ?>

View File

@ -73,6 +73,18 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame('<form name="form" method="get">', $html);
}
public function testStartTagHasActionAttributeWhenActionIsZero()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '0',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->engine->get('form')->form($view, $vars);

View File

@ -43,6 +43,18 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
$this->assertSame('<form name="form" method="get">', $html);
}
public function testStartTagHasActionAttributeWhenActionIsZero()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '0',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
protected function getExtensions()
{
// should be moved to the Form component once absolute file paths are supported