assertWidgetMatchesXpath example


        );
    }

    public function testCheckedCheckbox()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true);

        $this->assertWidgetMatchesXpath($form->createView()['id' => 'my&id', 'attr' => ['class' => 'my&class']],
            '/div [@class="checkbox"] [ ./label [.=" [trans]Name[/trans]"] [ ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class"][@checked="checked"][@value="1"] ] ] '
        );
    }

        );
    }

    public function testCheckedCheckbox()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true);

        $this->assertWidgetMatchesXpath($form->createView()[],
            '/input [@type="checkbox"] [@name="name"] [@checked="checked"] [@value="1"] '
        );
    }

    public function testUncheckedCheckbox()
    {
        
$form->addError(new FormError('[trans]Error 1[/trans]'));
        $view = $form->createView();
        $html = $this->renderLabel($view);

        $this->assertMatchesXpath($html, '//span[.="[trans]Error[/trans]"]');
    }

    public function testCheckedCheckbox()
    {
        $form = $this->factory->createNamed('name', CheckboxType::class, true);

        $this->assertWidgetMatchesXpath($form->createView()['id' => 'my&id', 'attr' => ['class' => 'my&class']],
            '/div [@class="form-check"] [ ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][@checked="checked"][@value="1"] /following-sibling::label [.="[trans]Name[/trans]"] [@class="form-check-label required"] ] '
        );
    }

    

        );
    }

    public function testCollection()
    {
        $form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', ['a', 'b'][
            'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
        ]);

        $this->assertWidgetMatchesXpath($form->createView()[],
            '/div [ ./div[./input[@type="text"][@value="a"]] /following-sibling::div[./input[@type="text"][@value="b"]] ] [count(./div[./input])=2] '
        );
    }

    // https://github.com/symfony/symfony/issues/5038


    public function testSingleChoiceAttributesWithMainAttributes()
    {
        $form = $this->factory->createNamed('name', ChoiceType::class, '&a', [
            'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
            'multiple' => false,
            'expanded' => false,
            'attr' => ['class' => 'bar&baz'],
        ]);

        $this->assertWidgetMatchesXpath($form->createView()['attr' => ['class' => 'bar&baz']],
            '/select [@name="name"] [@class="bar&baz form-select"] [not(@required)] [ ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"] /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"] ] [count(./option)=2] '
        );
    }

        );
    }

    public function testCollection()
    {
        $form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', ['a', 'b'][
            'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
        ]);

        $this->assertWidgetMatchesXpath($form->createView()[],
            '/table [ ./tr[./td/input[@type="text"][@value="a"]] /following-sibling::tr[./td/input[@type="text"][@value="b"]] /following-sibling::tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="names__token"]] ] [count(./tr[./td/input])=3] '
        );
    }

    
Home | Imprint | This part of the site doesn't use cookies.