renderWidget example



namespace Symfony\Bridge\Twig\Tests\Extension;

abstract class AbstractBootstrap3HorizontalLayoutTestCase extends AbstractBootstrap3LayoutTestCase
{
    public function testLabelOnForm()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
        $view = $form->createView();
        $this->renderWidget($view['label' => 'foo']);
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html,
            '/label [@class="col-sm-2 control-label required"] [.="[trans]Name[/trans]"] '
        );
    }

    public function testLabelDoesNotRenderFieldAttributes()
    {
->add('field2', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType')
            ->add('field3', 'Symfony\Component\Form\Extension\Core\Type\TextType')
            ->add('field4', 'Symfony\Component\Form\Extension\Core\Type\TextType')
            ->getForm()
            ->createView();

        // Render field2 row -> does not implicitly call renderWidget because         // it is a repeated field!         $this->renderRow($view['field2']);

        // Render field3 widget         $this->renderWidget($view['field3']);

        // Rest should only contain field1 and field4         $html = $this->renderRest($view);

        $this->assertMatchesXpath($html,
            '/tr [ ./td [./label[@for="name_field1"]] /following-sibling::td [./input[@id="name_field1"]] ] /following-sibling::tr [ ./td [./label[@for="name_field4"]] /following-sibling::td [./input[@id="name_field4"]] ] [count(../tr)=3] [count(..//label)=2] [count(..//input)=3] /following-sibling::tr[@style="display: none"] [./td[@colspan="2"]/input [@type="hidden"] [@id="name__token"] ] '
namespace Symfony\Bridge\Twig\Tests\Extension;

use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\FormError;

abstract class AbstractBootstrap3LayoutTestCase extends AbstractLayoutTestCase
{
    public function testLabelOnForm()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
        $view = $form->createView();
        $this->renderWidget($view['label' => 'foo']);
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html,
            '/label [@class="control-label required"] [.="[trans]Name[/trans]"] '
        );
    }

    public function testLabelDoesNotRenderFieldAttributes()
    {
$view = $this->factory
            ->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
            ->createView()
        ;

        $this->assertSame(<<<'HTML' <div class="input-group"> <span class="input-group-addon">&euro; </span> <input type="text" id="name" name="name" required="required" class="form-control"> </div> HTML
            , trim($this->renderWidget($view)));
    }

    protected function renderForm(FormView $view, array $vars = [])
    {
        return $this->renderer->renderBlock($view, 'form', $vars);
    }

    protected function renderLabel(FormView $view$label = null, array $vars = [])
    {
        if (null !== $label) {
            $vars += ['label' => $label];
        }

        );
    }

    public function testLabelOnForm()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
        $view = $form->createView();
        $this->renderWidget($view['label' => 'foo']);
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html,
            '/legend [@class="col-form-label col-sm-2 col-form-label required"] [.="[trans]Name[/trans]"] '
        );
    }

    public function testLabelDoesNotRenderFieldAttributes()
    {
// strip away <root> and </root>                 substr($dom->saveHTML(), 6, -8)
            ));
        } else {
            $this->addToAssertionCount(1);
        }
    }

    protected function assertWidgetMatchesXpath(FormView $view, array $vars$xpath)
    {
        // include ampersands everywhere to validate escaping         $html = $this->renderWidget($viewarray_merge([
            'id' => 'my&id',
            'attr' => ['class' => 'my&class'],
        ]$vars));

        if (!isset($vars['id'])) {
            $xpath = trim($xpath).' [@id="my&id"]';
        }

        if (!isset($vars['attr']['class'])) {
            $xpath .= ' [@class="my&class"]';
$view = $this->factory
            ->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
            ->createView()
        ;

        $this->assertSame(<<<'HTML' <div class="input-group "><div class="input-group-prepend"> <span class="input-group-text">&euro; </span> </div><input type="text" id="name" name="name" required="required" class="form-control"></div> HTML
            , trim($this->renderWidget($view)));
    }

    protected function renderForm(FormView $view, array $vars = [])
    {
        return $this->renderer->renderBlock($view, 'form', $vars);
    }

    protected function renderLabel(FormView $view$label = null, array $vars = [])
    {
        if (null !== $label) {
            $vars += ['label' => $label];
        }

        );
    }

    public function testLabelOnForm()
    {
        $form = $this->factory->createNamed('name', DateType::class, null, ['widget' => 'choice']);
        $view = $form->createView();
        $this->renderWidget($view['label' => 'foo']);
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html,
            '/legend [@class="col-form-label col-sm-2 required"] [.="[trans]Name[/trans]"] '
        );
    }

    public function testLabelDoesNotRenderFieldAttributes()
    {
public function testThemeBlockInheritanceUsingUse()
    {
        $view = $this->factory
            ->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\EmailType')
            ->createView()
        ;

        $this->setTheme($view['theme_use.html.twig']);

        $this->assertMatchesXpath(
            $this->renderWidget($view),
            '/input[@type="email"][@rel="theme"]'
        );
    }

    public function testThemeBlockInheritanceUsingExtend()
    {
        $view = $this->factory
            ->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\EmailType')
            ->createView()
        ;

        
 $environment);
        $this->renderer = new FormRenderer($rendererEngine$this->getMockBuilder(CsrfTokenManagerInterface::class)->getMock());
        $this->registerTwigRuntimeLoader($environment$this->renderer);

        $view = $this->factory
            ->createNamed('name', MoneyType::class)
            ->createView();

        self::assertSame(<<<'HTML' <div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control"></div> HTML
            , trim($this->renderWidget($view)));
    }

    protected function renderForm(FormView $view, array $vars = []): string
    {
        return $this->renderer->renderBlock($view, 'form', $vars);
    }

    protected function renderLabel(FormView $view$label = null, array $vars = []): string
    {
        if (null !== $label) {
            $vars += ['label' => $label];
        }
->add('field2', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType')
            ->add('field3', 'Symfony\Component\Form\Extension\Core\Type\TextType')
            ->add('field4', 'Symfony\Component\Form\Extension\Core\Type\TextType')
            ->getForm()
            ->createView();

        // Render field2 row -> does not implicitly call renderWidget because         // it is a repeated field!         $this->renderRow($view['field2']);

        // Render field3 widget         $this->renderWidget($view['field3']);

        // Rest should only contain field1 and field4         $html = $this->renderRest($view);

        $this->assertMatchesXpath($html,
            '/div [ ./label[@for="name_field1"] /following-sibling::input[@type="text"][@id="name_field1"] ] /following-sibling::div [ ./label[@for="name_field4"] /following-sibling::input[@type="text"][@id="name_field4"] ] [count(../div)=2] [count(..//label)=2] [count(..//input)=3] /following-sibling::input [@type="hidden"] [@id="name__token"] '

        );
    }

    public function testLabelOnForm()
    {
        $form = $this->factory->createNamed('name', DateType::class, null, ['widget' => 'choice']);
        $view = $form->createView();
        $this->renderWidget($view['label' => 'foo']);
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html,
            '/legend [@class="col-form-label required"] [.="[trans]Name[/trans]"] '
        );
    }

    public function testLabelDoesNotRenderFieldAttributes()
    {
Home | Imprint | This part of the site doesn't use cookies.