123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553 |
- <?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;
- use Symfony\Component\Form\FormError;
- abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
- {
- 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="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="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 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 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 control-label required"]
- [.="[trans]Custom label[/trans]"]
- '
- );
- }
- public function testErrors()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
- $form->addError(new FormError('[trans]Error 1[/trans]'));
- $form->addError(new FormError('[trans]Error 2[/trans]'));
- $view = $form->createView();
- $html = $this->renderErrors($view);
- $this->assertMatchesXpath($html,
- '/div
- [@class="alert alert-danger"]
- [
- ./ul
- [@class="list-unstyled"]
- [
- ./li
- [.=" [trans]Error 1[/trans]"]
- [
- ./span[@class="glyphicon glyphicon-exclamation-sign"]
- ]
- /following-sibling::li
- [.=" [trans]Error 2[/trans]"]
- [
- ./span[@class="glyphicon glyphicon-exclamation-sign"]
- ]
- ]
- [count(./li)=2]
- ]
- '
- );
- }
- public function testOverrideWidgetBlock()
- {
- // see custom_widgets.html.twig
- $form = $this->factory->createNamed('text_id', 'Symfony\Component\Form\Extension\Core\Type\TextType');
- $html = $this->renderWidget($form->createView());
- $this->assertMatchesXpath($html,
- '/div
- [
- ./input
- [@type="text"]
- [@id="text_id"]
- [@class="form-control"]
- ]
- [@id="container"]
- '
- );
- }
- public function testCheckedCheckbox()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true);
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('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 testUncheckedCheckbox()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', false);
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Name[/trans]"]
- [
- ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class"][not(@checked)]
- ]
- ]
- '
- );
- }
- public function testCheckboxWithValue()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', false, array(
- 'value' => 'foo&bar',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Name[/trans]"]
- [
- ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class"][@value="foo&bar"]
- ]
- ]
- '
- );
- }
- public function testSingleChoice()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [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 testSingleChoiceAttributesWithMainAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'attr' => array('class' => 'bar&baz'),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
- '/select
- [@name="name"]
- [@class="bar&baz form-control"]
- [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 testSingleExpandedChoiceAttributesWithMainAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- 'attr' => array('class' => 'bar&baz'),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'bar&baz')),
- '/div
- [@class="bar&baz"]
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSelectWithSizeBiggerThanOneCanBeRequired()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
- 'choices' => array('a', 'b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'attr' => array('size' => 2),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => '')),
- '/select
- [@name="name"]
- [@required="required"]
- [@size="2"]
- [count(./option)=2]
- '
- );
- }
- public function testSingleChoiceWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'choice_translation_domain' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value="&a"][@selected="selected"][.="Choice&A"]
- /following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
- ]
- [count(./option)=2]
- '
- );
- }
- public function testSingleChoiceWithPlaceholderWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'required' => false,
- 'translation_domain' => false,
- 'placeholder' => 'Placeholder&Not&Translated',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value=""][not(@selected)][not(@disabled)][.="Placeholder&Not&Translated"]
- /following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"]
- /following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
- 'multiple' => false,
- 'expanded' => false,
- ));
- $classPart = \in_array('choice_attr', $this->testableFeatures) ? '[@class="foo&bar"]' : '';
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"]'.$classPart.'[not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=2]
- '
- );
- }
- public function testSingleChoiceWithPreferred()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'preferred_choices' => array('&b'),
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('separator' => '-- sep --', 'attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- /following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceWithPreferredAndNoSeparator()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'preferred_choices' => array('&b'),
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('separator' => null, 'attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- ]
- [count(./option)=2]
- '
- );
- }
- public function testSingleChoiceWithPreferredAndBlankSeparator()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'preferred_choices' => array('&b'),
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('separator' => '', 'attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- /following-sibling::option[@disabled="disabled"][not(@selected)][.=""]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testChoiceWithOnlyPreferred()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'preferred_choices' => array('&a', '&b'),
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@class="my&class form-control"]
- [count(./option)=2]
- '
- );
- }
- public function testSingleChoiceNonRequired()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => false,
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value=""][.=""]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceNonRequiredNoneSelected()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => false,
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value=""][.=""]
- /following-sibling::option[@value="&a"][not(@selected)][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceNonRequiredWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'required' => false,
- 'placeholder' => 'Select&Anything&Not&Me',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [
- ./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Anything&Not&Me[/trans]"]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceRequiredWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => true,
- 'multiple' => false,
- 'expanded' => false,
- 'placeholder' => 'Test&Me',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [@required="required"]
- [
- ./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Test&Me[/trans]"]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceRequiredWithPlaceholderViaView()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => true,
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('placeholder' => '', 'attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [@required="required"]
- [
- ./option[@value=""][not(@selected)][not(@disabled)][.=""]
- /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=3]
- '
- );
- }
- public function testSingleChoiceGrouped()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array(
- 'Group&1' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'Group&2' => array('Choice&C' => '&c'),
- ),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [./optgroup[@label="[trans]Group&1[/trans]"]
- [
- ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=2]
- ]
- [./optgroup[@label="[trans]Group&2[/trans]"]
- [./option[@value="&c"][not(@selected)][.="[trans]Choice&C[/trans]"]]
- [count(./option)=1]
- ]
- [count(./optgroup)=2]
- '
- );
- }
- public function testMultipleChoice()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => true,
- 'multiple' => true,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name[]"]
- [@class="my&class form-control"]
- [@required="required"]
- [@multiple="multiple"]
- [
- ./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 testMultipleChoiceAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
- 'required' => true,
- 'multiple' => true,
- 'expanded' => false,
- ));
- $classPart = \in_array('choice_attr', $this->testableFeatures) ? '[@class="foo&bar"]' : '';
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name[]"]
- [@class="my&class form-control"]
- [@required="required"]
- [@multiple="multiple"]
- [
- ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
- /following-sibling::option[@value="&b"]'.$classPart.'[not(@selected)][.="[trans]Choice&B[/trans]"]
- ]
- [count(./option)=2]
- '
- );
- }
- public function testMultipleChoiceSkipsPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => true,
- 'expanded' => false,
- 'placeholder' => 'Test&Me',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name[]"]
- [@class="my&class form-control"]
- [@multiple="multiple"]
- [
- ./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 testMultipleChoiceNonRequired()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'required' => false,
- 'multiple' => true,
- 'expanded' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name[]"]
- [@class="my&class form-control"]
- [@multiple="multiple"]
- [
- ./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 testSingleChoiceExpanded()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithLabelsAsFalse()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_label' => false,
- 'multiple' => false,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithLabelsSetByCallable()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
- 'choices_as_values' => true,
- 'choice_label' => function ($choice, $label, $value) {
- if ('&b' === $choice) {
- return false;
- }
- return 'label.'.$value;
- },
- 'multiple' => false,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]label.&a[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]label.&c[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithLabelsSetFalseByCallable()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_label' => function () {
- return false;
- },
- 'multiple' => false,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- 'choice_translation_domain' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" Choice&A"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" Choice&B"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
- 'multiple' => false,
- 'expanded' => true,
- ));
- $classPart = \in_array('choice_attr', $this->testableFeatures) ? '[@class="foo&bar"]' : '';
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]'.$classPart.'
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- 'placeholder' => 'Test&Me',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Test&Me[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- 'required' => false,
- 'choice_translation_domain' => false,
- 'placeholder' => 'Placeholder&Not&Translated',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" Placeholder&Not&Translated"]
- [
- ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" Choice&A"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" Choice&B"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testSingleChoiceExpandedWithBooleanValue()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
- 'choices' => array('Choice&A' => '1', 'Choice&B' => '0'),
- 'choices_as_values' => true,
- 'multiple' => false,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_0"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="radio"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpanded()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
- 'choices_as_values' => true,
- 'multiple' => true,
- 'expanded' => true,
- 'required' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&C[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpandedWithLabelsAsFalse()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_label' => false,
- 'multiple' => true,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpandedWithLabelsSetByCallable()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
- 'choices_as_values' => true,
- 'choice_label' => function ($choice, $label, $value) {
- if ('&b' === $choice) {
- return false;
- }
- return 'label.'.$value;
- },
- 'multiple' => true,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]label.&a[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]label.&c[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
- 'choices_as_values' => true,
- 'choice_label' => function () {
- return false;
- },
- 'multiple' => true,
- 'expanded' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpandedWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
- 'choices_as_values' => true,
- 'multiple' => true,
- 'expanded' => true,
- 'required' => true,
- 'choice_translation_domain' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [.=" Choice&A"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" Choice&B"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" Choice&C"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testMultipleChoiceExpandedAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
- 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
- 'choices_as_values' => true,
- 'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
- 'multiple' => true,
- 'expanded' => true,
- 'required' => true,
- ));
- $classPart = \in_array('choice_attr', $this->testableFeatures) ? '[@class="foo&bar"]' : '';
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&A[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&B[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]'.$classPart.'
- ]
- ]
- /following-sibling::div
- [@class="checkbox"]
- [
- ./label
- [.=" [trans]Choice&C[/trans]"]
- [
- ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
- ]
- ]
- /following-sibling::input[@type="hidden"][@id="name__token"]
- ]
- '
- );
- }
- public function testCountry()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CountryType', 'AT');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [./option[@value="AT"][@selected="selected"][.="Austria"]]
- [count(./option)>200]
- '
- );
- }
- public function testCountryWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CountryType', 'AT', array(
- 'placeholder' => 'Select&Country',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Country[/trans]"]]
- [./option[@value="AT"][@selected="selected"][.="Austria"]]
- [count(./option)>201]
- '
- );
- }
- public function testDateTime()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', array(
- 'input' => 'string',
- 'with_seconds' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [
- ./select
- [@id="name_date_month"]
- [@class="form-control"]
- [./option[@value="2"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_day"]
- [@class="form-control"]
- [./option[@value="3"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_year"]
- [@class="form-control"]
- [./option[@value="'.date('Y').'"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_hour"]
- [@class="form-control"]
- [./option[@value="4"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_minute"]
- [@class="form-control"]
- [./option[@value="5"][@selected="selected"]]
- ]
- [count(.//select)=5]
- '
- );
- }
- public function testDateTimeWithPlaceholderGlobal()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
- 'input' => 'string',
- 'placeholder' => 'Change&Me',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_date_month"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_date_day"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_date_year"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_time_hour"]
- [@class="form-control"]
- [./option[@value=""][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_time_minute"]
- [@class="form-control"]
- [./option[@value=""][.="[trans]Change&Me[/trans]"]]
- ]
- [count(.//select)=5]
- '
- );
- }
- public function testDateTimeWithHourAndMinute()
- {
- $data = array('year' => date('Y'), 'month' => '2', 'day' => '3', 'hour' => '4', 'minute' => '5');
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', $data, array(
- 'input' => 'array',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_date_month"]
- [@class="form-control"]
- [./option[@value="2"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_day"]
- [@class="form-control"]
- [./option[@value="3"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_year"]
- [@class="form-control"]
- [./option[@value="'.date('Y').'"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_hour"]
- [@class="form-control"]
- [./option[@value="4"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_minute"]
- [@class="form-control"]
- [./option[@value="5"][@selected="selected"]]
- ]
- [count(.//select)=5]
- '
- );
- }
- public function testDateTimeWithSeconds()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', array(
- 'input' => 'string',
- 'with_seconds' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_date_month"]
- [@class="form-control"]
- [./option[@value="2"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_day"]
- [@class="form-control"]
- [./option[@value="3"][@selected="selected"]]
- /following-sibling::select
- [@id="name_date_year"]
- [@class="form-control"]
- [./option[@value="'.date('Y').'"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_hour"]
- [@class="form-control"]
- [./option[@value="4"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_minute"]
- [@class="form-control"]
- [./option[@value="5"][@selected="selected"]]
- /following-sibling::select
- [@id="name_time_second"]
- [@class="form-control"]
- [./option[@value="6"][@selected="selected"]]
- ]
- [count(.//select)=6]
- '
- );
- }
- public function testDateTimeSingleText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', array(
- 'input' => 'string',
- 'date_widget' => 'single_text',
- 'time_widget' => 'single_text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./input
- [@type="date"]
- [@id="name_date"]
- [@name="name[date]"]
- [@class="form-control"]
- [@value="2011-02-03"]
- /following-sibling::input
- [@type="time"]
- [@id="name_time"]
- [@name="name[time]"]
- [@class="form-control"]
- [@value="04:05"]
- ]
- '
- );
- }
- public function testDateTimeWithWidgetSingleText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', array(
- 'input' => 'string',
- 'widget' => 'single_text',
- 'model_timezone' => 'UTC',
- 'view_timezone' => 'UTC',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="datetime-local"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="2011-02-03T04:05:06"]
- '
- );
- }
- public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', array(
- 'input' => 'string',
- 'date_widget' => 'choice',
- 'time_widget' => 'choice',
- 'widget' => 'single_text',
- 'model_timezone' => 'UTC',
- 'view_timezone' => 'UTC',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="datetime-local"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="2011-02-03T04:05:06"]
- '
- );
- }
- public function testDateChoice()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', date('Y').'-02-03', array(
- 'input' => 'string',
- 'widget' => 'choice',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_month"]
- [@class="form-control"]
- [./option[@value="2"][@selected="selected"]]
- /following-sibling::select
- [@id="name_day"]
- [@class="form-control"]
- [./option[@value="3"][@selected="selected"]]
- /following-sibling::select
- [@id="name_year"]
- [@class="form-control"]
- [./option[@value="'.date('Y').'"][@selected="selected"]]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testDateChoiceWithPlaceholderGlobal()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
- 'input' => 'string',
- 'widget' => 'choice',
- 'placeholder' => 'Change&Me',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_month"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_day"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- /following-sibling::select
- [@id="name_year"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testDateChoiceWithPlaceholderOnYear()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
- 'input' => 'string',
- 'widget' => 'choice',
- 'required' => false,
- 'placeholder' => array('year' => 'Change&Me'),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_month"]
- [@class="form-control"]
- [./option[@value="1"]]
- /following-sibling::select
- [@id="name_day"]
- [@class="form-control"]
- [./option[@value="1"]]
- /following-sibling::select
- [@id="name_year"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testDateText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', '2011-02-03', array(
- 'input' => 'string',
- 'widget' => 'text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./input
- [@id="name_month"]
- [@type="text"]
- [@class="form-control"]
- [@value="2"]
- /following-sibling::input
- [@id="name_day"]
- [@type="text"]
- [@class="form-control"]
- [@value="3"]
- /following-sibling::input
- [@id="name_year"]
- [@type="text"]
- [@class="form-control"]
- [@value="2011"]
- ]
- [count(./input)=3]
- '
- );
- }
- public function testDateSingleText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', '2011-02-03', array(
- 'input' => 'string',
- 'widget' => 'single_text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="date"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="2011-02-03"]
- '
- );
- }
- public function testBirthDay()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '2000-02-03', array(
- 'input' => 'string',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_month"]
- [@class="form-control"]
- [./option[@value="2"][@selected="selected"]]
- /following-sibling::select
- [@id="name_day"]
- [@class="form-control"]
- [./option[@value="3"][@selected="selected"]]
- /following-sibling::select
- [@id="name_year"]
- [@class="form-control"]
- [./option[@value="2000"][@selected="selected"]]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testBirthDayWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '1950-01-01', array(
- 'input' => 'string',
- 'placeholder' => '',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_month"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.=""]]
- [./option[@value="1"][@selected="selected"]]
- /following-sibling::select
- [@id="name_day"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.=""]]
- [./option[@value="1"][@selected="selected"]]
- /following-sibling::select
- [@id="name_year"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.=""]]
- [./option[@value="1950"][@selected="selected"]]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testEmail()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\EmailType', 'foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="email"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- [not(@maxlength)]
- '
- );
- }
- public function testEmailWithMaxLength()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\EmailType', 'foo&bar', array(
- 'attr' => array('maxlength' => 123),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="email"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- [@maxlength="123"]
- '
- );
- }
- public function testHidden()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\HiddenType', 'foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="hidden"]
- [@name="name"]
- [@class="my&class"]
- [@value="foo&bar"]
- '
- );
- }
- /**
- * @group legacy
- */
- public function testLegacyReadOnly()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
- 'read_only' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@readonly="readonly"]
- '
- );
- }
- public function testDisabled()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
- 'disabled' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@disabled="disabled"]
- '
- );
- }
- public function testInteger()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 123);
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="number"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="123"]
- '
- );
- }
- public function testLanguage()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LanguageType', 'de');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [./option[@value="de"][@selected="selected"][.="German"]]
- [count(./option)>200]
- '
- );
- }
- public function testLocale()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LocaleType', 'de_AT');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [./option[@value="de_AT"][@selected="selected"][.="German (Austria)"]]
- [count(./option)>200]
- '
- );
- }
- public function testMoney()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType', 1234.56, array(
- 'currency' => 'EUR',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="input-group"]
- [
- ./span
- [@class="input-group-addon"]
- [contains(.., "€")]
- /following-sibling::input
- [@id="my&id"]
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="1234.56"]
- ]
- '
- );
- }
- public function testMoneyWithoutCurrency()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType', 1234.56, array(
- 'currency' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/input
- [@id="my&id"]
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="1234.56"]
- [not(preceding-sibling::*)]
- [not(following-sibling::*)]
- '
- );
- }
- public function testNumber()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56);
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="1234.56"]
- '
- );
- }
- public function testPassword()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', 'foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="password"]
- [@name="name"]
- [@class="my&class form-control"]
- '
- );
- }
- public function testPasswordSubmittedWithNotAlwaysEmpty()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', null, array(
- 'always_empty' => false,
- ));
- $form->submit('foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="password"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- '
- );
- }
- public function testPasswordWithMaxLength()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', 'foo&bar', array(
- 'attr' => array('maxlength' => 123),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="password"]
- [@name="name"]
- [@class="my&class form-control"]
- [@maxlength="123"]
- '
- );
- }
- public function testPercent()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1);
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="input-group"]
- [
- ./input
- [@id="my&id"]
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="10"]
- /following-sibling::span
- [@class="input-group-addon"]
- [contains(.., "%")]
- ]
- '
- );
- }
- public function testCheckedRadio()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RadioType', true);
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="radio"]
- [
- ./label
- [@class="required"]
- [
- ./input
- [@id="my&id"]
- [@type="radio"]
- [@name="name"]
- [@class="my&class"]
- [@checked="checked"]
- [@value="1"]
- ]
- ]
- '
- );
- }
- public function testUncheckedRadio()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RadioType', false);
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="radio"]
- [
- ./label
- [@class="required"]
- [
- ./input
- [@id="my&id"]
- [@type="radio"]
- [@name="name"]
- [@class="my&class"]
- [not(@checked)]
- ]
- ]
- '
- );
- }
- public function testRadioWithValue()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RadioType', false, array(
- 'value' => 'foo&bar',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
- '/div
- [@class="radio"]
- [
- ./label
- [@class="required"]
- [
- ./input
- [@id="my&id"]
- [@type="radio"]
- [@name="name"]
- [@class="my&class"]
- [@value="foo&bar"]
- ]
- ]
- '
- );
- }
- public function testRange()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RangeType', 42, array('attr' => array('min' => 5)));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="range"]
- [@name="name"]
- [@value="42"]
- [@min="5"]
- [@class="my&class form-control"]
- '
- );
- }
- public function testRangeWithMinMaxValues()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RangeType', 42, array('attr' => array('min' => 5, 'max' => 57)));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="range"]
- [@name="name"]
- [@value="42"]
- [@min="5"]
- [@max="57"]
- [@class="my&class form-control"]
- '
- );
- }
- public function testTextarea()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextareaType', 'foo&bar', array(
- 'attr' => array('pattern' => 'foo'),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/textarea
- [@name="name"]
- [@pattern="foo"]
- [@class="my&class form-control"]
- [.="foo&bar"]
- '
- );
- }
- public function testText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', 'foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- [not(@maxlength)]
- '
- );
- }
- public function testTextWithMaxLength()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', 'foo&bar', array(
- 'attr' => array('maxlength' => 123),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="text"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- [@maxlength="123"]
- '
- );
- }
- public function testSearch()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\SearchType', 'foo&bar');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="search"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="foo&bar"]
- [not(@maxlength)]
- '
- );
- }
- public function testTime()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', array(
- 'input' => 'string',
- 'with_seconds' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_hour"]
- [@class="form-control"]
- [not(@size)]
- [./option[@value="4"][@selected="selected"]]
- /following-sibling::select
- [@id="name_minute"]
- [@class="form-control"]
- [not(@size)]
- [./option[@value="5"][@selected="selected"]]
- ]
- [count(./select)=2]
- '
- );
- }
- public function testTimeWithSeconds()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', array(
- 'input' => 'string',
- 'with_seconds' => true,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_hour"]
- [@class="form-control"]
- [not(@size)]
- [./option[@value="4"][@selected="selected"]]
- [count(./option)>23]
- /following-sibling::select
- [@id="name_minute"]
- [@class="form-control"]
- [not(@size)]
- [./option[@value="5"][@selected="selected"]]
- [count(./option)>59]
- /following-sibling::select
- [@id="name_second"]
- [@class="form-control"]
- [not(@size)]
- [./option[@value="6"][@selected="selected"]]
- [count(./option)>59]
- ]
- [count(./select)=3]
- '
- );
- }
- public function testTimeText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', array(
- 'input' => 'string',
- 'widget' => 'text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./input
- [@type="text"]
- [@id="name_hour"]
- [@name="name[hour]"]
- [@class="form-control"]
- [@value="04"]
- [@required="required"]
- [not(@size)]
- /following-sibling::input
- [@type="text"]
- [@id="name_minute"]
- [@name="name[minute]"]
- [@class="form-control"]
- [@value="05"]
- [@required="required"]
- [not(@size)]
- ]
- [count(./input)=2]
- '
- );
- }
- public function testTimeSingleText()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', array(
- 'input' => 'string',
- 'widget' => 'single_text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="time"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="04:05"]
- [not(@size)]
- '
- );
- }
- public function testTimeWithPlaceholderGlobal()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
- 'input' => 'string',
- 'placeholder' => 'Change&Me',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_hour"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- [count(./option)>24]
- /following-sibling::select
- [@id="name_minute"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- [count(./option)>60]
- ]
- [count(./select)=2]
- '
- );
- }
- public function testTimeWithPlaceholderOnYear()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
- 'input' => 'string',
- 'required' => false,
- 'placeholder' => array('hour' => 'Change&Me'),
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/div
- [@class="my&class form-inline"]
- [
- ./select
- [@id="name_hour"]
- [@class="form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Change&Me[/trans]"]]
- [count(./option)>24]
- /following-sibling::select
- [@id="name_minute"]
- [./option[@value="1"]]
- [count(./option)>59]
- ]
- [count(./select)=2]
- '
- );
- }
- public function testTimezone()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimezoneType', 'Europe/Vienna');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@name="name"]
- [@class="my&class form-control"]
- [not(@required)]
- [./optgroup
- [@label="Europe"]
- [./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]]
- ]
- [count(./optgroup)>10]
- [count(.//option)>200]
- '
- );
- }
- public function testTimezoneWithPlaceholder()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimezoneType', null, array(
- 'placeholder' => 'Select&Timezone',
- 'required' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/select
- [@class="my&class form-control"]
- [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Timezone[/trans]"]]
- [count(./optgroup)>10]
- [count(.//option)>201]
- '
- );
- }
- public function testUrl()
- {
- $url = 'http://www.google.com?foo1=bar1&foo2=bar2';
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/input
- [@type="url"]
- [@name="name"]
- [@class="my&class form-control"]
- [@value="http://www.google.com?foo1=bar1&foo2=bar2"]
- '
- );
- }
- public function testButton()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/button[@type="button"][@name="name"][.="[trans]Name[/trans]"][@class="my&class btn"]'
- );
- }
- public function testButtonlabelWithoutTranslation()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, array(
- 'translation_domain' => false,
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/button[@type="button"][@name="name"][.="Name"][@class="my&class btn"]'
- );
- }
- public function testSubmit()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/button[@type="submit"][@name="name"][@class="my&class btn"]'
- );
- }
- public function testReset()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ResetType');
- $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
- '/button[@type="reset"][@name="name"][@class="my&class btn"]'
- );
- }
- public function testWidgetAttributes()
- {
- $form = $this->factory->createNamed('text', 'Symfony\Component\Form\Extension\Core\Type\TextType', 'value', array(
- 'required' => true,
- 'disabled' => true,
- 'attr' => array('readonly' => true, 'maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
- ));
- $html = $this->renderWidget($form->createView());
- // compare plain HTML to check the whitespace
- $this->assertSame('<input type="text" id="text" name="text" readonly="readonly" disabled="disabled" required="required" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
- }
- public function testWidgetAttributeNameRepeatedIfTrue()
- {
- $form = $this->factory->createNamed('text', 'Symfony\Component\Form\Extension\Core\Type\TextType', 'value', array(
- 'attr' => array('foo' => true),
- ));
- $html = $this->renderWidget($form->createView());
- // foo="foo"
- $this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value" />', $html);
- }
- public function testButtonAttributes()
- {
- $form = $this->factory->createNamed('button', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, array(
- 'disabled' => true,
- 'attr' => array('class' => 'foobar', 'data-foo' => 'bar'),
- ));
- $html = $this->renderWidget($form->createView());
- // compare plain HTML to check the whitespace
- $this->assertSame('<button type="button" id="button" name="button" disabled="disabled" class="foobar btn" data-foo="bar">[trans]Button[/trans]</button>', $html);
- }
- public function testButtonAttributeNameRepeatedIfTrue()
- {
- $form = $this->factory->createNamed('button', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, array(
- 'attr' => array('foo' => true),
- ));
- $html = $this->renderWidget($form->createView());
- // foo="foo"
- $this->assertSame('<button type="button" id="button" name="button" foo="foo" class="btn-default btn">[trans]Button[/trans]</button>', $html);
- }
- }
|