-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[WIP] [Form] [TwigBridge] Bootstrap horizontal theme missing tests #16351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Tests\Extension; | ||
|
||
use Symfony\Bridge\Twig\Extension\FormExtension; | ||
use Symfony\Bridge\Twig\Form\TwigRenderer; | ||
use Symfony\Bridge\Twig\Form\TwigRendererEngine; | ||
use Symfony\Bridge\Twig\Extension\TranslationExtension; | ||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; | ||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\Form\Tests\AbstractBootstrap3HorizontalLayoutTest; | ||
|
||
class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest | ||
{ | ||
/** | ||
* @var FormExtension | ||
*/ | ||
protected $extension; | ||
|
||
protected $testableFeatures = array( | ||
'choice_attr', | ||
); | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$rendererEngine = new TwigRendererEngine(array( | ||
'bootstrap_3_horizontal_layout.html.twig', | ||
'custom_widgets.html.twig', | ||
)); | ||
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); | ||
|
||
$this->extension = new FormExtension($renderer); | ||
|
||
$loader = new StubFilesystemLoader(array( | ||
__DIR__.'/../../Resources/views/Form', | ||
__DIR__.'/Fixtures/templates/form', | ||
)); | ||
|
||
$environment = new \Twig_Environment($loader, array('strict_variables' => true)); | ||
$environment->addExtension(new TranslationExtension(new StubTranslator())); | ||
$environment->addExtension($this->extension); | ||
|
||
$this->extension->initRuntime($environment); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->extension = null; | ||
} | ||
|
||
protected function renderForm(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars); | ||
} | ||
|
||
protected function renderEnctype(FormView $view) | ||
{ | ||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype'); | ||
} | ||
|
||
protected function renderLabel(FormView $view, $label = null, array $vars = array()) | ||
{ | ||
if ($label !== null) { | ||
$vars += array('label' => $label); | ||
} | ||
|
||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars); | ||
} | ||
|
||
protected function renderErrors(FormView $view) | ||
{ | ||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors'); | ||
} | ||
|
||
protected function renderWidget(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars); | ||
} | ||
|
||
protected function renderRow(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars); | ||
} | ||
|
||
protected function renderRest(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars); | ||
} | ||
|
||
protected function renderStart(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars); | ||
} | ||
|
||
protected function renderEnd(FormView $view, array $vars = array()) | ||
{ | ||
return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars); | ||
} | ||
|
||
protected function setTheme(FormView $view, array $themes) | ||
{ | ||
$this->extension->renderer->setTheme($view, $themes); | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Tests; | ||
|
||
abstract class AbstractBootstrap3HorizontalLayoutTest extends AbstractBootstrap3LayoutTest | ||
{ | ||
public function testLabelOnForm() | ||
{ | ||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType'); | ||
$view = $form->createView(); | ||
$this->renderWidget($view, array('label' => 'foo')); | ||
$html = $this->renderLabel($view); | ||
|
||
$this->assertMatchesXpath($html, | ||
'/label | ||
[@class="col-sm-2 control-label required"] | ||
[.="[trans]Name[/trans]"] | ||
' | ||
); | ||
} | ||
|
||
public function testLabelDoesNotRenderFieldAttributes() | ||
{ | ||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); | ||
$html = $this->renderLabel($form->createView(), null, array( | ||
'attr' => array( | ||
'class' => 'my&class', | ||
), | ||
)); | ||
|
||
$this->assertMatchesXpath($html, | ||
'/label | ||
[@for="name"] | ||
[@class="col-sm-2 control-label required"] | ||
' | ||
); | ||
} | ||
|
||
public function testLabelWithCustomAttributesPassedDirectly() | ||
{ | ||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); | ||
$html = $this->renderLabel($form->createView(), null, array( | ||
'label_attr' => array( | ||
'class' => 'my&class', | ||
), | ||
)); | ||
|
||
$this->assertMatchesXpath($html, | ||
'/label | ||
[@for="name"] | ||
[@class="my&class col-sm-2 control-label required"] | ||
' | ||
); | ||
} | ||
|
||
public function testLabelWithCustomTextAndCustomAttributesPassedDirectly() | ||
{ | ||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); | ||
$html = $this->renderLabel($form->createView(), 'Custom label', array( | ||
'label_attr' => array( | ||
'class' => 'my&class', | ||
), | ||
)); | ||
|
||
$this->assertMatchesXpath($html, | ||
'/label | ||
[@for="name"] | ||
[@class="my&class col-sm-2 control-label required"] | ||
[.="[trans]Custom label[/trans]"] | ||
' | ||
); | ||
} | ||
|
||
public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly() | ||
{ | ||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array( | ||
'label' => 'Custom label', | ||
)); | ||
$html = $this->renderLabel($form->createView(), null, array( | ||
'label_attr' => array( | ||
'class' => 'my&class', | ||
), | ||
)); | ||
|
||
$this->assertMatchesXpath($html, | ||
'/label | ||
[@for="name"] | ||
[@class="my&class col-sm-2 control-label required"] | ||
[.="[trans]Custom label[/trans]"] | ||
' | ||
); | ||
} | ||
|
||
public function testStartTag() | ||
{ | ||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( | ||
'method' => 'get', | ||
'action' => 'http://example.com/directory', | ||
)); | ||
|
||
$html = $this->renderStart($form->createView()); | ||
|
||
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal">', $html); | ||
} | ||
|
||
public function testStartTagWithOverriddenVars() | ||
{ | ||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( | ||
'method' => 'put', | ||
'action' => 'http://example.com/directory', | ||
)); | ||
|
||
$html = $this->renderStart($form->createView(), array( | ||
'method' => 'post', | ||
'action' => 'http://foo.com/directory', | ||
)); | ||
|
||
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" class="form-horizontal">', $html); | ||
} | ||
|
||
public function testStartTagForMultipartForm() | ||
{ | ||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( | ||
'method' => 'get', | ||
'action' => 'http://example.com/directory', | ||
)) | ||
->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType') | ||
->getForm(); | ||
|
||
$html = $this->renderStart($form->createView()); | ||
|
||
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" enctype="multipart/form-data">', $html); | ||
} | ||
|
||
public function testStartTagWithExtraAttributes() | ||
{ | ||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( | ||
'method' => 'get', | ||
'action' => 'http://example.com/directory', | ||
)); | ||
|
||
$html = $this->renderStart($form->createView(), array( | ||
'attr' => array('class' => 'foobar'), | ||
)); | ||
|
||
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you added
{##}
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was the only why I could think of to have a 'space control' between the two closing div tags without having to use
spaceless
. I guess the last closing div can also be moved directly to the end of the previous one, but that will break the indents.