FormHelperTest.php 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712
  1. <?php
  2. /**
  3. * FormHelperTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @since CakePHP(tm) v 1.2.0.4206
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\View\Helper;
  18. use Cake\Controller\Controller;
  19. use Cake\Core\App;
  20. use Cake\Core\Configure;
  21. use Cake\Core\Plugin;
  22. use Cake\Network\Request;
  23. use Cake\ORM\Entity;
  24. use Cake\ORM\Table;
  25. use Cake\ORM\TableRegistry;
  26. use Cake\Routing\Router;
  27. use Cake\TestSuite\TestCase;
  28. use Cake\Utility\Security;
  29. use Cake\View\Helper\FormHelper;
  30. use Cake\View\Helper\HtmlHelper;
  31. use Cake\View\View;
  32. /**
  33. * Test stub.
  34. */
  35. class Article extends Entity {
  36. }
  37. /**
  38. * ContactTestController class
  39. *
  40. */
  41. class ContactTestController extends Controller {
  42. /**
  43. * uses property
  44. *
  45. * @var mixed null
  46. */
  47. public $uses = null;
  48. }
  49. /**
  50. * Contact class
  51. *
  52. */
  53. class ContactsTable extends Table {
  54. /**
  55. * Default schema
  56. *
  57. * @var array
  58. */
  59. protected $_schema = array(
  60. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  61. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  62. 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  63. 'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  64. 'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  65. 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
  66. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  67. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
  68. 'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
  69. );
  70. /**
  71. * validate property
  72. *
  73. * @var array
  74. */
  75. public $validate = array(
  76. 'non_existing' => array(),
  77. 'idontexist' => array(),
  78. 'imrequired' => array('_allowEmpty' => false, array('rule' => array('between', 5, 30))),
  79. 'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
  80. 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
  81. 'imrequiredonboth' => array(
  82. 'required' => array('rule' => 'alphaNumeric'),
  83. ),
  84. 'string_required' => 'notEmpty',
  85. 'imalsorequired' => array('_allowEmpty' => false, array('rule' => 'alphaNumeric')),
  86. 'imrequiredtoo' => array('rule' => 'notEmpty'),
  87. 'required_one' => array('required' => array('rule' => array('notEmpty'))),
  88. 'imnotrequired' => array(
  89. '_allowEmpty' => true,
  90. array('rule' => 'alphaNumeric')
  91. ),
  92. 'imalsonotrequired' => array(
  93. '_allowEmpty' => true,
  94. 'alpha' => array('rule' => 'alphaNumeric'),
  95. 'between' => array('rule' => array('between', 5, 30)),
  96. ),
  97. 'imnotrequiredeither' => array(
  98. '_allowEmpty' => true,
  99. array('rule' => array('between', 5, 30))
  100. ),
  101. 'iamrequiredalways' => array(
  102. 'email' => array('rule' => 'email'),
  103. 'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
  104. 'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
  105. ),
  106. 'boolean_field' => array('rule' => 'boolean')
  107. );
  108. /**
  109. * schema method
  110. *
  111. * @return void
  112. */
  113. public function setSchema($schema) {
  114. $this->_schema = $schema;
  115. }
  116. /**
  117. * hasAndBelongsToMany property
  118. *
  119. * @var array
  120. */
  121. public $hasAndBelongsToMany = array(
  122. 'ContactTag' => array(
  123. 'className' => 'Cake\Test\TestCase\View\Helper\ContactTag',
  124. 'with' => 'Cake\Test\TestCase\View\Helper\ContactTagsContact'
  125. )
  126. );
  127. /**
  128. * hasAndBelongsToMany property
  129. *
  130. * @var array
  131. */
  132. public $belongsTo = array(
  133. 'User' => array('className' => 'UserForm'
  134. ));
  135. }
  136. /**
  137. * ContactTagsContact class
  138. *
  139. */
  140. class ContactTagsContactsTable extends Table {
  141. /**
  142. * Default schema
  143. *
  144. * @var array
  145. */
  146. protected $_schema = array(
  147. 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  148. 'contact_tag_id' => array(
  149. 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
  150. )
  151. );
  152. /**
  153. * schema method
  154. *
  155. * @return void
  156. */
  157. public function setSchema($schema) {
  158. $this->_schema = $schema;
  159. }
  160. }
  161. /**
  162. * ContactNonStandardPk class
  163. *
  164. */
  165. class ContactNonStandardPk extends ContactsTable {
  166. /**
  167. * primaryKey property
  168. *
  169. * @var string
  170. */
  171. public $primaryKey = 'pk';
  172. /**
  173. * schema method
  174. *
  175. * @return void
  176. */
  177. public function schema($field = false) {
  178. $this->_schema = parent::schema();
  179. $this->_schema['pk'] = $this->_schema['id'];
  180. unset($this->_schema['id']);
  181. return $this->_schema;
  182. }
  183. }
  184. /**
  185. * ContactTag class
  186. *
  187. */
  188. class ContactTagsTable extends Table {
  189. /**
  190. * schema definition
  191. *
  192. * @var array
  193. */
  194. protected $_schema = array(
  195. 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
  196. 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  197. 'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
  198. 'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
  199. );
  200. }
  201. /**
  202. * UserForm class
  203. *
  204. */
  205. class UserFormsTable extends Table {
  206. /**
  207. * hasMany property
  208. *
  209. * @var array
  210. */
  211. public $hasMany = array(
  212. 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
  213. ));
  214. /**
  215. * schema definition
  216. *
  217. * @var array
  218. */
  219. protected $_schema = array(
  220. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  221. 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
  222. 'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
  223. 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
  224. 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
  225. 'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
  226. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  227. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  228. );
  229. }
  230. /**
  231. * OpenidUrl class
  232. *
  233. */
  234. class OpenidUrlsTable extends Table {
  235. /**
  236. * belongsTo property
  237. *
  238. * @var array
  239. */
  240. public $belongsTo = array('UserForm' => array(
  241. 'className' => 'UserForm', 'foreignKey' => 'user_form_id'
  242. ));
  243. /**
  244. * validate property
  245. *
  246. * @var array
  247. */
  248. public $validate = array('openid_not_registered' => array());
  249. /**
  250. * schema method
  251. *
  252. * @var array
  253. */
  254. protected $_schema = array(
  255. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  256. 'user_form_id' => array(
  257. 'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
  258. ),
  259. 'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  260. );
  261. /**
  262. * beforeValidate method
  263. *
  264. * @return void
  265. */
  266. public function beforeValidate($options = array()) {
  267. $this->invalidate('openid_not_registered');
  268. return true;
  269. }
  270. }
  271. /**
  272. * ValidateUser class
  273. *
  274. */
  275. class ValidateUsersTable extends Table {
  276. /**
  277. * hasOne property
  278. *
  279. * @var array
  280. */
  281. public $hasOne = array('ValidateProfile' => array(
  282. 'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
  283. ));
  284. /**
  285. * schema method
  286. *
  287. * @var array
  288. */
  289. protected $_schema = array(
  290. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  291. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  292. 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  293. 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
  294. 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'),
  295. 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'),
  296. 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'),
  297. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  298. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  299. );
  300. /**
  301. * beforeValidate method
  302. *
  303. * @return void
  304. */
  305. public function beforeValidate($options = array()) {
  306. $this->invalidate('email');
  307. return false;
  308. }
  309. }
  310. /**
  311. * ValidateProfile class
  312. *
  313. */
  314. class ValidateProfilesTable extends Table {
  315. /**
  316. * useTable property
  317. *
  318. * @var boolean
  319. */
  320. public $useTable = false;
  321. /**
  322. * schema property
  323. *
  324. * @var array
  325. */
  326. protected $_schema = array(
  327. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  328. 'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  329. 'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  330. 'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  331. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  332. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  333. );
  334. /**
  335. * hasOne property
  336. *
  337. * @var array
  338. */
  339. public $hasOne = array('ValidateItem' => array(
  340. 'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
  341. ));
  342. /**
  343. * belongsTo property
  344. *
  345. * @var array
  346. */
  347. public $belongsTo = array('ValidateUser' => array(
  348. 'className' => 'ValidateUser', 'foreignKey' => 'user_id'
  349. ));
  350. /**
  351. * beforeValidate method
  352. *
  353. * @return void
  354. */
  355. public function beforeValidate($options = array()) {
  356. $this->invalidate('full_name');
  357. $this->invalidate('city');
  358. return false;
  359. }
  360. }
  361. /**
  362. * ValidateItem class
  363. *
  364. */
  365. class ValidateItemsTable extends Table {
  366. /**
  367. * schema property
  368. *
  369. * @var array
  370. */
  371. protected $_schema = array(
  372. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  373. 'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  374. 'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
  375. 'description' => array(
  376. 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
  377. ),
  378. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  379. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  380. );
  381. /**
  382. * belongsTo property
  383. *
  384. * @var array
  385. */
  386. public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
  387. /**
  388. * beforeValidate method
  389. *
  390. * @return void
  391. */
  392. public function beforeValidate($options = array()) {
  393. $this->invalidate('description');
  394. return false;
  395. }
  396. }
  397. /**
  398. * TestMail class
  399. *
  400. */
  401. class TestMailsTable extends Table {
  402. }
  403. /**
  404. * FormHelperTest class
  405. *
  406. * @property FormHelper $Form
  407. */
  408. class FormHelperTest extends TestCase {
  409. /**
  410. * Fixtures to be used
  411. *
  412. * @var array
  413. */
  414. public $fixtures = array('core.article');
  415. /**
  416. * Do not load the fixtures by default
  417. *
  418. * @var boolean
  419. */
  420. public $autoFixtures = false;
  421. /**
  422. * setUp method
  423. *
  424. * @return void
  425. */
  426. public function setUp() {
  427. parent::setUp();
  428. Configure::write('Config.language', 'eng');
  429. Configure::write('App.base', '');
  430. Configure::write('App.namespace', 'Cake\Test\TestCase\View\Helper');
  431. Configure::delete('Asset');
  432. $this->View = new View(null);
  433. $this->Form = new FormHelper($this->View);
  434. $this->Form->Html = new HtmlHelper($this->View);
  435. $this->Form->request = new Request('articles/add');
  436. $this->Form->request->here = '/articles/add';
  437. $this->Form->request['controller'] = 'articles';
  438. $this->Form->request['action'] = 'add';
  439. $this->Form->request->webroot = '';
  440. $this->Form->request->base = '';
  441. $this->dateRegex = array(
  442. 'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
  443. 'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
  444. 'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
  445. 'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
  446. 'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
  447. 'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
  448. );
  449. $this->article = [
  450. 'schema' => [
  451. 'id' => ['type' => 'integer'],
  452. 'author_id' => ['type' => 'integer', 'null' => true],
  453. 'title' => ['type' => 'string', 'null' => true],
  454. 'body' => 'text',
  455. 'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
  456. '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
  457. ],
  458. 'required' => [
  459. 'author_id' => true,
  460. 'title' => true,
  461. ]
  462. ];
  463. Configure::write('Security.salt', 'foo!');
  464. Router::connect('/:controller', array('action' => 'index'));
  465. Router::connect('/:controller/:action/*');
  466. }
  467. /**
  468. * tearDown method
  469. *
  470. * @return void
  471. */
  472. public function tearDown() {
  473. parent::tearDown();
  474. unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
  475. }
  476. /**
  477. * Test registering a new widget class and rendering it.
  478. *
  479. * @return void
  480. */
  481. public function testAddWidgetAndRenderWidget() {
  482. $data = [
  483. 'val' => 1
  484. ];
  485. $mock = $this->getMock('Cake\View\Widget\WidgetInterface');
  486. $this->assertNull($this->Form->addWidget('test', $mock));
  487. $mock->expects($this->once())
  488. ->method('render')
  489. ->with($data)
  490. ->will($this->returnValue('HTML'));
  491. $result = $this->Form->widget('test', $data);
  492. $this->assertEquals('HTML', $result);
  493. }
  494. /**
  495. * Test registering an invalid widget class.
  496. *
  497. * @expectedException \RuntimeException
  498. * @return void
  499. */
  500. public function testAddWidgetInvalid() {
  501. $mock = new \StdClass();
  502. $this->Form->addWidget('test', $mock);
  503. $this->Form->widget('test');
  504. }
  505. /**
  506. * Test adding a new context class.
  507. *
  508. * @return void
  509. */
  510. public function testAddContextProvider() {
  511. $context = 'My data';
  512. $this->Form->addContextProvider('test', function ($request, $data) use ($context) {
  513. $this->assertInstanceOf('Cake\Network\Request', $request);
  514. $this->assertEquals($context, $data['entity']);
  515. return $this->getMock('Cake\View\Form\ContextInterface');
  516. });
  517. $this->Form->create($context);
  518. }
  519. /**
  520. * Test adding an invalid context class.
  521. *
  522. * @expectedException RuntimeException
  523. * @expectedExceptionMessage Context objects must implement Cake\View\Form\ContextInterface
  524. * @return void
  525. */
  526. public function testAddContextProviderInvalid() {
  527. $context = 'My data';
  528. $this->Form->addContextProvider('test', function ($request, $data) use ($context) {
  529. return new \StdClass();
  530. });
  531. $this->Form->create($context);
  532. }
  533. /**
  534. * Provides context options for create().
  535. *
  536. * @return array
  537. */
  538. public function contextSelectionProvider() {
  539. $entity = new Article();
  540. $collection = $this->getMock('Cake\Collection\Collection', ['extract'], [[$entity]]);
  541. $data = [
  542. 'schema' => [
  543. 'title' => ['type' => 'string']
  544. ]
  545. ];
  546. return [
  547. 'entity' => [$entity, 'Cake\View\Form\EntityContext'],
  548. 'collection' => [$collection, 'Cake\View\Form\EntityContext'],
  549. 'array' => [$data, 'Cake\View\Form\ArrayContext'],
  550. 'none' => [null, 'Cake\View\Form\NullContext'],
  551. 'false' => [false, 'Cake\View\Form\NullContext'],
  552. ];
  553. }
  554. /**
  555. * Test default context selection in create()
  556. *
  557. * @dataProvider contextSelectionProvider
  558. * @return void
  559. */
  560. public function testCreateContextSelectionBuiltIn($data, $class) {
  561. $this->loadFixtures('Article');
  562. $this->Form->create($data);
  563. $this->assertInstanceOf($class, $this->Form->context());
  564. }
  565. /**
  566. * Data provider for type option.
  567. *
  568. * @return array
  569. */
  570. public static function requestTypeProvider() {
  571. return [
  572. // type, method, override
  573. ['post', 'post', 'POST'],
  574. ['put', 'post', 'PUT'],
  575. ['patch', 'post', 'PATCH'],
  576. ['delete', 'post', 'DELETE'],
  577. ];
  578. }
  579. /**
  580. * Test creating file forms.
  581. *
  582. * @return void
  583. */
  584. public function testCreateFile() {
  585. $encoding = strtolower(Configure::read('App.encoding'));
  586. $result = $this->Form->create(false, array('type' => 'file'));
  587. $expected = array(
  588. 'form' => array(
  589. 'method' => 'post', 'action' => '/articles/add',
  590. 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
  591. ),
  592. 'div' => array('style' => 'display:none;'),
  593. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  594. '/div'
  595. );
  596. $this->assertTags($result, $expected);
  597. }
  598. /**
  599. * Test creating GET forms.
  600. *
  601. * @return void
  602. */
  603. public function testCreateGet() {
  604. $encoding = strtolower(Configure::read('App.encoding'));
  605. $result = $this->Form->create(false, array('type' => 'get'));
  606. $expected = array('form' => array(
  607. 'method' => 'get', 'action' => '/articles/add',
  608. 'accept-charset' => $encoding
  609. ));
  610. $this->assertTags($result, $expected);
  611. }
  612. /**
  613. * test the create() method
  614. *
  615. * @dataProvider requestTypeProvider
  616. * @return void
  617. */
  618. public function testCreateTypeOptions($type, $method, $override) {
  619. $encoding = strtolower(Configure::read('App.encoding'));
  620. $result = $this->Form->create(false, array('type' => $type));
  621. $expected = array(
  622. 'form' => array(
  623. 'method' => $method, 'action' => '/articles/add',
  624. 'accept-charset' => $encoding
  625. ),
  626. 'div' => array('style' => 'display:none;'),
  627. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => $override),
  628. '/div'
  629. );
  630. $this->assertTags($result, $expected);
  631. }
  632. /**
  633. * Test opening a form for an update operation.
  634. *
  635. * @return void
  636. */
  637. public function testCreateUpdateForm() {
  638. $encoding = strtolower(Configure::read('App.encoding'));
  639. $this->Form->request->here = '/articles/edit/1';
  640. $this->Form->request['action'] = 'edit';
  641. $this->article['defaults']['id'] = 1;
  642. $result = $this->Form->create($this->article);
  643. $expected = array(
  644. 'form' => array(
  645. 'method' => 'post', 'action' => '/articles/edit/1',
  646. 'accept-charset' => $encoding
  647. ),
  648. 'div' => array('style' => 'display:none;'),
  649. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  650. '/div'
  651. );
  652. $this->assertTags($result, $expected);
  653. }
  654. /**
  655. * Test the onsubmit option for create()
  656. *
  657. * @return void
  658. */
  659. public function testCreateOnSubmit() {
  660. $this->Form->request->data = [];
  661. $this->Form->request['controller'] = 'articles';
  662. $result = $this->Form->create($this->article, ['url' => ['action' => 'index', 'param'], 'default' => false]);
  663. $expected = array(
  664. 'form' => array(
  665. 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/articles/index/param',
  666. 'accept-charset' => 'utf-8'
  667. ),
  668. 'div' => array('style' => 'display:none;'),
  669. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  670. '/div'
  671. );
  672. $this->assertTags($result, $expected);
  673. $this->Form->request->data = [];
  674. $this->Form->request['controller'] = 'articles';
  675. $result = $this->Form->create($this->article, array(
  676. 'url' => array('action' => 'index', 'param'),
  677. 'default' => false,
  678. 'onsubmit' => 'someFunction();'
  679. ));
  680. $expected = array(
  681. 'form' => array(
  682. 'method' => 'post',
  683. 'onsubmit' => 'someFunction();event.returnValue = false; return false;',
  684. 'action' => '/articles/index/param',
  685. 'accept-charset' => 'utf-8'
  686. ),
  687. 'div' => array('style' => 'display:none;'),
  688. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  689. '/div'
  690. );
  691. $this->assertTags($result, $expected);
  692. }
  693. /**
  694. * test create() with automatic url generation
  695. *
  696. * @return void
  697. */
  698. public function testCreateAutoUrl() {
  699. $encoding = strtolower(Configure::read('App.encoding'));
  700. $this->Form->request['action'] = 'delete';
  701. $this->Form->request->here = '/articles/delete/10';
  702. $this->Form->request->base = '';
  703. $result = $this->Form->create($this->article);
  704. $expected = array(
  705. 'form' => array(
  706. 'method' => 'post', 'action' => '/articles/delete/10',
  707. 'accept-charset' => $encoding
  708. ),
  709. 'div' => array('style' => 'display:none;'),
  710. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  711. '/div'
  712. );
  713. $this->assertTags($result, $expected);
  714. $this->article['defaults'] = ['id' => 1];
  715. $this->Form->request->here = '/articles/edit/1';
  716. $this->Form->request['action'] = 'delete';
  717. $result = $this->Form->create($this->article, ['action' => 'edit']);
  718. $expected = array(
  719. 'form' => array(
  720. 'method' => 'post',
  721. 'action' => '/articles/edit/1',
  722. 'accept-charset' => $encoding
  723. ),
  724. 'div' => array('style' => 'display:none;'),
  725. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  726. '/div'
  727. );
  728. $this->assertTags($result, $expected);
  729. $this->Form->request['action'] = 'add';
  730. $result = $this->Form->create($this->article, ['url' => ['action' => 'publish']]);
  731. $expected = array(
  732. 'form' => array(
  733. 'method' => 'post',
  734. 'action' => '/articles/publish/1',
  735. 'accept-charset' => $encoding
  736. ),
  737. 'div' => array('style' => 'display:none;'),
  738. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  739. '/div'
  740. );
  741. $this->assertTags($result, $expected);
  742. $result = $this->Form->create($this->article, array('url' => '/articles/publish'));
  743. $expected = array(
  744. 'form' => array('method' => 'post', 'action' => '/articles/publish', 'accept-charset' => $encoding),
  745. 'div' => array('style' => 'display:none;'),
  746. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  747. '/div'
  748. );
  749. $this->assertTags($result, $expected);
  750. $this->Form->request['controller'] = 'pages';
  751. $result = $this->Form->create($this->article, array('action' => 'signup'));
  752. $expected = array(
  753. 'form' => array(
  754. 'method' => 'post', 'action' => '/pages/signup/1',
  755. 'accept-charset' => $encoding
  756. ),
  757. 'div' => array('style' => 'display:none;'),
  758. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  759. '/div'
  760. );
  761. $this->assertTags($result, $expected);
  762. }
  763. /**
  764. * test create() with a custom route
  765. *
  766. * @return void
  767. */
  768. public function testCreateCustomRoute() {
  769. Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
  770. $encoding = strtolower(Configure::read('App.encoding'));
  771. $this->Form->request['controller'] = 'users';
  772. $result = $this->Form->create(false, array('action' => 'login'));
  773. $expected = array(
  774. 'form' => array(
  775. 'method' => 'post', 'action' => '/login',
  776. 'accept-charset' => $encoding
  777. ),
  778. 'div' => array('style' => 'display:none;'),
  779. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  780. '/div'
  781. );
  782. $this->assertTags($result, $expected);
  783. }
  784. /**
  785. * test that inputDefaults are stored and used.
  786. *
  787. * @return void
  788. */
  789. public function testCreateWithInputDefaults() {
  790. $this->markTestIncomplete('Need to revisit once models work again.');
  791. $this->Form->create('User', array(
  792. 'inputDefaults' => array(
  793. 'div' => false,
  794. 'label' => false,
  795. 'error' => array('attributes' => array('wrap' => 'small', 'class' => 'error')),
  796. 'format' => array('before', 'label', 'between', 'input', 'after', 'error')
  797. )
  798. ));
  799. $result = $this->Form->input('username');
  800. $expected = array(
  801. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername')
  802. );
  803. $this->assertTags($result, $expected);
  804. $result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
  805. $expected = array(
  806. 'div' => array('class' => 'input text'),
  807. 'label' => array('for' => 'UserUsername'), 'username', '/label',
  808. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  809. '/div'
  810. );
  811. $this->assertTags($result, $expected);
  812. $result = $this->Form->input('username', array('label' => 'Username', 'format' => array('input', 'label')));
  813. $expected = array(
  814. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  815. 'label' => array('for' => 'UserUsername'), 'Username', '/label',
  816. );
  817. $this->assertTags($result, $expected);
  818. $this->Form->create('User', array(
  819. 'inputDefaults' => array(
  820. 'div' => false,
  821. 'label' => array('class' => 'nice', 'for' => 'changed'),
  822. )
  823. ));
  824. $result = $this->Form->input('username', array('div' => true));
  825. $expected = array(
  826. 'div' => array('class' => 'input text'),
  827. 'label' => array('for' => 'changed', 'class' => 'nice'), 'Username', '/label',
  828. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  829. '/div'
  830. );
  831. $this->assertTags($result, $expected);
  832. }
  833. /**
  834. * test automatic accept-charset overriding
  835. *
  836. * @return void
  837. */
  838. public function testCreateWithAcceptCharset() {
  839. $this->markTestIncomplete('Need to revisit once models work again.');
  840. $result = $this->Form->create('UserForm', array(
  841. 'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
  842. )
  843. );
  844. $expected = array(
  845. 'form' => array(
  846. 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
  847. 'accept-charset' => 'iso-8859-1'
  848. ),
  849. 'div' => array('style' => 'display:none;'),
  850. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  851. '/div'
  852. );
  853. $this->assertTags($result, $expected);
  854. }
  855. /**
  856. * Test base form URL when url param is passed with multiple parameters (&)
  857. *
  858. */
  859. public function testCreateQuerystringrequest() {
  860. $this->markTestIncomplete('Need to revisit once models work again.');
  861. $encoding = strtolower(Configure::read('App.encoding'));
  862. $result = $this->Form->create('Contact', array(
  863. 'type' => 'post',
  864. 'escape' => false,
  865. 'url' => array(
  866. 'controller' => 'controller',
  867. 'action' => 'action',
  868. '?' => array('param1' => 'value1', 'param2' => 'value2')
  869. )
  870. ));
  871. $expected = array(
  872. 'form' => array(
  873. 'id' => 'ContactAddForm',
  874. 'method' => 'post',
  875. 'action' => '/controller/action?param1=value1&amp;param2=value2',
  876. 'accept-charset' => $encoding
  877. ),
  878. 'div' => array('style' => 'display:none;'),
  879. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  880. '/div'
  881. );
  882. $this->assertTags($result, $expected);
  883. $result = $this->Form->create('Contact', array(
  884. 'type' => 'post',
  885. 'url' => array(
  886. 'controller' => 'controller',
  887. 'action' => 'action',
  888. '?' => array('param1' => 'value1', 'param2' => 'value2')
  889. )
  890. ));
  891. $expected = array(
  892. 'form' => array(
  893. 'id' => 'ContactAddForm',
  894. 'method' => 'post',
  895. 'action' => '/controller/action?param1=value1&amp;param2=value2',
  896. 'accept-charset' => $encoding
  897. ),
  898. 'div' => array('style' => 'display:none;'),
  899. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  900. '/div'
  901. );
  902. $this->assertTags($result, $expected);
  903. }
  904. /**
  905. * test that create() doesn't cause errors by multiple id's being in the primary key
  906. * as could happen with multiple select or checkboxes.
  907. *
  908. * @return void
  909. */
  910. public function testCreateWithMultipleIdInData() {
  911. $this->markTestIncomplete('Need to revisit once models work again.');
  912. $encoding = strtolower(Configure::read('App.encoding'));
  913. $this->Form->request->data['Contact']['id'] = array(1, 2);
  914. $result = $this->Form->create('Contact');
  915. $expected = array(
  916. 'form' => array(
  917. 'id' => 'ContactAddForm',
  918. 'method' => 'post',
  919. 'action' => '/contacts/add',
  920. 'accept-charset' => $encoding
  921. ),
  922. 'div' => array('style' => 'display:none;'),
  923. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  924. '/div'
  925. );
  926. $this->assertTags($result, $expected);
  927. }
  928. /**
  929. * test that create() doesn't add in extra passed params.
  930. *
  931. * @return void
  932. */
  933. public function testCreatePassedArgs() {
  934. $this->markTestIncomplete('Need to revisit once models work again.');
  935. $encoding = strtolower(Configure::read('App.encoding'));
  936. $this->Form->request->data['Contact']['id'] = 1;
  937. $result = $this->Form->create('Contact', array(
  938. 'type' => 'post',
  939. 'escape' => false,
  940. 'url' => array(
  941. 'action' => 'edit',
  942. 'myparam'
  943. )
  944. ));
  945. $expected = array(
  946. 'form' => array(
  947. 'id' => 'ContactAddForm',
  948. 'method' => 'post',
  949. 'action' => '/contacts/edit/myparam',
  950. 'accept-charset' => $encoding
  951. ),
  952. 'div' => array('style' => 'display:none;'),
  953. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  954. '/div'
  955. );
  956. $this->assertTags($result, $expected);
  957. }
  958. /**
  959. * test creating a get form, and get form inputs.
  960. *
  961. * @return void
  962. */
  963. public function testGetFormCreate() {
  964. $this->markTestIncomplete('Need to revisit once models work again.');
  965. $encoding = strtolower(Configure::read('App.encoding'));
  966. $result = $this->Form->create('Contact', array('type' => 'get'));
  967. $this->assertTags($result, array('form' => array(
  968. 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
  969. 'accept-charset' => $encoding
  970. )));
  971. $result = $this->Form->text('Contact.name');
  972. $this->assertTags($result, array('input' => array(
  973. 'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
  974. )));
  975. $result = $this->Form->password('password');
  976. $this->assertTags($result, array('input' => array(
  977. 'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
  978. )));
  979. $this->assertNotRegExp('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
  980. $result = $this->Form->text('user_form');
  981. $this->assertTags($result, array('input' => array(
  982. 'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
  983. )));
  984. }
  985. /**
  986. * test get form, and inputs when the model param is false
  987. *
  988. * @return void
  989. */
  990. public function testGetFormWithFalseModel() {
  991. $this->markTestIncomplete('Need to revisit once models work again.');
  992. $encoding = strtolower(Configure::read('App.encoding'));
  993. $this->Form->request['controller'] = 'contact_test';
  994. $result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
  995. $expected = array('form' => array(
  996. 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
  997. 'accept-charset' => $encoding
  998. ));
  999. $this->assertTags($result, $expected);
  1000. $result = $this->Form->text('reason');
  1001. $expected = array(
  1002. 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
  1003. );
  1004. $this->assertTags($result, $expected);
  1005. }
  1006. /**
  1007. * testFormCreateWithSecurity method
  1008. *
  1009. * Test form->create() with security key.
  1010. *
  1011. * @return void
  1012. */
  1013. public function testCreateWithSecurity() {
  1014. $this->Form->request->params['_csrfToken'] = 'testKey';
  1015. $encoding = strtolower(Configure::read('App.encoding'));
  1016. $result = $this->Form->create($this->article, [
  1017. 'url' => '/articles/publish',
  1018. ]);
  1019. $expected = array(
  1020. 'form' => array('method' => 'post', 'action' => '/articles/publish', 'accept-charset' => $encoding),
  1021. 'div' => array('style' => 'display:none;'),
  1022. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  1023. array('input' => array(
  1024. 'type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testKey'
  1025. )),
  1026. '/div'
  1027. );
  1028. $this->assertTags($result, $expected);
  1029. $result = $this->Form->create($this->article, ['url' => '/articles/publish', 'id' => 'MyForm']);
  1030. $expected['form']['id'] = 'MyForm';
  1031. $this->assertTags($result, $expected);
  1032. }
  1033. /**
  1034. * testFormCreateGetNoSecurity method
  1035. *
  1036. * Test form->create() with no security key as its a get form
  1037. *
  1038. * @return void
  1039. */
  1040. public function testCreateEndGetNoSecurity() {
  1041. $this->Form->request->params['_csrfToken'] = 'testKey';
  1042. $encoding = strtolower(Configure::read('App.encoding'));
  1043. $article = new Article();
  1044. $result = $this->Form->create($article, [
  1045. 'type' => 'get',
  1046. 'url' => '/contacts/add'
  1047. ]);
  1048. $this->assertNotContains('testKey', $result);
  1049. $result = $this->Form->end('Save');
  1050. $this->assertNotContains('testKey', $result);
  1051. }
  1052. /**
  1053. * test that create() clears the fields property so it starts fresh
  1054. *
  1055. * @return void
  1056. */
  1057. public function testCreateClearingFields() {
  1058. $this->Form->fields = array('model_id');
  1059. $this->Form->create($this->article);
  1060. $this->assertEquals(array(), $this->Form->fields);
  1061. }
  1062. /**
  1063. * Tests form hash generation with model-less data
  1064. *
  1065. * @return void
  1066. */
  1067. public function testValidateHashNoModel() {
  1068. $this->Form->request->params['_Token'] = 'foo';
  1069. $result = $this->Form->secure(array('anything'));
  1070. $this->assertRegExp('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
  1071. }
  1072. /**
  1073. * Tests that models with identical field names get resolved properly
  1074. *
  1075. * @return void
  1076. */
  1077. public function testDuplicateFieldNameResolution() {
  1078. $this->markTestIncomplete('Need to revisit once models work again.');
  1079. $result = $this->Form->create('ValidateUser');
  1080. $this->assertEquals(array('ValidateUser'), $this->Form->entity());
  1081. $result = $this->Form->input('ValidateItem.name');
  1082. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1083. $result = $this->Form->input('ValidateUser.name');
  1084. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1085. $this->assertContains('name="ValidateUser[name]"', $result);
  1086. $this->assertContains('type="text"', $result);
  1087. $result = $this->Form->input('ValidateItem.name');
  1088. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1089. $this->assertContains('name="ValidateItem[name]"', $result);
  1090. $this->assertContains('<textarea', $result);
  1091. $result = $this->Form->input('name');
  1092. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1093. $this->assertContains('name="ValidateUser[name]"', $result);
  1094. $this->assertContains('type="text"', $result);
  1095. }
  1096. /**
  1097. * Tests that hidden fields generated for checkboxes don't get locked
  1098. *
  1099. * @return void
  1100. */
  1101. public function testNoCheckboxLocking() {
  1102. $this->Form->request->params['_Token'] = 'foo';
  1103. $this->assertSame([], $this->Form->fields);
  1104. $this->Form->checkbox('check', array('value' => '1'));
  1105. $this->assertSame($this->Form->fields, array('check'));
  1106. }
  1107. /**
  1108. * testFormSecurityFields method
  1109. *
  1110. * Test generation of secure form hash generation.
  1111. *
  1112. * @return void
  1113. */
  1114. public function testFormSecurityFields() {
  1115. $this->markTestIncomplete('Need to revisit once models work again.');
  1116. $key = 'testKey';
  1117. $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
  1118. $this->Form->request->params['_csrfToken'] = $key;
  1119. $result = $this->Form->secure($fields);
  1120. $hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
  1121. $hash .= ':' . 'Model.valid';
  1122. $hash = urlencode($hash);
  1123. $expected = array(
  1124. 'div' => array('style' => 'display:none;'),
  1125. array('input' => array(
  1126. 'type' => 'hidden', 'name' => '_Token[fields]',
  1127. 'value' => $hash
  1128. )),
  1129. array('input' => array(
  1130. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1131. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1132. )),
  1133. '/div'
  1134. );
  1135. $this->assertTags($result, $expected);
  1136. $path = CAKE . 'Test/TestApp/Config/';
  1137. $this->Form->Html->loadConfig('htmlhelper_tags', $path);
  1138. $result = $this->Form->secure($fields);
  1139. $expected = array(
  1140. 'div' => array('class' => 'hidden'),
  1141. array('input' => array(
  1142. 'type' => 'hidden', 'name' => '_Token[fields]',
  1143. 'value' => $hash
  1144. )),
  1145. array('input' => array(
  1146. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1147. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1148. )),
  1149. '/div'
  1150. );
  1151. $this->assertTags($result, $expected);
  1152. }
  1153. /**
  1154. * Tests correct generation of number fields for double and float fields
  1155. *
  1156. * @return void
  1157. */
  1158. public function testTextFieldGenerationForFloats() {
  1159. $this->markTestIncomplete('Need to revisit once models work again.');
  1160. $this->article['schema'] = [
  1161. 'foo' => [
  1162. 'type' => 'float',
  1163. 'null' => false,
  1164. 'default' => null,
  1165. 'length' => 10
  1166. ]
  1167. ];
  1168. $this->Form->create('Contact');
  1169. $result = $this->Form->input('foo');
  1170. $expected = array(
  1171. 'div' => array('class' => 'input number'),
  1172. 'label' => array('for' => 'ContactFoo'),
  1173. 'Foo',
  1174. '/label',
  1175. array('input' => array(
  1176. 'type' => 'number',
  1177. 'name' => 'Contact[foo]',
  1178. 'id' => 'ContactFoo',
  1179. 'step' => 'any'
  1180. )),
  1181. '/div'
  1182. );
  1183. $this->assertTags($result, $expected);
  1184. $result = $this->Form->input('foo', array('step' => 0.5));
  1185. $expected = array(
  1186. 'div' => array('class' => 'input number'),
  1187. 'label' => array('for' => 'ContactFoo'),
  1188. 'Foo',
  1189. '/label',
  1190. array('input' => array(
  1191. 'type' => 'number',
  1192. 'name' => 'Contact[foo]',
  1193. 'id' => 'ContactFoo',
  1194. 'step' => '0.5'
  1195. )),
  1196. '/div'
  1197. );
  1198. $this->assertTags($result, $expected);
  1199. }
  1200. /**
  1201. * Tests correct generation of number fields for integer fields
  1202. *
  1203. * @return void
  1204. */
  1205. public function testTextFieldTypeNumberGenerationForIntegers() {
  1206. $this->markTestIncomplete('Need to revisit once models work again.');
  1207. $model->setSchema(array('foo' => array(
  1208. 'type' => 'integer',
  1209. 'null' => false,
  1210. 'default' => null,
  1211. 'length' => null
  1212. )));
  1213. $this->Form->create('Contact');
  1214. $result = $this->Form->input('foo');
  1215. $expected = array(
  1216. 'div' => array('class' => 'input number'),
  1217. 'label' => array('for' => 'ContactFoo'),
  1218. 'Foo',
  1219. '/label',
  1220. array('input' => array(
  1221. 'type' => 'number', 'name' => 'Contact[foo]',
  1222. 'id' => 'ContactFoo'
  1223. )),
  1224. '/div'
  1225. );
  1226. $this->assertTags($result, $expected);
  1227. }
  1228. /**
  1229. * Tests correct generation of file upload fields for binary fields
  1230. *
  1231. * @return void
  1232. */
  1233. public function testFileUploadFieldTypeGenerationForBinaries() {
  1234. $this->markTestIncomplete('Need to revisit once models work again.');
  1235. $model->setSchema(array('foo' => array(
  1236. 'type' => 'binary',
  1237. 'null' => false,
  1238. 'default' => null,
  1239. 'length' => 1024
  1240. )));
  1241. $this->Form->create('Contact');
  1242. $result = $this->Form->input('foo');
  1243. $expected = array(
  1244. 'div' => array('class' => 'input file'),
  1245. 'label' => array('for' => 'ContactFoo'),
  1246. 'Foo',
  1247. '/label',
  1248. array('input' => array(
  1249. 'type' => 'file', 'name' => 'data[Contact][foo]',
  1250. 'id' => 'ContactFoo'
  1251. )),
  1252. '/div'
  1253. );
  1254. $this->assertTags($result, $expected);
  1255. }
  1256. /**
  1257. * testFormSecurityMultipleFields method
  1258. *
  1259. * Test secure() with multiple row form. Ensure hash is correct.
  1260. *
  1261. * @return void
  1262. */
  1263. public function testFormSecurityMultipleFields() {
  1264. $this->Form->request->params['_Token'] = 'foo';
  1265. $fields = array(
  1266. 'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
  1267. 'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
  1268. 'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
  1269. );
  1270. $result = $this->Form->secure($fields);
  1271. $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
  1272. $hash .= '%7CModel.1.hidden%7CModel.1.valid';
  1273. $expected = array(
  1274. 'div' => array('style' => 'display:none;'),
  1275. array('input' => array(
  1276. 'type' => 'hidden', 'name' => '_Token[fields]',
  1277. 'value' => $hash
  1278. )),
  1279. array('input' => array(
  1280. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1281. 'value' => ''
  1282. )),
  1283. '/div'
  1284. );
  1285. $this->assertTags($result, $expected);
  1286. }
  1287. /**
  1288. * testFormSecurityMultipleSubmitButtons
  1289. *
  1290. * test form submit generation and ensure that _Token is only created on end()
  1291. *
  1292. * @return void
  1293. */
  1294. public function testFormSecurityMultipleSubmitButtons() {
  1295. $this->markTestIncomplete('Need to revisit once models work again.');
  1296. $key = 'testKey';
  1297. $this->Form->request->params['_csrfToken'] = $key;
  1298. $this->Form->create('Addresses');
  1299. $this->Form->input('Address.title');
  1300. $this->Form->input('Address.first_name');
  1301. $result = $this->Form->submit('Save', array('name' => 'save'));
  1302. $expected = array(
  1303. 'div' => array('class' => 'submit'),
  1304. 'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
  1305. '/div',
  1306. );
  1307. $this->assertTags($result, $expected);
  1308. $result = $this->Form->submit('Cancel', array('name' => 'cancel'));
  1309. $expected = array(
  1310. 'div' => array('class' => 'submit'),
  1311. 'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
  1312. '/div',
  1313. );
  1314. $this->assertTags($result, $expected);
  1315. $result = $this->Form->end(null);
  1316. $expected = array(
  1317. 'div' => array('style' => 'display:none;'),
  1318. array('input' => array(
  1319. 'type' => 'hidden', 'name' => '_Token[fields]',
  1320. 'value' => 'preg:/.+/'
  1321. )),
  1322. array('input' => array(
  1323. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1324. 'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
  1325. )),
  1326. '/div'
  1327. );
  1328. $this->assertTags($result, $expected);
  1329. }
  1330. /**
  1331. * Test that buttons created with foo[bar] name attributes are unlocked correctly.
  1332. *
  1333. * @return void
  1334. */
  1335. public function testSecurityButtonNestedNamed() {
  1336. $key = 'testKey';
  1337. $this->Form->request->params['_csrfToken'] = $key;
  1338. $this->Form->create('Addresses');
  1339. $this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1340. $result = $this->Form->unlockField();
  1341. $this->assertEquals(array('Address.button'), $result);
  1342. }
  1343. /**
  1344. * Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
  1345. *
  1346. * @return void
  1347. */
  1348. public function testSecuritySubmitNestedNamed() {
  1349. $this->markTestIncomplete('Need to revisit once models work again.');
  1350. $key = 'testKey';
  1351. $this->Form->request->params['_csrfToken'] = $key;
  1352. $this->Form->create('Addresses');
  1353. $this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1354. $result = $this->Form->unlockField();
  1355. $this->assertEquals(array('Address.button'), $result);
  1356. }
  1357. /**
  1358. * Test that the correct fields are unlocked for image submits with no names.
  1359. *
  1360. * @return void
  1361. */
  1362. public function testSecuritySubmitImageNoName() {
  1363. $this->markTestIncomplete('Need to revisit once models work again.');
  1364. $key = 'testKey';
  1365. $this->Form->request->params['_csrfToken'] = $key;
  1366. $this->Form->create('User');
  1367. $result = $this->Form->submit('save.png');
  1368. $expected = array(
  1369. 'div' => array('class' => 'submit'),
  1370. 'input' => array('type' => 'image', 'src' => 'img/save.png'),
  1371. '/div'
  1372. );
  1373. $this->assertTags($result, $expected);
  1374. $this->assertEquals(array('x', 'y'), $this->Form->unlockField());
  1375. }
  1376. /**
  1377. * Test that the correct fields are unlocked for image submits with names.
  1378. *
  1379. * @return void
  1380. */
  1381. public function testSecuritySubmitImageName() {
  1382. $this->markTestIncomplete('Need to revisit once models work again.');
  1383. $key = 'testKey';
  1384. $this->Form->request->params['_csrfToken'] = $key;
  1385. $this->Form->create('User');
  1386. $result = $this->Form->submit('save.png', array('name' => 'test'));
  1387. $expected = array(
  1388. 'div' => array('class' => 'submit'),
  1389. 'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
  1390. '/div'
  1391. );
  1392. $this->assertTags($result, $expected);
  1393. $this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
  1394. }
  1395. /**
  1396. * testFormSecurityMultipleInputFields method
  1397. *
  1398. * Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
  1399. *
  1400. * @return void
  1401. */
  1402. public function testFormSecurityMultipleInputFields() {
  1403. $this->markTestIncomplete('Need to revisit once models work again.');
  1404. $key = 'testKey';
  1405. $this->Form->request->params['_csrfToken'] = $key;
  1406. $this->Form->create('Addresses');
  1407. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1408. $this->Form->input('Addresses.0.title');
  1409. $this->Form->input('Addresses.0.first_name');
  1410. $this->Form->input('Addresses.0.last_name');
  1411. $this->Form->input('Addresses.0.address');
  1412. $this->Form->input('Addresses.0.city');
  1413. $this->Form->input('Addresses.0.phone');
  1414. $this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
  1415. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1416. $this->Form->input('Addresses.1.title');
  1417. $this->Form->input('Addresses.1.first_name');
  1418. $this->Form->input('Addresses.1.last_name');
  1419. $this->Form->input('Addresses.1.address');
  1420. $this->Form->input('Addresses.1.city');
  1421. $this->Form->input('Addresses.1.phone');
  1422. $this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
  1423. $result = $this->Form->secure($this->Form->fields);
  1424. $hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
  1425. $expected = array(
  1426. 'div' => array('style' => 'display:none;'),
  1427. array('input' => array(
  1428. 'type' => 'hidden', 'name' => '_Token[fields]',
  1429. 'value' => $hash
  1430. )),
  1431. array('input' => array(
  1432. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1433. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1434. )),
  1435. '/div'
  1436. );
  1437. $this->assertTags($result, $expected);
  1438. }
  1439. /**
  1440. * Test form security with Model.field.0 style inputs
  1441. *
  1442. * @return void
  1443. */
  1444. public function testFormSecurityArrayFields() {
  1445. $this->markTestIncomplete('Need to revisit once models work again.');
  1446. $key = 'testKey';
  1447. $this->Form->request->params['_csrfToken'] = $key;
  1448. $this->Form->create('Address');
  1449. $this->Form->input('Address.primary.1');
  1450. $this->assertEquals('Address.primary', $this->Form->fields[0]);
  1451. $this->Form->input('Address.secondary.1.0');
  1452. $this->assertEquals('Address.secondary', $this->Form->fields[1]);
  1453. }
  1454. /**
  1455. * testFormSecurityMultipleInputDisabledFields method
  1456. *
  1457. * test secure form generation with multiple records and disabled fields.
  1458. *
  1459. * @return void
  1460. */
  1461. public function testFormSecurityMultipleInputDisabledFields() {
  1462. $this->markTestIncomplete('Need to revisit once models work again.');
  1463. $key = 'testKey';
  1464. $this->Form->request->params['_csrfToken'] = $key;
  1465. $this->Form->request->params['_Token'] = array(
  1466. 'unlockedFields' => array('first_name', 'address')
  1467. );
  1468. $this->Form->create();
  1469. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1470. $this->Form->input('Addresses.0.title');
  1471. $this->Form->input('Addresses.0.first_name');
  1472. $this->Form->input('Addresses.0.last_name');
  1473. $this->Form->input('Addresses.0.address');
  1474. $this->Form->input('Addresses.0.city');
  1475. $this->Form->input('Addresses.0.phone');
  1476. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1477. $this->Form->input('Addresses.1.title');
  1478. $this->Form->input('Addresses.1.first_name');
  1479. $this->Form->input('Addresses.1.last_name');
  1480. $this->Form->input('Addresses.1.address');
  1481. $this->Form->input('Addresses.1.city');
  1482. $this->Form->input('Addresses.1.phone');
  1483. $result = $this->Form->secure($this->Form->fields);
  1484. $hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';
  1485. $expected = array(
  1486. 'div' => array('style' => 'display:none;'),
  1487. array('input' => array(
  1488. 'type' => 'hidden', 'name' => '_Token[fields]',
  1489. 'value' => $hash
  1490. )),
  1491. array('input' => array(
  1492. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1493. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1494. )),
  1495. '/div'
  1496. );
  1497. $this->assertTags($result, $expected);
  1498. }
  1499. /**
  1500. * testFormSecurityInputDisabledFields method
  1501. *
  1502. * Test single record form with disabled fields.
  1503. *
  1504. * @return void
  1505. */
  1506. public function testFormSecurityInputUnlockedFields() {
  1507. $this->markTestIncomplete('Need to revisit once models work again.');
  1508. $key = 'testKey';
  1509. $this->Form->request->params['_csrfToken'] = $key;
  1510. $this->Form->request['_Token'] = array(
  1511. 'unlockedFields' => array('first_name', 'address')
  1512. );
  1513. $this->Form->create();
  1514. $this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
  1515. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1516. $this->Form->input('Addresses.title');
  1517. $this->Form->input('Addresses.first_name');
  1518. $this->Form->input('Addresses.last_name');
  1519. $this->Form->input('Addresses.address');
  1520. $this->Form->input('Addresses.city');
  1521. $this->Form->input('Addresses.phone');
  1522. $result = $this->Form->fields;
  1523. $expected = array(
  1524. 'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
  1525. 'Addresses.city', 'Addresses.phone'
  1526. );
  1527. $this->assertEquals($expected, $result);
  1528. $result = $this->Form->secure($expected);
  1529. $hash = '2981c38990f3f6ba935e6561dc77277966fabd6d%3AAddresses.id';
  1530. $expected = array(
  1531. 'div' => array('style' => 'display:none;'),
  1532. array('input' => array(
  1533. 'type' => 'hidden', 'name' => '_Token[fields]',
  1534. 'value' => $hash
  1535. )),
  1536. array('input' => array(
  1537. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1538. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1539. )),
  1540. '/div'
  1541. );
  1542. $this->assertTags($result, $expected);
  1543. }
  1544. /**
  1545. * test securing inputs with custom name attributes.
  1546. *
  1547. * @return void
  1548. */
  1549. public function testFormSecureWithCustomNameAttribute() {
  1550. $this->markTestIncomplete('Need to revisit once models work again.');
  1551. $this->Form->request->params['_csrfToken'] = 'testKey';
  1552. $this->Form->text('UserForm.published', array('name' => 'User[custom]'));
  1553. $this->assertEquals('User.custom', $this->Form->fields[0]);
  1554. $this->Form->text('UserForm.published', array('name' => 'User[custom][another][value]'));
  1555. $this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
  1556. }
  1557. /**
  1558. * testFormSecuredInput method
  1559. *
  1560. * Test generation of entire secure form, assertions made on input() output.
  1561. *
  1562. * @return void
  1563. */
  1564. public function testFormSecuredInput() {
  1565. $this->markTestIncomplete('Need to revisit once models work again.');
  1566. $this->Form->request->params['_csrfToken'] = 'testKey';
  1567. $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
  1568. $encoding = strtolower(Configure::read('App.encoding'));
  1569. $expected = array(
  1570. 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
  1571. 'div' => array('style' => 'display:none;'),
  1572. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  1573. array('input' => array(
  1574. 'type' => 'hidden', 'name' => '_csrfToken',
  1575. 'value' => 'testKey', 'id' => 'preg:/Token\d+/'
  1576. )),
  1577. '/div'
  1578. );
  1579. $this->assertTags($result, $expected);
  1580. $result = $this->Form->input('ValidateUser.ratio');
  1581. $expected = array(
  1582. 'div' => array('class'),
  1583. 'label' => array('for'),
  1584. 'Ratio',
  1585. '/label',
  1586. 'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'),
  1587. '/div',
  1588. );
  1589. $this->assertTags($result, $expected);
  1590. $result = $this->Form->input('ValidateUser.population');
  1591. $expected = array(
  1592. 'div' => array('class'),
  1593. 'label' => array('for'),
  1594. 'Population',
  1595. '/label',
  1596. 'input' => array('name', 'type' => 'number', 'step' => '1', 'id'),
  1597. '/div',
  1598. );
  1599. $this->assertTags($result, $expected);
  1600. $result = $this->Form->input('UserForm.published', array('type' => 'text'));
  1601. $expected = array(
  1602. 'div' => array('class' => 'input text'),
  1603. 'label' => array('for' => 'UserFormPublished'),
  1604. 'Published',
  1605. '/label',
  1606. array('input' => array(
  1607. 'type' => 'text', 'name' => 'UserForm[published]',
  1608. 'id' => 'UserFormPublished'
  1609. )),
  1610. '/div'
  1611. );
  1612. $this->assertTags($result, $expected);
  1613. $result = $this->Form->input('UserForm.other', array('type' => 'text'));
  1614. $expected = array(
  1615. 'div' => array('class' => 'input text'),
  1616. 'label' => array('for' => 'UserFormOther'),
  1617. 'Other',
  1618. '/label',
  1619. array('input' => array(
  1620. 'type' => 'text', 'name' => 'UserForm[other]',
  1621. 'id' => 'UserFormOther'
  1622. )),
  1623. '/div'
  1624. );
  1625. $this->assertTags($result, $expected);
  1626. $result = $this->Form->hidden('UserForm.stuff');
  1627. $expected = array(
  1628. 'input' => array(
  1629. 'type' => 'hidden', 'name' => 'UserForm[stuff]',
  1630. 'id' => 'UserFormStuff'
  1631. ));
  1632. $this->assertTags($result, $expected);
  1633. $result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
  1634. $expected = array('input' => array(
  1635. 'type' => 'hidden', 'name' => 'UserForm[hidden]',
  1636. 'value' => '0', 'id' => 'UserFormHidden'
  1637. ));
  1638. $this->assertTags($result, $expected);
  1639. $result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
  1640. $expected = array(
  1641. 'div' => array('class' => 'input checkbox'),
  1642. array('input' => array(
  1643. 'type' => 'hidden', 'name' => 'UserForm[something]',
  1644. 'value' => '0', 'id' => 'UserFormSomething_'
  1645. )),
  1646. array('input' => array(
  1647. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  1648. 'value' => '1', 'id' => 'UserFormSomething'
  1649. )),
  1650. 'label' => array('for' => 'UserFormSomething'),
  1651. 'Something',
  1652. '/label',
  1653. '/div'
  1654. );
  1655. $this->assertTags($result, $expected);
  1656. $result = $this->Form->fields;
  1657. $expected = array(
  1658. 'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
  1659. 'UserForm.hidden' => '0', 'UserForm.something'
  1660. );
  1661. $this->assertEquals($expected, $result);
  1662. $hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
  1663. $result = $this->Form->secure($this->Form->fields);
  1664. $expected = array(
  1665. 'div' => array('style' => 'display:none;'),
  1666. array('input' => array(
  1667. 'type' => 'hidden', 'name' => '_Token[fields]',
  1668. 'value' => $hash
  1669. )),
  1670. array('input' => array(
  1671. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1672. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1673. )),
  1674. '/div'
  1675. );
  1676. $this->assertTags($result, $expected);
  1677. }
  1678. /**
  1679. * Test secured inputs with custom names.
  1680. *
  1681. * @return void
  1682. */
  1683. public function testSecuredInputCustomName() {
  1684. $this->markTestIncomplete('Need to revisit once models work again.');
  1685. $this->Form->request->params['_csrfToken'] = 'testKey';
  1686. $this->assertEquals(array(), $this->Form->fields);
  1687. $this->Form->input('text_input', array(
  1688. 'name' => 'data[Option][General.default_role]',
  1689. ));
  1690. $expected = array('Option.General.default_role');
  1691. $this->assertEquals($expected, $this->Form->fields);
  1692. $this->Form->input('select_box', array(
  1693. 'name' => 'data[Option][General.select_role]',
  1694. 'type' => 'select',
  1695. 'options' => array(1, 2),
  1696. ));
  1697. $expected = array('Option.General.default_role', 'Option.General.select_role');
  1698. $this->assertEquals($expected, $this->Form->fields);
  1699. }
  1700. /**
  1701. * Tests that the correct keys are added to the field hash index
  1702. *
  1703. * @return void
  1704. */
  1705. public function testFormSecuredFileInput() {
  1706. $this->assertEquals(array(), $this->Form->fields);
  1707. $this->Form->file('Attachment.file');
  1708. $expected = array(
  1709. 'Attachment.file.name', 'Attachment.file.type',
  1710. 'Attachment.file.tmp_name', 'Attachment.file.error',
  1711. 'Attachment.file.size'
  1712. );
  1713. $this->assertEquals($expected, $this->Form->fields);
  1714. }
  1715. /**
  1716. * test that multiple selects keys are added to field hash
  1717. *
  1718. * @return void
  1719. */
  1720. public function testFormSecuredMultipleSelect() {
  1721. $this->markTestIncomplete('Need to revisit once models work again.');
  1722. $this->Form->request->params['_csrfToken'] = 'testKey';
  1723. $this->assertEquals(array(), $this->Form->fields);
  1724. $options = array('1' => 'one', '2' => 'two');
  1725. $this->Form->select('Model.select', $options);
  1726. $expected = array('Model.select');
  1727. $this->assertEquals($expected, $this->Form->fields);
  1728. $this->Form->fields = array();
  1729. $this->Form->select('Model.select', $options, array('multiple' => true));
  1730. $this->assertEquals($expected, $this->Form->fields);
  1731. }
  1732. /**
  1733. * testFormSecuredRadio method
  1734. *
  1735. * @return void
  1736. */
  1737. public function testFormSecuredRadio() {
  1738. $this->assertEquals(array(), $this->Form->fields);
  1739. $options = array('1' => 'option1', '2' => 'option2');
  1740. $this->Form->radio('Test.test', $options);
  1741. $expected = array('Test[test]' => '');
  1742. $this->assertEquals($expected, $this->Form->fields);
  1743. }
  1744. /**
  1745. * Test that when disabled is in a list based attribute array it works.
  1746. *
  1747. * @return void
  1748. */
  1749. public function testFormSecuredAndDisabledNotAssoc() {
  1750. $this->markTestIncomplete('Need to revisit once models work again.');
  1751. $this->Form->request->params['_csrfToken'] = 'testKey';
  1752. $this->Form->select('Model.select', array(1, 2), array('disabled'));
  1753. $this->Form->checkbox('Model.checkbox', array('disabled'));
  1754. $this->Form->text('Model.text', array('disabled'));
  1755. $this->Form->textarea('Model.textarea', array('disabled'));
  1756. $this->Form->password('Model.password', array('disabled'));
  1757. $this->Form->radio('Model.radio', array(1, 2), array('disabled'));
  1758. $expected = array(
  1759. 'Model.radio' => ''
  1760. );
  1761. $this->assertEquals($expected, $this->Form->fields);
  1762. }
  1763. /**
  1764. * test that forms with disabled inputs + secured forms leave off the inputs from the form
  1765. * hashing.
  1766. *
  1767. * @return void
  1768. */
  1769. public function testFormSecuredAndDisabled() {
  1770. $this->markTestIncomplete('Need to revisit once models work again.');
  1771. $this->Form->request->params['_csrfToken'] = 'testKey';
  1772. $this->Form->checkbox('Model.checkbox', array('disabled' => true));
  1773. $this->Form->text('Model.text', array('disabled' => true));
  1774. $this->Form->password('Model.text', array('disabled' => true));
  1775. $this->Form->textarea('Model.textarea', array('disabled' => true));
  1776. $this->Form->select('Model.select', array(1, 2), array('disabled' => true));
  1777. $this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
  1778. $this->Form->year('Model.year', null, null, array('disabled' => true));
  1779. $this->Form->month('Model.month', array('disabled' => true));
  1780. $this->Form->day('Model.day', array('disabled' => true));
  1781. $this->Form->hour('Model.hour', false, array('disabled' => true));
  1782. $this->Form->minute('Model.minute', array('disabled' => true));
  1783. $this->Form->meridian('Model.meridian', array('disabled' => true));
  1784. $expected = array(
  1785. 'Model.radio' => ''
  1786. );
  1787. $this->assertEquals($expected, $this->Form->fields);
  1788. }
  1789. /**
  1790. * testDisableSecurityUsingForm method
  1791. *
  1792. * @return void
  1793. */
  1794. public function testDisableSecurityUsingForm() {
  1795. $this->markTestIncomplete('Need to revisit once models work again.');
  1796. $this->Form->request->params['_csrfToken'] = 'testKey';
  1797. $this->Form->request['_Token'] = array(
  1798. 'disabledFields' => array()
  1799. );
  1800. $this->Form->create();
  1801. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1802. $this->Form->input('Addresses.title');
  1803. $this->Form->input('Addresses.first_name', array('secure' => false));
  1804. $this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
  1805. $this->Form->input('Addresses.zip', array(
  1806. 'type' => 'select', 'options' => array(1, 2), 'secure' => false
  1807. ));
  1808. $result = $this->Form->fields;
  1809. $expected = array(
  1810. 'Addresses.id' => '123456', 'Addresses.title',
  1811. );
  1812. $this->assertEquals($expected, $result);
  1813. }
  1814. /**
  1815. * test disableField
  1816. *
  1817. * @return void
  1818. */
  1819. public function testUnlockFieldAddsToList() {
  1820. $this->markTestIncomplete('Need to revisit once models work again.');
  1821. $this->Form->request->params['_csrfToken'] = 'testKey';
  1822. $this->Form->request['_Token'] = array(
  1823. 'unlockedFields' => array()
  1824. );
  1825. $this->Form->create('Contact');
  1826. $this->Form->unlockField('Contact.name');
  1827. $this->Form->text('Contact.name');
  1828. $this->assertEquals(array('Contact.name'), $this->Form->unlockField());
  1829. $this->assertEquals(array(), $this->Form->fields);
  1830. }
  1831. /**
  1832. * test unlockField removing from fields array.
  1833. *
  1834. * @return void
  1835. */
  1836. public function testUnlockFieldRemovingFromFields() {
  1837. $this->markTestIncomplete('Need to revisit once models work again.');
  1838. $this->Form->request->params['_csrfToken'] = 'testKey';
  1839. $this->Form->request['_Token'] = array(
  1840. 'unlockedFields' => array()
  1841. );
  1842. $this->Form->create('Contact');
  1843. $this->Form->hidden('Contact.id', array('value' => 1));
  1844. $this->Form->text('Contact.name');
  1845. $this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
  1846. $this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
  1847. $this->Form->unlockField('Contact.name');
  1848. $this->Form->unlockField('Contact.id');
  1849. $this->assertEquals(array(), $this->Form->fields);
  1850. }
  1851. /**
  1852. * testTagIsInvalid method
  1853. *
  1854. * @return void
  1855. */
  1856. public function testTagIsInvalid() {
  1857. $this->markTestIncomplete('Need to revisit once models work again.');
  1858. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1859. $this->Form->setEntity('Contact.0.email');
  1860. $result = $this->Form->tagIsInvalid();
  1861. $this->assertEquals($expected, $result);
  1862. $this->Form->setEntity('Contact.1.email');
  1863. $result = $this->Form->tagIsInvalid();
  1864. $this->assertFalse($result);
  1865. $this->Form->setEntity('Contact.0.name');
  1866. $result = $this->Form->tagIsInvalid();
  1867. $this->assertFalse($result);
  1868. }
  1869. /**
  1870. * Test tagIsInvalid with validation errors from a saveMany
  1871. *
  1872. * @return void
  1873. */
  1874. public function testTagIsInvalidSaveMany() {
  1875. $this->markTestIncomplete('Need to revisit once models work again.');
  1876. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1877. $this->Form->create('Contact');
  1878. $this->Form->setEntity('0.email');
  1879. $result = $this->Form->tagIsInvalid();
  1880. $this->assertEquals($expected, $result);
  1881. $this->Form->setEntity('0.Contact.email');
  1882. $result = $this->Form->tagIsInvalid();
  1883. $this->assertEquals($expected, $result);
  1884. }
  1885. /**
  1886. * Test validation errors.
  1887. *
  1888. * @return void
  1889. */
  1890. public function testPasswordValidation() {
  1891. $this->markTestIncomplete('Need to revisit once models work again.');
  1892. $Contact->validationErrors['password'] = array('Please provide a password');
  1893. $result = $this->Form->input('Contact.password');
  1894. $expected = array(
  1895. 'div' => array('class' => 'input password error'),
  1896. 'label' => array('for' => 'ContactPassword'),
  1897. 'Password',
  1898. '/label',
  1899. 'input' => array(
  1900. 'type' => 'password', 'name' => 'Contact[password]',
  1901. 'id' => 'ContactPassword', 'class' => 'form-error'
  1902. ),
  1903. array('div' => array('class' => 'error-message')),
  1904. 'Please provide a password',
  1905. '/div',
  1906. '/div'
  1907. );
  1908. $this->assertTags($result, $expected);
  1909. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1910. $expected = array(
  1911. 'div' => array('class' => 'input password error'),
  1912. 'label' => array('for' => 'ContactPassword'),
  1913. 'Password',
  1914. '/label',
  1915. 'input' => array(
  1916. 'type' => 'password', 'name' => 'Contact[password]',
  1917. 'id' => 'ContactPassword', 'class' => 'form-error'
  1918. ),
  1919. '/div'
  1920. );
  1921. $this->assertTags($result, $expected);
  1922. }
  1923. /**
  1924. * Test validation errors, when validation message is an empty string.
  1925. *
  1926. * @return void
  1927. */
  1928. public function testEmptyErrorValidation() {
  1929. $this->markTestIncomplete('Need to revisit once models work again.');
  1930. $this->Form->validationErrors['Contact']['password'] = '';
  1931. $result = $this->Form->input('Contact.password');
  1932. $expected = array(
  1933. 'div' => array('class' => 'input password error'),
  1934. 'label' => array('for' => 'ContactPassword'),
  1935. 'Password',
  1936. '/label',
  1937. 'input' => array(
  1938. 'type' => 'password', 'name' => 'Contact[password]',
  1939. 'id' => 'ContactPassword', 'class' => 'form-error'
  1940. ),
  1941. array('div' => array('class' => 'error-message')),
  1942. array(),
  1943. '/div',
  1944. '/div'
  1945. );
  1946. $this->assertTags($result, $expected);
  1947. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1948. $expected = array(
  1949. 'div' => array('class' => 'input password error'),
  1950. 'label' => array('for' => 'ContactPassword'),
  1951. 'Password',
  1952. '/label',
  1953. 'input' => array(
  1954. 'type' => 'password', 'name' => 'Contact[password]',
  1955. 'id' => 'ContactPassword', 'class' => 'form-error'
  1956. ),
  1957. '/div'
  1958. );
  1959. $this->assertTags($result, $expected);
  1960. }
  1961. /**
  1962. * Test validation errors, when calling input() overriding validation message by an empty string.
  1963. *
  1964. * @return void
  1965. */
  1966. public function testEmptyInputErrorValidation() {
  1967. $this->markTestIncomplete('Need to revisit once models work again.');
  1968. $this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
  1969. $result = $this->Form->input('Contact.password', array('error' => ''));
  1970. $expected = array(
  1971. 'div' => array('class' => 'input password error'),
  1972. 'label' => array('for' => 'ContactPassword'),
  1973. 'Password',
  1974. '/label',
  1975. 'input' => array(
  1976. 'type' => 'password', 'name' => 'Contact[password]',
  1977. 'id' => 'ContactPassword', 'class' => 'form-error'
  1978. ),
  1979. array('div' => array('class' => 'error-message')),
  1980. array(),
  1981. '/div',
  1982. '/div'
  1983. );
  1984. $this->assertTags($result, $expected);
  1985. $result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
  1986. $expected = array(
  1987. 'div' => array('class' => 'input password error'),
  1988. 'label' => array('for' => 'ContactPassword'),
  1989. 'Password',
  1990. '/label',
  1991. 'input' => array(
  1992. 'type' => 'password', 'name' => 'Contact[password]',
  1993. 'id' => 'ContactPassword', 'class' => 'form-error'
  1994. ),
  1995. '/div'
  1996. );
  1997. $this->assertTags($result, $expected);
  1998. }
  1999. /**
  2000. * testFormValidationAssociated method
  2001. *
  2002. * test display of form errors in conjunction with model::validates.
  2003. *
  2004. * @return void
  2005. */
  2006. public function testFormValidationAssociated() {
  2007. $this->markTestIncomplete('Need to revisit once models work again.');
  2008. $data = array(
  2009. 'UserForm' => array('name' => 'user'),
  2010. 'OpenidUrl' => array('url' => 'http://www.cakephp.org')
  2011. );
  2012. $result = $this->UserForm->OpenidUrl->create($data);
  2013. $this->assertFalse(empty($result));
  2014. $this->assertFalse($this->UserForm->OpenidUrl->validates());
  2015. $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
  2016. $encoding = strtolower(Configure::read('App.encoding'));
  2017. $expected = array(
  2018. 'form' => array(
  2019. 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
  2020. 'accept-charset' => $encoding
  2021. ),
  2022. 'div' => array('style' => 'display:none;'),
  2023. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2024. '/div'
  2025. );
  2026. $this->assertTags($result, $expected);
  2027. $result = $this->Form->error(
  2028. 'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
  2029. );
  2030. $this->assertEquals('Error, not registered', $result);
  2031. unset($this->UserForm->OpenidUrl, $this->UserForm);
  2032. }
  2033. /**
  2034. * testFormValidationAssociatedFirstLevel method
  2035. *
  2036. * test form error display with associated model.
  2037. *
  2038. * @return void
  2039. */
  2040. public function testFormValidationAssociatedFirstLevel() {
  2041. $this->markTestIncomplete('Need to revisit once models work again.');
  2042. $data = array(
  2043. 'ValidateUser' => array('name' => 'mariano'),
  2044. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
  2045. );
  2046. $result = $this->ValidateUser->create($data);
  2047. $this->assertFalse(empty($result));
  2048. $this->assertFalse($this->ValidateUser->validates());
  2049. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2050. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2051. $encoding = strtolower(Configure::read('App.encoding'));
  2052. $expected = array(
  2053. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2054. 'div' => array('style' => 'display:none;'),
  2055. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2056. '/div'
  2057. );
  2058. $this->assertTags($result, $expected);
  2059. $result = $this->Form->error(
  2060. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2061. );
  2062. $this->assertEquals('Invalid email', $result);
  2063. $result = $this->Form->error(
  2064. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2065. );
  2066. $this->assertEquals('Invalid name', $result);
  2067. $result = $this->Form->error(
  2068. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2069. );
  2070. $this->assertEquals('Invalid city', $result);
  2071. unset($this->ValidateUser->ValidateProfile);
  2072. unset($this->ValidateUser);
  2073. }
  2074. /**
  2075. * testFormValidationAssociatedSecondLevel method
  2076. *
  2077. * test form error display with associated model.
  2078. *
  2079. * @return void
  2080. */
  2081. public function testFormValidationAssociatedSecondLevel() {
  2082. $this->markTestIncomplete('Need to revisit once models work again.');
  2083. $data = array(
  2084. 'ValidateUser' => array('name' => 'mariano'),
  2085. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
  2086. 'ValidateItem' => array('name' => 'Item')
  2087. );
  2088. $result = $this->ValidateUser->create($data);
  2089. $this->assertFalse(empty($result));
  2090. $this->assertFalse($this->ValidateUser->validates());
  2091. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2092. $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
  2093. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2094. $encoding = strtolower(Configure::read('App.encoding'));
  2095. $expected = array(
  2096. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2097. 'div' => array('style' => 'display:none;'),
  2098. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2099. '/div'
  2100. );
  2101. $this->assertTags($result, $expected);
  2102. $result = $this->Form->error(
  2103. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2104. );
  2105. $this->assertEquals('Invalid email', $result);
  2106. $result = $this->Form->error(
  2107. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2108. );
  2109. $this->assertEquals('Invalid name', $result);
  2110. $result = $this->Form->error(
  2111. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2112. );
  2113. $result = $this->Form->error(
  2114. 'ValidateItem.description', 'Invalid description', array('wrap' => false)
  2115. );
  2116. $this->assertEquals('Invalid description', $result);
  2117. unset($this->ValidateUser->ValidateProfile->ValidateItem);
  2118. unset($this->ValidateUser->ValidateProfile);
  2119. unset($this->ValidateUser);
  2120. }
  2121. /**
  2122. * testFormValidationMultiRecord method
  2123. *
  2124. * test form error display with multiple records.
  2125. *
  2126. * @return void
  2127. */
  2128. public function testFormValidationMultiRecord() {
  2129. $this->markTestIncomplete('Need to revisit once models work again.');
  2130. $Contact->validationErrors[2] = array(
  2131. 'name' => array('The provided value is invalid')
  2132. );
  2133. $result = $this->Form->input('Contact.2.name');
  2134. $expected = array(
  2135. 'div' => array('class' => 'input text error'),
  2136. 'label' => array('for' => 'Contact2Name'),
  2137. 'Name',
  2138. '/label',
  2139. 'input' => array(
  2140. 'type' => 'text', 'name' => 'Contact[2][name]', 'id' => 'Contact2Name',
  2141. 'class' => 'form-error', 'maxlength' => 255
  2142. ),
  2143. array('div' => array('class' => 'error-message')),
  2144. 'The provided value is invalid',
  2145. '/div',
  2146. '/div'
  2147. );
  2148. $this->assertTags($result, $expected);
  2149. }
  2150. /**
  2151. * testMultipleInputValidation method
  2152. *
  2153. * test multiple record form validation error display.
  2154. *
  2155. * @return void
  2156. */
  2157. public function testMultipleInputValidation() {
  2158. $this->markTestIncomplete('Need to revisit once models work again.');
  2159. $Address->validationErrors[0] = array(
  2160. 'title' => array('This field cannot be empty'),
  2161. 'first_name' => array('This field cannot be empty')
  2162. );
  2163. $Address->validationErrors[1] = array(
  2164. 'last_name' => array('You must have a last name')
  2165. );
  2166. $this->Form->create();
  2167. $result = $this->Form->input('Address.0.title');
  2168. $expected = array(
  2169. 'div' => array('class'),
  2170. 'label' => array('for'),
  2171. 'preg:/[^<]+/',
  2172. '/label',
  2173. 'input' => array(
  2174. 'type' => 'text', 'name', 'id', 'class' => 'form-error'
  2175. ),
  2176. array('div' => array('class' => 'error-message')),
  2177. 'This field cannot be empty',
  2178. '/div',
  2179. '/div'
  2180. );
  2181. $this->assertTags($result, $expected);
  2182. $result = $this->Form->input('Address.0.first_name');
  2183. $expected = array(
  2184. 'div' => array('class'),
  2185. 'label' => array('for'),
  2186. 'preg:/[^<]+/',
  2187. '/label',
  2188. 'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
  2189. array('div' => array('class' => 'error-message')),
  2190. 'This field cannot be empty',
  2191. '/div',
  2192. '/div'
  2193. );
  2194. $this->assertTags($result, $expected);
  2195. $result = $this->Form->input('Address.0.last_name');
  2196. $expected = array(
  2197. 'div' => array('class'),
  2198. 'label' => array('for'),
  2199. 'preg:/[^<]+/',
  2200. '/label',
  2201. 'input' => array('type' => 'text', 'name', 'id'),
  2202. '/div'
  2203. );
  2204. $this->assertTags($result, $expected);
  2205. $result = $this->Form->input('Address.1.last_name');
  2206. $expected = array(
  2207. 'div' => array('class'),
  2208. 'label' => array('for'),
  2209. 'preg:/[^<]+/',
  2210. '/label',
  2211. 'input' => array(
  2212. 'type' => 'text', 'name' => 'preg:/[^<]+/',
  2213. 'id' => 'preg:/[^<]+/', 'class' => 'form-error'
  2214. ),
  2215. array('div' => array('class' => 'error-message')),
  2216. 'You must have a last name',
  2217. '/div',
  2218. '/div'
  2219. );
  2220. $this->assertTags($result, $expected);
  2221. }
  2222. /**
  2223. * testInput method
  2224. *
  2225. * Test various incarnations of input().
  2226. *
  2227. * @return void
  2228. */
  2229. public function testInput() {
  2230. $this->markTestIncomplete('Need to revisit once models work again.');
  2231. $result = $this->Form->input('ValidateUser.balance');
  2232. $expected = array(
  2233. 'div' => array('class'),
  2234. 'label' => array('for'),
  2235. 'Balance',
  2236. '/label',
  2237. 'input' => array('name', 'type' => 'number', 'id'),
  2238. '/div',
  2239. );
  2240. $this->assertTags($result, $expected);
  2241. $result = $this->Form->input('ValidateUser.cost_decimal');
  2242. $expected = array(
  2243. 'div' => array('class'),
  2244. 'label' => array('for'),
  2245. 'Cost Decimal',
  2246. '/label',
  2247. 'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
  2248. '/div',
  2249. );
  2250. $this->assertTags($result, $expected);
  2251. $result = $this->Form->input('Contact.email', array('id' => 'custom'));
  2252. $expected = array(
  2253. 'div' => array('class' => 'input email'),
  2254. 'label' => array('for' => 'custom'),
  2255. 'Email',
  2256. '/label',
  2257. array('input' => array(
  2258. 'type' => 'email', 'name' => 'Contact[email]',
  2259. 'id' => 'custom', 'maxlength' => 255
  2260. )),
  2261. '/div'
  2262. );
  2263. $this->assertTags($result, $expected);
  2264. $result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
  2265. $expected = array(
  2266. '<div',
  2267. 'label' => array('for' => 'ContactEmail'),
  2268. 'Email',
  2269. '/label',
  2270. array('input' => array(
  2271. 'type' => 'email', 'name' => 'Contact[email]',
  2272. 'id' => 'ContactEmail', 'maxlength' => 255
  2273. )),
  2274. '/div'
  2275. );
  2276. $this->assertTags($result, $expected);
  2277. $result = $this->Form->hidden('Contact.idontexist');
  2278. $expected = array('input' => array(
  2279. 'type' => 'hidden', 'name' => 'Contact[idontexist]',
  2280. 'id' => 'ContactIdontexist'
  2281. ));
  2282. $this->assertTags($result, $expected);
  2283. $result = $this->Form->input('Contact.email', array('type' => 'text'));
  2284. $expected = array(
  2285. 'div' => array('class' => 'input text'),
  2286. 'label' => array('for' => 'ContactEmail'),
  2287. 'Email',
  2288. '/label',
  2289. array('input' => array(
  2290. 'type' => 'text', 'name' => 'Contact[email]',
  2291. 'id' => 'ContactEmail'
  2292. )),
  2293. '/div'
  2294. );
  2295. $this->assertTags($result, $expected);
  2296. $result = $this->Form->input('Contact.5.email', array('type' => 'text'));
  2297. $expected = array(
  2298. 'div' => array('class' => 'input text'),
  2299. 'label' => array('for' => 'Contact5Email'),
  2300. 'Email',
  2301. '/label',
  2302. array('input' => array(
  2303. 'type' => 'text', 'name' => 'Contact[5][email]',
  2304. 'id' => 'Contact5Email'
  2305. )),
  2306. '/div'
  2307. );
  2308. $this->assertTags($result, $expected);
  2309. $result = $this->Form->input('Contact.password');
  2310. $expected = array(
  2311. 'div' => array('class' => 'input password'),
  2312. 'label' => array('for' => 'ContactPassword'),
  2313. 'Password',
  2314. '/label',
  2315. array('input' => array(
  2316. 'type' => 'password', 'name' => 'Contact[password]',
  2317. 'id' => 'ContactPassword'
  2318. )),
  2319. '/div'
  2320. );
  2321. $this->assertTags($result, $expected);
  2322. $result = $this->Form->input('Contact.email', array(
  2323. 'type' => 'file', 'class' => 'textbox'
  2324. ));
  2325. $expected = array(
  2326. 'div' => array('class' => 'input file'),
  2327. 'label' => array('for' => 'ContactEmail'),
  2328. 'Email',
  2329. '/label',
  2330. array('input' => array(
  2331. 'type' => 'file', 'name' => 'Contact[email]', 'class' => 'textbox',
  2332. 'id' => 'ContactEmail'
  2333. )),
  2334. '/div'
  2335. );
  2336. $this->assertTags($result, $expected);
  2337. $this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
  2338. $result = $this->Form->input('Contact.phone');
  2339. $expected = array(
  2340. 'div' => array('class' => 'input tel'),
  2341. 'label' => array('for' => 'ContactPhone'),
  2342. 'Phone',
  2343. '/label',
  2344. array('input' => array(
  2345. 'type' => 'tel', 'name' => 'Contact[phone]',
  2346. 'value' => 'Hello &amp; World &gt; weird chars',
  2347. 'id' => 'ContactPhone', 'maxlength' => 255
  2348. )),
  2349. '/div'
  2350. );
  2351. $this->assertTags($result, $expected);
  2352. $this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
  2353. $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
  2354. $expected = array(
  2355. 'div' => array('class' => 'input text'),
  2356. 'label' => array('for' => 'myId'),
  2357. 'Field',
  2358. '/label',
  2359. 'input' => array(
  2360. 'type' => 'text', 'name' => 'Model[0][OtherModel][field]',
  2361. 'value' => 'My value', 'id' => 'myId'
  2362. ),
  2363. '/div'
  2364. );
  2365. $this->assertTags($result, $expected);
  2366. unset($this->Form->request->data);
  2367. $Contact->validationErrors['field'] = array('Badness!');
  2368. $result = $this->Form->input('Contact.field');
  2369. $expected = array(
  2370. 'div' => array('class' => 'input text error'),
  2371. 'label' => array('for' => 'ContactField'),
  2372. 'Field',
  2373. '/label',
  2374. 'input' => array(
  2375. 'type' => 'text', 'name' => 'Contact[field]',
  2376. 'id' => 'ContactField', 'class' => 'form-error'
  2377. ),
  2378. array('div' => array('class' => 'error-message')),
  2379. 'Badness!',
  2380. '/div',
  2381. '/div'
  2382. );
  2383. $this->assertTags($result, $expected);
  2384. $result = $this->Form->input('Contact.field', array(
  2385. 'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
  2386. ));
  2387. $expected = array(
  2388. 'label' => array('for' => 'ContactField'),
  2389. 'Field',
  2390. '/label',
  2391. 'input' => array(
  2392. 'type' => 'text', 'name' => 'Contact[field]',
  2393. 'id' => 'ContactField', 'class' => 'form-error'
  2394. ),
  2395. array('span' => array('class' => 'error-message')),
  2396. 'Badness!',
  2397. '/span'
  2398. );
  2399. $this->assertTags($result, $expected);
  2400. $result = $this->Form->input('Contact.field', array(
  2401. 'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
  2402. ));
  2403. $expected = array(
  2404. 'div' => array('class' => 'input text error'),
  2405. 'label' => array('for' => 'ContactField'),
  2406. 'Field',
  2407. '/label',
  2408. 'input' => array(
  2409. 'type' => 'text', 'name' => 'Contact[field]',
  2410. 'id' => 'ContactField', 'class' => 'form-error'
  2411. ),
  2412. array('div' => array('class' => 'error')),
  2413. 'Badness!',
  2414. '/div'
  2415. );
  2416. $this->assertTags($result, $expected);
  2417. $result = $this->Form->input('Contact.field', array(
  2418. 'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
  2419. ));
  2420. $expected = array(
  2421. 'span' => array('class' => 'input text error'),
  2422. 'label' => array('for' => 'ContactField'),
  2423. 'Field',
  2424. '/label',
  2425. 'input' => array(
  2426. 'type' => 'text', 'name' => 'Contact[field]',
  2427. 'id' => 'ContactField', 'class' => 'form-error'
  2428. ),
  2429. 'Badness!',
  2430. '/span'
  2431. );
  2432. $this->assertTags($result, $expected);
  2433. $result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
  2434. $expected = array(
  2435. 'div' => array('class' => 'input text error'),
  2436. 'label' => array('for' => 'ContactField'),
  2437. 'Field',
  2438. '/label',
  2439. 'input' => array(
  2440. 'type' => 'text', 'name' => 'Contact[field]',
  2441. 'id' => 'ContactField', 'class' => 'form-error'
  2442. ),
  2443. 'A message to you, Rudy',
  2444. array('div' => array('class' => 'error-message')),
  2445. 'Badness!',
  2446. '/div',
  2447. '/div'
  2448. );
  2449. $this->assertTags($result, $expected);
  2450. $this->Form->setEntity(null);
  2451. $this->Form->setEntity('Contact.field');
  2452. $result = $this->Form->input('Contact.field', array(
  2453. 'after' => 'A message to you, Rudy', 'error' => false
  2454. ));
  2455. $expected = array(
  2456. 'div' => array('class' => 'input text'),
  2457. 'label' => array('for' => 'ContactField'),
  2458. 'Field',
  2459. '/label',
  2460. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2461. 'A message to you, Rudy',
  2462. '/div'
  2463. );
  2464. $this->assertTags($result, $expected);
  2465. $result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
  2466. $expected = array(
  2467. 'div' => array('class' => 'input text'),
  2468. 'label' => array('for' => 'ObjectField'),
  2469. 'Field',
  2470. '/label',
  2471. 'input' => array('type' => 'text', 'name' => 'Object[field]', 'id' => 'ObjectField'),
  2472. 'A message to you, Rudy',
  2473. '/div'
  2474. );
  2475. $this->assertTags($result, $expected);
  2476. $Contact->validationErrors['field'] = array('minLength');
  2477. $result = $this->Form->input('Contact.field', array(
  2478. 'error' => array(
  2479. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2480. 'maxLength' => 'login too large'
  2481. )
  2482. ));
  2483. $expected = array(
  2484. 'div' => array('class' => 'input text error'),
  2485. 'label' => array('for' => 'ContactField'),
  2486. 'Field',
  2487. '/label',
  2488. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2489. array('div' => array('class' => 'error-message')),
  2490. 'Le login doit contenir au moins 2 caractères',
  2491. '/div',
  2492. '/div'
  2493. );
  2494. $this->assertTags($result, $expected);
  2495. $Contact->validationErrors['field'] = array('maxLength');
  2496. $result = $this->Form->input('Contact.field', array(
  2497. 'error' => array(
  2498. 'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
  2499. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2500. 'maxLength' => 'login too large',
  2501. )
  2502. ));
  2503. $expected = array(
  2504. 'div' => array('class' => 'input text error'),
  2505. 'label' => array('for' => 'ContactField'),
  2506. 'Field',
  2507. '/label',
  2508. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2509. array('span' => array('class' => 'error-message', 'rel' => 'fake')),
  2510. 'login too large',
  2511. '/span',
  2512. '/div'
  2513. );
  2514. $this->assertTags($result, $expected);
  2515. }
  2516. /**
  2517. * Test that inputs with 0 can be created.
  2518. *
  2519. * @return void
  2520. */
  2521. public function testInputZero() {
  2522. $this->markTestIncomplete('Need to revisit once models work again.');
  2523. $this->Form->create('User');
  2524. $result = $this->Form->input('0');
  2525. $expected = array(
  2526. 'div' => array('class' => 'input text'),
  2527. 'label' => array('for' => 'User0'), '/label',
  2528. 'input' => array('type' => 'text', 'name' => 'User[0]', 'id' => 'User0'),
  2529. '/div'
  2530. );
  2531. $this->assertTags($result, $expected);
  2532. }
  2533. /**
  2534. * test input() with checkbox creation
  2535. *
  2536. * @return void
  2537. */
  2538. public function testInputCheckbox() {
  2539. $this->markTestIncomplete('Need to revisit once models work again.');
  2540. $result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
  2541. $expected = array(
  2542. 'div' => array('class' => 'input checkbox'),
  2543. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2544. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2545. '/div'
  2546. );
  2547. $this->assertTags($result, $expected);
  2548. $result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
  2549. $expected = array(
  2550. 'div' => array('class' => 'input checkbox'),
  2551. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2552. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2553. '/div'
  2554. );
  2555. $this->assertTags($result, $expected);
  2556. $result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
  2557. $expected = array(
  2558. 'div' => array('class' => 'input checkbox'),
  2559. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2560. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2561. '/div'
  2562. );
  2563. $this->assertTags($result, $expected);
  2564. $result = $this->Form->input('User.disabled', array(
  2565. 'label' => 'Disabled',
  2566. 'type' => 'checkbox',
  2567. 'data-foo' => 'disabled'
  2568. ));
  2569. $expected = array(
  2570. 'div' => array('class' => 'input checkbox'),
  2571. 'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
  2572. array('input' => array(
  2573. 'type' => 'checkbox',
  2574. 'name' => 'data[User][disabled]',
  2575. 'value' => '1',
  2576. 'id' => 'UserDisabled',
  2577. 'data-foo' => 'disabled'
  2578. )),
  2579. 'label' => array('for' => 'UserDisabled'),
  2580. 'Disabled',
  2581. '/label',
  2582. '/div'
  2583. );
  2584. $this->assertTags($result, $expected);
  2585. }
  2586. /**
  2587. * test form->input() with time types.
  2588. *
  2589. */
  2590. public function testInputTime() {
  2591. $this->markTestIncomplete('Need to revisit once models work again.');
  2592. extract($this->dateRegex);
  2593. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2594. $result = explode(':', $result);
  2595. $this->assertRegExp('/option value="23"/', $result[0]);
  2596. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2597. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2598. $result = explode(':', $result);
  2599. $this->assertRegExp('/option value="23"/', $result[0]);
  2600. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2601. $result = $this->Form->input('Model.field', array(
  2602. 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
  2603. ));
  2604. $result = explode(':', $result);
  2605. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2606. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2607. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2608. $result = $this->Form->input('Model.field', array(
  2609. 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
  2610. ));
  2611. $result = explode(':', $result);
  2612. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2613. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2614. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2615. $result = $this->Form->input('prueba', array(
  2616. 'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2617. 'maxYear' => date('Y') + 1, 'interval' => 15
  2618. ));
  2619. $result = explode(':', $result);
  2620. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2621. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2622. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2623. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2624. $result = $this->Form->input('Random.start_time', array(
  2625. 'type' => 'time',
  2626. 'selected' => '18:15'
  2627. ));
  2628. $this->assertContains('<option value="06" selected="selected">6</option>', $result);
  2629. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2630. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2631. $result = $this->Form->input('published', array('type' => 'time'));
  2632. $now = strtotime('now');
  2633. $this->assertContains('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
  2634. $now = strtotime('2013-03-09 00:42:21');
  2635. $result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
  2636. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2637. $this->assertContains('<option value="42" selected="selected">42</option>', $result);
  2638. }
  2639. /**
  2640. * Test interval + selected near the hour roll over.
  2641. *
  2642. * @return void
  2643. */
  2644. public function testTimeSelectedWithInterval() {
  2645. $this->markTestIncomplete('Need to revisit once models work again.');
  2646. $result = $this->Form->input('Model.start_time', array(
  2647. 'type' => 'time',
  2648. 'interval' => 15,
  2649. 'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
  2650. ));
  2651. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2652. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2653. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2654. $result = $this->Form->input('Model.start_time', array(
  2655. 'type' => 'time',
  2656. 'interval' => 15,
  2657. 'selected' => '2012-10-23 15:57:00'
  2658. ));
  2659. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2660. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2661. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2662. $result = $this->Form->input('Model.start_time', array(
  2663. 'timeFormat' => 24,
  2664. 'type' => 'time',
  2665. 'interval' => 15,
  2666. 'selected' => '15:57'
  2667. ));
  2668. $this->assertContains('<option value="16" selected="selected">16</option>', $result);
  2669. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2670. $result = $this->Form->input('Model.start_time', array(
  2671. 'timeFormat' => 24,
  2672. 'type' => 'time',
  2673. 'interval' => 15,
  2674. 'selected' => '23:57'
  2675. ));
  2676. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2677. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2678. $result = $this->Form->input('Model.created', array(
  2679. 'timeFormat' => 24,
  2680. 'type' => 'datetime',
  2681. 'interval' => 15,
  2682. 'selected' => '2012-09-30 23:56'
  2683. ));
  2684. $this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
  2685. $this->assertContains('<option value="10" selected="selected">October</option>', $result);
  2686. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2687. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2688. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2689. }
  2690. /**
  2691. * Test time with selected values around 12:xx:xx
  2692. *
  2693. * @return void
  2694. */
  2695. public function testTimeSelectedWithIntervalTwelve() {
  2696. $this->markTestIncomplete('Need to revisit once models work again.');
  2697. $result = $this->Form->input('Model.start_time', array(
  2698. 'type' => 'time',
  2699. 'timeFormat' => 12,
  2700. 'interval' => 15,
  2701. 'selected' => '00:00:00'
  2702. ));
  2703. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2704. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2705. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2706. $result = $this->Form->input('Model.start_time', array(
  2707. 'type' => 'time',
  2708. 'timeFormat' => 12,
  2709. 'interval' => 15,
  2710. 'selected' => '12:00:00'
  2711. ));
  2712. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2713. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2714. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2715. $result = $this->Form->input('Model.start_time', array(
  2716. 'type' => 'time',
  2717. 'timeFormat' => 12,
  2718. 'interval' => 15,
  2719. 'selected' => '12:15:00'
  2720. ));
  2721. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2722. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2723. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2724. }
  2725. /**
  2726. * Test interval & timeFormat = 12
  2727. *
  2728. * @return void
  2729. */
  2730. public function testInputTimeWithIntervalAnd12HourFormat() {
  2731. $this->markTestIncomplete('Need to revisit once models work again.');
  2732. $result = $this->Form->input('Model.start_time', array(
  2733. 'type' => 'time',
  2734. 'timeFormat' => 12,
  2735. 'interval' => 5,
  2736. 'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
  2737. ));
  2738. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2739. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2740. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2741. $result = $this->Form->input('Model.start_time', array(
  2742. 'type' => 'time',
  2743. 'timeFormat' => '12',
  2744. 'interval' => 5,
  2745. 'selected' => '2013-04-19 16:30:00'
  2746. ));
  2747. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2748. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2749. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2750. $result = $this->Form->input('Model.start_time', array(
  2751. 'type' => 'time',
  2752. 'timeFormat' => '12',
  2753. 'interval' => 10,
  2754. 'selected' => '2013-05-19 00:33:00'
  2755. ));
  2756. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2757. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2758. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2759. $result = $this->Form->input('Model.start_time', array(
  2760. 'type' => 'time',
  2761. 'timeFormat' => '12',
  2762. 'interval' => 10,
  2763. 'selected' => '2013-05-19 13:33:00'
  2764. ));
  2765. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2766. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2767. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2768. $result = $this->Form->input('Model.start_time', array(
  2769. 'type' => 'time',
  2770. 'timeFormat' => '12',
  2771. 'interval' => 10,
  2772. 'selected' => '2013-05-19 01:33:00'
  2773. ));
  2774. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2775. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2776. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2777. }
  2778. /**
  2779. * test form->input() with datetime, date and time types
  2780. *
  2781. * @return void
  2782. */
  2783. public function testInputDatetime() {
  2784. $this->markTestIncomplete('Need to revisit once models work again.');
  2785. extract($this->dateRegex);
  2786. $result = $this->Form->input('prueba', array(
  2787. 'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2788. 'maxYear' => date('Y') + 1, 'interval' => 15
  2789. ));
  2790. $result = explode(':', $result);
  2791. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2792. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2793. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2794. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2795. //related to ticket #5013
  2796. $result = $this->Form->input('Contact.date', array(
  2797. 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
  2798. ));
  2799. $this->assertRegExp('/class="customClass"/', $result);
  2800. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2801. $result = $this->Form->input('Contact.date', array(
  2802. 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
  2803. ));
  2804. $this->assertRegExp('/id="customIdDay"/', $result);
  2805. $this->assertRegExp('/id="customIdMonth"/', $result);
  2806. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2807. $result = $this->Form->input('Model.field', array(
  2808. 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
  2809. ));
  2810. $this->assertRegExp('/id="customIDDay"/', $result);
  2811. $this->assertRegExp('/id="customIDHour"/', $result);
  2812. $result = explode('</select><select', $result);
  2813. $result = explode(':', $result[1]);
  2814. $this->assertRegExp('/option value="23"/', $result[0]);
  2815. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2816. $result = $this->Form->input('Model.field', array(
  2817. 'type' => 'datetime', 'timeFormat' => 12
  2818. ));
  2819. $result = explode('</select><select', $result);
  2820. $result = explode(':', $result[1]);
  2821. $this->assertRegExp('/option value="12"/', $result[0]);
  2822. $this->assertNotRegExp('/option value="13"/', $result[0]);
  2823. $this->Form->request->data = array('Contact' => array('created' => null));
  2824. $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
  2825. $expected = array(
  2826. 'div' => array('class' => 'input date'),
  2827. 'label' => array('for' => 'ContactCreatedMonth'),
  2828. 'Created',
  2829. '/label',
  2830. array('select' => array('name' => 'Contact[created][month]', 'id' => 'ContactCreatedMonth')),
  2831. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2832. $monthsRegex,
  2833. '/select', '-',
  2834. array('select' => array('name' => 'Contact[created][day]', 'id' => 'ContactCreatedDay')),
  2835. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2836. $daysRegex,
  2837. '/select', '-',
  2838. array('select' => array('name' => 'Contact[created][year]', 'id' => 'ContactCreatedYear')),
  2839. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2840. $yearsRegex,
  2841. '/select',
  2842. '/div'
  2843. );
  2844. $this->assertTags($result, $expected);
  2845. $this->Form->request->data = array('Contact' => array('created' => null));
  2846. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
  2847. $this->assertRegExp('/for\="ContactCreatedHour"/', $result);
  2848. $this->Form->request->data = array('Contact' => array('created' => null));
  2849. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
  2850. $this->assertRegExp('/for\="ContactCreatedMonth"/', $result);
  2851. $result = $this->Form->input('Contact.created', array(
  2852. 'type' => 'date',
  2853. 'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
  2854. 'timeFormat' => 'NONE'
  2855. ));
  2856. $this->assertRegExp('/for\="created-month"/', $result);
  2857. }
  2858. /**
  2859. * Test generating checkboxes with disabled elements.
  2860. *
  2861. * @return void
  2862. */
  2863. public function testInputCheckboxWithDisabledElements() {
  2864. $this->markTestIncomplete('Need to revisit once models work again.');
  2865. $options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
  2866. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
  2867. $expected = array(
  2868. array('div' => array('class' => 'input select')),
  2869. array('label' => array('for' => "ContactMultiple")),
  2870. 'Multiple',
  2871. '/label',
  2872. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2873. array('div' => array('class' => 'checkbox')),
  2874. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
  2875. array('label' => array('for' => "ContactMultiple1")),
  2876. 'One',
  2877. '/label',
  2878. '/div',
  2879. array('div' => array('class' => 'checkbox')),
  2880. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2881. array('label' => array('for' => "ContactMultiple2")),
  2882. 'Two',
  2883. '/label',
  2884. '/div',
  2885. array('div' => array('class' => 'checkbox')),
  2886. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2887. array('label' => array('for' => "ContactMultiple3")),
  2888. 'Three',
  2889. '/label',
  2890. '/div',
  2891. '/div'
  2892. );
  2893. $this->assertTags($result, $expected);
  2894. $result = $this->Form->radio('Model.field', array('1/2' => 'half'));
  2895. $expected = array(
  2896. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '', 'id' => 'ModelField_'),
  2897. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1/2', 'id' => 'ModelField12')),
  2898. 'label' => array('for' => 'ModelField12'),
  2899. 'half',
  2900. '/label'
  2901. );
  2902. $this->assertTags($result, $expected);
  2903. $disabled = array('2', 3);
  2904. $expected = array(
  2905. array('div' => array('class' => 'input select')),
  2906. array('label' => array('for' => "ContactMultiple")),
  2907. 'Multiple',
  2908. '/label',
  2909. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2910. array('div' => array('class' => 'checkbox')),
  2911. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
  2912. array('label' => array('for' => "ContactMultiple1")),
  2913. 'One',
  2914. '/label',
  2915. '/div',
  2916. array('div' => array('class' => 'checkbox')),
  2917. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2918. array('label' => array('for' => "ContactMultiple2")),
  2919. 'Two',
  2920. '/label',
  2921. '/div',
  2922. array('div' => array('class' => 'checkbox')),
  2923. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2924. array('label' => array('for' => "ContactMultiple3")),
  2925. 'Three',
  2926. '/label',
  2927. '/div',
  2928. '/div'
  2929. );
  2930. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2931. $this->assertTags($result, $expected);
  2932. // make sure 50 does only disable 50, and not 50f5c0cf
  2933. $options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
  2934. $disabled = array(50);
  2935. $expected = array(
  2936. array('div' => array('class' => 'input select')),
  2937. array('label' => array('for' => "ContactMultiple")),
  2938. 'Multiple',
  2939. '/label',
  2940. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2941. array('div' => array('class' => 'checkbox')),
  2942. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
  2943. array('label' => array('for' => "ContactMultiple50")),
  2944. 'Fifty',
  2945. '/label',
  2946. '/div',
  2947. array('div' => array('class' => 'checkbox')),
  2948. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
  2949. array('label' => array('for' => "ContactMultiple50f5c0cf")),
  2950. 'Stringy',
  2951. '/label',
  2952. '/div',
  2953. '/div'
  2954. );
  2955. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2956. $this->assertTags($result, $expected);
  2957. }
  2958. /**
  2959. * test input name with leading integer, ensure attributes are generated correctly.
  2960. *
  2961. * @return void
  2962. */
  2963. public function testInputWithLeadingInteger() {
  2964. $result = $this->Form->text('0.Node.title');
  2965. $expected = array(
  2966. 'input' => array('name' => '0[Node][title]', 'type' => 'text')
  2967. );
  2968. $this->assertTags($result, $expected);
  2969. }
  2970. /**
  2971. * test form->input() with select type inputs.
  2972. *
  2973. * @return void
  2974. */
  2975. public function testInputSelectType() {
  2976. $this->markTestIncomplete('Need to revisit once models work again.');
  2977. $result = $this->Form->input('email', array(
  2978. 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
  2979. );
  2980. $expected = array(
  2981. 'div' => array('class' => 'input select'),
  2982. 'label' => array('for' => 'email'),
  2983. 'Email',
  2984. '/label',
  2985. array('select' => array('name' => 'email', 'id' => 'email')),
  2986. array('option' => array('value' => '')),
  2987. '/option',
  2988. array('option' => array('value' => 'è')),
  2989. 'Firést',
  2990. '/option',
  2991. array('option' => array('value' => 'é')),
  2992. 'Secoènd',
  2993. '/option',
  2994. '/select',
  2995. '/div'
  2996. );
  2997. $this->assertTags($result, $expected);
  2998. $result = $this->Form->input('email', array(
  2999. 'options' => array('First', 'Second'), 'empty' => true)
  3000. );
  3001. $expected = array(
  3002. 'div' => array('class' => 'input select'),
  3003. 'label' => array('for' => 'email'),
  3004. 'Email',
  3005. '/label',
  3006. array('select' => array('name' => 'email', 'id' => 'email')),
  3007. array('option' => array('value' => '')),
  3008. '/option',
  3009. array('option' => array('value' => '0')),
  3010. 'First',
  3011. '/option',
  3012. array('option' => array('value' => '1')),
  3013. 'Second',
  3014. '/option',
  3015. '/select',
  3016. '/div'
  3017. );
  3018. $this->assertTags($result, $expected);
  3019. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3020. $this->Form->request->data = array('Model' => array('user_id' => 'value'));
  3021. $result = $this->Form->input('Model.user_id', array('empty' => true));
  3022. $expected = array(
  3023. 'div' => array('class' => 'input select'),
  3024. 'label' => array('for' => 'ModelUserId'),
  3025. 'User',
  3026. '/label',
  3027. 'select' => array('name' => 'Model[user_id]', 'id' => 'ModelUserId'),
  3028. array('option' => array('value' => '')),
  3029. '/option',
  3030. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3031. 'good',
  3032. '/option',
  3033. array('option' => array('value' => 'other')),
  3034. 'bad',
  3035. '/option',
  3036. '/select',
  3037. '/div'
  3038. );
  3039. $this->assertTags($result, $expected);
  3040. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3041. $this->Form->request->data = array('Thing' => array('user_id' => null));
  3042. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3043. $expected = array(
  3044. 'div' => array('class' => 'input select'),
  3045. 'label' => array('for' => 'ThingUserId'),
  3046. 'User',
  3047. '/label',
  3048. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3049. array('option' => array('value' => '')),
  3050. 'Some Empty',
  3051. '/option',
  3052. array('option' => array('value' => 'value')),
  3053. 'good',
  3054. '/option',
  3055. array('option' => array('value' => 'other')),
  3056. 'bad',
  3057. '/option',
  3058. '/select',
  3059. '/div'
  3060. );
  3061. $this->assertTags($result, $expected);
  3062. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3063. $this->Form->request->data = array('Thing' => array('user_id' => 'value'));
  3064. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3065. $expected = array(
  3066. 'div' => array('class' => 'input select'),
  3067. 'label' => array('for' => 'ThingUserId'),
  3068. 'User',
  3069. '/label',
  3070. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3071. array('option' => array('value' => '')),
  3072. 'Some Empty',
  3073. '/option',
  3074. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3075. 'good',
  3076. '/option',
  3077. array('option' => array('value' => 'other')),
  3078. 'bad',
  3079. '/option',
  3080. '/select',
  3081. '/div'
  3082. );
  3083. $this->assertTags($result, $expected);
  3084. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3085. $this->Form->request->data = array('User' => array('User' => array('value')));
  3086. $result = $this->Form->input('User.User', array('empty' => true));
  3087. $expected = array(
  3088. 'div' => array('class' => 'input select'),
  3089. 'label' => array('for' => 'UserUser'),
  3090. 'User',
  3091. '/label',
  3092. 'input' => array('type' => 'hidden', 'name' => 'User[User]', 'value' => '', 'id' => 'UserUser_'),
  3093. 'select' => array('name' => 'User[User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
  3094. array('option' => array('value' => '')),
  3095. '/option',
  3096. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3097. 'good',
  3098. '/option',
  3099. array('option' => array('value' => 'other')),
  3100. 'bad',
  3101. '/option',
  3102. '/select',
  3103. '/div'
  3104. );
  3105. $this->assertTags($result, $expected);
  3106. $this->Form->data = array();
  3107. $result = $this->Form->input('Publisher.id', array(
  3108. 'label' => 'Publisher',
  3109. 'type' => 'select',
  3110. 'multiple' => 'checkbox',
  3111. 'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
  3112. ));
  3113. $expected = array(
  3114. array('div' => array('class' => 'input select')),
  3115. array('label' => array('for' => 'PublisherId')),
  3116. 'Publisher',
  3117. '/label',
  3118. 'input' => array('type' => 'hidden', 'name' => 'Publisher[id]', 'value' => '', 'id' => 'PublisherId'),
  3119. array('div' => array('class' => 'checkbox')),
  3120. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
  3121. array('label' => array('for' => 'PublisherIdValue1')),
  3122. 'Label 1',
  3123. '/label',
  3124. '/div',
  3125. array('div' => array('class' => 'checkbox')),
  3126. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
  3127. array('label' => array('for' => 'PublisherIdValue2')),
  3128. 'Label 2',
  3129. '/label',
  3130. '/div',
  3131. '/div'
  3132. );
  3133. $this->assertTags($result, $expected);
  3134. }
  3135. /**
  3136. * test that input() and a non standard primary key makes a hidden input by default.
  3137. *
  3138. * @return void
  3139. */
  3140. public function testInputWithNonStandardPrimaryKeyMakesHidden() {
  3141. $this->markTestIncomplete('Need to revisit once models work again.');
  3142. $this->Form->create('User');
  3143. $this->Form->fieldset = array(
  3144. 'User' => array(
  3145. 'fields' => array(
  3146. 'model_id' => array('type' => 'integer')
  3147. ),
  3148. 'validates' => array(),
  3149. 'key' => 'model_id'
  3150. )
  3151. );
  3152. $result = $this->Form->input('model_id');
  3153. $expected = array(
  3154. 'input' => array('type' => 'hidden', 'name' => 'User[model_id]', 'id' => 'UserModelId'),
  3155. );
  3156. $this->assertTags($result, $expected);
  3157. }
  3158. /**
  3159. * test that overriding the magic select type widget is possible
  3160. *
  3161. * @return void
  3162. */
  3163. public function testInputOverridingMagicSelectType() {
  3164. $this->markTestIncomplete('Need to revisit once models work again.');
  3165. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3166. $result = $this->Form->input('Model.user_id', array('type' => 'text'));
  3167. $expected = array(
  3168. 'div' => array('class' => 'input text'),
  3169. 'label' => array('for' => 'ModelUserId'), 'User', '/label',
  3170. 'input' => array('name' => 'Model[user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
  3171. '/div'
  3172. );
  3173. $this->assertTags($result, $expected);
  3174. //Check that magic types still work for plural/singular vars
  3175. $this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
  3176. $result = $this->Form->input('Model.type');
  3177. $expected = array(
  3178. 'div' => array('class' => 'input select'),
  3179. 'label' => array('for' => 'ModelType'), 'Type', '/label',
  3180. 'select' => array('name' => 'Model[type]', 'id' => 'ModelType'),
  3181. array('option' => array('value' => 'value')), 'good', '/option',
  3182. array('option' => array('value' => 'other')), 'bad', '/option',
  3183. '/select',
  3184. '/div'
  3185. );
  3186. $this->assertTags($result, $expected);
  3187. }
  3188. /**
  3189. * Test that inferred types do not override developer input
  3190. *
  3191. * @return void
  3192. */
  3193. public function testInputMagicTypeDoesNotOverride() {
  3194. $this->markTestIncomplete('Need to revisit once models work again.');
  3195. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3196. $result = $this->Form->input('Model.user', array('type' => 'checkbox'));
  3197. $expected = array(
  3198. 'div' => array('class' => 'input checkbox'),
  3199. array('input' => array(
  3200. 'type' => 'hidden',
  3201. 'name' => 'data[Model][user]',
  3202. 'id' => 'ModelUser_',
  3203. 'value' => 0,
  3204. )),
  3205. array('input' => array(
  3206. 'name' => 'data[Model][user]',
  3207. 'type' => 'checkbox',
  3208. 'id' => 'ModelUser',
  3209. 'value' => 1
  3210. )),
  3211. 'label' => array('for' => 'ModelUser'), 'User', '/label',
  3212. '/div'
  3213. );
  3214. $this->assertTags($result, $expected);
  3215. }
  3216. /**
  3217. * Test that magic input() selects are created for type=number
  3218. *
  3219. * @return void
  3220. */
  3221. public function testInputMagicSelectForTypeNumber() {
  3222. $this->markTestIncomplete('Need to revisit once models work again.');
  3223. $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
  3224. $this->Form->request->data = array('ValidateUser' => array('balance' => 1));
  3225. $result = $this->Form->input('ValidateUser.balance');
  3226. $expected = array(
  3227. 'div' => array('class' => 'input select'),
  3228. 'label' => array('for' => 'ValidateUserBalance'),
  3229. 'Balance',
  3230. '/label',
  3231. 'select' => array('name' => 'ValidateUser[balance]', 'id' => 'ValidateUserBalance'),
  3232. array('option' => array('value' => '0')),
  3233. 'nothing',
  3234. '/option',
  3235. array('option' => array('value' => '1', 'selected' => 'selected')),
  3236. 'some',
  3237. '/option',
  3238. array('option' => array('value' => '100')),
  3239. 'a lot',
  3240. '/option',
  3241. '/select',
  3242. '/div'
  3243. );
  3244. $this->assertTags($result, $expected);
  3245. }
  3246. /**
  3247. * Test that magic input() selects can easily be converted into radio types without error.
  3248. *
  3249. * @return void
  3250. */
  3251. public function testInputMagicSelectChangeToRadio() {
  3252. $this->markTestIncomplete('Need to revisit once models work again.');
  3253. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3254. $result = $this->Form->input('Model.user_id', array('type' => 'radio'));
  3255. $this->assertRegExp('/input type="radio"/', $result);
  3256. }
  3257. /**
  3258. * fields with the same name as the model should work.
  3259. *
  3260. * @return void
  3261. */
  3262. public function testInputWithMatchingFieldAndModelName() {
  3263. $this->markTestIncomplete('Need to revisit once models work again.');
  3264. $this->Form->create('User');
  3265. $this->Form->fieldset = array(
  3266. 'User' => array(
  3267. 'fields' => array(
  3268. 'User' => array('type' => 'text')
  3269. ),
  3270. 'validates' => array(),
  3271. 'key' => 'id'
  3272. )
  3273. );
  3274. $this->Form->request->data['User']['User'] = 'ABC, Inc.';
  3275. $result = $this->Form->input('User', array('type' => 'text'));
  3276. $expected = array(
  3277. 'div' => array('class' => 'input text'),
  3278. 'label' => array('for' => 'UserUser'), 'User', '/label',
  3279. 'input' => array('name' => 'User[User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
  3280. '/div'
  3281. );
  3282. $this->assertTags($result, $expected);
  3283. }
  3284. /**
  3285. * testFormInputs method
  3286. *
  3287. * test correct results from form::inputs().
  3288. *
  3289. * @return void
  3290. */
  3291. public function testFormInputs() {
  3292. $this->markTestIncomplete('Need to revisit once models work again.');
  3293. $this->Form->create('Cake\Test\TestCase\View\Helper\Contact');
  3294. $result = $this->Form->inputs('The Legend');
  3295. $expected = array(
  3296. '<fieldset',
  3297. '<legend',
  3298. 'The Legend',
  3299. '/legend',
  3300. '*/fieldset',
  3301. );
  3302. $this->assertTags($result, $expected);
  3303. $result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3304. $expected = array(
  3305. 'fieldset' => array('class' => 'classy-stuff'),
  3306. '<legend',
  3307. 'Field of Dreams',
  3308. '/legend',
  3309. '*/fieldset'
  3310. );
  3311. $this->assertTags($result, $expected);
  3312. $result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3313. $this->assertTags($result, $expected);
  3314. $result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
  3315. $this->assertTags($result, $expected);
  3316. $this->Form->create('Contact');
  3317. $this->Form->request['prefix'] = 'admin';
  3318. $this->Form->request['action'] = 'admin_edit';
  3319. $result = $this->Form->inputs();
  3320. $expected = array(
  3321. '<fieldset',
  3322. '<legend',
  3323. 'Edit Contact',
  3324. '/legend',
  3325. '*/fieldset',
  3326. );
  3327. $this->assertTags($result, $expected);
  3328. $this->Form->create('Contact');
  3329. $result = $this->Form->inputs(false);
  3330. $expected = array(
  3331. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3332. array('div' => array('class' => 'input text')),
  3333. '*/div',
  3334. array('div' => array('class' => 'input email')),
  3335. '*/div',
  3336. array('div' => array('class' => 'input tel')),
  3337. '*/div',
  3338. array('div' => array('class' => 'input password')),
  3339. '*/div',
  3340. array('div' => array('class' => 'input date')),
  3341. '*/div',
  3342. array('div' => array('class' => 'input date')),
  3343. '*/div',
  3344. array('div' => array('class' => 'input datetime')),
  3345. '*/div',
  3346. array('div' => array('class' => 'input number')),
  3347. '*/div',
  3348. array('div' => array('class' => 'input select')),
  3349. '*/div',
  3350. );
  3351. $this->assertTags($result, $expected);
  3352. $this->Form->create('Contact');
  3353. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
  3354. $expected = array(
  3355. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3356. array('div' => array('class' => 'input text')),
  3357. '*/div',
  3358. array('div' => array('class' => 'input email')),
  3359. '*/div',
  3360. array('div' => array('class' => 'input tel')),
  3361. '*/div',
  3362. array('div' => array('class' => 'input password')),
  3363. '*/div',
  3364. array('div' => array('class' => 'input date')),
  3365. '*/div',
  3366. array('div' => array('class' => 'input date')),
  3367. '*/div',
  3368. array('div' => array('class' => 'input datetime')),
  3369. '*/div',
  3370. array('div' => array('class' => 'input number')),
  3371. '*/div',
  3372. array('div' => array('class' => 'input select')),
  3373. '*/div',
  3374. );
  3375. $this->assertTags($result, $expected);
  3376. $this->Form->create('Contact');
  3377. $result = $this->Form->inputs(null, null, array('fieldset' => false));
  3378. $this->assertTags($result, $expected);
  3379. $this->Form->create('Contact');
  3380. $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
  3381. $expected = array(
  3382. 'fieldset' => array(),
  3383. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3384. array('div' => array('class' => 'input text')),
  3385. '*/div',
  3386. array('div' => array('class' => 'input email')),
  3387. '*/div',
  3388. array('div' => array('class' => 'input tel')),
  3389. '*/div',
  3390. array('div' => array('class' => 'input password')),
  3391. '*/div',
  3392. array('div' => array('class' => 'input date')),
  3393. '*/div',
  3394. array('div' => array('class' => 'input date')),
  3395. '*/div',
  3396. array('div' => array('class' => 'input datetime')),
  3397. '*/div',
  3398. array('div' => array('class' => 'input number')),
  3399. '*/div',
  3400. array('div' => array('class' => 'input select')),
  3401. '*/div',
  3402. '/fieldset'
  3403. );
  3404. $this->assertTags($result, $expected);
  3405. $this->Form->create('Contact');
  3406. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
  3407. $expected = array(
  3408. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3409. array('div' => array('class' => 'input text')),
  3410. '*/div',
  3411. array('div' => array('class' => 'input email')),
  3412. '*/div',
  3413. array('div' => array('class' => 'input tel')),
  3414. '*/div',
  3415. array('div' => array('class' => 'input password')),
  3416. '*/div',
  3417. array('div' => array('class' => 'input date')),
  3418. '*/div',
  3419. array('div' => array('class' => 'input date')),
  3420. '*/div',
  3421. array('div' => array('class' => 'input datetime')),
  3422. '*/div',
  3423. array('div' => array('class' => 'input number')),
  3424. '*/div',
  3425. array('div' => array('class' => 'input select')),
  3426. '*/div',
  3427. );
  3428. $this->assertTags($result, $expected);
  3429. $this->Form->create('Contact');
  3430. $result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
  3431. $this->assertTags($result, $expected);
  3432. $this->Form->create('Contact');
  3433. $result = $this->Form->inputs('Hello');
  3434. $expected = array(
  3435. 'fieldset' => array(),
  3436. 'legend' => array(),
  3437. 'Hello',
  3438. '/legend',
  3439. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3440. array('div' => array('class' => 'input text')),
  3441. '*/div',
  3442. array('div' => array('class' => 'input email')),
  3443. '*/div',
  3444. array('div' => array('class' => 'input tel')),
  3445. '*/div',
  3446. array('div' => array('class' => 'input password')),
  3447. '*/div',
  3448. array('div' => array('class' => 'input date')),
  3449. '*/div',
  3450. array('div' => array('class' => 'input date')),
  3451. '*/div',
  3452. array('div' => array('class' => 'input datetime')),
  3453. '*/div',
  3454. array('div' => array('class' => 'input number')),
  3455. '*/div',
  3456. array('div' => array('class' => 'input select')),
  3457. '*/div',
  3458. '/fieldset'
  3459. );
  3460. $this->assertTags($result, $expected);
  3461. $this->Form->create('Contact');
  3462. $result = $this->Form->inputs(array('legend' => 'Hello'));
  3463. $expected = array(
  3464. 'fieldset' => array(),
  3465. 'legend' => array(),
  3466. 'Hello',
  3467. '/legend',
  3468. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3469. array('div' => array('class' => 'input text')),
  3470. '*/div',
  3471. array('div' => array('class' => 'input email')),
  3472. '*/div',
  3473. array('div' => array('class' => 'input tel')),
  3474. '*/div',
  3475. array('div' => array('class' => 'input password')),
  3476. '*/div',
  3477. array('div' => array('class' => 'input date')),
  3478. '*/div',
  3479. array('div' => array('class' => 'input date')),
  3480. '*/div',
  3481. array('div' => array('class' => 'input datetime')),
  3482. '*/div',
  3483. array('div' => array('class' => 'input number')),
  3484. '*/div',
  3485. array('div' => array('class' => 'input select')),
  3486. '*/div',
  3487. '/fieldset'
  3488. );
  3489. $this->assertTags($result, $expected);
  3490. $this->Form->create('Contact');
  3491. $result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
  3492. $this->assertTags($result, $expected);
  3493. $this->Form->end();
  3494. $this->Form->create(false);
  3495. $expected = array(
  3496. 'fieldset' => array(),
  3497. array('div' => array('class' => 'input text')),
  3498. 'label' => array('for' => 'foo'),
  3499. 'Foo',
  3500. '/label',
  3501. 'input' => array('type' => 'text', 'name' => 'foo', 'id' => 'foo'),
  3502. '*/div',
  3503. '/fieldset'
  3504. );
  3505. $result = $this->Form->inputs(
  3506. array('foo' => array('type' => 'text')),
  3507. array(),
  3508. array('legend' => false)
  3509. );
  3510. $this->assertTags($result, $expected);
  3511. }
  3512. /**
  3513. * Tests inputs() works with plugin models
  3514. *
  3515. * @return void
  3516. */
  3517. public function testInputsPluginModel() {
  3518. $this->markTestIncomplete('Need to revisit once models work again.');
  3519. $this->loadFixtures('Post');
  3520. Plugin::load('TestPlugin');
  3521. $this->Form->request['models'] = array(
  3522. 'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
  3523. );
  3524. $this->Form->create('TestPlugin.TestPluginPost');
  3525. $result = $this->Form->inputs();
  3526. $this->assertContains('TestPluginPost[id]', $result);
  3527. $this->assertContains('TestPluginPost[author_id]', $result);
  3528. $this->assertContains('TestPluginPost[title]', $result);
  3529. $this->assertEquals('TestPluginPost', $this->Form->model());
  3530. }
  3531. /**
  3532. * testSelectAsCheckbox method
  3533. *
  3534. * test multi-select widget with checkbox formatting.
  3535. *
  3536. * @return void
  3537. */
  3538. public function testSelectAsCheckbox() {
  3539. $this->markTestIncomplete('Need to revisit once models work again.');
  3540. $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
  3541. $expected = array(
  3542. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3543. array('div' => array('class' => 'checkbox')),
  3544. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
  3545. array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
  3546. 'first',
  3547. '/label',
  3548. '/div',
  3549. array('div' => array('class' => 'checkbox')),
  3550. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
  3551. array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
  3552. 'second',
  3553. '/label',
  3554. '/div',
  3555. array('div' => array('class' => 'checkbox')),
  3556. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  3557. array('label' => array('for' => 'ModelMultiField2')),
  3558. 'third',
  3559. '/label',
  3560. '/div',
  3561. );
  3562. $this->assertTags($result, $expected);
  3563. $result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
  3564. $expected = array(
  3565. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3566. array('div' => array('class' => 'checkbox')),
  3567. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField1/22')),
  3568. array('label' => array('for' => 'ModelMultiField1/22')),
  3569. 'half',
  3570. '/label',
  3571. '/div',
  3572. );
  3573. $this->assertTags($result, $expected);
  3574. }
  3575. /**
  3576. * testLabel method
  3577. *
  3578. * test label generation.
  3579. *
  3580. * @return void
  3581. */
  3582. public function testLabel() {
  3583. $result = $this->Form->label('Person.name');
  3584. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3585. $result = $this->Form->label('Person.name');
  3586. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3587. $result = $this->Form->label('Person.first_name');
  3588. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'First Name', '/label'));
  3589. $result = $this->Form->label('Person.first_name', 'Your first name');
  3590. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'Your first name', '/label'));
  3591. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
  3592. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class'), 'Your first name', '/label'));
  3593. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
  3594. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
  3595. $result = $this->Form->label('Person.first_name', '');
  3596. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), '/label'));
  3597. $result = $this->Form->label('Person.2.name', '');
  3598. $this->assertTags($result, array('label' => array('for' => 'person-2-name'), '/label'));
  3599. }
  3600. /**
  3601. * testTextbox method
  3602. *
  3603. * test textbox element generation
  3604. *
  3605. * @return void
  3606. */
  3607. public function testTextbox() {
  3608. $result = $this->Form->text('Model.field');
  3609. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]')));
  3610. $result = $this->Form->text('Model.field', array('type' => 'password'));
  3611. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Model[field]')));
  3612. $result = $this->Form->text('Model.field', array('id' => 'theID'));
  3613. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]', 'id' => 'theID')));
  3614. }
  3615. /**
  3616. * Test that text() hooks up with request data and error fields.
  3617. *
  3618. * @return void
  3619. */
  3620. public function testTextBoxDataAndError() {
  3621. $this->article['errors'] = [
  3622. 'Contact' => ['text' => 'wrong']
  3623. ];
  3624. $this->Form->create($this->article);
  3625. $this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
  3626. $result = $this->Form->text('Model.text');
  3627. $expected = [
  3628. 'input' => [
  3629. 'type' => 'text',
  3630. 'name' => 'Model[text]',
  3631. 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values',
  3632. ]
  3633. ];
  3634. $this->assertTags($result, $expected);
  3635. $this->Form->request->data['Contact']['text'] = 'test';
  3636. $result = $this->Form->text('Contact.text', ['id' => 'theID']);
  3637. $expected = [
  3638. 'input' => [
  3639. 'type' => 'text',
  3640. 'name' => 'Contact[text]',
  3641. 'value' => 'test',
  3642. 'id' => 'theID',
  3643. 'class' => 'form-error'
  3644. ]
  3645. ];
  3646. $this->assertTags($result, $expected);
  3647. }
  3648. /**
  3649. * testDefaultValue method
  3650. *
  3651. * Test default value setting
  3652. *
  3653. * @return void
  3654. */
  3655. public function testTextDefaultValue() {
  3656. $this->Form->request->data['Model']['field'] = 'test';
  3657. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3658. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'test']];
  3659. $this->assertTags($result, $expected);
  3660. unset($this->Form->request->data['Model']['field']);
  3661. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3662. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'default value']];
  3663. $this->assertTags($result, $expected);
  3664. }
  3665. /**
  3666. * testCheckboxDefaultValue method
  3667. *
  3668. * Test default value setting on checkbox() method
  3669. *
  3670. * @return void
  3671. */
  3672. public function testCheckboxDefaultValue() {
  3673. $this->markTestIncomplete('Need to revisit once models work again.');
  3674. $this->Form->request->data['Model']['field'] = false;
  3675. $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
  3676. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField')));
  3677. unset($this->Form->request->data['Model']['field']);
  3678. $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
  3679. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
  3680. $this->Form->request->data['Model']['field'] = true;
  3681. $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
  3682. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
  3683. unset($this->Form->request->data['Model']['field']);
  3684. $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
  3685. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField')));
  3686. }
  3687. /**
  3688. * testError method
  3689. *
  3690. * Test field error generation
  3691. *
  3692. * @return void
  3693. */
  3694. public function testError() {
  3695. $this->markTestIncomplete('Need to revisit once models work again.');
  3696. $Contact->validationErrors['field'] = array(1);
  3697. $result = $this->Form->error('Contact.field');
  3698. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
  3699. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3700. $this->assertEquals('Error in field Field', $result);
  3701. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3702. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3703. $this->assertEquals('This field contains invalid input', $result);
  3704. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3705. $result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
  3706. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
  3707. $result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
  3708. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
  3709. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
  3710. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3711. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
  3712. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3713. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
  3714. $this->assertEquals('<strong>Badness!</strong>', $result);
  3715. $Contact->validationErrors['field'] = array("email");
  3716. $result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
  3717. $expected = array(
  3718. 'div' => array('class' => 'field-error'),
  3719. 'No good!',
  3720. '/div'
  3721. );
  3722. $this->assertTags($result, $expected);
  3723. $Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
  3724. $result = $this->Form->error('Contact.field', array(
  3725. 'notEmpty' => 'Cannot be empty',
  3726. 'email' => 'No good!'
  3727. ));
  3728. $expected = array(
  3729. 'div' => array('class' => 'error-message'),
  3730. 'ul' => array(),
  3731. '<li', 'Cannot be empty', '/li',
  3732. '<li', 'No good!', '/li',
  3733. '<li', 'Something else', '/li',
  3734. '/ul',
  3735. '/div'
  3736. );
  3737. $this->assertTags($result, $expected);
  3738. // Testing error messages list options
  3739. $Contact->validationErrors['field'] = array('notEmpty', 'email');
  3740. $result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
  3741. $expected = array(
  3742. 'div' => array('class' => 'error-message'),
  3743. 'ol' => array(),
  3744. '<li', 'notEmpty', '/li',
  3745. '<li', 'email', '/li',
  3746. '/ol',
  3747. '/div'
  3748. );
  3749. $this->assertTags($result, $expected);
  3750. $result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
  3751. $expected = array(
  3752. 'div' => array('class' => 'error-message'),
  3753. 'ol' => array(),
  3754. '<li', 'notEmpty', '/li',
  3755. '<li', 'email', '/li',
  3756. '/ol',
  3757. '/div'
  3758. );
  3759. $this->assertTags($result, $expected);
  3760. $result = $this->Form->error('Contact.field', null, array(
  3761. 'listOptions' => array(
  3762. 'class' => 'ul-class',
  3763. 'itemOptions' => array(
  3764. 'class' => 'li-class'
  3765. )
  3766. )
  3767. ));
  3768. $expected = array(
  3769. 'div' => array('class' => 'error-message'),
  3770. 'ul' => array('class' => 'ul-class'),
  3771. array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
  3772. array('li' => array('class' => 'li-class')), 'email', '/li',
  3773. '/ul',
  3774. '/div'
  3775. );
  3776. $this->assertTags($result, $expected);
  3777. }
  3778. /**
  3779. * test error options when using form->input();
  3780. *
  3781. * @return void
  3782. */
  3783. public function testInputErrorEscape() {
  3784. $this->markTestIncomplete('Need to revisit once models work again.');
  3785. $this->Form->create('ValidateProfile');
  3786. $ValidateProfile->validationErrors['city'] = array('required<br>');
  3787. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
  3788. $this->assertRegExp('/required&lt;br&gt;/', $result);
  3789. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
  3790. $this->assertRegExp('/required<br>/', $result);
  3791. }
  3792. /**
  3793. * testPassword method
  3794. *
  3795. * Test password element generation
  3796. *
  3797. * @return void
  3798. */
  3799. public function testPassword() {
  3800. $this->article['errors'] = [
  3801. 'Contact' => [
  3802. 'passwd' => 1
  3803. ]
  3804. ];
  3805. $this->Form->create($this->article);
  3806. $result = $this->Form->password('Contact.field');
  3807. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[field]')));
  3808. $this->Form->request->data['Contact']['passwd'] = 'test';
  3809. $result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
  3810. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
  3811. }
  3812. /**
  3813. * testRadio method
  3814. *
  3815. * Test radio element set generation
  3816. *
  3817. * @return void
  3818. */
  3819. public function testRadio() {
  3820. $result = $this->Form->radio('Model.field', array('option A'));
  3821. $expected = array(
  3822. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3823. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3824. 'label' => array('for' => 'model-field-0'),
  3825. 'option A',
  3826. '/label'
  3827. );
  3828. $this->assertTags($result, $expected);
  3829. $result = $this->Form->radio('Model.field', array('option A', 'option B'));
  3830. $expected = array(
  3831. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3832. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3833. array('label' => array('for' => 'model-field-0')),
  3834. 'option A',
  3835. '/label',
  3836. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1', 'id' => 'model-field-1')),
  3837. array('label' => array('for' => 'model-field-1')),
  3838. 'option B',
  3839. '/label',
  3840. );
  3841. $this->assertTags($result, $expected);
  3842. $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
  3843. $expected = array(
  3844. 'input' => array('type' => 'hidden', 'name' => 'Employee[gender]', 'value' => ''),
  3845. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'male', 'id' => 'employee-gender-male')),
  3846. array('label' => array('for' => 'employee-gender-male')),
  3847. 'Male',
  3848. '/label',
  3849. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'female', 'id' => 'employee-gender-female')),
  3850. array('label' => array('for' => 'employee-gender-female')),
  3851. 'Female',
  3852. '/label',
  3853. );
  3854. $this->assertTags($result, $expected);
  3855. $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'Model[custom]'));
  3856. $expected = array(
  3857. array('input' => array('type' => 'hidden', 'name' => 'Model[custom]', 'value' => '')),
  3858. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '0', 'id' => 'model-custom-0')),
  3859. array('label' => array('for' => 'model-custom-0')),
  3860. 'option A',
  3861. '/label',
  3862. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '1', 'id' => 'model-custom-1')),
  3863. array('label' => array('for' => 'model-custom-1')),
  3864. 'option B',
  3865. '/label',
  3866. );
  3867. $this->assertTags($result, $expected);
  3868. }
  3869. /**
  3870. * test disabling the hidden input for radio buttons
  3871. *
  3872. * @return void
  3873. */
  3874. public function testRadioHiddenInputDisabling() {
  3875. $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
  3876. $expected = array(
  3877. 'input' => array('type' => 'radio', 'name' => 'Model[1][field]', 'value' => '0', 'id' => 'model-1-field-0'),
  3878. 'label' => array('for' => 'model-1-field-0'),
  3879. 'option A',
  3880. '/label'
  3881. );
  3882. $this->assertTags($result, $expected);
  3883. }
  3884. /**
  3885. * testDomIdSuffix method
  3886. *
  3887. * @return void
  3888. */
  3889. public function testDomIdSuffix() {
  3890. $this->markTestIncomplete('Need to revisit once models work again.');
  3891. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs');
  3892. $this->assertEquals('1StringWith1$-dollarSigns', $result);
  3893. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>');
  3894. $this->assertEquals('AbcX=FooY=Bar', $result);
  3895. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs', 'xhtml');
  3896. $this->assertEquals('1StringWith1-dollarSigns', $result);
  3897. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>', 'xhtml');
  3898. $this->assertEquals('AbcXFooYBar', $result);
  3899. }
  3900. /**
  3901. * testDomIdSuffixCollisionResolvement()
  3902. *
  3903. * @return void
  3904. */
  3905. public function testDomIdSuffixCollisionResolvement() {
  3906. $this->markTestIncomplete('Need to revisit once models work again.');
  3907. $result = $this->Form->domIdSuffix('a>b');
  3908. $this->assertEquals('AB', $result);
  3909. $result = $this->Form->domIdSuffix('a<b');
  3910. $this->assertEquals('AB1', $result);
  3911. $result = $this->Form->domIdSuffix('a\'b');
  3912. $this->assertEquals('AB2', $result);
  3913. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3914. $this->assertEquals('1StringWith1-dollar', $result);
  3915. $result = $this->Form->domIdSuffix('1 string with 1€-dollar', 'xhtml');
  3916. $this->assertEquals('1StringWith1-dollar1', $result);
  3917. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3918. $this->assertEquals('1StringWith1-dollar2', $result);
  3919. }
  3920. /**
  3921. * testSelect method
  3922. *
  3923. * Test select element generation.
  3924. *
  3925. * @return void
  3926. */
  3927. public function testSelect() {
  3928. $result = $this->Form->select('Model.field', array());
  3929. $expected = array(
  3930. 'select' => array('name' => 'Model[field]'),
  3931. array('option' => array('value' => '')),
  3932. '/option',
  3933. '/select'
  3934. );
  3935. $this->assertTags($result, $expected);
  3936. $this->Form->request->data = array('Model' => array('field' => 'value'));
  3937. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3938. $expected = array(
  3939. 'select' => array('name' => 'Model[field]'),
  3940. array('option' => array('value' => '')),
  3941. '/option',
  3942. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3943. 'good',
  3944. '/option',
  3945. array('option' => array('value' => 'other')),
  3946. 'bad',
  3947. '/option',
  3948. '/select'
  3949. );
  3950. $this->assertTags($result, $expected);
  3951. $this->Form->request->data = array();
  3952. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3953. $expected = array(
  3954. 'select' => array('name' => 'Model[field]'),
  3955. array('option' => array('value' => '')),
  3956. '/option',
  3957. array('option' => array('value' => 'value')),
  3958. 'good',
  3959. '/option',
  3960. array('option' => array('value' => 'other')),
  3961. 'bad',
  3962. '/option',
  3963. '/select'
  3964. );
  3965. $this->assertTags($result, $expected);
  3966. $result = $this->Form->select(
  3967. 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
  3968. array('empty' => false)
  3969. );
  3970. $expected = array(
  3971. 'select' => array('name' => 'Model[field]'),
  3972. array('option' => array('value' => 'first')),
  3973. 'first &quot;html&quot; &lt;chars&gt;',
  3974. '/option',
  3975. array('option' => array('value' => 'second')),
  3976. 'value',
  3977. '/option',
  3978. '/select'
  3979. );
  3980. $this->assertTags($result, $expected);
  3981. $result = $this->Form->select(
  3982. 'Model.field',
  3983. array('first' => 'first "html" <chars>', 'second' => 'value'),
  3984. array('escape' => false, 'empty' => false)
  3985. );
  3986. $expected = array(
  3987. 'select' => array('name' => 'Model[field]'),
  3988. array('option' => array('value' => 'first')),
  3989. 'first "html" <chars>',
  3990. '/option',
  3991. array('option' => array('value' => 'second')),
  3992. 'value',
  3993. '/option',
  3994. '/select'
  3995. );
  3996. $this->assertTags($result, $expected);
  3997. $options = array(
  3998. array('value' => 'first', 'text' => 'First'),
  3999. array('value' => 'first', 'text' => 'Another First'),
  4000. );
  4001. $result = $this->Form->select(
  4002. 'Model.field',
  4003. $options,
  4004. array('escape' => false, 'empty' => false)
  4005. );
  4006. $expected = array(
  4007. 'select' => array('name' => 'Model[field]'),
  4008. array('option' => array('value' => 'first')),
  4009. 'First',
  4010. '/option',
  4011. array('option' => array('value' => 'first')),
  4012. 'Another First',
  4013. '/option',
  4014. '/select'
  4015. );
  4016. $this->assertTags($result, $expected);
  4017. $this->Form->request->data = array('Model' => array('contact_id' => 228));
  4018. $result = $this->Form->select(
  4019. 'Model.contact_id',
  4020. array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
  4021. array('escape' => false, 'empty' => 'pick something')
  4022. );
  4023. $expected = array(
  4024. 'select' => array('name' => 'Model[contact_id]'),
  4025. array('option' => array('value' => '')), 'pick something', '/option',
  4026. array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
  4027. array('option' => array('value' => '228-1')), '228-1 value', '/option',
  4028. array('option' => array('value' => '228-2')), '228-2 value', '/option',
  4029. '/select'
  4030. );
  4031. $this->assertTags($result, $expected);
  4032. $this->Form->request->data['Model']['field'] = 0;
  4033. $result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
  4034. $expected = array(
  4035. 'select' => array('name' => 'Model[field]'),
  4036. array('option' => array('value' => '')), '/option',
  4037. array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
  4038. array('option' => array('value' => '1')), 'Yes', '/option',
  4039. '/select'
  4040. );
  4041. $this->assertTags($result, $expected);
  4042. }
  4043. /**
  4044. * test select() with required and disabled attributes.
  4045. *
  4046. * @return void
  4047. */
  4048. public function testSelectRequired() {
  4049. $this->article['required'] = [
  4050. 'user_id' => true
  4051. ];
  4052. $this->Form->create($this->article);
  4053. $result = $this->Form->select('user_id', array('option A'));
  4054. $expected = array(
  4055. 'select' => array(
  4056. 'name' => 'user_id',
  4057. 'required' => 'required'
  4058. ),
  4059. array('option' => array('value' => '')), '/option',
  4060. array('option' => array('value' => '0')), 'option A', '/option',
  4061. '/select'
  4062. );
  4063. $this->assertTags($result, $expected);
  4064. $result = $this->Form->select('user_id', array('option A'), array('disabled' => true));
  4065. $expected = array(
  4066. 'select' => array(
  4067. 'name' => 'user_id',
  4068. 'disabled' => 'disabled'
  4069. ),
  4070. array('option' => array('value' => '')), '/option',
  4071. array('option' => array('value' => '0')), 'option A', '/option',
  4072. '/select'
  4073. );
  4074. $this->assertTags($result, $expected);
  4075. }
  4076. /**
  4077. * testNestedSelect method
  4078. *
  4079. * test select element generation with optgroups
  4080. *
  4081. * @return void
  4082. */
  4083. public function testNestedSelect() {
  4084. $result = $this->Form->select(
  4085. 'Model.field',
  4086. array(1 => 'One', 2 => 'Two', 'Three' => array(
  4087. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  4088. )), array('empty' => false)
  4089. );
  4090. $expected = array(
  4091. 'select' => array('name' => 'Model[field]'),
  4092. array('option' => array('value' => 1)),
  4093. 'One',
  4094. '/option',
  4095. array('option' => array('value' => 2)),
  4096. 'Two',
  4097. '/option',
  4098. array('optgroup' => array('label' => 'Three')),
  4099. array('option' => array('value' => 3)),
  4100. 'Three',
  4101. '/option',
  4102. array('option' => array('value' => 4)),
  4103. 'Four',
  4104. '/option',
  4105. array('option' => array('value' => 5)),
  4106. 'Five',
  4107. '/option',
  4108. '/optgroup',
  4109. '/select'
  4110. );
  4111. $this->assertTags($result, $expected);
  4112. }
  4113. /**
  4114. * testSelectMultiple method
  4115. *
  4116. * test generation of multiple select elements
  4117. *
  4118. * @return void
  4119. */
  4120. public function testSelectMultiple() {
  4121. $options = array('first', 'second', 'third');
  4122. $result = $this->Form->select(
  4123. 'Model.multi_field',
  4124. $options,
  4125. array('multiple' => true)
  4126. );
  4127. $expected = array(
  4128. 'input' => array(
  4129. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => ''
  4130. ),
  4131. 'select' => array(
  4132. 'name' => 'Model[multi_field][]',
  4133. 'multiple' => 'multiple'
  4134. ),
  4135. array('option' => array('value' => '0')),
  4136. 'first',
  4137. '/option',
  4138. array('option' => array('value' => '1')),
  4139. 'second',
  4140. '/option',
  4141. array('option' => array('value' => '2')),
  4142. 'third',
  4143. '/option',
  4144. '/select'
  4145. );
  4146. $this->assertTags($result, $expected);
  4147. $result = $this->Form->select(
  4148. 'Model.multi_field',
  4149. $options,
  4150. array('multiple' => 'multiple')
  4151. );
  4152. $this->assertTags($result, $expected);
  4153. }
  4154. /**
  4155. * Test that a checkbox can have 0 for the value and 1 for the hidden input.
  4156. *
  4157. * @return void
  4158. */
  4159. public function testCheckboxZeroValue() {
  4160. $this->markTestIncomplete('Need to revisit once models work again.');
  4161. $result = $this->Form->input('User.get_spam', array(
  4162. 'type' => 'checkbox',
  4163. 'value' => '0',
  4164. 'hiddenField' => '1',
  4165. ));
  4166. $expected = array(
  4167. 'div' => array('class' => 'input checkbox'),
  4168. array('input' => array(
  4169. 'type' => 'hidden', 'name' => 'data[User][get_spam]',
  4170. 'value' => '1', 'id' => 'UserGetSpam_'
  4171. )),
  4172. array('input' => array(
  4173. 'type' => 'checkbox', 'name' => 'data[User][get_spam]',
  4174. 'value' => '0', 'id' => 'UserGetSpam'
  4175. )),
  4176. 'label' => array('for' => 'UserGetSpam'),
  4177. 'Get Spam',
  4178. '/label',
  4179. '/div'
  4180. );
  4181. $this->assertTags($result, $expected);
  4182. }
  4183. /**
  4184. * test generation of habtm select boxes.
  4185. *
  4186. * @return void
  4187. */
  4188. public function testHabtmSelectBox() {
  4189. $this->markTestIncomplete('Need to revisit once models work again.');
  4190. $this->View->viewVars['contactTags'] = array(
  4191. 1 => 'blue',
  4192. 2 => 'red',
  4193. 3 => 'green'
  4194. );
  4195. $this->Form->request->data = array(
  4196. 'Contact' => array(),
  4197. 'ContactTag' => array(
  4198. array(
  4199. 'id' => '1',
  4200. 'name' => 'blue'
  4201. ),
  4202. array(
  4203. 'id' => 3,
  4204. 'name' => 'green'
  4205. )
  4206. )
  4207. );
  4208. $this->Form->create('Contact');
  4209. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4210. $expected = array(
  4211. 'input' => array(
  4212. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4213. ),
  4214. 'select' => array(
  4215. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4216. 'multiple' => 'multiple'
  4217. ),
  4218. array('option' => array('value' => '1', 'selected' => 'selected')),
  4219. 'blue',
  4220. '/option',
  4221. array('option' => array('value' => '2')),
  4222. 'red',
  4223. '/option',
  4224. array('option' => array('value' => '3', 'selected' => 'selected')),
  4225. 'green',
  4226. '/option',
  4227. '/select'
  4228. );
  4229. $this->assertTags($result, $expected);
  4230. // make sure only 50 is selected, and not 50f5c0cf
  4231. $this->View->viewVars['contactTags'] = array(
  4232. '1' => 'blue',
  4233. '50f5c0cf' => 'red',
  4234. '50' => 'green'
  4235. );
  4236. $this->Form->request->data = array(
  4237. 'Contact' => array(),
  4238. 'ContactTag' => array(
  4239. array(
  4240. 'id' => 1,
  4241. 'name' => 'blue'
  4242. ),
  4243. array(
  4244. 'id' => 50,
  4245. 'name' => 'green'
  4246. )
  4247. )
  4248. );
  4249. $this->Form->create('Contact');
  4250. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4251. $expected = array(
  4252. 'input' => array(
  4253. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4254. ),
  4255. 'select' => array(
  4256. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4257. 'multiple' => 'multiple'
  4258. ),
  4259. array('option' => array('value' => '1', 'selected' => 'selected')),
  4260. 'blue',
  4261. '/option',
  4262. array('option' => array('value' => '50f5c0cf')),
  4263. 'red',
  4264. '/option',
  4265. array('option' => array('value' => '50', 'selected' => 'selected')),
  4266. 'green',
  4267. '/option',
  4268. '/select'
  4269. );
  4270. $this->assertTags($result, $expected);
  4271. }
  4272. /**
  4273. * test generation of multi select elements in checkbox format
  4274. *
  4275. * @return void
  4276. */
  4277. public function testSelectMultipleCheckboxes() {
  4278. $this->markTestIncomplete('Need to revisit once models work again.');
  4279. $result = $this->Form->select(
  4280. 'Model.multi_field',
  4281. array('first', 'second', 'third'),
  4282. array('multiple' => 'checkbox')
  4283. );
  4284. $expected = array(
  4285. 'input' => array(
  4286. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4287. ),
  4288. array('div' => array('class' => 'checkbox')),
  4289. array('input' => array(
  4290. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4291. 'value' => '0', 'id' => 'ModelMultiField0'
  4292. )),
  4293. array('label' => array('for' => 'ModelMultiField0')),
  4294. 'first',
  4295. '/label',
  4296. '/div',
  4297. array('div' => array('class' => 'checkbox')),
  4298. array('input' => array(
  4299. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4300. 'value' => '1', 'id' => 'ModelMultiField1'
  4301. )),
  4302. array('label' => array('for' => 'ModelMultiField1')),
  4303. 'second',
  4304. '/label',
  4305. '/div',
  4306. array('div' => array('class' => 'checkbox')),
  4307. array('input' => array(
  4308. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4309. 'value' => '2', 'id' => 'ModelMultiField2'
  4310. )),
  4311. array('label' => array('for' => 'ModelMultiField2')),
  4312. 'third',
  4313. '/label',
  4314. '/div'
  4315. );
  4316. $this->assertTags($result, $expected);
  4317. $result = $this->Form->select(
  4318. 'Model.multi_field',
  4319. array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4320. array('multiple' => 'checkbox')
  4321. );
  4322. $expected = array(
  4323. 'input' => array(
  4324. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4325. ),
  4326. array('div' => array('class' => 'checkbox')),
  4327. array('input' => array(
  4328. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4329. 'value' => 'a', 'id' => 'ModelMultiFieldA'
  4330. )),
  4331. array('label' => array('for' => 'ModelMultiFieldA')),
  4332. 'first',
  4333. '/label',
  4334. '/div',
  4335. array('div' => array('class' => 'checkbox')),
  4336. array('input' => array(
  4337. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4338. 'value' => 'b', 'id' => 'ModelMultiFieldB'
  4339. )),
  4340. array('label' => array('for' => 'ModelMultiFieldB')),
  4341. 'second',
  4342. '/label',
  4343. '/div',
  4344. array('div' => array('class' => 'checkbox')),
  4345. array('input' => array(
  4346. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4347. 'value' => 'c', 'id' => 'ModelMultiFieldC'
  4348. )),
  4349. array('label' => array('for' => 'ModelMultiFieldC')),
  4350. 'third',
  4351. '/label',
  4352. '/div'
  4353. );
  4354. $this->assertTags($result, $expected);
  4355. $result = $this->Form->select(
  4356. 'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
  4357. );
  4358. $expected = array(
  4359. 'input' => array(
  4360. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4361. ),
  4362. array('div' => array('class' => 'checkbox')),
  4363. array('input' => array(
  4364. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4365. 'value' => '1', 'id' => 'ModelMultiField1'
  4366. )),
  4367. array('label' => array('for' => 'ModelMultiField1')),
  4368. 'first',
  4369. '/label',
  4370. '/div'
  4371. );
  4372. $this->assertTags($result, $expected);
  4373. $this->Form->request->data = array('Model' => array('tags' => array(1)));
  4374. $result = $this->Form->select(
  4375. 'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
  4376. );
  4377. $expected = array(
  4378. 'input' => array(
  4379. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4380. ),
  4381. array('div' => array('class' => 'checkbox')),
  4382. array('input' => array(
  4383. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4384. 'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
  4385. )),
  4386. array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
  4387. 'first',
  4388. '/label',
  4389. '/div',
  4390. array('div' => array('class' => 'checkbox')),
  4391. array('input' => array(
  4392. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4393. 'value' => 'Array', 'id' => 'ModelTagsArray'
  4394. )),
  4395. array('label' => array('for' => 'ModelTagsArray')),
  4396. 'Array',
  4397. '/label',
  4398. '/div'
  4399. );
  4400. $this->assertTags($result, $expected);
  4401. $result = $this->Form->select(
  4402. 'Model.multi_field',
  4403. array('a+' => 'first', 'a++' => 'second', 'a+++' => 'third'),
  4404. array('multiple' => 'checkbox')
  4405. );
  4406. $expected = array(
  4407. 'input' => array(
  4408. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4409. ),
  4410. array('div' => array('class' => 'checkbox')),
  4411. array('input' => array(
  4412. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4413. 'value' => 'a+', 'id' => 'ModelMultiFieldA+'
  4414. )),
  4415. array('label' => array('for' => 'ModelMultiFieldA+')),
  4416. 'first',
  4417. '/label',
  4418. '/div',
  4419. array('div' => array('class' => 'checkbox')),
  4420. array('input' => array(
  4421. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4422. 'value' => 'a++', 'id' => 'ModelMultiFieldA++'
  4423. )),
  4424. array('label' => array('for' => 'ModelMultiFieldA++')),
  4425. 'second',
  4426. '/label',
  4427. '/div',
  4428. array('div' => array('class' => 'checkbox')),
  4429. array('input' => array(
  4430. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4431. 'value' => 'a+++', 'id' => 'ModelMultiFieldA+++'
  4432. )),
  4433. array('label' => array('for' => 'ModelMultiFieldA+++')),
  4434. 'third',
  4435. '/label',
  4436. '/div'
  4437. );
  4438. $this->assertTags($result, $expected);
  4439. $result = $this->Form->select(
  4440. 'Model.multi_field',
  4441. array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
  4442. array('multiple' => 'checkbox')
  4443. );
  4444. $expected = array(
  4445. 'input' => array(
  4446. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4447. ),
  4448. array('div' => array('class' => 'checkbox')),
  4449. array('input' => array(
  4450. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4451. 'value' => 'a&gt;b', 'id' => 'ModelMultiFieldAB2'
  4452. )),
  4453. array('label' => array('for' => 'ModelMultiFieldAB2')),
  4454. 'first',
  4455. '/label',
  4456. '/div',
  4457. array('div' => array('class' => 'checkbox')),
  4458. array('input' => array(
  4459. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4460. 'value' => 'a&lt;b', 'id' => 'ModelMultiFieldAB1'
  4461. )),
  4462. array('label' => array('for' => 'ModelMultiFieldAB1')),
  4463. 'second',
  4464. '/label',
  4465. '/div',
  4466. array('div' => array('class' => 'checkbox')),
  4467. array('input' => array(
  4468. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4469. 'value' => 'a&quot;b', 'id' => 'ModelMultiFieldAB'
  4470. )),
  4471. array('label' => array('for' => 'ModelMultiFieldAB')),
  4472. 'third',
  4473. '/label',
  4474. '/div'
  4475. );
  4476. $this->assertTags($result, $expected);
  4477. }
  4478. /**
  4479. * test multiple checkboxes with div styles.
  4480. *
  4481. * @return void
  4482. */
  4483. public function testSelectMultipleCheckboxDiv() {
  4484. $this->markTestIncomplete('Need to revisit once models work again.');
  4485. $result = $this->Form->select(
  4486. 'Model.tags',
  4487. array('first', 'second'),
  4488. array('multiple' => 'checkbox', 'class' => 'my-class')
  4489. );
  4490. $expected = array(
  4491. 'input' => array(
  4492. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4493. ),
  4494. array('div' => array('class' => 'my-class')),
  4495. array('input' => array(
  4496. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4497. 'value' => '0', 'id' => 'ModelTags0'
  4498. )),
  4499. array('label' => array('for' => 'ModelTags0')), 'first', '/label',
  4500. '/div',
  4501. array('div' => array('class' => 'my-class')),
  4502. array('input' => array(
  4503. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4504. 'value' => '1', 'id' => 'ModelTags1'
  4505. )),
  4506. array('label' => array('for' => 'ModelTags1')), 'second', '/label',
  4507. '/div'
  4508. );
  4509. $this->assertTags($result, $expected);
  4510. $result = $this->Form->input('Model.tags', array(
  4511. 'options' => array('first', 'second'),
  4512. 'multiple' => 'checkbox',
  4513. 'class' => 'my-class',
  4514. 'div' => false,
  4515. 'label' => false
  4516. ));
  4517. $this->assertTags($result, $expected);
  4518. $Contact->validationErrors['tags'] = 'Select atleast one option';
  4519. $result = $this->Form->input('Contact.tags', array(
  4520. 'options' => array('one'),
  4521. 'multiple' => 'checkbox',
  4522. 'label' => false,
  4523. 'div' => false
  4524. ));
  4525. $expected = array(
  4526. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4527. array('div' => array('class' => 'checkbox form-error')),
  4528. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4529. array('label' => array('for' => 'ContactTags0')),
  4530. 'one',
  4531. '/label',
  4532. '/div'
  4533. );
  4534. $this->assertTags($result, $expected);
  4535. $result = $this->Form->input('Contact.tags', array(
  4536. 'options' => array('one'),
  4537. 'multiple' => 'checkbox',
  4538. 'class' => 'mycheckbox',
  4539. 'label' => false,
  4540. 'div' => false
  4541. ));
  4542. $expected = array(
  4543. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4544. array('div' => array('class' => 'mycheckbox form-error')),
  4545. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4546. array('label' => array('for' => 'ContactTags0')),
  4547. 'one',
  4548. '/label',
  4549. '/div'
  4550. );
  4551. $this->assertTags($result, $expected);
  4552. }
  4553. /**
  4554. * Checks the security hash array generated for multiple-input checkbox elements
  4555. *
  4556. * @return void
  4557. */
  4558. public function testSelectMultipleCheckboxSecurity() {
  4559. $this->Form->request->params['_Token'] = 'foo';
  4560. $this->assertEquals(array(), $this->Form->fields);
  4561. $result = $this->Form->select(
  4562. 'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
  4563. array('multiple' => 'checkbox')
  4564. );
  4565. $this->assertEquals(array('Model.multi_field'), $this->Form->fields);
  4566. $result = $this->Form->secure($this->Form->fields);
  4567. $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
  4568. $this->assertRegExp('/"' . $key . '"/', $result);
  4569. }
  4570. /**
  4571. * Multiple select elements should always be secured as they always participate
  4572. * in the POST data.
  4573. *
  4574. * @return void
  4575. */
  4576. public function testSelectMultipleSecureWithNoOptions() {
  4577. $this->Form->request->params['_Token'] = 'testkey';
  4578. $this->assertEquals(array(), $this->Form->fields);
  4579. $this->Form->select(
  4580. 'Model.select',
  4581. array(),
  4582. array('multiple' => true)
  4583. );
  4584. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4585. }
  4586. /**
  4587. * When a select box has no options it should not be added to the fields list
  4588. * as it always fail post validation.
  4589. *
  4590. * @return void
  4591. */
  4592. public function testSelectNoSecureWithNoOptions() {
  4593. $this->markTestIncomplete('Need to revisit once models work again.');
  4594. $this->Form->request->params['_csrfToken'] = 'testkey';
  4595. $this->assertEquals(array(), $this->Form->fields);
  4596. $this->Form->select(
  4597. 'Model.select',
  4598. array()
  4599. );
  4600. $this->assertEquals(array(), $this->Form->fields);
  4601. $this->Form->select(
  4602. 'Model.select',
  4603. array(),
  4604. array('empty' => true)
  4605. );
  4606. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4607. }
  4608. /**
  4609. * testInputMultipleCheckboxes method
  4610. *
  4611. * test input() resulting in multi select elements being generated.
  4612. *
  4613. * @return void
  4614. */
  4615. public function testInputMultipleCheckboxes() {
  4616. $this->markTestIncomplete('Need to revisit once models work again.');
  4617. $result = $this->Form->input('Model.multi_field', array(
  4618. 'options' => array('first', 'second', 'third'),
  4619. 'multiple' => 'checkbox'
  4620. ));
  4621. $expected = array(
  4622. array('div' => array('class' => 'input select')),
  4623. array('label' => array('for' => 'ModelMultiField')),
  4624. 'Multi Field',
  4625. '/label',
  4626. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4627. array('div' => array('class' => 'checkbox')),
  4628. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4629. array('label' => array('for' => 'ModelMultiField0')),
  4630. 'first',
  4631. '/label',
  4632. '/div',
  4633. array('div' => array('class' => 'checkbox')),
  4634. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4635. array('label' => array('for' => 'ModelMultiField1')),
  4636. 'second',
  4637. '/label',
  4638. '/div',
  4639. array('div' => array('class' => 'checkbox')),
  4640. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4641. array('label' => array('for' => 'ModelMultiField2')),
  4642. 'third',
  4643. '/label',
  4644. '/div',
  4645. '/div'
  4646. );
  4647. $this->assertTags($result, $expected);
  4648. $result = $this->Form->input('Model.multi_field', array(
  4649. 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4650. 'multiple' => 'checkbox'
  4651. ));
  4652. $expected = array(
  4653. array('div' => array('class' => 'input select')),
  4654. array('label' => array('for' => 'ModelMultiField')),
  4655. 'Multi Field',
  4656. '/label',
  4657. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4658. array('div' => array('class' => 'checkbox')),
  4659. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
  4660. array('label' => array('for' => 'ModelMultiFieldA')),
  4661. 'first',
  4662. '/label',
  4663. '/div',
  4664. array('div' => array('class' => 'checkbox')),
  4665. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
  4666. array('label' => array('for' => 'ModelMultiFieldB')),
  4667. 'second',
  4668. '/label',
  4669. '/div',
  4670. array('div' => array('class' => 'checkbox')),
  4671. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
  4672. array('label' => array('for' => 'ModelMultiFieldC')),
  4673. 'third',
  4674. '/label',
  4675. '/div',
  4676. '/div'
  4677. );
  4678. $this->assertTags($result, $expected);
  4679. $result = $this->Form->input('Model.multi_field', array(
  4680. 'options' => array('1' => 'first'),
  4681. 'multiple' => 'checkbox',
  4682. 'label' => false,
  4683. 'div' => false
  4684. ));
  4685. $expected = array(
  4686. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4687. array('div' => array('class' => 'checkbox')),
  4688. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4689. array('label' => array('for' => 'ModelMultiField1')),
  4690. 'first',
  4691. '/label',
  4692. '/div'
  4693. );
  4694. $this->assertTags($result, $expected);
  4695. $result = $this->Form->input('Model.multi_field', array(
  4696. 'options' => array('2' => 'second'),
  4697. 'multiple' => 'checkbox',
  4698. 'label' => false,
  4699. 'div' => false
  4700. ));
  4701. $expected = array(
  4702. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4703. array('div' => array('class' => 'checkbox')),
  4704. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4705. array('label' => array('for' => 'ModelMultiField2')),
  4706. 'second',
  4707. '/label',
  4708. '/div'
  4709. );
  4710. $this->assertTags($result, $expected);
  4711. }
  4712. /**
  4713. * testSelectHiddenFieldOmission method
  4714. *
  4715. * test that select() with 'hiddenField' => false omits the hidden field
  4716. *
  4717. * @return void
  4718. */
  4719. public function testSelectHiddenFieldOmission() {
  4720. $this->markTestIncomplete('Need to revisit once models work again.');
  4721. $result = $this->Form->select('Model.multi_field',
  4722. array('first', 'second'),
  4723. array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
  4724. );
  4725. $expected = array(
  4726. array('div' => array('class' => 'checkbox')),
  4727. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4728. array('label' => array('for' => 'ModelMultiField0')),
  4729. 'first',
  4730. '/label',
  4731. '/div',
  4732. array('div' => array('class' => 'checkbox')),
  4733. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4734. array('label' => array('for' => 'ModelMultiField1')),
  4735. 'second',
  4736. '/label',
  4737. '/div'
  4738. );
  4739. $this->assertTags($result, $expected);
  4740. $result = $this->Form->input('Model.multi_field', array(
  4741. 'options' => array('first', 'second'),
  4742. 'multiple' => 'checkbox',
  4743. 'hiddenField' => false
  4744. ));
  4745. $expected = array(
  4746. array('div' => array('class' => 'input select')),
  4747. array('label' => array('for' => 'ModelMultiField')),
  4748. 'Multi Field',
  4749. '/label',
  4750. array('div' => array('class' => 'checkbox')),
  4751. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4752. array('label' => array('for' => 'ModelMultiField0')),
  4753. 'first',
  4754. '/label',
  4755. '/div',
  4756. array('div' => array('class' => 'checkbox')),
  4757. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4758. array('label' => array('for' => 'ModelMultiField1')),
  4759. 'second',
  4760. '/label',
  4761. '/div',
  4762. '/div'
  4763. );
  4764. $this->assertTags($result, $expected);
  4765. }
  4766. /**
  4767. * test that select() with multiple = checkbox works with overriding name attribute.
  4768. *
  4769. * @return void
  4770. */
  4771. public function testSelectCheckboxMultipleOverrideName() {
  4772. $this->markTestIncomplete('Need to revisit once models work again.');
  4773. $result = $this->Form->input('category', array(
  4774. 'type' => 'select',
  4775. 'multiple' => 'checkbox',
  4776. 'name' => 'fish',
  4777. 'options' => array('1', '2'),
  4778. 'div' => false,
  4779. 'label' => false,
  4780. ));
  4781. $expected = array(
  4782. 'input' => array('type' => 'hidden', 'name' => 'fish', 'value' => '', 'id' => 'category'),
  4783. array('div' => array('class' => 'checkbox')),
  4784. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '0', 'id' => 'Category0')),
  4785. array('label' => array('for' => 'Category0')), '1', '/label',
  4786. '/div',
  4787. array('div' => array('class' => 'checkbox')),
  4788. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '1', 'id' => 'Category1')),
  4789. array('label' => array('for' => 'Category1')), '2', '/label',
  4790. '/div'
  4791. );
  4792. $this->assertTags($result, $expected);
  4793. }
  4794. /**
  4795. * Test that 'id' overrides all the checkbox id's as well.
  4796. *
  4797. * @return void
  4798. */
  4799. public function testSelectCheckboxMultipleId() {
  4800. $this->markTestIncomplete('Need to revisit once models work again.');
  4801. $result = $this->Form->select(
  4802. 'Model.multi_field',
  4803. array('first', 'second', 'third'),
  4804. array('multiple' => 'checkbox', 'id' => 'CustomId')
  4805. );
  4806. $expected = array(
  4807. 'input' => array(
  4808. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'CustomId'
  4809. ),
  4810. array('div' => array('class' => 'checkbox')),
  4811. array('input' => array(
  4812. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4813. 'value' => '0', 'id' => 'CustomId0'
  4814. )),
  4815. array('label' => array('for' => 'CustomId0')),
  4816. 'first',
  4817. '/label',
  4818. '/div',
  4819. array('div' => array('class' => 'checkbox')),
  4820. array('input' => array(
  4821. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4822. 'value' => '1', 'id' => 'CustomId1'
  4823. )),
  4824. array('label' => array('for' => 'CustomId1')),
  4825. 'second',
  4826. '/label',
  4827. '/div',
  4828. array('div' => array('class' => 'checkbox')),
  4829. array('input' => array(
  4830. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4831. 'value' => '2', 'id' => 'CustomId2'
  4832. )),
  4833. array('label' => array('for' => 'CustomId2')),
  4834. 'third',
  4835. '/label',
  4836. '/div'
  4837. );
  4838. $this->assertTags($result, $expected);
  4839. }
  4840. /**
  4841. * testCheckbox method
  4842. *
  4843. * Test generation of checkboxes
  4844. *
  4845. * @return void
  4846. */
  4847. public function testCheckbox() {
  4848. $result = $this->Form->checkbox('Model.field');
  4849. $expected = array(
  4850. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4851. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1'))
  4852. );
  4853. $this->assertTags($result, $expected);
  4854. $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
  4855. $expected = array(
  4856. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4857. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => 'myvalue', 'id' => 'theID'))
  4858. );
  4859. $this->assertTags($result, $expected);
  4860. }
  4861. /**
  4862. * Test checkbox being checked or having errors.
  4863. *
  4864. * @return void
  4865. */
  4866. public function testCheckboxCheckedAndError() {
  4867. $this->article['errors'] = [
  4868. 'published' => true
  4869. ];
  4870. $this->Form->request->data['published'] = 'myvalue';
  4871. $this->Form->create($this->article);
  4872. $result = $this->Form->checkbox('published', array('id' => 'theID', 'value' => 'myvalue'));
  4873. $expected = array(
  4874. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4875. array('input' => array(
  4876. 'type' => 'checkbox',
  4877. 'name' => 'published',
  4878. 'value' => 'myvalue',
  4879. 'id' => 'theID',
  4880. 'checked' => 'checked',
  4881. 'class' => 'form-error'
  4882. ))
  4883. );
  4884. $this->assertTags($result, $expected);
  4885. $this->Form->request->data['published'] = '';
  4886. $result = $this->Form->checkbox('published');
  4887. $expected = array(
  4888. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4889. array('input' => array('type' => 'checkbox', 'name' => 'published', 'value' => '1', 'class' => 'form-error'))
  4890. );
  4891. $this->assertTags($result, $expected);
  4892. }
  4893. /**
  4894. * test checkbox() with a custom name attribute
  4895. *
  4896. * @return void
  4897. */
  4898. public function testCheckboxCustomNameAttribute() {
  4899. $result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
  4900. $expected = array(
  4901. 'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0'),
  4902. array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1'))
  4903. );
  4904. $this->assertTags($result, $expected);
  4905. }
  4906. /**
  4907. * Test that the hidden input for checkboxes can be omitted or set to a
  4908. * specific value.
  4909. *
  4910. * @return void
  4911. */
  4912. public function testCheckboxHiddenField() {
  4913. $result = $this->Form->checkbox('UserForm.something', array(
  4914. 'hiddenField' => false
  4915. ));
  4916. $expected = array(
  4917. 'input' => array(
  4918. 'type' => 'checkbox',
  4919. 'name' => 'UserForm[something]',
  4920. 'value' => '1'
  4921. ),
  4922. );
  4923. $this->assertTags($result, $expected);
  4924. $result = $this->Form->checkbox('UserForm.something', array(
  4925. 'value' => 'Y',
  4926. 'hiddenField' => 'N',
  4927. ));
  4928. $expected = array(
  4929. array('input' => array(
  4930. 'type' => 'hidden', 'name' => 'UserForm[something]',
  4931. 'value' => 'N'
  4932. )),
  4933. array('input' => array(
  4934. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  4935. 'value' => 'Y'
  4936. )),
  4937. );
  4938. $this->assertTags($result, $expected);
  4939. }
  4940. /**
  4941. * testDateTime method
  4942. *
  4943. * Test generation of date/time select elements
  4944. *
  4945. * @return void
  4946. */
  4947. public function testDateTime() {
  4948. $this->markTestIncomplete('Need to revisit once models work again.');
  4949. extract($this->dateRegex);
  4950. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  4951. $now = strtotime('now');
  4952. $expected = array(
  4953. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  4954. $daysRegex,
  4955. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  4956. date('j', $now),
  4957. '/option',
  4958. '*/select',
  4959. '-',
  4960. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  4961. $monthsRegex,
  4962. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  4963. date('F', $now),
  4964. '/option',
  4965. '*/select',
  4966. '-',
  4967. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  4968. $yearsRegex,
  4969. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  4970. date('Y', $now),
  4971. '/option',
  4972. '*/select',
  4973. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  4974. $hoursRegex,
  4975. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  4976. date('g', $now),
  4977. '/option',
  4978. '*/select',
  4979. ':',
  4980. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  4981. $minutesRegex,
  4982. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  4983. date('i', $now),
  4984. '/option',
  4985. '*/select',
  4986. ' ',
  4987. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  4988. $meridianRegex,
  4989. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  4990. date('a', $now),
  4991. '/option',
  4992. '*/select'
  4993. );
  4994. $this->assertTags($result, $expected);
  4995. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  4996. $expected = array(
  4997. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  4998. $daysRegex,
  4999. array('option' => array('value' => '')),
  5000. '/option',
  5001. '*/select',
  5002. '-',
  5003. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5004. $monthsRegex,
  5005. array('option' => array('value' => '')),
  5006. '/option',
  5007. '*/select',
  5008. '-',
  5009. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5010. $yearsRegex,
  5011. array('option' => array('value' => '')),
  5012. '/option',
  5013. '*/select',
  5014. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5015. $hoursRegex,
  5016. array('option' => array('value' => '')),
  5017. '/option',
  5018. '*/select',
  5019. ':',
  5020. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5021. $minutesRegex,
  5022. array('option' => array('value' => '')),
  5023. '/option',
  5024. '*/select',
  5025. ' ',
  5026. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5027. $meridianRegex,
  5028. array('option' => array('value' => '')),
  5029. '/option',
  5030. '*/select'
  5031. );
  5032. $this->assertTags($result, $expected);
  5033. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5034. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
  5035. $this->assertTags($result, $expected);
  5036. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5037. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
  5038. $this->assertTags($result, $expected);
  5039. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5040. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
  5041. $expected = array(
  5042. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5043. $daysRegex,
  5044. array('option' => array('value' => '')),
  5045. '/option',
  5046. '*/select',
  5047. '-',
  5048. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5049. $monthsRegex,
  5050. array('option' => array('value' => '')),
  5051. '/option',
  5052. '*/select',
  5053. '-',
  5054. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5055. $yearsRegex,
  5056. array('option' => array('value' => '')),
  5057. '/option',
  5058. '*/select',
  5059. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5060. $hoursRegex,
  5061. array('option' => array('value' => '')),
  5062. '/option',
  5063. '*/select',
  5064. ':',
  5065. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5066. $minutesRegex,
  5067. array('option' => array('value' => '')),
  5068. '/option',
  5069. array('option' => array('value' => '00')),
  5070. '00',
  5071. '/option',
  5072. array('option' => array('value' => '05')),
  5073. '05',
  5074. '/option',
  5075. array('option' => array('value' => '10')),
  5076. '10',
  5077. '/option',
  5078. '*/select',
  5079. ' ',
  5080. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5081. $meridianRegex,
  5082. array('option' => array('value' => '')),
  5083. '/option',
  5084. '*/select'
  5085. );
  5086. $this->assertTags($result, $expected);
  5087. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5088. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5089. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5090. $this->Form->request->data['Contact']['data'] = null;
  5091. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  5092. $expected = array(
  5093. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5094. $daysRegex,
  5095. array('option' => array('value' => '')),
  5096. '/option',
  5097. '*/select',
  5098. '-',
  5099. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5100. $monthsRegex,
  5101. array('option' => array('value' => '')),
  5102. '/option',
  5103. '*/select',
  5104. '-',
  5105. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5106. $yearsRegex,
  5107. array('option' => array('value' => '')),
  5108. '/option',
  5109. '*/select',
  5110. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5111. $hoursRegex,
  5112. array('option' => array('value' => '')),
  5113. '/option',
  5114. '*/select',
  5115. ':',
  5116. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5117. $minutesRegex,
  5118. array('option' => array('value' => '')),
  5119. '/option',
  5120. '*/select',
  5121. ' ',
  5122. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5123. $meridianRegex,
  5124. array('option' => array('value' => '')),
  5125. '/option',
  5126. '*/select'
  5127. );
  5128. $this->assertTags($result, $expected);
  5129. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5130. $this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
  5131. $now = strtotime($this->Form->data['Model']['field']);
  5132. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
  5133. $expected = array(
  5134. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5135. $daysRegex,
  5136. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5137. date('j', $now),
  5138. '/option',
  5139. '*/select',
  5140. '-',
  5141. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5142. $monthsRegex,
  5143. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5144. date('F', $now),
  5145. '/option',
  5146. '*/select',
  5147. '-',
  5148. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5149. $yearsRegex,
  5150. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5151. date('Y', $now),
  5152. '/option',
  5153. '*/select',
  5154. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5155. $hoursRegex,
  5156. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5157. date('g', $now),
  5158. '/option',
  5159. '*/select',
  5160. ':',
  5161. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5162. $minutesRegex,
  5163. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  5164. date('i', $now),
  5165. '/option',
  5166. '*/select',
  5167. ' ',
  5168. array('select' => array('name' => 'Model[field][meridian]', 'id' => 'ModelFieldMeridian')),
  5169. $meridianRegex,
  5170. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  5171. date('a', $now),
  5172. '/option',
  5173. '*/select'
  5174. );
  5175. $this->assertTags($result, $expected);
  5176. $selected = strtotime('2008-10-26 12:33:00');
  5177. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
  5178. $this->assertRegExp('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
  5179. $this->assertRegExp('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
  5180. $this->assertRegExp('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
  5181. $this->assertRegExp('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
  5182. $this->assertRegExp('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
  5183. $this->assertRegExp('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
  5184. $this->Form->create('Contact');
  5185. $result = $this->Form->input('published');
  5186. $now = strtotime('now');
  5187. $expected = array(
  5188. 'div' => array('class' => 'input date'),
  5189. 'label' => array('for' => 'ContactPublishedMonth'),
  5190. 'Published',
  5191. '/label',
  5192. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5193. $monthsRegex,
  5194. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5195. date('F', $now),
  5196. '/option',
  5197. '*/select',
  5198. '-',
  5199. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5200. $daysRegex,
  5201. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5202. date('j', $now),
  5203. '/option',
  5204. '*/select',
  5205. '-',
  5206. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5207. $yearsRegex,
  5208. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5209. date('Y', $now),
  5210. '/option',
  5211. '*/select',
  5212. '/div'
  5213. );
  5214. $this->assertTags($result, $expected);
  5215. $result = $this->Form->input('published2', array('type' => 'date'));
  5216. $now = strtotime('now');
  5217. $expected = array(
  5218. 'div' => array('class' => 'input date'),
  5219. 'label' => array('for' => 'ContactPublished2Month'),
  5220. 'Published2',
  5221. '/label',
  5222. array('select' => array('name' => 'Contact[published2][month]', 'id' => 'ContactPublished2Month')),
  5223. $monthsRegex,
  5224. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5225. date('F', $now),
  5226. '/option',
  5227. '*/select',
  5228. '-',
  5229. array('select' => array('name' => 'Contact[published2][day]', 'id' => 'ContactPublished2Day')),
  5230. $daysRegex,
  5231. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5232. date('j', $now),
  5233. '/option',
  5234. '*/select',
  5235. '-',
  5236. array('select' => array('name' => 'Contact[published2][year]', 'id' => 'ContactPublished2Year')),
  5237. $yearsRegex,
  5238. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5239. date('Y', $now),
  5240. '/option',
  5241. '*/select',
  5242. '/div'
  5243. );
  5244. $this->assertTags($result, $expected);
  5245. $this->Form->create('Contact');
  5246. $result = $this->Form->input('published', array('monthNames' => false));
  5247. $now = strtotime('now');
  5248. $expected = array(
  5249. 'div' => array('class' => 'input date'),
  5250. 'label' => array('for' => 'ContactPublishedMonth'),
  5251. 'Published',
  5252. '/label',
  5253. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5254. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5255. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5256. date('m', $now),
  5257. '/option',
  5258. '*/select',
  5259. '-',
  5260. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5261. $daysRegex,
  5262. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5263. date('j', $now),
  5264. '/option',
  5265. '*/select',
  5266. '-',
  5267. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5268. $yearsRegex,
  5269. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5270. date('Y', $now),
  5271. '/option',
  5272. '*/select',
  5273. '/div'
  5274. );
  5275. $this->assertTags($result, $expected);
  5276. $result = $this->Form->input('published', array('type' => 'time'));
  5277. $now = strtotime('now');
  5278. $expected = array(
  5279. 'div' => array('class' => 'input time'),
  5280. 'label' => array('for' => 'ContactPublishedHour'),
  5281. 'Published',
  5282. '/label',
  5283. array('select' => array('name' => 'Contact[published][hour]', 'id' => 'ContactPublishedHour')),
  5284. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5285. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5286. date('g', $now),
  5287. '/option',
  5288. '*/select',
  5289. ':',
  5290. );
  5291. $this->assertTags($result, $expected);
  5292. $result = $this->Form->input('published', array(
  5293. 'timeFormat' => 24,
  5294. 'interval' => 5,
  5295. 'selected' => strtotime('2009-09-03 13:37:00'),
  5296. 'type' => 'datetime'
  5297. ));
  5298. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5299. $this->assertRegExp('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
  5300. $this->assertRegExp('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
  5301. $this->assertRegExp('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
  5302. $this->assertRegExp('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
  5303. }
  5304. /**
  5305. * Test dateTime with rounding
  5306. *
  5307. * @return void
  5308. */
  5309. public function testDateTimeRounding() {
  5310. $this->markTestIncomplete('Need to revisit once models work again.');
  5311. $this->Form->request->data['Contact'] = array(
  5312. 'date' => array(
  5313. 'day' => '13',
  5314. 'month' => '12',
  5315. 'year' => '2010',
  5316. 'hour' => '04',
  5317. 'min' => '19',
  5318. 'meridian' => 'AM'
  5319. )
  5320. );
  5321. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
  5322. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5323. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
  5324. $this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
  5325. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
  5326. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5327. }
  5328. /**
  5329. * Test that empty values don't trigger errors.
  5330. *
  5331. * @return void
  5332. */
  5333. public function testDateTimeNoErrorsOnEmptyData() {
  5334. $this->markTestIncomplete('Need to revisit once models work again.');
  5335. $this->Form->request->data['Contact'] = array(
  5336. 'date' => array(
  5337. 'day' => '',
  5338. 'month' => '',
  5339. 'year' => '',
  5340. 'hour' => '',
  5341. 'min' => '',
  5342. 'meridian' => ''
  5343. )
  5344. );
  5345. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  5346. $this->assertNotEmpty($result);
  5347. }
  5348. /**
  5349. * test that datetime() and default values work.
  5350. *
  5351. * @return void
  5352. */
  5353. public function testDatetimeWithDefault() {
  5354. $this->markTestIncomplete('Need to revisit once models work again.');
  5355. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
  5356. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5357. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5358. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5359. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
  5360. 'default' => '2009-06-01 11:15:30'
  5361. ));
  5362. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5363. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5364. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5365. }
  5366. /**
  5367. * test that bogus non-date time data doesn't cause errors.
  5368. *
  5369. * @return void
  5370. */
  5371. public function testDateTimeWithBogusData() {
  5372. $this->markTestIncomplete('Need to revisit once models work again.');
  5373. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
  5374. $this->assertNotRegExp('/selected="selected">\d/', $result);
  5375. }
  5376. /**
  5377. * testDateTime all zeros
  5378. *
  5379. * @return void
  5380. */
  5381. public function testDateTimeAllZeros() {
  5382. $this->markTestIncomplete('Need to revisit once models work again.');
  5383. $result = $this->Form->dateTime('Contact.date',
  5384. 'DMY',
  5385. false,
  5386. array(
  5387. 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
  5388. 'value' => '0000-00-00'
  5389. )
  5390. );
  5391. $this->assertRegExp('/<option value="">-<\/option>/', $result);
  5392. $this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
  5393. }
  5394. /**
  5395. * testDateTimeEmptyAsArray
  5396. *
  5397. * @return void
  5398. */
  5399. public function testDateTimeEmptyAsArray() {
  5400. $this->markTestIncomplete('Need to revisit once models work again.');
  5401. $result = $this->Form->dateTime('Contact.date',
  5402. 'DMY',
  5403. '12',
  5404. array(
  5405. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
  5406. 'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
  5407. )
  5408. )
  5409. );
  5410. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5411. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5412. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5413. $this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
  5414. $this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
  5415. $this->assertNotRegExp('/<option value=""><\/option>/', $result);
  5416. $result = $this->Form->dateTime('Contact.date',
  5417. 'DMY',
  5418. '12',
  5419. array(
  5420. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
  5421. )
  5422. );
  5423. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5424. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5425. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5426. $this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
  5427. $this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
  5428. $this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
  5429. }
  5430. /**
  5431. * testFormDateTimeMulti method
  5432. *
  5433. * test multiple datetime element generation
  5434. *
  5435. * @return void
  5436. */
  5437. public function testFormDateTimeMulti() {
  5438. $this->markTestIncomplete('Need to revisit once models work again.');
  5439. extract($this->dateRegex);
  5440. $result = $this->Form->dateTime('Contact.1.updated');
  5441. $expected = array(
  5442. array('select' => array('name' => 'Contact[1][updated][day]', 'id' => 'Contact1UpdatedDay')),
  5443. $daysRegex,
  5444. array('option' => array('value' => '')),
  5445. '/option',
  5446. '*/select',
  5447. '-',
  5448. array('select' => array('name' => 'Contact[1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
  5449. $monthsRegex,
  5450. array('option' => array('value' => '')),
  5451. '/option',
  5452. '*/select',
  5453. '-',
  5454. array('select' => array('name' => 'Contact[1][updated][year]', 'id' => 'Contact1UpdatedYear')),
  5455. $yearsRegex,
  5456. array('option' => array('value' => '')),
  5457. '/option',
  5458. '*/select',
  5459. array('select' => array('name' => 'Contact[1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
  5460. $hoursRegex,
  5461. array('option' => array('value' => '')),
  5462. '/option',
  5463. '*/select',
  5464. ':',
  5465. array('select' => array('name' => 'Contact[1][updated][min]', 'id' => 'Contact1UpdatedMin')),
  5466. $minutesRegex,
  5467. array('option' => array('value' => '')),
  5468. '/option',
  5469. '*/select',
  5470. ' ',
  5471. array('select' => array('name' => 'Contact[1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
  5472. $meridianRegex,
  5473. array('option' => array('value' => '')),
  5474. '/option',
  5475. '*/select'
  5476. );
  5477. $this->assertTags($result, $expected);
  5478. $result = $this->Form->dateTime('Contact.2.updated');
  5479. $expected = array(
  5480. array('select' => array('name' => 'Contact[2][updated][day]', 'id' => 'Contact2UpdatedDay')),
  5481. $daysRegex,
  5482. array('option' => array('value' => '')),
  5483. '/option',
  5484. '*/select',
  5485. '-',
  5486. array('select' => array('name' => 'Contact[2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
  5487. $monthsRegex,
  5488. array('option' => array('value' => '')),
  5489. '/option',
  5490. '*/select',
  5491. '-',
  5492. array('select' => array('name' => 'Contact[2][updated][year]', 'id' => 'Contact2UpdatedYear')),
  5493. $yearsRegex,
  5494. array('option' => array('value' => '')),
  5495. '/option',
  5496. '*/select',
  5497. array('select' => array('name' => 'Contact[2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
  5498. $hoursRegex,
  5499. array('option' => array('value' => '')),
  5500. '/option',
  5501. '*/select',
  5502. ':',
  5503. array('select' => array('name' => 'Contact[2][updated][min]', 'id' => 'Contact2UpdatedMin')),
  5504. $minutesRegex,
  5505. array('option' => array('value' => '')),
  5506. '/option',
  5507. '*/select',
  5508. ' ',
  5509. array('select' => array('name' => 'Contact[2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
  5510. $meridianRegex,
  5511. array('option' => array('value' => '')),
  5512. '/option',
  5513. '*/select'
  5514. );
  5515. $this->assertTags($result, $expected);
  5516. }
  5517. /**
  5518. * When changing the date format, the label should always focus the first select box when
  5519. * clicked.
  5520. *
  5521. * @return void
  5522. */
  5523. public function testDateTimeLabelIdMatchesFirstInput() {
  5524. $this->markTestIncomplete('Need to revisit once models work again.');
  5525. $result = $this->Form->input('Model.date', array('type' => 'date'));
  5526. $this->assertContains('label for="ModelDateMonth"', $result);
  5527. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
  5528. $this->assertContains('label for="ModelDateDay"', $result);
  5529. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
  5530. $this->assertContains('label for="ModelDateYear"', $result);
  5531. }
  5532. /**
  5533. * testMonth method
  5534. *
  5535. * @return void
  5536. */
  5537. public function testMonth() {
  5538. $this->markTestIncomplete('Need to revisit once models work again.');
  5539. $result = $this->Form->month('Model.field');
  5540. $expected = array(
  5541. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5542. array('option' => array('value' => '')),
  5543. '/option',
  5544. array('option' => array('value' => '01')),
  5545. date('F', strtotime('2008-01-01 00:00:00')),
  5546. '/option',
  5547. array('option' => array('value' => '02')),
  5548. date('F', strtotime('2008-02-01 00:00:00')),
  5549. '/option',
  5550. '*/select',
  5551. );
  5552. $this->assertTags($result, $expected);
  5553. $result = $this->Form->month('Model.field', array('empty' => true));
  5554. $expected = array(
  5555. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5556. array('option' => array('value' => '')),
  5557. '/option',
  5558. array('option' => array('value' => '01')),
  5559. date('F', strtotime('2008-01-01 00:00:00')),
  5560. '/option',
  5561. array('option' => array('value' => '02')),
  5562. date('F', strtotime('2008-02-01 00:00:00')),
  5563. '/option',
  5564. '*/select',
  5565. );
  5566. $this->assertTags($result, $expected);
  5567. $result = $this->Form->month('Model.field', array('monthNames' => false));
  5568. $expected = array(
  5569. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5570. array('option' => array('value' => '')),
  5571. '/option',
  5572. array('option' => array('value' => '01')),
  5573. '01',
  5574. '/option',
  5575. array('option' => array('value' => '02')),
  5576. '02',
  5577. '/option',
  5578. '*/select',
  5579. );
  5580. $this->assertTags($result, $expected);
  5581. $monthNames = array(
  5582. '01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
  5583. '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
  5584. $result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
  5585. $expected = array(
  5586. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5587. array('option' => array('value' => '')),
  5588. '/option',
  5589. array('option' => array('value' => '01')),
  5590. 'Jan',
  5591. '/option',
  5592. array('option' => array('value' => '02')),
  5593. 'Feb',
  5594. '/option',
  5595. '*/select',
  5596. );
  5597. $this->assertTags($result, $expected);
  5598. $this->Form->request->data['Project']['release'] = '2050-02-10';
  5599. $result = $this->Form->month('Project.release');
  5600. $expected = array(
  5601. array('select' => array('name' => 'Project[release][month]', 'id' => 'ProjectReleaseMonth')),
  5602. array('option' => array('value' => '')),
  5603. '/option',
  5604. array('option' => array('value' => '01')),
  5605. 'January',
  5606. '/option',
  5607. array('option' => array('value' => '02', 'selected' => 'selected')),
  5608. 'February',
  5609. '/option',
  5610. '*/select',
  5611. );
  5612. $this->assertTags($result, $expected);
  5613. }
  5614. /**
  5615. * testDay method
  5616. *
  5617. * @return void
  5618. */
  5619. public function testDay() {
  5620. $this->markTestIncomplete('Need to revisit once models work again.');
  5621. extract($this->dateRegex);
  5622. $result = $this->Form->day('Model.field', array('value' => false));
  5623. $expected = array(
  5624. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5625. array('option' => array('value' => '')),
  5626. '/option',
  5627. array('option' => array('value' => '01')),
  5628. '1',
  5629. '/option',
  5630. array('option' => array('value' => '02')),
  5631. '2',
  5632. '/option',
  5633. $daysRegex,
  5634. '/select',
  5635. );
  5636. $this->assertTags($result, $expected);
  5637. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5638. $result = $this->Form->day('Model.field');
  5639. $expected = array(
  5640. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5641. array('option' => array('value' => '')),
  5642. '/option',
  5643. array('option' => array('value' => '01')),
  5644. '1',
  5645. '/option',
  5646. array('option' => array('value' => '02')),
  5647. '2',
  5648. '/option',
  5649. $daysRegex,
  5650. array('option' => array('value' => '10', 'selected' => 'selected')),
  5651. '10',
  5652. '/option',
  5653. $daysRegex,
  5654. '/select',
  5655. );
  5656. $this->assertTags($result, $expected);
  5657. $this->Form->request->data['Model']['field'] = '';
  5658. $result = $this->Form->day('Model.field', array('value' => '10'));
  5659. $expected = array(
  5660. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5661. array('option' => array('value' => '')),
  5662. '/option',
  5663. array('option' => array('value' => '01')),
  5664. '1',
  5665. '/option',
  5666. array('option' => array('value' => '02')),
  5667. '2',
  5668. '/option',
  5669. $daysRegex,
  5670. array('option' => array('value' => '10', 'selected' => 'selected')),
  5671. '10',
  5672. '/option',
  5673. $daysRegex,
  5674. '/select',
  5675. );
  5676. $this->assertTags($result, $expected);
  5677. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5678. $result = $this->Form->day('Model.field', array('value' => true));
  5679. $expected = array(
  5680. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5681. array('option' => array('value' => '')),
  5682. '/option',
  5683. array('option' => array('value' => '01')),
  5684. '1',
  5685. '/option',
  5686. array('option' => array('value' => '02')),
  5687. '2',
  5688. '/option',
  5689. $daysRegex,
  5690. array('option' => array('value' => '10', 'selected' => 'selected')),
  5691. '10',
  5692. '/option',
  5693. $daysRegex,
  5694. '/select',
  5695. );
  5696. $this->assertTags($result, $expected);
  5697. $this->Form->request->data['Project']['release'] = '2050-10-10';
  5698. $result = $this->Form->day('Project.release');
  5699. $expected = array(
  5700. array('select' => array('name' => 'Project[release][day]', 'id' => 'ProjectReleaseDay')),
  5701. array('option' => array('value' => '')),
  5702. '/option',
  5703. array('option' => array('value' => '01')),
  5704. '1',
  5705. '/option',
  5706. array('option' => array('value' => '02')),
  5707. '2',
  5708. '/option',
  5709. $daysRegex,
  5710. array('option' => array('value' => '10', 'selected' => 'selected')),
  5711. '10',
  5712. '/option',
  5713. $daysRegex,
  5714. '/select',
  5715. );
  5716. $this->assertTags($result, $expected);
  5717. }
  5718. /**
  5719. * testMinute method
  5720. *
  5721. * @return void
  5722. */
  5723. public function testMinute() {
  5724. $this->markTestIncomplete('Need to revisit once models work again.');
  5725. extract($this->dateRegex);
  5726. $result = $this->Form->minute('Model.field');
  5727. $expected = array(
  5728. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5729. array('option' => array('value' => '')),
  5730. '/option',
  5731. array('option' => array('value' => '00')),
  5732. '00',
  5733. '/option',
  5734. array('option' => array('value' => '01')),
  5735. '01',
  5736. '/option',
  5737. array('option' => array('value' => '02')),
  5738. '02',
  5739. '/option',
  5740. $minutesRegex,
  5741. '/select',
  5742. );
  5743. $this->assertTags($result, $expected);
  5744. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5745. $result = $this->Form->minute('Model.field');
  5746. $expected = array(
  5747. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5748. array('option' => array('value' => '')),
  5749. '/option',
  5750. array('option' => array('value' => '00')),
  5751. '00',
  5752. '/option',
  5753. array('option' => array('value' => '01')),
  5754. '01',
  5755. '/option',
  5756. array('option' => array('value' => '02')),
  5757. '02',
  5758. '/option',
  5759. $minutesRegex,
  5760. array('option' => array('value' => '12', 'selected' => 'selected')),
  5761. '12',
  5762. '/option',
  5763. $minutesRegex,
  5764. '/select',
  5765. );
  5766. $this->assertTags($result, $expected);
  5767. $this->Form->request->data['Model']['field'] = '';
  5768. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5769. $expected = array(
  5770. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5771. array('option' => array('value' => '')),
  5772. '/option',
  5773. array('option' => array('value' => '00')),
  5774. '00',
  5775. '/option',
  5776. array('option' => array('value' => '05')),
  5777. '05',
  5778. '/option',
  5779. array('option' => array('value' => '10')),
  5780. '10',
  5781. '/option',
  5782. $minutesRegex,
  5783. '/select',
  5784. );
  5785. $this->assertTags($result, $expected);
  5786. $this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
  5787. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5788. $expected = array(
  5789. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5790. array('option' => array('value' => '')),
  5791. '/option',
  5792. array('option' => array('value' => '00')),
  5793. '00',
  5794. '/option',
  5795. array('option' => array('value' => '05')),
  5796. '05',
  5797. '/option',
  5798. array('option' => array('value' => '10', 'selected' => 'selected')),
  5799. '10',
  5800. '/option',
  5801. $minutesRegex,
  5802. '/select',
  5803. );
  5804. $this->assertTags($result, $expected);
  5805. }
  5806. /**
  5807. * testHour method
  5808. *
  5809. * @return void
  5810. */
  5811. public function testHour() {
  5812. $this->markTestIncomplete('Need to revisit once models work again.');
  5813. extract($this->dateRegex);
  5814. $result = $this->Form->hour('Model.field', false);
  5815. $expected = array(
  5816. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5817. array('option' => array('value' => '')),
  5818. '/option',
  5819. array('option' => array('value' => '01')),
  5820. '1',
  5821. '/option',
  5822. array('option' => array('value' => '02')),
  5823. '2',
  5824. '/option',
  5825. $hoursRegex,
  5826. '/select',
  5827. );
  5828. $this->assertTags($result, $expected);
  5829. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5830. $result = $this->Form->hour('Model.field', false);
  5831. $expected = array(
  5832. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5833. array('option' => array('value' => '')),
  5834. '/option',
  5835. array('option' => array('value' => '01')),
  5836. '1',
  5837. '/option',
  5838. array('option' => array('value' => '02')),
  5839. '2',
  5840. '/option',
  5841. $hoursRegex,
  5842. array('option' => array('value' => '12', 'selected' => 'selected')),
  5843. '12',
  5844. '/option',
  5845. '/select',
  5846. );
  5847. $this->assertTags($result, $expected);
  5848. $this->Form->request->data['Model']['field'] = '';
  5849. $result = $this->Form->hour('Model.field', true, array('value' => '23'));
  5850. $this->assertContains('<option value="23" selected="selected">23</option>', $result);
  5851. $result = $this->Form->hour('Model.field', false, array('value' => '23'));
  5852. $this->assertContains('<option value="11" selected="selected">11</option>', $result);
  5853. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5854. $result = $this->Form->hour('Model.field', true);
  5855. $expected = array(
  5856. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5857. array('option' => array('value' => '')),
  5858. '/option',
  5859. array('option' => array('value' => '00', 'selected' => 'selected')),
  5860. '0',
  5861. '/option',
  5862. array('option' => array('value' => '01')),
  5863. '1',
  5864. '/option',
  5865. array('option' => array('value' => '02')),
  5866. '2',
  5867. '/option',
  5868. $hoursRegex,
  5869. '/select',
  5870. );
  5871. $this->assertTags($result, $expected);
  5872. unset($this->Form->request->data['Model']['field']);
  5873. $result = $this->Form->hour('Model.field', true, array('value' => 'now'));
  5874. $thisHour = date('H');
  5875. $optValue = date('G');
  5876. $this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
  5877. $this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
  5878. $result = $this->Form->hour('Model.field', true);
  5879. $expected = array(
  5880. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5881. array('option' => array('value' => '')),
  5882. '/option',
  5883. array('option' => array('value' => '00')),
  5884. '0',
  5885. '/option',
  5886. array('option' => array('value' => '01', 'selected' => 'selected')),
  5887. '1',
  5888. '/option',
  5889. array('option' => array('value' => '02')),
  5890. '2',
  5891. '/option',
  5892. $hoursRegex,
  5893. '/select',
  5894. );
  5895. $this->assertTags($result, $expected);
  5896. }
  5897. /**
  5898. * testYear method
  5899. *
  5900. * @return void
  5901. */
  5902. public function testYear() {
  5903. $this->markTestIncomplete('Need to revisit once models work again.');
  5904. $result = $this->Form->year('Model.field', 2006, 2007);
  5905. $expected = array(
  5906. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5907. array('option' => array('value' => '')),
  5908. '/option',
  5909. array('option' => array('value' => '2007')),
  5910. '2007',
  5911. '/option',
  5912. array('option' => array('value' => '2006')),
  5913. '2006',
  5914. '/option',
  5915. '/select',
  5916. );
  5917. $this->assertTags($result, $expected);
  5918. $result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
  5919. $expected = array(
  5920. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5921. array('option' => array('value' => '')),
  5922. '/option',
  5923. array('option' => array('value' => '2006')),
  5924. '2006',
  5925. '/option',
  5926. array('option' => array('value' => '2007')),
  5927. '2007',
  5928. '/option',
  5929. '/select',
  5930. );
  5931. $this->assertTags($result, $expected);
  5932. $this->request->data['Contact']['published'] = '';
  5933. $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
  5934. $expected = array(
  5935. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
  5936. array('option' => array('value' => '')),
  5937. '/option',
  5938. array('option' => array('value' => '2007')),
  5939. '2007',
  5940. '/option',
  5941. array('option' => array('value' => '2006')),
  5942. '2006',
  5943. '/option',
  5944. '/select',
  5945. );
  5946. $this->assertTags($result, $expected);
  5947. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  5948. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
  5949. $expected = array(
  5950. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5951. array('option' => array('value' => '2007')),
  5952. '2007',
  5953. '/option',
  5954. array('option' => array('value' => '2006', 'selected' => 'selected')),
  5955. '2006',
  5956. '/option',
  5957. '/select',
  5958. );
  5959. $this->assertTags($result, $expected);
  5960. $this->Form->request->data['Contact']['published'] = '';
  5961. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
  5962. $expected = array(
  5963. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5964. array('option' => array('value' => '')),
  5965. '/option',
  5966. array('option' => array('value' => '2007')),
  5967. '2007',
  5968. '/option',
  5969. array('option' => array('value' => '2006')),
  5970. '2006',
  5971. '/option',
  5972. '/select',
  5973. );
  5974. $this->assertTags($result, $expected);
  5975. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  5976. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
  5977. $expected = array(
  5978. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5979. array('option' => array('value' => '2007')),
  5980. '2007',
  5981. '/option',
  5982. array('option' => array('value' => '2006', 'selected' => 'selected')),
  5983. '2006',
  5984. '/option',
  5985. '/select',
  5986. );
  5987. $this->assertTags($result, $expected);
  5988. $this->Form->request->data['Contact']['published'] = '';
  5989. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
  5990. $expected = array(
  5991. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5992. array('option' => array('value' => '')),
  5993. '/option',
  5994. array('option' => array('value' => '2007', 'selected' => 'selected')),
  5995. '2007',
  5996. '/option',
  5997. array('option' => array('value' => '2006')),
  5998. '2006',
  5999. '/option',
  6000. '/select',
  6001. );
  6002. $this->assertTags($result, $expected);
  6003. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6004. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
  6005. $expected = array(
  6006. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6007. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6008. '2007',
  6009. '/option',
  6010. array('option' => array('value' => '2006')),
  6011. '2006',
  6012. '/option',
  6013. '/select',
  6014. );
  6015. $this->assertTags($result, $expected);
  6016. $this->Form->request->data['Contact']['published'] = '';
  6017. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
  6018. $expected = array(
  6019. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6020. array('option' => array('value' => '2008')),
  6021. '2008',
  6022. '/option',
  6023. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6024. '2007',
  6025. '/option',
  6026. array('option' => array('value' => '2006')),
  6027. '2006',
  6028. '/option',
  6029. '/select',
  6030. );
  6031. $this->assertTags($result, $expected);
  6032. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6033. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
  6034. $expected = array(
  6035. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6036. array('option' => array('value' => '2008')),
  6037. '2008',
  6038. '/option',
  6039. array('option' => array('value' => '2007')),
  6040. '2007',
  6041. '/option',
  6042. array('option' => array('value' => '2006', 'selected' => 'selected')),
  6043. '2006',
  6044. '/option',
  6045. '/select',
  6046. );
  6047. $this->assertTags($result, $expected);
  6048. $this->Form->request->data = array();
  6049. $this->Form->create('Contact');
  6050. $result = $this->Form->year('published', 2006, 2008, array('empty' => false));
  6051. $expected = array(
  6052. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6053. array('option' => array('value' => '2008')),
  6054. '2008',
  6055. '/option',
  6056. array('option' => array('value' => '2007')),
  6057. '2007',
  6058. '/option',
  6059. array('option' => array('value' => '2006')),
  6060. '2006',
  6061. '/option',
  6062. '/select',
  6063. );
  6064. $this->assertTags($result, $expected);
  6065. $result = $this->Form->year('published', array(), array(), array('empty' => false));
  6066. $this->assertContains('Contact[published][year]', $result);
  6067. }
  6068. /**
  6069. * testYearAutoExpandRange method
  6070. *
  6071. * @return void
  6072. */
  6073. public function testYearAutoExpandRange() {
  6074. $this->markTestIncomplete('Need to revisit once models work again.');
  6075. $this->Form->request->data['User']['birthday'] = '1930-10-10';
  6076. $result = $this->Form->year('User.birthday');
  6077. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6078. $result = $matches[1];
  6079. $expected = range(date('Y') + 20, 1930);
  6080. $this->assertEquals($expected, $result);
  6081. $this->Form->request->data['Project']['release'] = '2050-10-10';
  6082. $result = $this->Form->year('Project.release');
  6083. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6084. $result = $matches[1];
  6085. $expected = range(2050, date('Y') - 20);
  6086. $this->assertEquals($expected, $result);
  6087. $this->Form->request->data['Project']['release'] = '1881-10-10';
  6088. $result = $this->Form->year('Project.release', 1890, 1900);
  6089. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6090. $result = $matches[1];
  6091. $expected = range(1900, 1881);
  6092. $this->assertEquals($expected, $result);
  6093. }
  6094. /**
  6095. * testInputDate method
  6096. *
  6097. * Test various inputs with type date and different dateFormat values.
  6098. * Failing to provide a dateFormat key should not error.
  6099. * It should simply not pre-select any value then.
  6100. *
  6101. * @return void
  6102. */
  6103. public function testInputDate() {
  6104. $this->markTestIncomplete('Need to revisit once models work again.');
  6105. $this->Form->request->data = array(
  6106. 'User' => array(
  6107. 'month_year' => array('month' => date('m')),
  6108. 'just_year' => array('month' => date('m')),
  6109. 'just_month' => array('year' => date('Y')),
  6110. 'just_day' => array('month' => date('m')),
  6111. )
  6112. );
  6113. $this->Form->create('User');
  6114. $result = $this->Form->input('month_year',
  6115. array(
  6116. 'label' => false,
  6117. 'div' => false,
  6118. 'type' => 'date',
  6119. 'dateFormat' => 'MY',
  6120. 'minYear' => 2006,
  6121. 'maxYear' => 2008
  6122. )
  6123. );
  6124. $this->assertContains('value="' . date('m') . '" selected="selected"', $result);
  6125. $this->assertNotContains('value="2008" selected="selected"', $result);
  6126. $result = $this->Form->input('just_year',
  6127. array(
  6128. 'type' => 'date',
  6129. 'label' => false,
  6130. 'dateFormat' => 'Y',
  6131. 'minYear' => date('Y'),
  6132. 'maxYear' => date('Y', strtotime('+20 years'))
  6133. )
  6134. );
  6135. $this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
  6136. $result = $this->Form->input('just_month',
  6137. array(
  6138. 'type' => 'date',
  6139. 'label' => false,
  6140. 'dateFormat' => 'M',
  6141. 'empty' => false,
  6142. )
  6143. );
  6144. $this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
  6145. $result = $this->Form->input('just_day',
  6146. array(
  6147. 'type' => 'date',
  6148. 'label' => false,
  6149. 'dateFormat' => 'D',
  6150. 'empty' => false,
  6151. )
  6152. );
  6153. $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
  6154. }
  6155. /**
  6156. * testInputDateMaxYear method
  6157. *
  6158. * Let's say we want to only allow users born from 2006 to 2008 to register
  6159. * This being the first singup page, we still don't have any data
  6160. *
  6161. * @return void
  6162. */
  6163. public function testInputDateMaxYear() {
  6164. $this->markTestIncomplete('Need to revisit once models work again.');
  6165. $this->Form->request->data = array();
  6166. $this->Form->create('User');
  6167. $result = $this->Form->input('birthday',
  6168. array(
  6169. 'label' => false,
  6170. 'div' => false,
  6171. 'type' => 'date',
  6172. 'dateFormat' => 'DMY',
  6173. 'minYear' => 2006,
  6174. 'maxYear' => 2008
  6175. )
  6176. );
  6177. $this->assertContains('value="2008" selected="selected"', $result);
  6178. }
  6179. /**
  6180. * testTextArea method
  6181. *
  6182. * @return void
  6183. */
  6184. public function testTextArea() {
  6185. $this->Form->request->data = array('field' => 'some test data');
  6186. $result = $this->Form->textarea('field');
  6187. $expected = array(
  6188. 'textarea' => array('name' => 'field'),
  6189. 'some test data',
  6190. '/textarea',
  6191. );
  6192. $this->assertTags($result, $expected);
  6193. $result = $this->Form->textarea('user.bio');
  6194. $expected = array(
  6195. 'textarea' => array('name' => 'user[bio]'),
  6196. '/textarea',
  6197. );
  6198. $this->assertTags($result, $expected);
  6199. $this->Form->request->data = array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars');
  6200. $result = $this->Form->textarea('field');
  6201. $expected = array(
  6202. 'textarea' => array('name' => 'field'),
  6203. htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
  6204. '/textarea',
  6205. );
  6206. $this->assertTags($result, $expected);
  6207. $this->Form->request->data = [
  6208. 'Model' => ['field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars']
  6209. ];
  6210. $result = $this->Form->textarea('Model.field', ['escape' => false]);
  6211. $expected = array(
  6212. 'textarea' => array('name' => 'Model[field]'),
  6213. 'some <strong>test</strong> data with <a href="#">HTML</a> chars',
  6214. '/textarea',
  6215. );
  6216. $this->assertTags($result, $expected);
  6217. $result = $this->Form->textarea('0.OtherModel.field');
  6218. $expected = array(
  6219. 'textarea' => array('name' => '0[OtherModel][field]'),
  6220. '/textarea'
  6221. );
  6222. $this->assertTags($result, $expected);
  6223. }
  6224. /**
  6225. * testTextAreaWithStupidCharacters method
  6226. *
  6227. * test text area with non-ascii characters
  6228. *
  6229. * @return void
  6230. */
  6231. public function testTextAreaWithStupidCharacters() {
  6232. $result = $this->Form->textarea('Post.content', [
  6233. 'value' => "GREAT®",
  6234. 'rows' => '15',
  6235. 'cols' => '75'
  6236. ]);
  6237. $expected = [
  6238. 'textarea' => ['name' => 'Post[content]', 'rows' => '15', 'cols' => '75'],
  6239. 'GREAT®',
  6240. '/textarea',
  6241. ];
  6242. $this->assertTags($result, $expected);
  6243. }
  6244. /**
  6245. * testHiddenField method
  6246. *
  6247. * @return void
  6248. */
  6249. public function testHiddenField() {
  6250. $this->article['errors'] = [
  6251. 'field' => true
  6252. ];
  6253. $this->Form->request->data['field'] = 'test';
  6254. $this->Form->create($this->article);
  6255. $result = $this->Form->hidden('field', array('id' => 'theID'));
  6256. $this->assertTags($result, array(
  6257. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'id' => 'theID', 'value' => 'test'))
  6258. );
  6259. $result = $this->Form->hidden('field', ['value' => 'my value']);
  6260. $expected = [
  6261. 'input' => ['type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'value' => 'my value']
  6262. ];
  6263. $this->assertTags($result, $expected);
  6264. }
  6265. /**
  6266. * testFileUploadField method
  6267. *
  6268. * @return void
  6269. */
  6270. public function testFileUploadField() {
  6271. $expected = ['input' => ['type' => 'file', 'name' => 'Model[upload]']];
  6272. $result = $this->Form->file('Model.upload');
  6273. $this->assertTags($result, $expected);
  6274. $this->Form->request->data['Model']['upload'] = [
  6275. 'name' => '', 'type' => '', 'tmp_name' => '',
  6276. 'error' => 4, 'size' => 0
  6277. ];
  6278. $result = $this->Form->file('Model.upload');
  6279. $this->assertTags($result, $expected);
  6280. $this->Form->request->data['Model']['upload'] = 'no data should be set in value';
  6281. $result = $this->Form->file('Model.upload');
  6282. $this->assertTags($result, $expected);
  6283. }
  6284. /**
  6285. * test File upload input on a model not used in create();
  6286. *
  6287. * @return void
  6288. */
  6289. public function testFileUploadOnOtherModel() {
  6290. $this->Form->create($this->article, array('type' => 'file'));
  6291. $result = $this->Form->file('ValidateProfile.city');
  6292. $expected = array(
  6293. 'input' => array('type' => 'file', 'name' => 'ValidateProfile[city]')
  6294. );
  6295. $this->assertTags($result, $expected);
  6296. }
  6297. /**
  6298. * testButton method
  6299. *
  6300. * @return void
  6301. */
  6302. public function testButton() {
  6303. $result = $this->Form->button('Hi');
  6304. $this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
  6305. $result = $this->Form->button('Clear Form >', array('type' => 'reset'));
  6306. $this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
  6307. $result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
  6308. $this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
  6309. $result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
  6310. $this->assertTags($result, array('button' => array('type' => 'reset'), '&lt;Clear Form&gt;', '/button'));
  6311. $result = $this->Form->button('No type', array('type' => false));
  6312. $this->assertTags($result, array('button' => array(), 'No type', '/button'));
  6313. $result = $this->Form->button('Upload Text', array(
  6314. 'onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'",
  6315. 'escape' => false
  6316. ));
  6317. $this->assertNotRegExp('/\&039/', $result);
  6318. }
  6319. /**
  6320. * Test that button() makes unlocked fields by default.
  6321. *
  6322. * @return void
  6323. */
  6324. public function testButtonUnlockedByDefault() {
  6325. $this->Form->request->params['_csrfToken'] = 'secured';
  6326. $this->Form->button('Save', array('name' => 'save'));
  6327. $this->Form->button('Clear');
  6328. $result = $this->Form->unlockField();
  6329. $this->assertEquals(array('save'), $result);
  6330. }
  6331. /**
  6332. * testPostButton method
  6333. *
  6334. * @return void
  6335. */
  6336. public function testPostButton() {
  6337. $result = $this->Form->postButton('Hi', '/controller/action');
  6338. $this->assertTags($result, array(
  6339. 'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
  6340. 'div' => array('style' => 'display:none;'),
  6341. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6342. '/div',
  6343. 'button' => array('type' => 'submit'),
  6344. 'Hi',
  6345. '/button',
  6346. '/form'
  6347. ));
  6348. $result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
  6349. $this->assertTrue(strpos($result, '<input type="hidden" name="extra" value="value"') !== false);
  6350. }
  6351. /**
  6352. * Test that postButton adds _Token fields.
  6353. *
  6354. * @return void
  6355. */
  6356. public function testSecurePostButton() {
  6357. $this->Form->request->params['_csrfToken'] = 'testkey';
  6358. $this->Form->request->params['_Token'] = ['unlockedFields' => []];
  6359. $result = $this->Form->postButton('Delete', '/posts/delete/1');
  6360. $expected = array(
  6361. 'form' => array(
  6362. 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
  6363. ),
  6364. array('div' => array('style' => 'display:none;')),
  6365. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6366. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6367. '/div',
  6368. 'button' => array('type' => 'submit'),
  6369. 'Delete',
  6370. '/button',
  6371. array('div' => array('style' => 'display:none;')),
  6372. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6373. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6374. '/div',
  6375. '/form',
  6376. );
  6377. $this->assertTags($result, $expected);
  6378. }
  6379. /**
  6380. * testPostLink method
  6381. *
  6382. * @return void
  6383. */
  6384. public function testPostLink() {
  6385. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6386. $this->assertTags($result, array(
  6387. 'form' => array(
  6388. 'method' => 'post', 'action' => '/posts/delete/1',
  6389. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6390. ),
  6391. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6392. '/form',
  6393. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6394. 'Delete',
  6395. '/a'
  6396. ));
  6397. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
  6398. $this->assertTags($result, array(
  6399. 'form' => array(
  6400. 'method' => 'post', 'action' => '/posts/delete/1',
  6401. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6402. ),
  6403. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
  6404. '/form',
  6405. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6406. 'Delete',
  6407. '/a'
  6408. ));
  6409. $result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
  6410. $this->assertTags($result, array(
  6411. 'form' => array(
  6412. 'method' => 'post', 'action' => '/posts/delete/1',
  6413. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6414. ),
  6415. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6416. '/form',
  6417. 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\(&quot;Confirm\?&quot;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6418. 'Delete',
  6419. '/a'
  6420. ));
  6421. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
  6422. $this->assertTags($result, array(
  6423. 'form' => array(
  6424. 'method' => 'post', 'action' => '/posts/delete/1',
  6425. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6426. ),
  6427. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6428. '/form',
  6429. 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\(&quot;&#039;Confirm&#039; this \\\\&quot;deletion\\\\&quot;\?&quot;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6430. 'Delete',
  6431. '/a'
  6432. ));
  6433. $result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
  6434. $this->assertContains('<input type="hidden" name="id" value="1"', $result);
  6435. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
  6436. $this->assertTags($result, array(
  6437. 'form' => array(
  6438. 'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
  6439. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6440. ),
  6441. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6442. '/form',
  6443. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6444. 'Delete',
  6445. '/a'
  6446. ));
  6447. $result = $this->Form->postLink(
  6448. '',
  6449. array('controller' => 'items', 'action' => 'delete', 10),
  6450. array('class' => 'btn btn-danger', 'escape' => false),
  6451. 'Confirm thing'
  6452. );
  6453. $this->assertTags($result, array(
  6454. 'form' => array(
  6455. 'method' => 'post', 'action' => '/items/delete/10',
  6456. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6457. ),
  6458. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6459. '/form',
  6460. 'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\&quot\;Confirm thing\&quot\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6461. '/a'
  6462. ));
  6463. }
  6464. /**
  6465. * test creating postLinks after a GET form.
  6466. *
  6467. * @return void
  6468. */
  6469. public function testPostLinkAfterGetForm() {
  6470. $this->Form->request->params['_csrfToken'] = 'testkey';
  6471. $this->Form->request->params['_Token'] = 'val';
  6472. $this->Form->create($this->article, array('type' => 'get'));
  6473. $this->Form->end();
  6474. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6475. $this->assertTags($result, array(
  6476. 'form' => array(
  6477. 'method' => 'post', 'action' => '/posts/delete/1',
  6478. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6479. ),
  6480. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6481. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6482. 'div' => array('style' => 'display:none;'),
  6483. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6484. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6485. '/div',
  6486. '/form',
  6487. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6488. 'Delete',
  6489. '/a'
  6490. ));
  6491. }
  6492. /**
  6493. * Test that postLink adds form tags to view block
  6494. *
  6495. * @return void
  6496. */
  6497. public function testPostLinkFormBuffer() {
  6498. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
  6499. $this->assertTags($result, array(
  6500. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6501. 'Delete',
  6502. '/a'
  6503. ));
  6504. $result = $this->View->fetch('postLink');
  6505. $this->assertTags($result, array(
  6506. 'form' => array(
  6507. 'method' => 'post', 'action' => '/posts/delete/1',
  6508. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6509. ),
  6510. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6511. '/form'
  6512. ));
  6513. $result = $this->Form->postLink('Delete', '/posts/delete/2',
  6514. array('inline' => false, 'method' => 'DELETE')
  6515. );
  6516. $this->assertTags($result, array(
  6517. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6518. 'Delete',
  6519. '/a'
  6520. ));
  6521. $result = $this->View->fetch('postLink');
  6522. $this->assertTags($result, array(
  6523. 'form' => array(
  6524. 'method' => 'post', 'action' => '/posts/delete/1',
  6525. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6526. ),
  6527. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6528. '/form',
  6529. array(
  6530. 'form' => array(
  6531. 'method' => 'post', 'action' => '/posts/delete/2',
  6532. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6533. ),
  6534. ),
  6535. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
  6536. '/form'
  6537. ));
  6538. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'foobar'));
  6539. $this->assertTags($result, array(
  6540. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6541. 'Delete',
  6542. '/a'
  6543. ));
  6544. $result = $this->View->fetch('foobar');
  6545. $this->assertTags($result, array(
  6546. 'form' => array(
  6547. 'method' => 'post', 'action' => '/posts/delete/1',
  6548. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6549. ),
  6550. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6551. '/form'
  6552. ));
  6553. }
  6554. /**
  6555. * testSubmitButton method
  6556. *
  6557. * @return void
  6558. */
  6559. public function testSubmitButton() {
  6560. $this->markTestIncomplete('Need to revisit once models work again.');
  6561. $result = $this->Form->submit('');
  6562. $expected = array(
  6563. 'div' => array('class' => 'submit'),
  6564. 'input' => array('type' => 'submit', 'value' => ''),
  6565. '/div'
  6566. );
  6567. $this->assertTags($result, $expected);
  6568. $result = $this->Form->submit('Test Submit');
  6569. $expected = array(
  6570. 'div' => array('class' => 'submit'),
  6571. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6572. '/div'
  6573. );
  6574. $this->assertTags($result, $expected);
  6575. $result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
  6576. $expected = array(
  6577. 'span' => array('class' => 'submit'),
  6578. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6579. '/span'
  6580. );
  6581. $this->assertTags($result, $expected);
  6582. $result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
  6583. $expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
  6584. $this->assertTags($result, $expected);
  6585. $result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
  6586. $expected = array(
  6587. 'div' => array('class' => 'submit', 'id' => 'SaveButton'),
  6588. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6589. '/div'
  6590. );
  6591. $this->assertTags($result, $expected);
  6592. $result = $this->Form->submit('Next >');
  6593. $expected = array(
  6594. 'div' => array('class' => 'submit'),
  6595. 'input' => array('type' => 'submit', 'value' => 'Next &gt;'),
  6596. '/div'
  6597. );
  6598. $this->assertTags($result, $expected);
  6599. $result = $this->Form->submit('Next >', array('escape' => false));
  6600. $expected = array(
  6601. 'div' => array('class' => 'submit'),
  6602. 'input' => array('type' => 'submit', 'value' => 'Next >'),
  6603. '/div'
  6604. );
  6605. $this->assertTags($result, $expected);
  6606. $result = $this->Form->submit('Reset!', array('type' => 'reset'));
  6607. $expected = array(
  6608. 'div' => array('class' => 'submit'),
  6609. 'input' => array('type' => 'reset', 'value' => 'Reset!'),
  6610. '/div'
  6611. );
  6612. $this->assertTags($result, $expected);
  6613. $before = '--before--';
  6614. $after = '--after--';
  6615. $result = $this->Form->submit('Test', array('before' => $before));
  6616. $expected = array(
  6617. 'div' => array('class' => 'submit'),
  6618. '--before--',
  6619. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6620. '/div'
  6621. );
  6622. $this->assertTags($result, $expected);
  6623. $result = $this->Form->submit('Test', array('after' => $after));
  6624. $expected = array(
  6625. 'div' => array('class' => 'submit'),
  6626. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6627. '--after--',
  6628. '/div'
  6629. );
  6630. $this->assertTags($result, $expected);
  6631. $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
  6632. $expected = array(
  6633. 'div' => array('class' => 'submit'),
  6634. '--before--',
  6635. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6636. '--after--',
  6637. '/div'
  6638. );
  6639. $this->assertTags($result, $expected);
  6640. }
  6641. /**
  6642. * test image submit types.
  6643. *
  6644. * @return void
  6645. */
  6646. public function testSubmitImage() {
  6647. $this->markTestIncomplete('Need to revisit once models work again.');
  6648. $result = $this->Form->submit('http://example.com/cake.power.gif');
  6649. $expected = array(
  6650. 'div' => array('class' => 'submit'),
  6651. 'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
  6652. '/div'
  6653. );
  6654. $this->assertTags($result, $expected);
  6655. $result = $this->Form->submit('/relative/cake.power.gif');
  6656. $expected = array(
  6657. 'div' => array('class' => 'submit'),
  6658. 'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
  6659. '/div'
  6660. );
  6661. $this->assertTags($result, $expected);
  6662. $result = $this->Form->submit('cake.power.gif');
  6663. $expected = array(
  6664. 'div' => array('class' => 'submit'),
  6665. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6666. '/div'
  6667. );
  6668. $this->assertTags($result, $expected);
  6669. $result = $this->Form->submit('Not.an.image');
  6670. $expected = array(
  6671. 'div' => array('class' => 'submit'),
  6672. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6673. '/div'
  6674. );
  6675. $this->assertTags($result, $expected);
  6676. $after = '--after--';
  6677. $before = '--before--';
  6678. $result = $this->Form->submit('cake.power.gif', array('after' => $after));
  6679. $expected = array(
  6680. 'div' => array('class' => 'submit'),
  6681. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6682. '--after--',
  6683. '/div'
  6684. );
  6685. $this->assertTags($result, $expected);
  6686. $result = $this->Form->submit('cake.power.gif', array('before' => $before));
  6687. $expected = array(
  6688. 'div' => array('class' => 'submit'),
  6689. '--before--',
  6690. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6691. '/div'
  6692. );
  6693. $this->assertTags($result, $expected);
  6694. $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
  6695. $expected = array(
  6696. 'div' => array('class' => 'submit'),
  6697. '--before--',
  6698. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6699. '--after--',
  6700. '/div'
  6701. );
  6702. $this->assertTags($result, $expected);
  6703. $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
  6704. $expected = array(
  6705. 'div' => array('class' => 'submit'),
  6706. '--before--',
  6707. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6708. '--after--',
  6709. '/div'
  6710. );
  6711. $this->assertTags($result, $expected);
  6712. }
  6713. /**
  6714. * Submit buttons should be unlocked by default as there could be multiples, and only one will
  6715. * be submitted at a time.
  6716. *
  6717. * @return void
  6718. */
  6719. public function testSubmitUnlockedByDefault() {
  6720. $this->markTestIncomplete('Need to revisit once models work again.');
  6721. $this->Form->request->params['_csrfToken'] = 'secured';
  6722. $this->Form->submit('Go go');
  6723. $this->Form->submit('Save', array('name' => 'save'));
  6724. $result = $this->Form->unlockField();
  6725. $this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
  6726. }
  6727. /**
  6728. * Test submit image with timestamps.
  6729. *
  6730. * @return void
  6731. */
  6732. public function testSubmitImageTimestamp() {
  6733. $this->markTestIncomplete('Need to revisit once models work again.');
  6734. Configure::write('Asset.timestamp', 'force');
  6735. $result = $this->Form->submit('cake.power.gif');
  6736. $expected = array(
  6737. 'div' => array('class' => 'submit'),
  6738. 'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
  6739. '/div'
  6740. );
  6741. $this->assertTags($result, $expected);
  6742. }
  6743. /**
  6744. * test that datetime() works with GET style forms.
  6745. *
  6746. * @return void
  6747. */
  6748. public function testDateTimeWithGetForms() {
  6749. $this->markTestIncomplete('Need to revisit once models work again.');
  6750. extract($this->dateRegex);
  6751. $this->Form->create('Contact', array('type' => 'get'));
  6752. $result = $this->Form->datetime('created');
  6753. $this->assertRegExp('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
  6754. $this->assertRegExp('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
  6755. $this->assertRegExp('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
  6756. $this->assertRegExp('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
  6757. $this->assertRegExp('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
  6758. $this->assertRegExp('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
  6759. }
  6760. /**
  6761. * testEditFormWithData method
  6762. *
  6763. * test auto populating form elements from submitted data.
  6764. *
  6765. * @return void
  6766. */
  6767. public function testEditFormWithData() {
  6768. $this->markTestIncomplete('Need to revisit once models work again.');
  6769. $this->Form->request->data = array('Person' => array(
  6770. 'id' => 1,
  6771. 'first_name' => 'Nate',
  6772. 'last_name' => 'Abele',
  6773. 'email' => 'nate@example.com'
  6774. ));
  6775. $this->Form->request->addParams(array(
  6776. 'models' => array('Person'),
  6777. 'controller' => 'people',
  6778. 'action' => 'add'
  6779. ));
  6780. $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
  6781. $this->Form->create();
  6782. $result = $this->Form->select('People.People', $options, array('multiple' => true));
  6783. $expected = array(
  6784. 'input' => array('type' => 'hidden', 'name' => 'People[People]', 'value' => '', 'id' => 'PeoplePeople_'),
  6785. 'select' => array(
  6786. 'name' => 'People[People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
  6787. ),
  6788. array('option' => array('value' => 1)), 'Nate', '/option',
  6789. array('option' => array('value' => 2)), 'Garrett', '/option',
  6790. array('option' => array('value' => 3)), 'Larry', '/option',
  6791. '/select'
  6792. );
  6793. $this->assertTags($result, $expected);
  6794. }
  6795. /**
  6796. * Test that required fields are created for various types of validation.
  6797. *
  6798. * @return void
  6799. */
  6800. public function testFormInputRequiredDetection() {
  6801. $this->markTestIncomplete('Need to revisit once models work again.');
  6802. $this->Form->create('Contact');
  6803. $result = $this->Form->input('Contact.non_existing');
  6804. $expected = array(
  6805. 'div' => array('class' => 'input text'),
  6806. 'label' => array('for' => 'ContactNonExisting'),
  6807. 'Non Existing',
  6808. '/label',
  6809. 'input' => array(
  6810. 'type' => 'text', 'name' => 'Contact[non_existing]',
  6811. 'id' => 'ContactNonExisting'
  6812. ),
  6813. '/div'
  6814. );
  6815. $this->assertTags($result, $expected);
  6816. $result = $this->Form->input('Contact.imrequired');
  6817. $expected = array(
  6818. 'div' => array('class' => 'input text required'),
  6819. 'label' => array('for' => 'ContactImrequired'),
  6820. 'Imrequired',
  6821. '/label',
  6822. 'input' => array(
  6823. 'type' => 'text', 'name' => 'Contact[imrequired]',
  6824. 'id' => 'ContactImrequired',
  6825. 'required' => 'required'
  6826. ),
  6827. '/div'
  6828. );
  6829. $this->assertTags($result, $expected);
  6830. $result = $this->Form->input('Contact.imalsorequired');
  6831. $expected = array(
  6832. 'div' => array('class' => 'input text required'),
  6833. 'label' => array('for' => 'ContactImalsorequired'),
  6834. 'Imalsorequired',
  6835. '/label',
  6836. 'input' => array(
  6837. 'type' => 'text', 'name' => 'Contact[imalsorequired]',
  6838. 'id' => 'ContactImalsorequired',
  6839. 'required' => 'required'
  6840. ),
  6841. '/div'
  6842. );
  6843. $this->assertTags($result, $expected);
  6844. $result = $this->Form->input('Contact.imrequiredtoo');
  6845. $expected = array(
  6846. 'div' => array('class' => 'input text required'),
  6847. 'label' => array('for' => 'ContactImrequiredtoo'),
  6848. 'Imrequiredtoo',
  6849. '/label',
  6850. 'input' => array(
  6851. 'type' => 'text', 'name' => 'Contact[imrequiredtoo]',
  6852. 'id' => 'ContactImrequiredtoo',
  6853. 'required' => 'required'
  6854. ),
  6855. '/div'
  6856. );
  6857. $this->assertTags($result, $expected);
  6858. $result = $this->Form->input('Contact.required_one');
  6859. $expected = array(
  6860. 'div' => array('class' => 'input text required'),
  6861. 'label' => array('for' => 'ContactRequiredOne'),
  6862. 'Required One',
  6863. '/label',
  6864. 'input' => array(
  6865. 'type' => 'text', 'name' => 'Contact[required_one]',
  6866. 'id' => 'ContactRequiredOne',
  6867. 'required' => 'required'
  6868. ),
  6869. '/div'
  6870. );
  6871. $this->assertTags($result, $expected);
  6872. $result = $this->Form->input('Contact.string_required');
  6873. $expected = array(
  6874. 'div' => array('class' => 'input text required'),
  6875. 'label' => array('for' => 'ContactStringRequired'),
  6876. 'String Required',
  6877. '/label',
  6878. 'input' => array(
  6879. 'type' => 'text', 'name' => 'Contact[string_required]',
  6880. 'id' => 'ContactStringRequired',
  6881. 'required' => 'required'
  6882. ),
  6883. '/div'
  6884. );
  6885. $this->assertTags($result, $expected);
  6886. $result = $this->Form->input('Contact.imnotrequired');
  6887. $expected = array(
  6888. 'div' => array('class' => 'input text'),
  6889. 'label' => array('for' => 'ContactImnotrequired'),
  6890. 'Imnotrequired',
  6891. '/label',
  6892. 'input' => array(
  6893. 'type' => 'text', 'name' => 'Contact[imnotrequired]',
  6894. 'id' => 'ContactImnotrequired'
  6895. ),
  6896. '/div'
  6897. );
  6898. $this->assertTags($result, $expected);
  6899. $result = $this->Form->input('Contact.imalsonotrequired');
  6900. $expected = array(
  6901. 'div' => array('class' => 'input text'),
  6902. 'label' => array('for' => 'ContactImalsonotrequired'),
  6903. 'Imalsonotrequired',
  6904. '/label',
  6905. 'input' => array(
  6906. 'type' => 'text', 'name' => 'Contact[imalsonotrequired]',
  6907. 'id' => 'ContactImalsonotrequired'
  6908. ),
  6909. '/div'
  6910. );
  6911. $this->assertTags($result, $expected);
  6912. $result = $this->Form->input('Contact.imalsonotrequired2');
  6913. $expected = array(
  6914. 'div' => array('class' => 'input text'),
  6915. 'label' => array('for' => 'ContactImalsonotrequired2'),
  6916. 'Imalsonotrequired2',
  6917. '/label',
  6918. 'input' => array(
  6919. 'type' => 'text', 'name' => 'Contact[imalsonotrequired2]',
  6920. 'id' => 'ContactImalsonotrequired2'
  6921. ),
  6922. '/div'
  6923. );
  6924. $this->assertTags($result, $expected);
  6925. $result = $this->Form->input('Contact.imnotrequiredeither');
  6926. $expected = array(
  6927. 'div' => array('class' => 'input text'),
  6928. 'label' => array('for' => 'ContactImnotrequiredeither'),
  6929. 'Imnotrequiredeither',
  6930. '/label',
  6931. 'input' => array(
  6932. 'type' => 'text', 'name' => 'Contact[imnotrequiredeither]',
  6933. 'id' => 'ContactImnotrequiredeither'
  6934. ),
  6935. '/div'
  6936. );
  6937. $this->assertTags($result, $expected);
  6938. $result = $this->Form->input('Contact.iamrequiredalways');
  6939. $expected = array(
  6940. 'div' => array('class' => 'input text required'),
  6941. 'label' => array('for' => 'ContactIamrequiredalways'),
  6942. 'Iamrequiredalways',
  6943. '/label',
  6944. 'input' => array(
  6945. 'type' => 'text', 'name' => 'Contact[iamrequiredalways]',
  6946. 'id' => 'ContactIamrequiredalways',
  6947. 'required' => 'required'
  6948. ),
  6949. '/div'
  6950. );
  6951. $this->assertTags($result, $expected);
  6952. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
  6953. $expected = array(
  6954. 'div' => array('class' => 'input checkbox required'),
  6955. array('input' => array(
  6956. 'type' => 'hidden',
  6957. 'name' => 'Contact[boolean_field]',
  6958. 'id' => 'ContactBooleanField_',
  6959. 'value' => '0'
  6960. )),
  6961. array('input' => array(
  6962. 'type' => 'checkbox',
  6963. 'name' => 'Contact[boolean_field]',
  6964. 'value' => '1',
  6965. 'id' => 'ContactBooleanField'
  6966. )),
  6967. 'label' => array('for' => 'ContactBooleanField'),
  6968. 'Boolean Field',
  6969. '/label',
  6970. '/div'
  6971. );
  6972. $this->assertTags($result, $expected);
  6973. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
  6974. $expected = array(
  6975. 'div' => array('class' => 'input checkbox required'),
  6976. array('input' => array(
  6977. 'type' => 'hidden',
  6978. 'name' => 'Contact[boolean_field]',
  6979. 'id' => 'ContactBooleanField_',
  6980. 'value' => '0'
  6981. )),
  6982. array('input' => array(
  6983. 'type' => 'checkbox',
  6984. 'name' => 'Contact[boolean_field]',
  6985. 'value' => '1',
  6986. 'id' => 'ContactBooleanField',
  6987. 'required' => 'required'
  6988. )),
  6989. 'label' => array('for' => 'ContactBooleanField'),
  6990. 'Boolean Field',
  6991. '/label',
  6992. '/div'
  6993. );
  6994. $this->assertTags($result, $expected);
  6995. $result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
  6996. $expected = array(
  6997. 'div' => array('class' => 'input file required'),
  6998. 'label' => array('for' => 'ContactIamrequiredalways'),
  6999. 'Iamrequiredalways',
  7000. '/label',
  7001. 'input' => array(
  7002. 'type' => 'file',
  7003. 'name' => 'data[Contact][iamrequiredalways]',
  7004. 'id' => 'ContactIamrequiredalways',
  7005. 'required' => 'required'
  7006. ),
  7007. '/div'
  7008. );
  7009. $this->assertTags($result, $expected);
  7010. }
  7011. /**
  7012. * Test that required fields are created when only using ModelValidator::add().
  7013. *
  7014. * @return void
  7015. */
  7016. public function testFormInputRequiredDetectionModelValidator() {
  7017. $this->markTestIncomplete('Need to revisit once models work again.');
  7018. $this->Form->create('ContactTag');
  7019. $result = $this->Form->input('ContactTag.iwillberequired');
  7020. $expected = array(
  7021. 'div' => array('class' => 'input text required'),
  7022. 'label' => array('for' => 'ContactTagIwillberequired'),
  7023. 'Iwillberequired',
  7024. '/label',
  7025. 'input' => array(
  7026. 'name' => 'data[ContactTag][iwillberequired]',
  7027. 'type' => 'text',
  7028. 'id' => 'ContactTagIwillberequired',
  7029. 'required' => 'required'
  7030. ),
  7031. '/div'
  7032. );
  7033. $this->assertTags($result, $expected);
  7034. }
  7035. /**
  7036. * testFormMagicInput method
  7037. *
  7038. * @return void
  7039. */
  7040. public function testFormMagicInput() {
  7041. $this->markTestIncomplete('Need to revisit once models work again.');
  7042. $encoding = strtolower(Configure::read('App.encoding'));
  7043. $result = $this->Form->create('Contact');
  7044. $expected = array(
  7045. 'form' => array(
  7046. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7047. 'accept-charset' => $encoding
  7048. ),
  7049. 'div' => array('style' => 'display:none;'),
  7050. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7051. '/div'
  7052. );
  7053. $this->assertTags($result, $expected);
  7054. $result = $this->Form->input('name');
  7055. $expected = array(
  7056. 'div' => array('class' => 'input text'),
  7057. 'label' => array('for' => 'ContactName'),
  7058. 'Name',
  7059. '/label',
  7060. 'input' => array(
  7061. 'type' => 'text', 'name' => 'Contact[name]',
  7062. 'id' => 'ContactName', 'maxlength' => '255'
  7063. ),
  7064. '/div'
  7065. );
  7066. $this->assertTags($result, $expected);
  7067. $result = $this->Form->input('non_existing_field_in_contact_model');
  7068. $expected = array(
  7069. 'div' => array('class' => 'input text'),
  7070. 'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
  7071. 'Non Existing Field In Contact Model',
  7072. '/label',
  7073. 'input' => array(
  7074. 'type' => 'text', 'name' => 'Contact[non_existing_field_in_contact_model]',
  7075. 'id' => 'ContactNonExistingFieldInContactModel'
  7076. ),
  7077. '/div'
  7078. );
  7079. $this->assertTags($result, $expected);
  7080. $result = $this->Form->input('Address.street');
  7081. $expected = array(
  7082. 'div' => array('class' => 'input text'),
  7083. 'label' => array('for' => 'AddressStreet'),
  7084. 'Street',
  7085. '/label',
  7086. 'input' => array(
  7087. 'type' => 'text', 'name' => 'Address[street]',
  7088. 'id' => 'AddressStreet'
  7089. ),
  7090. '/div'
  7091. );
  7092. $this->assertTags($result, $expected);
  7093. $result = $this->Form->input('Address.non_existing_field_in_model');
  7094. $expected = array(
  7095. 'div' => array('class' => 'input text'),
  7096. 'label' => array('for' => 'AddressNonExistingFieldInModel'),
  7097. 'Non Existing Field In Model',
  7098. '/label',
  7099. 'input' => array(
  7100. 'type' => 'text', 'name' => 'Address[non_existing_field_in_model]',
  7101. 'id' => 'AddressNonExistingFieldInModel'
  7102. ),
  7103. '/div'
  7104. );
  7105. $this->assertTags($result, $expected);
  7106. $result = $this->Form->input('name', array('div' => false));
  7107. $expected = array(
  7108. 'label' => array('for' => 'ContactName'),
  7109. 'Name',
  7110. '/label',
  7111. 'input' => array(
  7112. 'type' => 'text', 'name' => 'Contact[name]',
  7113. 'id' => 'ContactName', 'maxlength' => '255'
  7114. )
  7115. );
  7116. $this->assertTags($result, $expected);
  7117. extract($this->dateRegex);
  7118. $now = strtotime('now');
  7119. $result = $this->Form->input('Contact.published', array('div' => false));
  7120. $expected = array(
  7121. 'label' => array('for' => 'ContactPublishedMonth'),
  7122. 'Published',
  7123. '/label',
  7124. array('select' => array(
  7125. 'name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth'
  7126. )),
  7127. $monthsRegex,
  7128. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7129. date('F', $now),
  7130. '/option',
  7131. '*/select',
  7132. '-',
  7133. array('select' => array(
  7134. 'name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay'
  7135. )),
  7136. $daysRegex,
  7137. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7138. date('j', $now),
  7139. '/option',
  7140. '*/select',
  7141. '-',
  7142. array('select' => array(
  7143. 'name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear'
  7144. )),
  7145. $yearsRegex,
  7146. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7147. date('Y', $now),
  7148. '*/select'
  7149. );
  7150. $this->assertTags($result, $expected);
  7151. $result = $this->Form->input('Contact.updated', array('div' => false));
  7152. $expected = array(
  7153. 'label' => array('for' => 'ContactUpdatedMonth'),
  7154. 'Updated',
  7155. '/label',
  7156. array('select' => array(
  7157. 'name' => 'Contact[updated][month]', 'id' => 'ContactUpdatedMonth'
  7158. )),
  7159. $monthsRegex,
  7160. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7161. date('F', $now),
  7162. '/option',
  7163. '*/select',
  7164. '-',
  7165. array('select' => array(
  7166. 'name' => 'Contact[updated][day]', 'id' => 'ContactUpdatedDay'
  7167. )),
  7168. $daysRegex,
  7169. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7170. date('j', $now),
  7171. '/option',
  7172. '*/select',
  7173. '-',
  7174. array('select' => array(
  7175. 'name' => 'Contact[updated][year]', 'id' => 'ContactUpdatedYear'
  7176. )),
  7177. $yearsRegex,
  7178. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7179. date('Y', $now),
  7180. '*/select'
  7181. );
  7182. $this->assertTags($result, $expected);
  7183. $result = $this->Form->input('UserForm.stuff');
  7184. $expected = array(
  7185. 'div' => array('class' => 'input text'),
  7186. 'label' => array('for' => 'UserFormStuff'),
  7187. 'Stuff',
  7188. '/label',
  7189. 'input' => array(
  7190. 'type' => 'text', 'name' => 'UserForm[stuff]',
  7191. 'id' => 'UserFormStuff', 'maxlength' => 10
  7192. ),
  7193. '/div'
  7194. );
  7195. $this->assertTags($result, $expected);
  7196. }
  7197. /**
  7198. * testForMagicInputNonExistingNorValidated method
  7199. *
  7200. * @return void
  7201. */
  7202. public function testForMagicInputNonExistingNorValidated() {
  7203. $this->markTestIncomplete('Need to revisit once models work again.');
  7204. $encoding = strtolower(Configure::read('App.encoding'));
  7205. $result = $this->Form->create('Contact');
  7206. $expected = array(
  7207. 'form' => array(
  7208. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7209. 'accept-charset' => $encoding
  7210. ),
  7211. 'div' => array('style' => 'display:none;'),
  7212. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7213. '/div'
  7214. );
  7215. $this->assertTags($result, $expected);
  7216. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7217. $expected = array(
  7218. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7219. 'Non Existing Nor Validated',
  7220. '/label',
  7221. 'input' => array(
  7222. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7223. 'id' => 'ContactNonExistingNorValidated'
  7224. )
  7225. );
  7226. $this->assertTags($result, $expected);
  7227. $result = $this->Form->input('Contact.non_existing_nor_validated', array(
  7228. 'div' => false, 'value' => 'my value'
  7229. ));
  7230. $expected = array(
  7231. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7232. 'Non Existing Nor Validated',
  7233. '/label',
  7234. 'input' => array(
  7235. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7236. 'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
  7237. )
  7238. );
  7239. $this->assertTags($result, $expected);
  7240. $this->Form->request->data = array(
  7241. 'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
  7242. ));
  7243. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7244. $expected = array(
  7245. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7246. 'Non Existing Nor Validated',
  7247. '/label',
  7248. 'input' => array(
  7249. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7250. 'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
  7251. )
  7252. );
  7253. $this->assertTags($result, $expected);
  7254. }
  7255. /**
  7256. * testFormMagicInputLabel method
  7257. *
  7258. * @return void
  7259. */
  7260. public function testFormMagicInputLabel() {
  7261. $this->markTestIncomplete('Need to revisit once models work again.');
  7262. $encoding = strtolower(Configure::read('App.encoding'));
  7263. $result = $this->Form->create('Contact');
  7264. $expected = array(
  7265. 'form' => array(
  7266. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7267. 'accept-charset' => $encoding
  7268. ),
  7269. 'div' => array('style' => 'display:none;'),
  7270. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7271. '/div'
  7272. );
  7273. $this->assertTags($result, $expected);
  7274. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
  7275. $this->assertTags($result, array('input' => array(
  7276. 'name' => 'Contact[name]', 'type' => 'text',
  7277. 'id' => 'ContactName', 'maxlength' => '255')
  7278. ));
  7279. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
  7280. $expected = array(
  7281. 'label' => array('for' => 'ContactName'),
  7282. 'My label',
  7283. '/label',
  7284. 'input' => array(
  7285. 'type' => 'text', 'name' => 'Contact[name]',
  7286. 'id' => 'ContactName', 'maxlength' => '255'
  7287. )
  7288. );
  7289. $this->assertTags($result, $expected);
  7290. $result = $this->Form->input('Contact.name', array(
  7291. 'div' => false, 'label' => array('class' => 'mandatory')
  7292. ));
  7293. $expected = array(
  7294. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7295. 'Name',
  7296. '/label',
  7297. 'input' => array(
  7298. 'type' => 'text', 'name' => 'Contact[name]',
  7299. 'id' => 'ContactName', 'maxlength' => '255'
  7300. )
  7301. );
  7302. $this->assertTags($result, $expected);
  7303. $result = $this->Form->input('Contact.name', array(
  7304. 'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
  7305. ));
  7306. $expected = array(
  7307. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7308. 'My label',
  7309. '/label',
  7310. 'input' => array(
  7311. 'type' => 'text', 'name' => 'Contact[name]',
  7312. 'id' => 'ContactName', 'maxlength' => '255'
  7313. )
  7314. );
  7315. $this->assertTags($result, $expected);
  7316. $result = $this->Form->input('Contact.name', array(
  7317. 'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
  7318. ));
  7319. $expected = array(
  7320. 'label' => array('for' => 'my_id'),
  7321. 'Name',
  7322. '/label',
  7323. 'input' => array(
  7324. 'type' => 'text', 'name' => 'Contact[name]',
  7325. 'id' => 'my_id', 'maxlength' => '255'
  7326. )
  7327. );
  7328. $this->assertTags($result, $expected);
  7329. $result = $this->Form->input('1.id');
  7330. $this->assertTags($result, array('input' => array(
  7331. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7332. 'id' => 'Contact1Id'
  7333. )));
  7334. $result = $this->Form->input("1.name");
  7335. $expected = array(
  7336. 'div' => array('class' => 'input text'),
  7337. 'label' => array('for' => 'Contact1Name'),
  7338. 'Name',
  7339. '/label',
  7340. 'input' => array(
  7341. 'type' => 'text', 'name' => 'Contact[1][name]',
  7342. 'id' => 'Contact1Name', 'maxlength' => '255'
  7343. ),
  7344. '/div'
  7345. );
  7346. $this->assertTags($result, $expected);
  7347. $result = $this->Form->input('Contact.1.id');
  7348. $this->assertTags($result, array(
  7349. 'input' => array(
  7350. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7351. 'id' => 'Contact1Id'
  7352. )
  7353. ));
  7354. $result = $this->Form->input("Model.1.name");
  7355. $expected = array(
  7356. 'div' => array('class' => 'input text'),
  7357. 'label' => array('for' => 'Model1Name'),
  7358. 'Name',
  7359. '/label',
  7360. 'input' => array(
  7361. 'type' => 'text', 'name' => 'Model[1][name]',
  7362. 'id' => 'Model1Name'
  7363. ),
  7364. '/div'
  7365. );
  7366. $this->assertTags($result, $expected);
  7367. }
  7368. /**
  7369. * testFormEnd method
  7370. *
  7371. * @return void
  7372. */
  7373. public function testFormEnd() {
  7374. $this->assertEquals('</form>', $this->Form->end());
  7375. }
  7376. /**
  7377. * testMultipleFormWithIdFields method
  7378. *
  7379. * @return void
  7380. */
  7381. public function testMultipleFormWithIdFields() {
  7382. $this->markTestIncomplete('Need to revisit once models work again.');
  7383. $this->Form->create('UserForm');
  7384. $result = $this->Form->input('id');
  7385. $this->assertTags($result, array('input' => array(
  7386. 'type' => 'hidden', 'name' => 'UserForm[id]', 'id' => 'UserFormId'
  7387. )));
  7388. $result = $this->Form->input('ValidateItem.id');
  7389. $this->assertTags($result, array('input' => array(
  7390. 'type' => 'hidden', 'name' => 'ValidateItem[id]',
  7391. 'id' => 'ValidateItemId'
  7392. )));
  7393. $result = $this->Form->input('ValidateUser.id');
  7394. $this->assertTags($result, array('input' => array(
  7395. 'type' => 'hidden', 'name' => 'ValidateUser[id]',
  7396. 'id' => 'ValidateUserId'
  7397. )));
  7398. }
  7399. /**
  7400. * testDbLessModel method
  7401. *
  7402. * @return void
  7403. */
  7404. public function testDbLessModel() {
  7405. $this->markTestIncomplete('Need to revisit once models work again.');
  7406. $this->Form->create('TestMail');
  7407. $result = $this->Form->input('name');
  7408. $expected = array(
  7409. 'div' => array('class' => 'input text'),
  7410. 'label' => array('for' => 'TestMailName'),
  7411. 'Name',
  7412. '/label',
  7413. 'input' => array(
  7414. 'name' => 'TestMail[name]', 'type' => 'text',
  7415. 'id' => 'TestMailName'
  7416. ),
  7417. '/div'
  7418. );
  7419. $this->assertTags($result, $expected);
  7420. $this->Form->create('TestMail');
  7421. $result = $this->Form->input('name');
  7422. $expected = array(
  7423. 'div' => array('class' => 'input text'),
  7424. 'label' => array('for' => 'TestMailName'),
  7425. 'Name',
  7426. '/label',
  7427. 'input' => array(
  7428. 'name' => 'TestMail[name]', 'type' => 'text',
  7429. 'id' => 'TestMailName'
  7430. ),
  7431. '/div'
  7432. );
  7433. $this->assertTags($result, $expected);
  7434. }
  7435. /**
  7436. * testBrokenness method
  7437. *
  7438. * @return void
  7439. */
  7440. public function testBrokenness() {
  7441. $this->markTestIncomplete('Need to revisit once models work again.');
  7442. /*
  7443. * #4 This test has two parents and four children. By default (as of r7117) both
  7444. * parents are show but the first parent is missing a child. This is the inconsistency
  7445. * in the default behaviour - one parent has all children, the other does not - dependent
  7446. * on the data values.
  7447. */
  7448. $result = $this->Form->select('Model.field', array(
  7449. 'Fred' => array(
  7450. 'freds_son_1' => 'Fred',
  7451. 'freds_son_2' => 'Freddie'
  7452. ),
  7453. 'Bert' => array(
  7454. 'berts_son_1' => 'Albert',
  7455. 'berts_son_2' => 'Bertie')
  7456. ),
  7457. array('showParents' => true, 'empty' => false)
  7458. );
  7459. $expected = array(
  7460. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7461. array('optgroup' => array('label' => 'Fred')),
  7462. array('option' => array('value' => 'freds_son_1')),
  7463. 'Fred',
  7464. '/option',
  7465. array('option' => array('value' => 'freds_son_2')),
  7466. 'Freddie',
  7467. '/option',
  7468. '/optgroup',
  7469. array('optgroup' => array('label' => 'Bert')),
  7470. array('option' => array('value' => 'berts_son_1')),
  7471. 'Albert',
  7472. '/option',
  7473. array('option' => array('value' => 'berts_son_2')),
  7474. 'Bertie',
  7475. '/option',
  7476. '/optgroup',
  7477. '/select'
  7478. );
  7479. $this->assertTags($result, $expected);
  7480. /*
  7481. * #2 This is structurally identical to the test above (#1) - only the parent name has
  7482. * changed, so we should expect the same select list data, just with a different name
  7483. * for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
  7484. * This is where data corruption can occur, because when a select value is missing from
  7485. * a list a form will substitute the first value in the list - without the user knowing.
  7486. * If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
  7487. * affect the availability of 3 => 'Three' as a valid option.
  7488. */
  7489. $options = array(1 => 'One', 2 => 'Two', 'Three' => array(
  7490. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  7491. ));
  7492. $result = $this->Form->select(
  7493. 'Model.field', $options, array('showParents' => true, 'empty' => false)
  7494. );
  7495. $expected = array(
  7496. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7497. array('option' => array('value' => 1)),
  7498. 'One',
  7499. '/option',
  7500. array('option' => array('value' => 2)),
  7501. 'Two',
  7502. '/option',
  7503. array('optgroup' => array('label' => 'Three')),
  7504. array('option' => array('value' => 3)),
  7505. 'Three',
  7506. '/option',
  7507. array('option' => array('value' => 4)),
  7508. 'Four',
  7509. '/option',
  7510. array('option' => array('value' => 5)),
  7511. 'Five',
  7512. '/option',
  7513. '/optgroup',
  7514. '/select'
  7515. );
  7516. $this->assertTags($result, $expected);
  7517. }
  7518. /**
  7519. * Test the generation of fields for a multi record form.
  7520. *
  7521. * @return void
  7522. */
  7523. public function testMultiRecordForm() {
  7524. $this->markTestIncomplete('Need to revisit once models work again.');
  7525. $this->Form->create('ValidateProfile');
  7526. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
  7527. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
  7528. $expected = array(
  7529. 'div' => array('class' => 'input textarea'),
  7530. 'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
  7531. 'Name',
  7532. '/label',
  7533. 'textarea' => array(
  7534. 'id' => 'ValidateProfile1ValidateItem2Name',
  7535. 'name' => 'ValidateProfile[1][ValidateItem][2][name]',
  7536. 'cols' => 30,
  7537. 'rows' => 6
  7538. ),
  7539. 'Value',
  7540. '/textarea',
  7541. '/div'
  7542. );
  7543. $this->assertTags($result, $expected);
  7544. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
  7545. $expected = array(
  7546. 'div' => array('class' => 'input date'),
  7547. 'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
  7548. 'Created',
  7549. '/label',
  7550. array('select' => array(
  7551. 'name' => 'ValidateProfile[1][ValidateItem][2][created][month]',
  7552. 'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
  7553. )
  7554. ),
  7555. array('option' => array('value' => '')), '/option',
  7556. $this->dateRegex['monthsRegex'],
  7557. '/select', '-',
  7558. array('select' => array(
  7559. 'name' => 'ValidateProfile[1][ValidateItem][2][created][day]',
  7560. 'id' => 'ValidateProfile1ValidateItem2CreatedDay'
  7561. )
  7562. ),
  7563. array('option' => array('value' => '')), '/option',
  7564. $this->dateRegex['daysRegex'],
  7565. '/select', '-',
  7566. array('select' => array(
  7567. 'name' => 'ValidateProfile[1][ValidateItem][2][created][year]',
  7568. 'id' => 'ValidateProfile1ValidateItem2CreatedYear'
  7569. )
  7570. ),
  7571. array('option' => array('value' => '')), '/option',
  7572. $this->dateRegex['yearsRegex'],
  7573. '/select',
  7574. '/div'
  7575. );
  7576. $this->assertTags($result, $expected);
  7577. $ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
  7578. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
  7579. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
  7580. $expected = array(
  7581. 'div' => array('class' => 'input select error'),
  7582. 'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
  7583. 'Profile',
  7584. '/label',
  7585. 'select' => array(
  7586. 'name' => 'ValidateProfile[1][ValidateItem][2][profile_id]',
  7587. 'id' => 'ValidateProfile1ValidateItem2ProfileId',
  7588. 'class' => 'form-error'
  7589. ),
  7590. '/select',
  7591. array('div' => array('class' => 'error-message')),
  7592. 'Error',
  7593. '/div',
  7594. '/div'
  7595. );
  7596. $this->assertTags($result, $expected);
  7597. }
  7598. /**
  7599. * test the correct display of multi-record form validation errors.
  7600. *
  7601. * @return void
  7602. */
  7603. public function testMultiRecordFormValidationErrors() {
  7604. $this->markTestIncomplete('Need to revisit once models work again.');
  7605. $this->Form->create('ValidateProfile');
  7606. $ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
  7607. $result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
  7608. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7609. $ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
  7610. $result = $this->Form->error('ValidateProfile.2.city');
  7611. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7612. $result = $this->Form->error('2.city');
  7613. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7614. }
  7615. /**
  7616. * test the correct display of multi-record form validation errors.
  7617. *
  7618. * @return void
  7619. */
  7620. public function testSaveManyRecordFormValidationErrors() {
  7621. $this->markTestIncomplete('Need to revisit once models work again.');
  7622. $this->Form->create('ValidateUser');
  7623. $ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
  7624. $result = $this->Form->error('0.ValidateUser.ValidateItem.name');
  7625. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7626. $ValidateUser->validationErrors[0]['city'] = array('Error in field city');
  7627. $result = $this->Form->error('ValidateUser.0.city');
  7628. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7629. }
  7630. /**
  7631. * tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
  7632. *
  7633. * @return void
  7634. */
  7635. public function testInputTemplate() {
  7636. $this->markTestIncomplete('Need to revisit once models work again.');
  7637. $result = $this->Form->input('Contact.email', array(
  7638. 'type' => 'text', 'format' => array('input')
  7639. ));
  7640. $expected = array(
  7641. 'div' => array('class' => 'input text'),
  7642. 'input' => array(
  7643. 'type' => 'text', 'name' => 'Contact[email]',
  7644. 'id' => 'ContactEmail'
  7645. ),
  7646. '/div'
  7647. );
  7648. $this->assertTags($result, $expected);
  7649. $result = $this->Form->input('Contact.email', array(
  7650. 'type' => 'text', 'format' => array('input', 'label'),
  7651. 'label' => '<em>Email (required)</em>'
  7652. ));
  7653. $expected = array(
  7654. 'div' => array('class' => 'input text'),
  7655. array('input' => array(
  7656. 'type' => 'text', 'name' => 'Contact[email]',
  7657. 'id' => 'ContactEmail'
  7658. )),
  7659. 'label' => array('for' => 'ContactEmail'),
  7660. 'em' => array(),
  7661. 'Email (required)',
  7662. '/em',
  7663. '/label',
  7664. '/div'
  7665. );
  7666. $this->assertTags($result, $expected);
  7667. $result = $this->Form->input('Contact.email', array(
  7668. 'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
  7669. 'between' => '<div>Something in the middle</div>',
  7670. 'after' => '<span>Some text at the end</span>'
  7671. ));
  7672. $expected = array(
  7673. 'div' => array('class' => 'input text'),
  7674. array('input' => array(
  7675. 'type' => 'text', 'name' => 'Contact[email]',
  7676. 'id' => 'ContactEmail'
  7677. )),
  7678. array('div' => array()),
  7679. 'Something in the middle',
  7680. '/div',
  7681. 'label' => array('for' => 'ContactEmail'),
  7682. 'Email',
  7683. '/label',
  7684. 'span' => array(),
  7685. 'Some text at the end',
  7686. '/span',
  7687. '/div'
  7688. );
  7689. $this->assertTags($result, $expected);
  7690. $result = $this->Form->input('Contact.method', array(
  7691. 'type' => 'radio',
  7692. 'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
  7693. 'between' => 'I am between',
  7694. ));
  7695. $expected = array(
  7696. 'div' => array('class' => 'input radio'),
  7697. 'fieldset' => array(),
  7698. 'legend' => array(),
  7699. 'Method',
  7700. '/legend',
  7701. 'I am between',
  7702. 'input' => array(
  7703. 'type' => 'hidden', 'name' => 'Contact[method]',
  7704. 'value' => '', 'id' => 'ContactMethod_'
  7705. ),
  7706. array('input' => array(
  7707. 'type' => 'radio', 'name' => 'Contact[method]',
  7708. 'value' => 'email', 'id' => 'ContactMethodEmail'
  7709. )),
  7710. array('label' => array('for' => 'ContactMethodEmail')),
  7711. 'Email',
  7712. '/label',
  7713. array('input' => array(
  7714. 'type' => 'radio', 'name' => 'Contact[method]',
  7715. 'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
  7716. )),
  7717. array('label' => array('for' => 'ContactMethodPigeon')),
  7718. 'Pigeon',
  7719. '/label',
  7720. '/fieldset',
  7721. '/div',
  7722. );
  7723. $this->assertTags($result, $expected);
  7724. }
  7725. /**
  7726. * test that some html5 inputs + FormHelper::__call() work
  7727. *
  7728. * @return void
  7729. */
  7730. public function testHtml5Inputs() {
  7731. $result = $this->Form->email('User.email');
  7732. $expected = array(
  7733. 'input' => array('type' => 'email', 'name' => 'User[email]')
  7734. );
  7735. $this->assertTags($result, $expected);
  7736. $result = $this->Form->search('User.query');
  7737. $expected = array(
  7738. 'input' => array('type' => 'search', 'name' => 'User[query]')
  7739. );
  7740. $this->assertTags($result, $expected);
  7741. $result = $this->Form->search('User.query', array('value' => 'test'));
  7742. $expected = array(
  7743. 'input' => array('type' => 'search', 'name' => 'User[query]', 'value' => 'test')
  7744. );
  7745. $this->assertTags($result, $expected);
  7746. $result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
  7747. $expected = array(
  7748. 'input' => array('type' => 'text', 'name' => 'User[query]', 'value' => 'test')
  7749. );
  7750. $this->assertTags($result, $expected);
  7751. }
  7752. /**
  7753. * Test accessing html5 inputs through input().
  7754. *
  7755. * @return void
  7756. */
  7757. public function testHtml5InputWithInput() {
  7758. $this->markTestIncomplete('Need to revisit once models work again.');
  7759. $result = $this->Form->input('User.website', array(
  7760. 'type' => 'url',
  7761. 'value' => 'http://domain.tld',
  7762. 'div' => false,
  7763. 'label' => false));
  7764. $expected = array(
  7765. 'input' => array('type' => 'url', 'name' => 'User[website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
  7766. );
  7767. $this->assertTags($result, $expected);
  7768. }
  7769. /**
  7770. * Test errors when field name is missing.
  7771. *
  7772. * @expectedException Cake\Error\Exception
  7773. * @return void
  7774. */
  7775. public function testHtml5InputException() {
  7776. $this->Form->email();
  7777. }
  7778. /**
  7779. * Tests that a model can be loaded from the model names passed in the request object
  7780. *
  7781. * @return void
  7782. */
  7783. public function testIntrospectModelFromRequest() {
  7784. $this->markTestIncomplete('Need to revisit once models work again.');
  7785. $this->loadFixtures('Post');
  7786. App::build(array(
  7787. 'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
  7788. ));
  7789. Plugin::load('TestPlugin');
  7790. $this->Form->request['models'] = array(
  7791. 'TestPluginPost' => array(
  7792. 'plugin' => 'TestPlugin',
  7793. 'className' => 'TestPluginPost'
  7794. )
  7795. );
  7796. $this->Form->create('TestPluginPost');
  7797. Plugin::unload();
  7798. }
  7799. /**
  7800. * Tests that it is possible to set the validation errors directly in the helper for a field
  7801. *
  7802. * @return void
  7803. */
  7804. public function testCustomValidationErrors() {
  7805. $this->markTestIncomplete('Need to revisit once models work again.');
  7806. $this->Form->validationErrors['Thing']['field'] = 'Badness!';
  7807. $result = $this->Form->error('Thing.field', null, array('wrap' => false));
  7808. $this->assertEquals('Badness!', $result);
  7809. }
  7810. /**
  7811. * Tests that the 'on' key validates as expected on create
  7812. *
  7813. * @return void
  7814. */
  7815. public function testRequiredOnCreate() {
  7816. $this->markTestIncomplete('Need to revisit once models work again.');
  7817. $this->Form->create('Contact');
  7818. $result = $this->Form->input('Contact.imrequiredonupdate');
  7819. $expected = array(
  7820. 'div' => array('class' => 'input text'),
  7821. 'label' => array('for' => 'ContactImrequiredonupdate'),
  7822. 'Imrequiredonupdate',
  7823. '/label',
  7824. 'input' => array(
  7825. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  7826. 'id' => 'ContactImrequiredonupdate'
  7827. ),
  7828. '/div'
  7829. );
  7830. $this->assertTags($result, $expected);
  7831. $result = $this->Form->input('Contact.imrequiredoncreate');
  7832. $expected = array(
  7833. 'div' => array('class' => 'input text required'),
  7834. 'label' => array('for' => 'ContactImrequiredoncreate'),
  7835. 'Imrequiredoncreate',
  7836. '/label',
  7837. 'input' => array(
  7838. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  7839. 'id' => 'ContactImrequiredoncreate',
  7840. 'required' => 'required'
  7841. ),
  7842. '/div'
  7843. );
  7844. $this->assertTags($result, $expected);
  7845. $result = $this->Form->input('Contact.imrequiredonboth');
  7846. $expected = array(
  7847. 'div' => array('class' => 'input text required'),
  7848. 'label' => array('for' => 'ContactImrequiredonboth'),
  7849. 'Imrequiredonboth',
  7850. '/label',
  7851. 'input' => array(
  7852. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  7853. 'id' => 'ContactImrequiredonboth',
  7854. 'required' => 'required'
  7855. ),
  7856. '/div'
  7857. );
  7858. $this->assertTags($result, $expected);
  7859. $this->Form->inputDefaults(array('required' => false));
  7860. $result = $this->Form->input('Contact.imrequired');
  7861. $expected = array(
  7862. 'div' => array('class' => 'input text'),
  7863. 'label' => array('for' => 'ContactImrequired'),
  7864. 'Imrequired',
  7865. '/label',
  7866. 'input' => array(
  7867. 'type' => 'text', 'name' => 'Contact[imrequired]',
  7868. 'id' => 'ContactImrequired'
  7869. ),
  7870. '/div'
  7871. );
  7872. $this->assertTags($result, $expected);
  7873. $result = $this->Form->input('Contact.imrequired', array('required' => false));
  7874. $this->assertTags($result, $expected);
  7875. $result = $this->Form->input('Contact.imrequired', array('required' => true));
  7876. $expected = array(
  7877. 'div' => array('class' => 'input text required'),
  7878. 'label' => array('for' => 'ContactImrequired'),
  7879. 'Imrequired',
  7880. '/label',
  7881. 'input' => array(
  7882. 'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
  7883. 'id' => 'ContactImrequired'
  7884. ),
  7885. '/div'
  7886. );
  7887. $this->assertTags($result, $expected);
  7888. $result = $this->Form->input('Contact.imrequired', array('required' => null));
  7889. $this->assertTags($result, $expected);
  7890. }
  7891. /**
  7892. * Tests that the 'on' key validates as expected on update
  7893. *
  7894. * @return void
  7895. */
  7896. public function testRequiredOnUpdate() {
  7897. $this->markTestIncomplete('Need to revisit once models work again.');
  7898. $this->Form->request->data['Contact']['id'] = 1;
  7899. $this->Form->create('Contact');
  7900. $result = $this->Form->input('Contact.imrequiredonupdate');
  7901. $expected = array(
  7902. 'div' => array('class' => 'input text required'),
  7903. 'label' => array('for' => 'ContactImrequiredonupdate'),
  7904. 'Imrequiredonupdate',
  7905. '/label',
  7906. 'input' => array(
  7907. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  7908. 'id' => 'ContactImrequiredonupdate',
  7909. 'required' => 'required'
  7910. ),
  7911. '/div'
  7912. );
  7913. $this->assertTags($result, $expected);
  7914. $result = $this->Form->input('Contact.imrequiredoncreate');
  7915. $expected = array(
  7916. 'div' => array('class' => 'input text'),
  7917. 'label' => array('for' => 'ContactImrequiredoncreate'),
  7918. 'Imrequiredoncreate',
  7919. '/label',
  7920. 'input' => array(
  7921. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  7922. 'id' => 'ContactImrequiredoncreate'
  7923. ),
  7924. '/div'
  7925. );
  7926. $this->assertTags($result, $expected);
  7927. $result = $this->Form->input('Contact.imrequiredonboth');
  7928. $expected = array(
  7929. 'div' => array('class' => 'input text required'),
  7930. 'label' => array('for' => 'ContactImrequiredonboth'),
  7931. 'Imrequiredonboth',
  7932. '/label',
  7933. 'input' => array(
  7934. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  7935. 'id' => 'ContactImrequiredonboth',
  7936. 'required' => 'required'
  7937. ),
  7938. '/div'
  7939. );
  7940. $this->assertTags($result, $expected);
  7941. $result = $this->Form->input('Contact.imrequired');
  7942. $expected = array(
  7943. 'div' => array('class' => 'input text required'),
  7944. 'label' => array('for' => 'ContactImrequired'),
  7945. 'Imrequired',
  7946. '/label',
  7947. 'input' => array(
  7948. 'type' => 'text', 'name' => 'Contact[imrequired]',
  7949. 'id' => 'ContactImrequired',
  7950. 'required' => 'required'
  7951. ),
  7952. '/div'
  7953. );
  7954. $this->assertTags($result, $expected);
  7955. }
  7956. /**
  7957. * Test inputDefaults setter and getter
  7958. *
  7959. * @return void
  7960. */
  7961. public function testInputDefaults() {
  7962. $this->markTestIncomplete('Need to revisit once models work again.');
  7963. $this->Form->create('Contact');
  7964. $this->Form->inputDefaults(array(
  7965. 'label' => false,
  7966. 'div' => array(
  7967. 'style' => 'color: #000;'
  7968. )
  7969. ));
  7970. $result = $this->Form->input('Contact.field1');
  7971. $expected = array(
  7972. 'div' => array('class' => 'input text', 'style' => 'color: #000;'),
  7973. 'input' => array(
  7974. 'type' => 'text', 'name' => 'Contact[field1]',
  7975. 'id' => 'ContactField1'
  7976. ),
  7977. '/div'
  7978. );
  7979. $this->assertTags($result, $expected);
  7980. $this->Form->inputDefaults(array(
  7981. 'div' => false,
  7982. 'label' => 'Label',
  7983. ));
  7984. $result = $this->Form->input('Contact.field1');
  7985. $expected = array(
  7986. 'label' => array('for' => 'ContactField1'),
  7987. 'Label',
  7988. '/label',
  7989. 'input' => array(
  7990. 'type' => 'text', 'name' => 'Contact[field1]',
  7991. 'id' => 'ContactField1'
  7992. ),
  7993. );
  7994. $this->assertTags($result, $expected);
  7995. $this->Form->inputDefaults(array(
  7996. 'label' => false,
  7997. ), true);
  7998. $result = $this->Form->input('Contact.field1');
  7999. $expected = array(
  8000. 'input' => array(
  8001. 'type' => 'text', 'name' => 'Contact[field1]',
  8002. 'id' => 'ContactField1'
  8003. ),
  8004. );
  8005. $this->assertTags($result, $expected);
  8006. $result = $this->Form->inputDefaults();
  8007. $expected = array(
  8008. 'div' => false,
  8009. 'label' => false,
  8010. );
  8011. $this->assertEquals($expected, $result);
  8012. }
  8013. }