FormHelperTest.php 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715
  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->markTestIncomplete('Need to revisit once models work again.');
  1069. $this->Form->request->params['_csrfToken'] = 'foo';
  1070. $result = $this->Form->secure(array('anything'));
  1071. $this->assertRegExp('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
  1072. }
  1073. /**
  1074. * Tests that models with identical field names get resolved properly
  1075. *
  1076. * @return void
  1077. */
  1078. public function testDuplicateFieldNameResolution() {
  1079. $this->markTestIncomplete('Need to revisit once models work again.');
  1080. $result = $this->Form->create('ValidateUser');
  1081. $this->assertEquals(array('ValidateUser'), $this->Form->entity());
  1082. $result = $this->Form->input('ValidateItem.name');
  1083. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1084. $result = $this->Form->input('ValidateUser.name');
  1085. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1086. $this->assertContains('name="ValidateUser[name]"', $result);
  1087. $this->assertContains('type="text"', $result);
  1088. $result = $this->Form->input('ValidateItem.name');
  1089. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1090. $this->assertContains('name="ValidateItem[name]"', $result);
  1091. $this->assertContains('<textarea', $result);
  1092. $result = $this->Form->input('name');
  1093. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1094. $this->assertContains('name="ValidateUser[name]"', $result);
  1095. $this->assertContains('type="text"', $result);
  1096. }
  1097. /**
  1098. * Tests that hidden fields generated for checkboxes don't get locked
  1099. *
  1100. * @return void
  1101. */
  1102. public function testNoCheckboxLocking() {
  1103. $this->Form->request->params['_Token'] = 'foo';
  1104. $this->assertSame([], $this->Form->fields);
  1105. $this->Form->checkbox('check', array('value' => '1'));
  1106. $this->assertSame($this->Form->fields, array('check'));
  1107. }
  1108. /**
  1109. * testFormSecurityFields method
  1110. *
  1111. * Test generation of secure form hash generation.
  1112. *
  1113. * @return void
  1114. */
  1115. public function testFormSecurityFields() {
  1116. $this->markTestIncomplete('Need to revisit once models work again.');
  1117. $key = 'testKey';
  1118. $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
  1119. $this->Form->request->params['_csrfToken'] = $key;
  1120. $result = $this->Form->secure($fields);
  1121. $hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
  1122. $hash .= ':' . 'Model.valid';
  1123. $hash = urlencode($hash);
  1124. $expected = array(
  1125. 'div' => array('style' => 'display:none;'),
  1126. array('input' => array(
  1127. 'type' => 'hidden', 'name' => '_Token[fields]',
  1128. 'value' => $hash
  1129. )),
  1130. array('input' => array(
  1131. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1132. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1133. )),
  1134. '/div'
  1135. );
  1136. $this->assertTags($result, $expected);
  1137. $path = CAKE . 'Test/TestApp/Config/';
  1138. $this->Form->Html->loadConfig('htmlhelper_tags', $path);
  1139. $result = $this->Form->secure($fields);
  1140. $expected = array(
  1141. 'div' => array('class' => 'hidden'),
  1142. array('input' => array(
  1143. 'type' => 'hidden', 'name' => '_Token[fields]',
  1144. 'value' => $hash
  1145. )),
  1146. array('input' => array(
  1147. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1148. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1149. )),
  1150. '/div'
  1151. );
  1152. $this->assertTags($result, $expected);
  1153. }
  1154. /**
  1155. * Tests correct generation of number fields for double and float fields
  1156. *
  1157. * @return void
  1158. */
  1159. public function testTextFieldGenerationForFloats() {
  1160. $this->markTestIncomplete('Need to revisit once models work again.');
  1161. $this->article['schema'] = [
  1162. 'foo' => [
  1163. 'type' => 'float',
  1164. 'null' => false,
  1165. 'default' => null,
  1166. 'length' => 10
  1167. ]
  1168. ];
  1169. $this->Form->create('Contact');
  1170. $result = $this->Form->input('foo');
  1171. $expected = array(
  1172. 'div' => array('class' => 'input number'),
  1173. 'label' => array('for' => 'ContactFoo'),
  1174. 'Foo',
  1175. '/label',
  1176. array('input' => array(
  1177. 'type' => 'number',
  1178. 'name' => 'Contact[foo]',
  1179. 'id' => 'ContactFoo',
  1180. 'step' => 'any'
  1181. )),
  1182. '/div'
  1183. );
  1184. $this->assertTags($result, $expected);
  1185. $result = $this->Form->input('foo', array('step' => 0.5));
  1186. $expected = array(
  1187. 'div' => array('class' => 'input number'),
  1188. 'label' => array('for' => 'ContactFoo'),
  1189. 'Foo',
  1190. '/label',
  1191. array('input' => array(
  1192. 'type' => 'number',
  1193. 'name' => 'Contact[foo]',
  1194. 'id' => 'ContactFoo',
  1195. 'step' => '0.5'
  1196. )),
  1197. '/div'
  1198. );
  1199. $this->assertTags($result, $expected);
  1200. }
  1201. /**
  1202. * Tests correct generation of number fields for integer fields
  1203. *
  1204. * @return void
  1205. */
  1206. public function testTextFieldTypeNumberGenerationForIntegers() {
  1207. $this->markTestIncomplete('Need to revisit once models work again.');
  1208. $model->setSchema(array('foo' => array(
  1209. 'type' => 'integer',
  1210. 'null' => false,
  1211. 'default' => null,
  1212. 'length' => null
  1213. )));
  1214. $this->Form->create('Contact');
  1215. $result = $this->Form->input('foo');
  1216. $expected = array(
  1217. 'div' => array('class' => 'input number'),
  1218. 'label' => array('for' => 'ContactFoo'),
  1219. 'Foo',
  1220. '/label',
  1221. array('input' => array(
  1222. 'type' => 'number', 'name' => 'Contact[foo]',
  1223. 'id' => 'ContactFoo'
  1224. )),
  1225. '/div'
  1226. );
  1227. $this->assertTags($result, $expected);
  1228. }
  1229. /**
  1230. * Tests correct generation of file upload fields for binary fields
  1231. *
  1232. * @return void
  1233. */
  1234. public function testFileUploadFieldTypeGenerationForBinaries() {
  1235. $this->markTestIncomplete('Need to revisit once models work again.');
  1236. $model->setSchema(array('foo' => array(
  1237. 'type' => 'binary',
  1238. 'null' => false,
  1239. 'default' => null,
  1240. 'length' => 1024
  1241. )));
  1242. $this->Form->create('Contact');
  1243. $result = $this->Form->input('foo');
  1244. $expected = array(
  1245. 'div' => array('class' => 'input file'),
  1246. 'label' => array('for' => 'ContactFoo'),
  1247. 'Foo',
  1248. '/label',
  1249. array('input' => array(
  1250. 'type' => 'file', 'name' => 'data[Contact][foo]',
  1251. 'id' => 'ContactFoo'
  1252. )),
  1253. '/div'
  1254. );
  1255. $this->assertTags($result, $expected);
  1256. }
  1257. /**
  1258. * testFormSecurityMultipleFields method
  1259. *
  1260. * Test secure() with multiple row form. Ensure hash is correct.
  1261. *
  1262. * @return void
  1263. */
  1264. public function testFormSecurityMultipleFields() {
  1265. $this->markTestIncomplete('Need to revisit once models work again.');
  1266. $key = 'testKey';
  1267. $fields = array(
  1268. 'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
  1269. 'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
  1270. 'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
  1271. );
  1272. $this->Form->request->params['_csrfToken'] = $key;
  1273. $result = $this->Form->secure($fields);
  1274. $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
  1275. $hash .= '%7CModel.1.hidden%7CModel.1.valid';
  1276. $expected = array(
  1277. 'div' => array('style' => 'display:none;'),
  1278. array('input' => array(
  1279. 'type' => 'hidden', 'name' => '_Token[fields]',
  1280. 'value' => $hash
  1281. )),
  1282. array('input' => array(
  1283. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1284. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1285. )),
  1286. '/div'
  1287. );
  1288. $this->assertTags($result, $expected);
  1289. }
  1290. /**
  1291. * testFormSecurityMultipleSubmitButtons
  1292. *
  1293. * test form submit generation and ensure that _Token is only created on end()
  1294. *
  1295. * @return void
  1296. */
  1297. public function testFormSecurityMultipleSubmitButtons() {
  1298. $this->markTestIncomplete('Need to revisit once models work again.');
  1299. $key = 'testKey';
  1300. $this->Form->request->params['_csrfToken'] = $key;
  1301. $this->Form->create('Addresses');
  1302. $this->Form->input('Address.title');
  1303. $this->Form->input('Address.first_name');
  1304. $result = $this->Form->submit('Save', array('name' => 'save'));
  1305. $expected = array(
  1306. 'div' => array('class' => 'submit'),
  1307. 'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
  1308. '/div',
  1309. );
  1310. $this->assertTags($result, $expected);
  1311. $result = $this->Form->submit('Cancel', array('name' => 'cancel'));
  1312. $expected = array(
  1313. 'div' => array('class' => 'submit'),
  1314. 'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
  1315. '/div',
  1316. );
  1317. $this->assertTags($result, $expected);
  1318. $result = $this->Form->end(null);
  1319. $expected = array(
  1320. 'div' => array('style' => 'display:none;'),
  1321. array('input' => array(
  1322. 'type' => 'hidden', 'name' => '_Token[fields]',
  1323. 'value' => 'preg:/.+/'
  1324. )),
  1325. array('input' => array(
  1326. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1327. 'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
  1328. )),
  1329. '/div'
  1330. );
  1331. $this->assertTags($result, $expected);
  1332. }
  1333. /**
  1334. * Test that buttons created with foo[bar] name attributes are unlocked correctly.
  1335. *
  1336. * @return void
  1337. */
  1338. public function testSecurityButtonNestedNamed() {
  1339. $key = 'testKey';
  1340. $this->Form->request->params['_csrfToken'] = $key;
  1341. $this->Form->create('Addresses');
  1342. $this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1343. $result = $this->Form->unlockField();
  1344. $this->assertEquals(array('Address.button'), $result);
  1345. }
  1346. /**
  1347. * Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
  1348. *
  1349. * @return void
  1350. */
  1351. public function testSecuritySubmitNestedNamed() {
  1352. $this->markTestIncomplete('Need to revisit once models work again.');
  1353. $key = 'testKey';
  1354. $this->Form->request->params['_csrfToken'] = $key;
  1355. $this->Form->create('Addresses');
  1356. $this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1357. $result = $this->Form->unlockField();
  1358. $this->assertEquals(array('Address.button'), $result);
  1359. }
  1360. /**
  1361. * Test that the correct fields are unlocked for image submits with no names.
  1362. *
  1363. * @return void
  1364. */
  1365. public function testSecuritySubmitImageNoName() {
  1366. $this->markTestIncomplete('Need to revisit once models work again.');
  1367. $key = 'testKey';
  1368. $this->Form->request->params['_csrfToken'] = $key;
  1369. $this->Form->create('User');
  1370. $result = $this->Form->submit('save.png');
  1371. $expected = array(
  1372. 'div' => array('class' => 'submit'),
  1373. 'input' => array('type' => 'image', 'src' => 'img/save.png'),
  1374. '/div'
  1375. );
  1376. $this->assertTags($result, $expected);
  1377. $this->assertEquals(array('x', 'y'), $this->Form->unlockField());
  1378. }
  1379. /**
  1380. * Test that the correct fields are unlocked for image submits with names.
  1381. *
  1382. * @return void
  1383. */
  1384. public function testSecuritySubmitImageName() {
  1385. $this->markTestIncomplete('Need to revisit once models work again.');
  1386. $key = 'testKey';
  1387. $this->Form->request->params['_csrfToken'] = $key;
  1388. $this->Form->create('User');
  1389. $result = $this->Form->submit('save.png', array('name' => 'test'));
  1390. $expected = array(
  1391. 'div' => array('class' => 'submit'),
  1392. 'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
  1393. '/div'
  1394. );
  1395. $this->assertTags($result, $expected);
  1396. $this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
  1397. }
  1398. /**
  1399. * testFormSecurityMultipleInputFields method
  1400. *
  1401. * Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
  1402. *
  1403. * @return void
  1404. */
  1405. public function testFormSecurityMultipleInputFields() {
  1406. $this->markTestIncomplete('Need to revisit once models work again.');
  1407. $key = 'testKey';
  1408. $this->Form->request->params['_csrfToken'] = $key;
  1409. $this->Form->create('Addresses');
  1410. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1411. $this->Form->input('Addresses.0.title');
  1412. $this->Form->input('Addresses.0.first_name');
  1413. $this->Form->input('Addresses.0.last_name');
  1414. $this->Form->input('Addresses.0.address');
  1415. $this->Form->input('Addresses.0.city');
  1416. $this->Form->input('Addresses.0.phone');
  1417. $this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
  1418. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1419. $this->Form->input('Addresses.1.title');
  1420. $this->Form->input('Addresses.1.first_name');
  1421. $this->Form->input('Addresses.1.last_name');
  1422. $this->Form->input('Addresses.1.address');
  1423. $this->Form->input('Addresses.1.city');
  1424. $this->Form->input('Addresses.1.phone');
  1425. $this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
  1426. $result = $this->Form->secure($this->Form->fields);
  1427. $hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
  1428. $expected = array(
  1429. 'div' => array('style' => 'display:none;'),
  1430. array('input' => array(
  1431. 'type' => 'hidden', 'name' => '_Token[fields]',
  1432. 'value' => $hash
  1433. )),
  1434. array('input' => array(
  1435. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1436. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1437. )),
  1438. '/div'
  1439. );
  1440. $this->assertTags($result, $expected);
  1441. }
  1442. /**
  1443. * Test form security with Model.field.0 style inputs
  1444. *
  1445. * @return void
  1446. */
  1447. public function testFormSecurityArrayFields() {
  1448. $this->markTestIncomplete('Need to revisit once models work again.');
  1449. $key = 'testKey';
  1450. $this->Form->request->params['_csrfToken'] = $key;
  1451. $this->Form->create('Address');
  1452. $this->Form->input('Address.primary.1');
  1453. $this->assertEquals('Address.primary', $this->Form->fields[0]);
  1454. $this->Form->input('Address.secondary.1.0');
  1455. $this->assertEquals('Address.secondary', $this->Form->fields[1]);
  1456. }
  1457. /**
  1458. * testFormSecurityMultipleInputDisabledFields method
  1459. *
  1460. * test secure form generation with multiple records and disabled fields.
  1461. *
  1462. * @return void
  1463. */
  1464. public function testFormSecurityMultipleInputDisabledFields() {
  1465. $this->markTestIncomplete('Need to revisit once models work again.');
  1466. $key = 'testKey';
  1467. $this->Form->request->params['_csrfToken'] = $key;
  1468. $this->Form->request->params['_Token'] = array(
  1469. 'unlockedFields' => array('first_name', 'address')
  1470. );
  1471. $this->Form->create();
  1472. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1473. $this->Form->input('Addresses.0.title');
  1474. $this->Form->input('Addresses.0.first_name');
  1475. $this->Form->input('Addresses.0.last_name');
  1476. $this->Form->input('Addresses.0.address');
  1477. $this->Form->input('Addresses.0.city');
  1478. $this->Form->input('Addresses.0.phone');
  1479. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1480. $this->Form->input('Addresses.1.title');
  1481. $this->Form->input('Addresses.1.first_name');
  1482. $this->Form->input('Addresses.1.last_name');
  1483. $this->Form->input('Addresses.1.address');
  1484. $this->Form->input('Addresses.1.city');
  1485. $this->Form->input('Addresses.1.phone');
  1486. $result = $this->Form->secure($this->Form->fields);
  1487. $hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';
  1488. $expected = array(
  1489. 'div' => array('style' => 'display:none;'),
  1490. array('input' => array(
  1491. 'type' => 'hidden', 'name' => '_Token[fields]',
  1492. 'value' => $hash
  1493. )),
  1494. array('input' => array(
  1495. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1496. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1497. )),
  1498. '/div'
  1499. );
  1500. $this->assertTags($result, $expected);
  1501. }
  1502. /**
  1503. * testFormSecurityInputDisabledFields method
  1504. *
  1505. * Test single record form with disabled fields.
  1506. *
  1507. * @return void
  1508. */
  1509. public function testFormSecurityInputUnlockedFields() {
  1510. $this->markTestIncomplete('Need to revisit once models work again.');
  1511. $key = 'testKey';
  1512. $this->Form->request->params['_csrfToken'] = $key;
  1513. $this->Form->request['_Token'] = array(
  1514. 'unlockedFields' => array('first_name', 'address')
  1515. );
  1516. $this->Form->create();
  1517. $this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
  1518. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1519. $this->Form->input('Addresses.title');
  1520. $this->Form->input('Addresses.first_name');
  1521. $this->Form->input('Addresses.last_name');
  1522. $this->Form->input('Addresses.address');
  1523. $this->Form->input('Addresses.city');
  1524. $this->Form->input('Addresses.phone');
  1525. $result = $this->Form->fields;
  1526. $expected = array(
  1527. 'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
  1528. 'Addresses.city', 'Addresses.phone'
  1529. );
  1530. $this->assertEquals($expected, $result);
  1531. $result = $this->Form->secure($expected);
  1532. $hash = '2981c38990f3f6ba935e6561dc77277966fabd6d%3AAddresses.id';
  1533. $expected = array(
  1534. 'div' => array('style' => 'display:none;'),
  1535. array('input' => array(
  1536. 'type' => 'hidden', 'name' => '_Token[fields]',
  1537. 'value' => $hash
  1538. )),
  1539. array('input' => array(
  1540. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1541. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1542. )),
  1543. '/div'
  1544. );
  1545. $this->assertTags($result, $expected);
  1546. }
  1547. /**
  1548. * test securing inputs with custom name attributes.
  1549. *
  1550. * @return void
  1551. */
  1552. public function testFormSecureWithCustomNameAttribute() {
  1553. $this->markTestIncomplete('Need to revisit once models work again.');
  1554. $this->Form->request->params['_csrfToken'] = 'testKey';
  1555. $this->Form->text('UserForm.published', array('name' => 'User[custom]'));
  1556. $this->assertEquals('User.custom', $this->Form->fields[0]);
  1557. $this->Form->text('UserForm.published', array('name' => 'User[custom][another][value]'));
  1558. $this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
  1559. }
  1560. /**
  1561. * testFormSecuredInput method
  1562. *
  1563. * Test generation of entire secure form, assertions made on input() output.
  1564. *
  1565. * @return void
  1566. */
  1567. public function testFormSecuredInput() {
  1568. $this->markTestIncomplete('Need to revisit once models work again.');
  1569. $this->Form->request->params['_csrfToken'] = 'testKey';
  1570. $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
  1571. $encoding = strtolower(Configure::read('App.encoding'));
  1572. $expected = array(
  1573. 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
  1574. 'div' => array('style' => 'display:none;'),
  1575. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  1576. array('input' => array(
  1577. 'type' => 'hidden', 'name' => '_csrfToken',
  1578. 'value' => 'testKey', 'id' => 'preg:/Token\d+/'
  1579. )),
  1580. '/div'
  1581. );
  1582. $this->assertTags($result, $expected);
  1583. $result = $this->Form->input('ValidateUser.ratio');
  1584. $expected = array(
  1585. 'div' => array('class'),
  1586. 'label' => array('for'),
  1587. 'Ratio',
  1588. '/label',
  1589. 'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'),
  1590. '/div',
  1591. );
  1592. $this->assertTags($result, $expected);
  1593. $result = $this->Form->input('ValidateUser.population');
  1594. $expected = array(
  1595. 'div' => array('class'),
  1596. 'label' => array('for'),
  1597. 'Population',
  1598. '/label',
  1599. 'input' => array('name', 'type' => 'number', 'step' => '1', 'id'),
  1600. '/div',
  1601. );
  1602. $this->assertTags($result, $expected);
  1603. $result = $this->Form->input('UserForm.published', array('type' => 'text'));
  1604. $expected = array(
  1605. 'div' => array('class' => 'input text'),
  1606. 'label' => array('for' => 'UserFormPublished'),
  1607. 'Published',
  1608. '/label',
  1609. array('input' => array(
  1610. 'type' => 'text', 'name' => 'UserForm[published]',
  1611. 'id' => 'UserFormPublished'
  1612. )),
  1613. '/div'
  1614. );
  1615. $this->assertTags($result, $expected);
  1616. $result = $this->Form->input('UserForm.other', array('type' => 'text'));
  1617. $expected = array(
  1618. 'div' => array('class' => 'input text'),
  1619. 'label' => array('for' => 'UserFormOther'),
  1620. 'Other',
  1621. '/label',
  1622. array('input' => array(
  1623. 'type' => 'text', 'name' => 'UserForm[other]',
  1624. 'id' => 'UserFormOther'
  1625. )),
  1626. '/div'
  1627. );
  1628. $this->assertTags($result, $expected);
  1629. $result = $this->Form->hidden('UserForm.stuff');
  1630. $expected = array(
  1631. 'input' => array(
  1632. 'type' => 'hidden', 'name' => 'UserForm[stuff]',
  1633. 'id' => 'UserFormStuff'
  1634. ));
  1635. $this->assertTags($result, $expected);
  1636. $result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
  1637. $expected = array('input' => array(
  1638. 'type' => 'hidden', 'name' => 'UserForm[hidden]',
  1639. 'value' => '0', 'id' => 'UserFormHidden'
  1640. ));
  1641. $this->assertTags($result, $expected);
  1642. $result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
  1643. $expected = array(
  1644. 'div' => array('class' => 'input checkbox'),
  1645. array('input' => array(
  1646. 'type' => 'hidden', 'name' => 'UserForm[something]',
  1647. 'value' => '0', 'id' => 'UserFormSomething_'
  1648. )),
  1649. array('input' => array(
  1650. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  1651. 'value' => '1', 'id' => 'UserFormSomething'
  1652. )),
  1653. 'label' => array('for' => 'UserFormSomething'),
  1654. 'Something',
  1655. '/label',
  1656. '/div'
  1657. );
  1658. $this->assertTags($result, $expected);
  1659. $result = $this->Form->fields;
  1660. $expected = array(
  1661. 'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
  1662. 'UserForm.hidden' => '0', 'UserForm.something'
  1663. );
  1664. $this->assertEquals($expected, $result);
  1665. $hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
  1666. $result = $this->Form->secure($this->Form->fields);
  1667. $expected = array(
  1668. 'div' => array('style' => 'display:none;'),
  1669. array('input' => array(
  1670. 'type' => 'hidden', 'name' => '_Token[fields]',
  1671. 'value' => $hash
  1672. )),
  1673. array('input' => array(
  1674. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1675. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1676. )),
  1677. '/div'
  1678. );
  1679. $this->assertTags($result, $expected);
  1680. }
  1681. /**
  1682. * Test secured inputs with custom names.
  1683. *
  1684. * @return void
  1685. */
  1686. public function testSecuredInputCustomName() {
  1687. $this->markTestIncomplete('Need to revisit once models work again.');
  1688. $this->Form->request->params['_csrfToken'] = 'testKey';
  1689. $this->assertEquals(array(), $this->Form->fields);
  1690. $this->Form->input('text_input', array(
  1691. 'name' => 'data[Option][General.default_role]',
  1692. ));
  1693. $expected = array('Option.General.default_role');
  1694. $this->assertEquals($expected, $this->Form->fields);
  1695. $this->Form->input('select_box', array(
  1696. 'name' => 'data[Option][General.select_role]',
  1697. 'type' => 'select',
  1698. 'options' => array(1, 2),
  1699. ));
  1700. $expected = array('Option.General.default_role', 'Option.General.select_role');
  1701. $this->assertEquals($expected, $this->Form->fields);
  1702. }
  1703. /**
  1704. * Tests that the correct keys are added to the field hash index
  1705. *
  1706. * @return void
  1707. */
  1708. public function testFormSecuredFileInput() {
  1709. $this->assertEquals(array(), $this->Form->fields);
  1710. $this->Form->file('Attachment.file');
  1711. $expected = array(
  1712. 'Attachment.file.name', 'Attachment.file.type',
  1713. 'Attachment.file.tmp_name', 'Attachment.file.error',
  1714. 'Attachment.file.size'
  1715. );
  1716. $this->assertEquals($expected, $this->Form->fields);
  1717. }
  1718. /**
  1719. * test that multiple selects keys are added to field hash
  1720. *
  1721. * @return void
  1722. */
  1723. public function testFormSecuredMultipleSelect() {
  1724. $this->markTestIncomplete('Need to revisit once models work again.');
  1725. $this->Form->request->params['_csrfToken'] = 'testKey';
  1726. $this->assertEquals(array(), $this->Form->fields);
  1727. $options = array('1' => 'one', '2' => 'two');
  1728. $this->Form->select('Model.select', $options);
  1729. $expected = array('Model.select');
  1730. $this->assertEquals($expected, $this->Form->fields);
  1731. $this->Form->fields = array();
  1732. $this->Form->select('Model.select', $options, array('multiple' => true));
  1733. $this->assertEquals($expected, $this->Form->fields);
  1734. }
  1735. /**
  1736. * testFormSecuredRadio method
  1737. *
  1738. * @return void
  1739. */
  1740. public function testFormSecuredRadio() {
  1741. $this->assertEquals(array(), $this->Form->fields);
  1742. $options = array('1' => 'option1', '2' => 'option2');
  1743. $this->Form->radio('Test.test', $options);
  1744. $expected = array('Test[test]' => '');
  1745. $this->assertEquals($expected, $this->Form->fields);
  1746. }
  1747. /**
  1748. * Test that when disabled is in a list based attribute array it works.
  1749. *
  1750. * @return void
  1751. */
  1752. public function testFormSecuredAndDisabledNotAssoc() {
  1753. $this->markTestIncomplete('Need to revisit once models work again.');
  1754. $this->Form->request->params['_csrfToken'] = 'testKey';
  1755. $this->Form->select('Model.select', array(1, 2), array('disabled'));
  1756. $this->Form->checkbox('Model.checkbox', array('disabled'));
  1757. $this->Form->text('Model.text', array('disabled'));
  1758. $this->Form->textarea('Model.textarea', array('disabled'));
  1759. $this->Form->password('Model.password', array('disabled'));
  1760. $this->Form->radio('Model.radio', array(1, 2), array('disabled'));
  1761. $expected = array(
  1762. 'Model.radio' => ''
  1763. );
  1764. $this->assertEquals($expected, $this->Form->fields);
  1765. }
  1766. /**
  1767. * test that forms with disabled inputs + secured forms leave off the inputs from the form
  1768. * hashing.
  1769. *
  1770. * @return void
  1771. */
  1772. public function testFormSecuredAndDisabled() {
  1773. $this->markTestIncomplete('Need to revisit once models work again.');
  1774. $this->Form->request->params['_csrfToken'] = 'testKey';
  1775. $this->Form->checkbox('Model.checkbox', array('disabled' => true));
  1776. $this->Form->text('Model.text', array('disabled' => true));
  1777. $this->Form->password('Model.text', array('disabled' => true));
  1778. $this->Form->textarea('Model.textarea', array('disabled' => true));
  1779. $this->Form->select('Model.select', array(1, 2), array('disabled' => true));
  1780. $this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
  1781. $this->Form->year('Model.year', null, null, array('disabled' => true));
  1782. $this->Form->month('Model.month', array('disabled' => true));
  1783. $this->Form->day('Model.day', array('disabled' => true));
  1784. $this->Form->hour('Model.hour', false, array('disabled' => true));
  1785. $this->Form->minute('Model.minute', array('disabled' => true));
  1786. $this->Form->meridian('Model.meridian', array('disabled' => true));
  1787. $expected = array(
  1788. 'Model.radio' => ''
  1789. );
  1790. $this->assertEquals($expected, $this->Form->fields);
  1791. }
  1792. /**
  1793. * testDisableSecurityUsingForm method
  1794. *
  1795. * @return void
  1796. */
  1797. public function testDisableSecurityUsingForm() {
  1798. $this->markTestIncomplete('Need to revisit once models work again.');
  1799. $this->Form->request->params['_csrfToken'] = 'testKey';
  1800. $this->Form->request['_Token'] = array(
  1801. 'disabledFields' => array()
  1802. );
  1803. $this->Form->create();
  1804. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1805. $this->Form->input('Addresses.title');
  1806. $this->Form->input('Addresses.first_name', array('secure' => false));
  1807. $this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
  1808. $this->Form->input('Addresses.zip', array(
  1809. 'type' => 'select', 'options' => array(1, 2), 'secure' => false
  1810. ));
  1811. $result = $this->Form->fields;
  1812. $expected = array(
  1813. 'Addresses.id' => '123456', 'Addresses.title',
  1814. );
  1815. $this->assertEquals($expected, $result);
  1816. }
  1817. /**
  1818. * test disableField
  1819. *
  1820. * @return void
  1821. */
  1822. public function testUnlockFieldAddsToList() {
  1823. $this->markTestIncomplete('Need to revisit once models work again.');
  1824. $this->Form->request->params['_csrfToken'] = 'testKey';
  1825. $this->Form->request['_Token'] = array(
  1826. 'unlockedFields' => array()
  1827. );
  1828. $this->Form->create('Contact');
  1829. $this->Form->unlockField('Contact.name');
  1830. $this->Form->text('Contact.name');
  1831. $this->assertEquals(array('Contact.name'), $this->Form->unlockField());
  1832. $this->assertEquals(array(), $this->Form->fields);
  1833. }
  1834. /**
  1835. * test unlockField removing from fields array.
  1836. *
  1837. * @return void
  1838. */
  1839. public function testUnlockFieldRemovingFromFields() {
  1840. $this->markTestIncomplete('Need to revisit once models work again.');
  1841. $this->Form->request->params['_csrfToken'] = 'testKey';
  1842. $this->Form->request['_Token'] = array(
  1843. 'unlockedFields' => array()
  1844. );
  1845. $this->Form->create('Contact');
  1846. $this->Form->hidden('Contact.id', array('value' => 1));
  1847. $this->Form->text('Contact.name');
  1848. $this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
  1849. $this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
  1850. $this->Form->unlockField('Contact.name');
  1851. $this->Form->unlockField('Contact.id');
  1852. $this->assertEquals(array(), $this->Form->fields);
  1853. }
  1854. /**
  1855. * testTagIsInvalid method
  1856. *
  1857. * @return void
  1858. */
  1859. public function testTagIsInvalid() {
  1860. $this->markTestIncomplete('Need to revisit once models work again.');
  1861. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1862. $this->Form->setEntity('Contact.0.email');
  1863. $result = $this->Form->tagIsInvalid();
  1864. $this->assertEquals($expected, $result);
  1865. $this->Form->setEntity('Contact.1.email');
  1866. $result = $this->Form->tagIsInvalid();
  1867. $this->assertFalse($result);
  1868. $this->Form->setEntity('Contact.0.name');
  1869. $result = $this->Form->tagIsInvalid();
  1870. $this->assertFalse($result);
  1871. }
  1872. /**
  1873. * Test tagIsInvalid with validation errors from a saveMany
  1874. *
  1875. * @return void
  1876. */
  1877. public function testTagIsInvalidSaveMany() {
  1878. $this->markTestIncomplete('Need to revisit once models work again.');
  1879. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1880. $this->Form->create('Contact');
  1881. $this->Form->setEntity('0.email');
  1882. $result = $this->Form->tagIsInvalid();
  1883. $this->assertEquals($expected, $result);
  1884. $this->Form->setEntity('0.Contact.email');
  1885. $result = $this->Form->tagIsInvalid();
  1886. $this->assertEquals($expected, $result);
  1887. }
  1888. /**
  1889. * Test validation errors.
  1890. *
  1891. * @return void
  1892. */
  1893. public function testPasswordValidation() {
  1894. $this->markTestIncomplete('Need to revisit once models work again.');
  1895. $Contact->validationErrors['password'] = array('Please provide a password');
  1896. $result = $this->Form->input('Contact.password');
  1897. $expected = array(
  1898. 'div' => array('class' => 'input password error'),
  1899. 'label' => array('for' => 'ContactPassword'),
  1900. 'Password',
  1901. '/label',
  1902. 'input' => array(
  1903. 'type' => 'password', 'name' => 'Contact[password]',
  1904. 'id' => 'ContactPassword', 'class' => 'form-error'
  1905. ),
  1906. array('div' => array('class' => 'error-message')),
  1907. 'Please provide a password',
  1908. '/div',
  1909. '/div'
  1910. );
  1911. $this->assertTags($result, $expected);
  1912. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1913. $expected = array(
  1914. 'div' => array('class' => 'input password error'),
  1915. 'label' => array('for' => 'ContactPassword'),
  1916. 'Password',
  1917. '/label',
  1918. 'input' => array(
  1919. 'type' => 'password', 'name' => 'Contact[password]',
  1920. 'id' => 'ContactPassword', 'class' => 'form-error'
  1921. ),
  1922. '/div'
  1923. );
  1924. $this->assertTags($result, $expected);
  1925. }
  1926. /**
  1927. * Test validation errors, when validation message is an empty string.
  1928. *
  1929. * @return void
  1930. */
  1931. public function testEmptyErrorValidation() {
  1932. $this->markTestIncomplete('Need to revisit once models work again.');
  1933. $this->Form->validationErrors['Contact']['password'] = '';
  1934. $result = $this->Form->input('Contact.password');
  1935. $expected = array(
  1936. 'div' => array('class' => 'input password error'),
  1937. 'label' => array('for' => 'ContactPassword'),
  1938. 'Password',
  1939. '/label',
  1940. 'input' => array(
  1941. 'type' => 'password', 'name' => 'Contact[password]',
  1942. 'id' => 'ContactPassword', 'class' => 'form-error'
  1943. ),
  1944. array('div' => array('class' => 'error-message')),
  1945. array(),
  1946. '/div',
  1947. '/div'
  1948. );
  1949. $this->assertTags($result, $expected);
  1950. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1951. $expected = array(
  1952. 'div' => array('class' => 'input password error'),
  1953. 'label' => array('for' => 'ContactPassword'),
  1954. 'Password',
  1955. '/label',
  1956. 'input' => array(
  1957. 'type' => 'password', 'name' => 'Contact[password]',
  1958. 'id' => 'ContactPassword', 'class' => 'form-error'
  1959. ),
  1960. '/div'
  1961. );
  1962. $this->assertTags($result, $expected);
  1963. }
  1964. /**
  1965. * Test validation errors, when calling input() overriding validation message by an empty string.
  1966. *
  1967. * @return void
  1968. */
  1969. public function testEmptyInputErrorValidation() {
  1970. $this->markTestIncomplete('Need to revisit once models work again.');
  1971. $this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
  1972. $result = $this->Form->input('Contact.password', array('error' => ''));
  1973. $expected = array(
  1974. 'div' => array('class' => 'input password error'),
  1975. 'label' => array('for' => 'ContactPassword'),
  1976. 'Password',
  1977. '/label',
  1978. 'input' => array(
  1979. 'type' => 'password', 'name' => 'Contact[password]',
  1980. 'id' => 'ContactPassword', 'class' => 'form-error'
  1981. ),
  1982. array('div' => array('class' => 'error-message')),
  1983. array(),
  1984. '/div',
  1985. '/div'
  1986. );
  1987. $this->assertTags($result, $expected);
  1988. $result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
  1989. $expected = array(
  1990. 'div' => array('class' => 'input password error'),
  1991. 'label' => array('for' => 'ContactPassword'),
  1992. 'Password',
  1993. '/label',
  1994. 'input' => array(
  1995. 'type' => 'password', 'name' => 'Contact[password]',
  1996. 'id' => 'ContactPassword', 'class' => 'form-error'
  1997. ),
  1998. '/div'
  1999. );
  2000. $this->assertTags($result, $expected);
  2001. }
  2002. /**
  2003. * testFormValidationAssociated method
  2004. *
  2005. * test display of form errors in conjunction with model::validates.
  2006. *
  2007. * @return void
  2008. */
  2009. public function testFormValidationAssociated() {
  2010. $this->markTestIncomplete('Need to revisit once models work again.');
  2011. $data = array(
  2012. 'UserForm' => array('name' => 'user'),
  2013. 'OpenidUrl' => array('url' => 'http://www.cakephp.org')
  2014. );
  2015. $result = $this->UserForm->OpenidUrl->create($data);
  2016. $this->assertFalse(empty($result));
  2017. $this->assertFalse($this->UserForm->OpenidUrl->validates());
  2018. $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
  2019. $encoding = strtolower(Configure::read('App.encoding'));
  2020. $expected = array(
  2021. 'form' => array(
  2022. 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
  2023. 'accept-charset' => $encoding
  2024. ),
  2025. 'div' => array('style' => 'display:none;'),
  2026. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2027. '/div'
  2028. );
  2029. $this->assertTags($result, $expected);
  2030. $result = $this->Form->error(
  2031. 'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
  2032. );
  2033. $this->assertEquals('Error, not registered', $result);
  2034. unset($this->UserForm->OpenidUrl, $this->UserForm);
  2035. }
  2036. /**
  2037. * testFormValidationAssociatedFirstLevel method
  2038. *
  2039. * test form error display with associated model.
  2040. *
  2041. * @return void
  2042. */
  2043. public function testFormValidationAssociatedFirstLevel() {
  2044. $this->markTestIncomplete('Need to revisit once models work again.');
  2045. $data = array(
  2046. 'ValidateUser' => array('name' => 'mariano'),
  2047. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
  2048. );
  2049. $result = $this->ValidateUser->create($data);
  2050. $this->assertFalse(empty($result));
  2051. $this->assertFalse($this->ValidateUser->validates());
  2052. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2053. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2054. $encoding = strtolower(Configure::read('App.encoding'));
  2055. $expected = array(
  2056. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2057. 'div' => array('style' => 'display:none;'),
  2058. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2059. '/div'
  2060. );
  2061. $this->assertTags($result, $expected);
  2062. $result = $this->Form->error(
  2063. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2064. );
  2065. $this->assertEquals('Invalid email', $result);
  2066. $result = $this->Form->error(
  2067. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2068. );
  2069. $this->assertEquals('Invalid name', $result);
  2070. $result = $this->Form->error(
  2071. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2072. );
  2073. $this->assertEquals('Invalid city', $result);
  2074. unset($this->ValidateUser->ValidateProfile);
  2075. unset($this->ValidateUser);
  2076. }
  2077. /**
  2078. * testFormValidationAssociatedSecondLevel method
  2079. *
  2080. * test form error display with associated model.
  2081. *
  2082. * @return void
  2083. */
  2084. public function testFormValidationAssociatedSecondLevel() {
  2085. $this->markTestIncomplete('Need to revisit once models work again.');
  2086. $data = array(
  2087. 'ValidateUser' => array('name' => 'mariano'),
  2088. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
  2089. 'ValidateItem' => array('name' => 'Item')
  2090. );
  2091. $result = $this->ValidateUser->create($data);
  2092. $this->assertFalse(empty($result));
  2093. $this->assertFalse($this->ValidateUser->validates());
  2094. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2095. $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
  2096. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2097. $encoding = strtolower(Configure::read('App.encoding'));
  2098. $expected = array(
  2099. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2100. 'div' => array('style' => 'display:none;'),
  2101. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2102. '/div'
  2103. );
  2104. $this->assertTags($result, $expected);
  2105. $result = $this->Form->error(
  2106. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2107. );
  2108. $this->assertEquals('Invalid email', $result);
  2109. $result = $this->Form->error(
  2110. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2111. );
  2112. $this->assertEquals('Invalid name', $result);
  2113. $result = $this->Form->error(
  2114. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2115. );
  2116. $result = $this->Form->error(
  2117. 'ValidateItem.description', 'Invalid description', array('wrap' => false)
  2118. );
  2119. $this->assertEquals('Invalid description', $result);
  2120. unset($this->ValidateUser->ValidateProfile->ValidateItem);
  2121. unset($this->ValidateUser->ValidateProfile);
  2122. unset($this->ValidateUser);
  2123. }
  2124. /**
  2125. * testFormValidationMultiRecord method
  2126. *
  2127. * test form error display with multiple records.
  2128. *
  2129. * @return void
  2130. */
  2131. public function testFormValidationMultiRecord() {
  2132. $this->markTestIncomplete('Need to revisit once models work again.');
  2133. $Contact->validationErrors[2] = array(
  2134. 'name' => array('The provided value is invalid')
  2135. );
  2136. $result = $this->Form->input('Contact.2.name');
  2137. $expected = array(
  2138. 'div' => array('class' => 'input text error'),
  2139. 'label' => array('for' => 'Contact2Name'),
  2140. 'Name',
  2141. '/label',
  2142. 'input' => array(
  2143. 'type' => 'text', 'name' => 'Contact[2][name]', 'id' => 'Contact2Name',
  2144. 'class' => 'form-error', 'maxlength' => 255
  2145. ),
  2146. array('div' => array('class' => 'error-message')),
  2147. 'The provided value is invalid',
  2148. '/div',
  2149. '/div'
  2150. );
  2151. $this->assertTags($result, $expected);
  2152. }
  2153. /**
  2154. * testMultipleInputValidation method
  2155. *
  2156. * test multiple record form validation error display.
  2157. *
  2158. * @return void
  2159. */
  2160. public function testMultipleInputValidation() {
  2161. $this->markTestIncomplete('Need to revisit once models work again.');
  2162. $Address->validationErrors[0] = array(
  2163. 'title' => array('This field cannot be empty'),
  2164. 'first_name' => array('This field cannot be empty')
  2165. );
  2166. $Address->validationErrors[1] = array(
  2167. 'last_name' => array('You must have a last name')
  2168. );
  2169. $this->Form->create();
  2170. $result = $this->Form->input('Address.0.title');
  2171. $expected = array(
  2172. 'div' => array('class'),
  2173. 'label' => array('for'),
  2174. 'preg:/[^<]+/',
  2175. '/label',
  2176. 'input' => array(
  2177. 'type' => 'text', 'name', 'id', 'class' => 'form-error'
  2178. ),
  2179. array('div' => array('class' => 'error-message')),
  2180. 'This field cannot be empty',
  2181. '/div',
  2182. '/div'
  2183. );
  2184. $this->assertTags($result, $expected);
  2185. $result = $this->Form->input('Address.0.first_name');
  2186. $expected = array(
  2187. 'div' => array('class'),
  2188. 'label' => array('for'),
  2189. 'preg:/[^<]+/',
  2190. '/label',
  2191. 'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
  2192. array('div' => array('class' => 'error-message')),
  2193. 'This field cannot be empty',
  2194. '/div',
  2195. '/div'
  2196. );
  2197. $this->assertTags($result, $expected);
  2198. $result = $this->Form->input('Address.0.last_name');
  2199. $expected = array(
  2200. 'div' => array('class'),
  2201. 'label' => array('for'),
  2202. 'preg:/[^<]+/',
  2203. '/label',
  2204. 'input' => array('type' => 'text', 'name', 'id'),
  2205. '/div'
  2206. );
  2207. $this->assertTags($result, $expected);
  2208. $result = $this->Form->input('Address.1.last_name');
  2209. $expected = array(
  2210. 'div' => array('class'),
  2211. 'label' => array('for'),
  2212. 'preg:/[^<]+/',
  2213. '/label',
  2214. 'input' => array(
  2215. 'type' => 'text', 'name' => 'preg:/[^<]+/',
  2216. 'id' => 'preg:/[^<]+/', 'class' => 'form-error'
  2217. ),
  2218. array('div' => array('class' => 'error-message')),
  2219. 'You must have a last name',
  2220. '/div',
  2221. '/div'
  2222. );
  2223. $this->assertTags($result, $expected);
  2224. }
  2225. /**
  2226. * testInput method
  2227. *
  2228. * Test various incarnations of input().
  2229. *
  2230. * @return void
  2231. */
  2232. public function testInput() {
  2233. $this->markTestIncomplete('Need to revisit once models work again.');
  2234. $result = $this->Form->input('ValidateUser.balance');
  2235. $expected = array(
  2236. 'div' => array('class'),
  2237. 'label' => array('for'),
  2238. 'Balance',
  2239. '/label',
  2240. 'input' => array('name', 'type' => 'number', 'id'),
  2241. '/div',
  2242. );
  2243. $this->assertTags($result, $expected);
  2244. $result = $this->Form->input('ValidateUser.cost_decimal');
  2245. $expected = array(
  2246. 'div' => array('class'),
  2247. 'label' => array('for'),
  2248. 'Cost Decimal',
  2249. '/label',
  2250. 'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
  2251. '/div',
  2252. );
  2253. $this->assertTags($result, $expected);
  2254. $result = $this->Form->input('Contact.email', array('id' => 'custom'));
  2255. $expected = array(
  2256. 'div' => array('class' => 'input email'),
  2257. 'label' => array('for' => 'custom'),
  2258. 'Email',
  2259. '/label',
  2260. array('input' => array(
  2261. 'type' => 'email', 'name' => 'Contact[email]',
  2262. 'id' => 'custom', 'maxlength' => 255
  2263. )),
  2264. '/div'
  2265. );
  2266. $this->assertTags($result, $expected);
  2267. $result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
  2268. $expected = array(
  2269. '<div',
  2270. 'label' => array('for' => 'ContactEmail'),
  2271. 'Email',
  2272. '/label',
  2273. array('input' => array(
  2274. 'type' => 'email', 'name' => 'Contact[email]',
  2275. 'id' => 'ContactEmail', 'maxlength' => 255
  2276. )),
  2277. '/div'
  2278. );
  2279. $this->assertTags($result, $expected);
  2280. $result = $this->Form->hidden('Contact.idontexist');
  2281. $expected = array('input' => array(
  2282. 'type' => 'hidden', 'name' => 'Contact[idontexist]',
  2283. 'id' => 'ContactIdontexist'
  2284. ));
  2285. $this->assertTags($result, $expected);
  2286. $result = $this->Form->input('Contact.email', array('type' => 'text'));
  2287. $expected = array(
  2288. 'div' => array('class' => 'input text'),
  2289. 'label' => array('for' => 'ContactEmail'),
  2290. 'Email',
  2291. '/label',
  2292. array('input' => array(
  2293. 'type' => 'text', 'name' => 'Contact[email]',
  2294. 'id' => 'ContactEmail'
  2295. )),
  2296. '/div'
  2297. );
  2298. $this->assertTags($result, $expected);
  2299. $result = $this->Form->input('Contact.5.email', array('type' => 'text'));
  2300. $expected = array(
  2301. 'div' => array('class' => 'input text'),
  2302. 'label' => array('for' => 'Contact5Email'),
  2303. 'Email',
  2304. '/label',
  2305. array('input' => array(
  2306. 'type' => 'text', 'name' => 'Contact[5][email]',
  2307. 'id' => 'Contact5Email'
  2308. )),
  2309. '/div'
  2310. );
  2311. $this->assertTags($result, $expected);
  2312. $result = $this->Form->input('Contact.password');
  2313. $expected = array(
  2314. 'div' => array('class' => 'input password'),
  2315. 'label' => array('for' => 'ContactPassword'),
  2316. 'Password',
  2317. '/label',
  2318. array('input' => array(
  2319. 'type' => 'password', 'name' => 'Contact[password]',
  2320. 'id' => 'ContactPassword'
  2321. )),
  2322. '/div'
  2323. );
  2324. $this->assertTags($result, $expected);
  2325. $result = $this->Form->input('Contact.email', array(
  2326. 'type' => 'file', 'class' => 'textbox'
  2327. ));
  2328. $expected = array(
  2329. 'div' => array('class' => 'input file'),
  2330. 'label' => array('for' => 'ContactEmail'),
  2331. 'Email',
  2332. '/label',
  2333. array('input' => array(
  2334. 'type' => 'file', 'name' => 'Contact[email]', 'class' => 'textbox',
  2335. 'id' => 'ContactEmail'
  2336. )),
  2337. '/div'
  2338. );
  2339. $this->assertTags($result, $expected);
  2340. $this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
  2341. $result = $this->Form->input('Contact.phone');
  2342. $expected = array(
  2343. 'div' => array('class' => 'input tel'),
  2344. 'label' => array('for' => 'ContactPhone'),
  2345. 'Phone',
  2346. '/label',
  2347. array('input' => array(
  2348. 'type' => 'tel', 'name' => 'Contact[phone]',
  2349. 'value' => 'Hello &amp; World &gt; weird chars',
  2350. 'id' => 'ContactPhone', 'maxlength' => 255
  2351. )),
  2352. '/div'
  2353. );
  2354. $this->assertTags($result, $expected);
  2355. $this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
  2356. $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
  2357. $expected = array(
  2358. 'div' => array('class' => 'input text'),
  2359. 'label' => array('for' => 'myId'),
  2360. 'Field',
  2361. '/label',
  2362. 'input' => array(
  2363. 'type' => 'text', 'name' => 'Model[0][OtherModel][field]',
  2364. 'value' => 'My value', 'id' => 'myId'
  2365. ),
  2366. '/div'
  2367. );
  2368. $this->assertTags($result, $expected);
  2369. unset($this->Form->request->data);
  2370. $Contact->validationErrors['field'] = array('Badness!');
  2371. $result = $this->Form->input('Contact.field');
  2372. $expected = array(
  2373. 'div' => array('class' => 'input text error'),
  2374. 'label' => array('for' => 'ContactField'),
  2375. 'Field',
  2376. '/label',
  2377. 'input' => array(
  2378. 'type' => 'text', 'name' => 'Contact[field]',
  2379. 'id' => 'ContactField', 'class' => 'form-error'
  2380. ),
  2381. array('div' => array('class' => 'error-message')),
  2382. 'Badness!',
  2383. '/div',
  2384. '/div'
  2385. );
  2386. $this->assertTags($result, $expected);
  2387. $result = $this->Form->input('Contact.field', array(
  2388. 'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
  2389. ));
  2390. $expected = array(
  2391. 'label' => array('for' => 'ContactField'),
  2392. 'Field',
  2393. '/label',
  2394. 'input' => array(
  2395. 'type' => 'text', 'name' => 'Contact[field]',
  2396. 'id' => 'ContactField', 'class' => 'form-error'
  2397. ),
  2398. array('span' => array('class' => 'error-message')),
  2399. 'Badness!',
  2400. '/span'
  2401. );
  2402. $this->assertTags($result, $expected);
  2403. $result = $this->Form->input('Contact.field', array(
  2404. 'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
  2405. ));
  2406. $expected = array(
  2407. 'div' => array('class' => 'input text error'),
  2408. 'label' => array('for' => 'ContactField'),
  2409. 'Field',
  2410. '/label',
  2411. 'input' => array(
  2412. 'type' => 'text', 'name' => 'Contact[field]',
  2413. 'id' => 'ContactField', 'class' => 'form-error'
  2414. ),
  2415. array('div' => array('class' => 'error')),
  2416. 'Badness!',
  2417. '/div'
  2418. );
  2419. $this->assertTags($result, $expected);
  2420. $result = $this->Form->input('Contact.field', array(
  2421. 'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
  2422. ));
  2423. $expected = array(
  2424. 'span' => array('class' => 'input text error'),
  2425. 'label' => array('for' => 'ContactField'),
  2426. 'Field',
  2427. '/label',
  2428. 'input' => array(
  2429. 'type' => 'text', 'name' => 'Contact[field]',
  2430. 'id' => 'ContactField', 'class' => 'form-error'
  2431. ),
  2432. 'Badness!',
  2433. '/span'
  2434. );
  2435. $this->assertTags($result, $expected);
  2436. $result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
  2437. $expected = array(
  2438. 'div' => array('class' => 'input text error'),
  2439. 'label' => array('for' => 'ContactField'),
  2440. 'Field',
  2441. '/label',
  2442. 'input' => array(
  2443. 'type' => 'text', 'name' => 'Contact[field]',
  2444. 'id' => 'ContactField', 'class' => 'form-error'
  2445. ),
  2446. 'A message to you, Rudy',
  2447. array('div' => array('class' => 'error-message')),
  2448. 'Badness!',
  2449. '/div',
  2450. '/div'
  2451. );
  2452. $this->assertTags($result, $expected);
  2453. $this->Form->setEntity(null);
  2454. $this->Form->setEntity('Contact.field');
  2455. $result = $this->Form->input('Contact.field', array(
  2456. 'after' => 'A message to you, Rudy', 'error' => false
  2457. ));
  2458. $expected = array(
  2459. 'div' => array('class' => 'input text'),
  2460. 'label' => array('for' => 'ContactField'),
  2461. 'Field',
  2462. '/label',
  2463. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2464. 'A message to you, Rudy',
  2465. '/div'
  2466. );
  2467. $this->assertTags($result, $expected);
  2468. $result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
  2469. $expected = array(
  2470. 'div' => array('class' => 'input text'),
  2471. 'label' => array('for' => 'ObjectField'),
  2472. 'Field',
  2473. '/label',
  2474. 'input' => array('type' => 'text', 'name' => 'Object[field]', 'id' => 'ObjectField'),
  2475. 'A message to you, Rudy',
  2476. '/div'
  2477. );
  2478. $this->assertTags($result, $expected);
  2479. $Contact->validationErrors['field'] = array('minLength');
  2480. $result = $this->Form->input('Contact.field', array(
  2481. 'error' => array(
  2482. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2483. 'maxLength' => 'login too large'
  2484. )
  2485. ));
  2486. $expected = array(
  2487. 'div' => array('class' => 'input text error'),
  2488. 'label' => array('for' => 'ContactField'),
  2489. 'Field',
  2490. '/label',
  2491. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2492. array('div' => array('class' => 'error-message')),
  2493. 'Le login doit contenir au moins 2 caractères',
  2494. '/div',
  2495. '/div'
  2496. );
  2497. $this->assertTags($result, $expected);
  2498. $Contact->validationErrors['field'] = array('maxLength');
  2499. $result = $this->Form->input('Contact.field', array(
  2500. 'error' => array(
  2501. 'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
  2502. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2503. 'maxLength' => 'login too large',
  2504. )
  2505. ));
  2506. $expected = array(
  2507. 'div' => array('class' => 'input text error'),
  2508. 'label' => array('for' => 'ContactField'),
  2509. 'Field',
  2510. '/label',
  2511. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2512. array('span' => array('class' => 'error-message', 'rel' => 'fake')),
  2513. 'login too large',
  2514. '/span',
  2515. '/div'
  2516. );
  2517. $this->assertTags($result, $expected);
  2518. }
  2519. /**
  2520. * Test that inputs with 0 can be created.
  2521. *
  2522. * @return void
  2523. */
  2524. public function testInputZero() {
  2525. $this->markTestIncomplete('Need to revisit once models work again.');
  2526. $this->Form->create('User');
  2527. $result = $this->Form->input('0');
  2528. $expected = array(
  2529. 'div' => array('class' => 'input text'),
  2530. 'label' => array('for' => 'User0'), '/label',
  2531. 'input' => array('type' => 'text', 'name' => 'User[0]', 'id' => 'User0'),
  2532. '/div'
  2533. );
  2534. $this->assertTags($result, $expected);
  2535. }
  2536. /**
  2537. * test input() with checkbox creation
  2538. *
  2539. * @return void
  2540. */
  2541. public function testInputCheckbox() {
  2542. $this->markTestIncomplete('Need to revisit once models work again.');
  2543. $result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
  2544. $expected = array(
  2545. 'div' => array('class' => 'input checkbox'),
  2546. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2547. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2548. '/div'
  2549. );
  2550. $this->assertTags($result, $expected);
  2551. $result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
  2552. $expected = array(
  2553. 'div' => array('class' => 'input checkbox'),
  2554. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2555. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2556. '/div'
  2557. );
  2558. $this->assertTags($result, $expected);
  2559. $result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
  2560. $expected = array(
  2561. 'div' => array('class' => 'input checkbox'),
  2562. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2563. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2564. '/div'
  2565. );
  2566. $this->assertTags($result, $expected);
  2567. $result = $this->Form->input('User.disabled', array(
  2568. 'label' => 'Disabled',
  2569. 'type' => 'checkbox',
  2570. 'data-foo' => 'disabled'
  2571. ));
  2572. $expected = array(
  2573. 'div' => array('class' => 'input checkbox'),
  2574. 'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
  2575. array('input' => array(
  2576. 'type' => 'checkbox',
  2577. 'name' => 'data[User][disabled]',
  2578. 'value' => '1',
  2579. 'id' => 'UserDisabled',
  2580. 'data-foo' => 'disabled'
  2581. )),
  2582. 'label' => array('for' => 'UserDisabled'),
  2583. 'Disabled',
  2584. '/label',
  2585. '/div'
  2586. );
  2587. $this->assertTags($result, $expected);
  2588. }
  2589. /**
  2590. * test form->input() with time types.
  2591. *
  2592. */
  2593. public function testInputTime() {
  2594. $this->markTestIncomplete('Need to revisit once models work again.');
  2595. extract($this->dateRegex);
  2596. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2597. $result = explode(':', $result);
  2598. $this->assertRegExp('/option value="23"/', $result[0]);
  2599. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2600. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2601. $result = explode(':', $result);
  2602. $this->assertRegExp('/option value="23"/', $result[0]);
  2603. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2604. $result = $this->Form->input('Model.field', array(
  2605. 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
  2606. ));
  2607. $result = explode(':', $result);
  2608. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2609. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2610. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2611. $result = $this->Form->input('Model.field', array(
  2612. 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
  2613. ));
  2614. $result = explode(':', $result);
  2615. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2616. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2617. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2618. $result = $this->Form->input('prueba', array(
  2619. 'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2620. 'maxYear' => date('Y') + 1, 'interval' => 15
  2621. ));
  2622. $result = explode(':', $result);
  2623. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2624. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2625. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2626. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2627. $result = $this->Form->input('Random.start_time', array(
  2628. 'type' => 'time',
  2629. 'selected' => '18:15'
  2630. ));
  2631. $this->assertContains('<option value="06" selected="selected">6</option>', $result);
  2632. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2633. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2634. $result = $this->Form->input('published', array('type' => 'time'));
  2635. $now = strtotime('now');
  2636. $this->assertContains('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
  2637. $now = strtotime('2013-03-09 00:42:21');
  2638. $result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
  2639. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2640. $this->assertContains('<option value="42" selected="selected">42</option>', $result);
  2641. }
  2642. /**
  2643. * Test interval + selected near the hour roll over.
  2644. *
  2645. * @return void
  2646. */
  2647. public function testTimeSelectedWithInterval() {
  2648. $this->markTestIncomplete('Need to revisit once models work again.');
  2649. $result = $this->Form->input('Model.start_time', array(
  2650. 'type' => 'time',
  2651. 'interval' => 15,
  2652. 'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
  2653. ));
  2654. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2655. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2656. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2657. $result = $this->Form->input('Model.start_time', array(
  2658. 'type' => 'time',
  2659. 'interval' => 15,
  2660. 'selected' => '2012-10-23 15:57:00'
  2661. ));
  2662. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2663. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2664. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2665. $result = $this->Form->input('Model.start_time', array(
  2666. 'timeFormat' => 24,
  2667. 'type' => 'time',
  2668. 'interval' => 15,
  2669. 'selected' => '15:57'
  2670. ));
  2671. $this->assertContains('<option value="16" selected="selected">16</option>', $result);
  2672. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2673. $result = $this->Form->input('Model.start_time', array(
  2674. 'timeFormat' => 24,
  2675. 'type' => 'time',
  2676. 'interval' => 15,
  2677. 'selected' => '23:57'
  2678. ));
  2679. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2680. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2681. $result = $this->Form->input('Model.created', array(
  2682. 'timeFormat' => 24,
  2683. 'type' => 'datetime',
  2684. 'interval' => 15,
  2685. 'selected' => '2012-09-30 23:56'
  2686. ));
  2687. $this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
  2688. $this->assertContains('<option value="10" selected="selected">October</option>', $result);
  2689. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2690. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2691. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2692. }
  2693. /**
  2694. * Test time with selected values around 12:xx:xx
  2695. *
  2696. * @return void
  2697. */
  2698. public function testTimeSelectedWithIntervalTwelve() {
  2699. $this->markTestIncomplete('Need to revisit once models work again.');
  2700. $result = $this->Form->input('Model.start_time', array(
  2701. 'type' => 'time',
  2702. 'timeFormat' => 12,
  2703. 'interval' => 15,
  2704. 'selected' => '00:00:00'
  2705. ));
  2706. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2707. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2708. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2709. $result = $this->Form->input('Model.start_time', array(
  2710. 'type' => 'time',
  2711. 'timeFormat' => 12,
  2712. 'interval' => 15,
  2713. 'selected' => '12:00:00'
  2714. ));
  2715. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2716. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2717. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2718. $result = $this->Form->input('Model.start_time', array(
  2719. 'type' => 'time',
  2720. 'timeFormat' => 12,
  2721. 'interval' => 15,
  2722. 'selected' => '12:15:00'
  2723. ));
  2724. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2725. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2726. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2727. }
  2728. /**
  2729. * Test interval & timeFormat = 12
  2730. *
  2731. * @return void
  2732. */
  2733. public function testInputTimeWithIntervalAnd12HourFormat() {
  2734. $this->markTestIncomplete('Need to revisit once models work again.');
  2735. $result = $this->Form->input('Model.start_time', array(
  2736. 'type' => 'time',
  2737. 'timeFormat' => 12,
  2738. 'interval' => 5,
  2739. 'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
  2740. ));
  2741. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2742. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2743. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2744. $result = $this->Form->input('Model.start_time', array(
  2745. 'type' => 'time',
  2746. 'timeFormat' => '12',
  2747. 'interval' => 5,
  2748. 'selected' => '2013-04-19 16:30:00'
  2749. ));
  2750. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2751. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2752. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2753. $result = $this->Form->input('Model.start_time', array(
  2754. 'type' => 'time',
  2755. 'timeFormat' => '12',
  2756. 'interval' => 10,
  2757. 'selected' => '2013-05-19 00:33:00'
  2758. ));
  2759. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2760. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2761. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2762. $result = $this->Form->input('Model.start_time', array(
  2763. 'type' => 'time',
  2764. 'timeFormat' => '12',
  2765. 'interval' => 10,
  2766. 'selected' => '2013-05-19 13:33:00'
  2767. ));
  2768. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2769. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2770. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2771. $result = $this->Form->input('Model.start_time', array(
  2772. 'type' => 'time',
  2773. 'timeFormat' => '12',
  2774. 'interval' => 10,
  2775. 'selected' => '2013-05-19 01:33:00'
  2776. ));
  2777. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2778. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2779. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2780. }
  2781. /**
  2782. * test form->input() with datetime, date and time types
  2783. *
  2784. * @return void
  2785. */
  2786. public function testInputDatetime() {
  2787. $this->markTestIncomplete('Need to revisit once models work again.');
  2788. extract($this->dateRegex);
  2789. $result = $this->Form->input('prueba', array(
  2790. 'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2791. 'maxYear' => date('Y') + 1, 'interval' => 15
  2792. ));
  2793. $result = explode(':', $result);
  2794. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2795. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2796. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2797. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2798. //related to ticket #5013
  2799. $result = $this->Form->input('Contact.date', array(
  2800. 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
  2801. ));
  2802. $this->assertRegExp('/class="customClass"/', $result);
  2803. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2804. $result = $this->Form->input('Contact.date', array(
  2805. 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
  2806. ));
  2807. $this->assertRegExp('/id="customIdDay"/', $result);
  2808. $this->assertRegExp('/id="customIdMonth"/', $result);
  2809. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2810. $result = $this->Form->input('Model.field', array(
  2811. 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
  2812. ));
  2813. $this->assertRegExp('/id="customIDDay"/', $result);
  2814. $this->assertRegExp('/id="customIDHour"/', $result);
  2815. $result = explode('</select><select', $result);
  2816. $result = explode(':', $result[1]);
  2817. $this->assertRegExp('/option value="23"/', $result[0]);
  2818. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2819. $result = $this->Form->input('Model.field', array(
  2820. 'type' => 'datetime', 'timeFormat' => 12
  2821. ));
  2822. $result = explode('</select><select', $result);
  2823. $result = explode(':', $result[1]);
  2824. $this->assertRegExp('/option value="12"/', $result[0]);
  2825. $this->assertNotRegExp('/option value="13"/', $result[0]);
  2826. $this->Form->request->data = array('Contact' => array('created' => null));
  2827. $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
  2828. $expected = array(
  2829. 'div' => array('class' => 'input date'),
  2830. 'label' => array('for' => 'ContactCreatedMonth'),
  2831. 'Created',
  2832. '/label',
  2833. array('select' => array('name' => 'Contact[created][month]', 'id' => 'ContactCreatedMonth')),
  2834. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2835. $monthsRegex,
  2836. '/select', '-',
  2837. array('select' => array('name' => 'Contact[created][day]', 'id' => 'ContactCreatedDay')),
  2838. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2839. $daysRegex,
  2840. '/select', '-',
  2841. array('select' => array('name' => 'Contact[created][year]', 'id' => 'ContactCreatedYear')),
  2842. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2843. $yearsRegex,
  2844. '/select',
  2845. '/div'
  2846. );
  2847. $this->assertTags($result, $expected);
  2848. $this->Form->request->data = array('Contact' => array('created' => null));
  2849. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
  2850. $this->assertRegExp('/for\="ContactCreatedHour"/', $result);
  2851. $this->Form->request->data = array('Contact' => array('created' => null));
  2852. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
  2853. $this->assertRegExp('/for\="ContactCreatedMonth"/', $result);
  2854. $result = $this->Form->input('Contact.created', array(
  2855. 'type' => 'date',
  2856. 'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
  2857. 'timeFormat' => 'NONE'
  2858. ));
  2859. $this->assertRegExp('/for\="created-month"/', $result);
  2860. }
  2861. /**
  2862. * Test generating checkboxes with disabled elements.
  2863. *
  2864. * @return void
  2865. */
  2866. public function testInputCheckboxWithDisabledElements() {
  2867. $this->markTestIncomplete('Need to revisit once models work again.');
  2868. $options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
  2869. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
  2870. $expected = array(
  2871. array('div' => array('class' => 'input select')),
  2872. array('label' => array('for' => "ContactMultiple")),
  2873. 'Multiple',
  2874. '/label',
  2875. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2876. array('div' => array('class' => 'checkbox')),
  2877. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
  2878. array('label' => array('for' => "ContactMultiple1")),
  2879. 'One',
  2880. '/label',
  2881. '/div',
  2882. array('div' => array('class' => 'checkbox')),
  2883. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2884. array('label' => array('for' => "ContactMultiple2")),
  2885. 'Two',
  2886. '/label',
  2887. '/div',
  2888. array('div' => array('class' => 'checkbox')),
  2889. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2890. array('label' => array('for' => "ContactMultiple3")),
  2891. 'Three',
  2892. '/label',
  2893. '/div',
  2894. '/div'
  2895. );
  2896. $this->assertTags($result, $expected);
  2897. $result = $this->Form->radio('Model.field', array('1/2' => 'half'));
  2898. $expected = array(
  2899. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '', 'id' => 'ModelField_'),
  2900. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1/2', 'id' => 'ModelField12')),
  2901. 'label' => array('for' => 'ModelField12'),
  2902. 'half',
  2903. '/label'
  2904. );
  2905. $this->assertTags($result, $expected);
  2906. $disabled = array('2', 3);
  2907. $expected = array(
  2908. array('div' => array('class' => 'input select')),
  2909. array('label' => array('for' => "ContactMultiple")),
  2910. 'Multiple',
  2911. '/label',
  2912. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2913. array('div' => array('class' => 'checkbox')),
  2914. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
  2915. array('label' => array('for' => "ContactMultiple1")),
  2916. 'One',
  2917. '/label',
  2918. '/div',
  2919. array('div' => array('class' => 'checkbox')),
  2920. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2921. array('label' => array('for' => "ContactMultiple2")),
  2922. 'Two',
  2923. '/label',
  2924. '/div',
  2925. array('div' => array('class' => 'checkbox')),
  2926. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2927. array('label' => array('for' => "ContactMultiple3")),
  2928. 'Three',
  2929. '/label',
  2930. '/div',
  2931. '/div'
  2932. );
  2933. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2934. $this->assertTags($result, $expected);
  2935. // make sure 50 does only disable 50, and not 50f5c0cf
  2936. $options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
  2937. $disabled = array(50);
  2938. $expected = array(
  2939. array('div' => array('class' => 'input select')),
  2940. array('label' => array('for' => "ContactMultiple")),
  2941. 'Multiple',
  2942. '/label',
  2943. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2944. array('div' => array('class' => 'checkbox')),
  2945. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
  2946. array('label' => array('for' => "ContactMultiple50")),
  2947. 'Fifty',
  2948. '/label',
  2949. '/div',
  2950. array('div' => array('class' => 'checkbox')),
  2951. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
  2952. array('label' => array('for' => "ContactMultiple50f5c0cf")),
  2953. 'Stringy',
  2954. '/label',
  2955. '/div',
  2956. '/div'
  2957. );
  2958. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2959. $this->assertTags($result, $expected);
  2960. }
  2961. /**
  2962. * test input name with leading integer, ensure attributes are generated correctly.
  2963. *
  2964. * @return void
  2965. */
  2966. public function testInputWithLeadingInteger() {
  2967. $result = $this->Form->text('0.Node.title');
  2968. $expected = array(
  2969. 'input' => array('name' => '0[Node][title]', 'type' => 'text')
  2970. );
  2971. $this->assertTags($result, $expected);
  2972. }
  2973. /**
  2974. * test form->input() with select type inputs.
  2975. *
  2976. * @return void
  2977. */
  2978. public function testInputSelectType() {
  2979. $this->markTestIncomplete('Need to revisit once models work again.');
  2980. $result = $this->Form->input('email', array(
  2981. 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
  2982. );
  2983. $expected = array(
  2984. 'div' => array('class' => 'input select'),
  2985. 'label' => array('for' => 'email'),
  2986. 'Email',
  2987. '/label',
  2988. array('select' => array('name' => 'email', 'id' => 'email')),
  2989. array('option' => array('value' => '')),
  2990. '/option',
  2991. array('option' => array('value' => 'è')),
  2992. 'Firést',
  2993. '/option',
  2994. array('option' => array('value' => 'é')),
  2995. 'Secoènd',
  2996. '/option',
  2997. '/select',
  2998. '/div'
  2999. );
  3000. $this->assertTags($result, $expected);
  3001. $result = $this->Form->input('email', array(
  3002. 'options' => array('First', 'Second'), 'empty' => true)
  3003. );
  3004. $expected = array(
  3005. 'div' => array('class' => 'input select'),
  3006. 'label' => array('for' => 'email'),
  3007. 'Email',
  3008. '/label',
  3009. array('select' => array('name' => 'email', 'id' => 'email')),
  3010. array('option' => array('value' => '')),
  3011. '/option',
  3012. array('option' => array('value' => '0')),
  3013. 'First',
  3014. '/option',
  3015. array('option' => array('value' => '1')),
  3016. 'Second',
  3017. '/option',
  3018. '/select',
  3019. '/div'
  3020. );
  3021. $this->assertTags($result, $expected);
  3022. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3023. $this->Form->request->data = array('Model' => array('user_id' => 'value'));
  3024. $result = $this->Form->input('Model.user_id', array('empty' => true));
  3025. $expected = array(
  3026. 'div' => array('class' => 'input select'),
  3027. 'label' => array('for' => 'ModelUserId'),
  3028. 'User',
  3029. '/label',
  3030. 'select' => array('name' => 'Model[user_id]', 'id' => 'ModelUserId'),
  3031. array('option' => array('value' => '')),
  3032. '/option',
  3033. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3034. 'good',
  3035. '/option',
  3036. array('option' => array('value' => 'other')),
  3037. 'bad',
  3038. '/option',
  3039. '/select',
  3040. '/div'
  3041. );
  3042. $this->assertTags($result, $expected);
  3043. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3044. $this->Form->request->data = array('Thing' => array('user_id' => null));
  3045. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3046. $expected = array(
  3047. 'div' => array('class' => 'input select'),
  3048. 'label' => array('for' => 'ThingUserId'),
  3049. 'User',
  3050. '/label',
  3051. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3052. array('option' => array('value' => '')),
  3053. 'Some Empty',
  3054. '/option',
  3055. array('option' => array('value' => 'value')),
  3056. 'good',
  3057. '/option',
  3058. array('option' => array('value' => 'other')),
  3059. 'bad',
  3060. '/option',
  3061. '/select',
  3062. '/div'
  3063. );
  3064. $this->assertTags($result, $expected);
  3065. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3066. $this->Form->request->data = array('Thing' => array('user_id' => 'value'));
  3067. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3068. $expected = array(
  3069. 'div' => array('class' => 'input select'),
  3070. 'label' => array('for' => 'ThingUserId'),
  3071. 'User',
  3072. '/label',
  3073. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3074. array('option' => array('value' => '')),
  3075. 'Some Empty',
  3076. '/option',
  3077. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3078. 'good',
  3079. '/option',
  3080. array('option' => array('value' => 'other')),
  3081. 'bad',
  3082. '/option',
  3083. '/select',
  3084. '/div'
  3085. );
  3086. $this->assertTags($result, $expected);
  3087. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3088. $this->Form->request->data = array('User' => array('User' => array('value')));
  3089. $result = $this->Form->input('User.User', array('empty' => true));
  3090. $expected = array(
  3091. 'div' => array('class' => 'input select'),
  3092. 'label' => array('for' => 'UserUser'),
  3093. 'User',
  3094. '/label',
  3095. 'input' => array('type' => 'hidden', 'name' => 'User[User]', 'value' => '', 'id' => 'UserUser_'),
  3096. 'select' => array('name' => 'User[User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
  3097. array('option' => array('value' => '')),
  3098. '/option',
  3099. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3100. 'good',
  3101. '/option',
  3102. array('option' => array('value' => 'other')),
  3103. 'bad',
  3104. '/option',
  3105. '/select',
  3106. '/div'
  3107. );
  3108. $this->assertTags($result, $expected);
  3109. $this->Form->data = array();
  3110. $result = $this->Form->input('Publisher.id', array(
  3111. 'label' => 'Publisher',
  3112. 'type' => 'select',
  3113. 'multiple' => 'checkbox',
  3114. 'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
  3115. ));
  3116. $expected = array(
  3117. array('div' => array('class' => 'input select')),
  3118. array('label' => array('for' => 'PublisherId')),
  3119. 'Publisher',
  3120. '/label',
  3121. 'input' => array('type' => 'hidden', 'name' => 'Publisher[id]', 'value' => '', 'id' => 'PublisherId'),
  3122. array('div' => array('class' => 'checkbox')),
  3123. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
  3124. array('label' => array('for' => 'PublisherIdValue1')),
  3125. 'Label 1',
  3126. '/label',
  3127. '/div',
  3128. array('div' => array('class' => 'checkbox')),
  3129. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
  3130. array('label' => array('for' => 'PublisherIdValue2')),
  3131. 'Label 2',
  3132. '/label',
  3133. '/div',
  3134. '/div'
  3135. );
  3136. $this->assertTags($result, $expected);
  3137. }
  3138. /**
  3139. * test that input() and a non standard primary key makes a hidden input by default.
  3140. *
  3141. * @return void
  3142. */
  3143. public function testInputWithNonStandardPrimaryKeyMakesHidden() {
  3144. $this->markTestIncomplete('Need to revisit once models work again.');
  3145. $this->Form->create('User');
  3146. $this->Form->fieldset = array(
  3147. 'User' => array(
  3148. 'fields' => array(
  3149. 'model_id' => array('type' => 'integer')
  3150. ),
  3151. 'validates' => array(),
  3152. 'key' => 'model_id'
  3153. )
  3154. );
  3155. $result = $this->Form->input('model_id');
  3156. $expected = array(
  3157. 'input' => array('type' => 'hidden', 'name' => 'User[model_id]', 'id' => 'UserModelId'),
  3158. );
  3159. $this->assertTags($result, $expected);
  3160. }
  3161. /**
  3162. * test that overriding the magic select type widget is possible
  3163. *
  3164. * @return void
  3165. */
  3166. public function testInputOverridingMagicSelectType() {
  3167. $this->markTestIncomplete('Need to revisit once models work again.');
  3168. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3169. $result = $this->Form->input('Model.user_id', array('type' => 'text'));
  3170. $expected = array(
  3171. 'div' => array('class' => 'input text'),
  3172. 'label' => array('for' => 'ModelUserId'), 'User', '/label',
  3173. 'input' => array('name' => 'Model[user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
  3174. '/div'
  3175. );
  3176. $this->assertTags($result, $expected);
  3177. //Check that magic types still work for plural/singular vars
  3178. $this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
  3179. $result = $this->Form->input('Model.type');
  3180. $expected = array(
  3181. 'div' => array('class' => 'input select'),
  3182. 'label' => array('for' => 'ModelType'), 'Type', '/label',
  3183. 'select' => array('name' => 'Model[type]', 'id' => 'ModelType'),
  3184. array('option' => array('value' => 'value')), 'good', '/option',
  3185. array('option' => array('value' => 'other')), 'bad', '/option',
  3186. '/select',
  3187. '/div'
  3188. );
  3189. $this->assertTags($result, $expected);
  3190. }
  3191. /**
  3192. * Test that inferred types do not override developer input
  3193. *
  3194. * @return void
  3195. */
  3196. public function testInputMagicTypeDoesNotOverride() {
  3197. $this->markTestIncomplete('Need to revisit once models work again.');
  3198. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3199. $result = $this->Form->input('Model.user', array('type' => 'checkbox'));
  3200. $expected = array(
  3201. 'div' => array('class' => 'input checkbox'),
  3202. array('input' => array(
  3203. 'type' => 'hidden',
  3204. 'name' => 'data[Model][user]',
  3205. 'id' => 'ModelUser_',
  3206. 'value' => 0,
  3207. )),
  3208. array('input' => array(
  3209. 'name' => 'data[Model][user]',
  3210. 'type' => 'checkbox',
  3211. 'id' => 'ModelUser',
  3212. 'value' => 1
  3213. )),
  3214. 'label' => array('for' => 'ModelUser'), 'User', '/label',
  3215. '/div'
  3216. );
  3217. $this->assertTags($result, $expected);
  3218. }
  3219. /**
  3220. * Test that magic input() selects are created for type=number
  3221. *
  3222. * @return void
  3223. */
  3224. public function testInputMagicSelectForTypeNumber() {
  3225. $this->markTestIncomplete('Need to revisit once models work again.');
  3226. $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
  3227. $this->Form->request->data = array('ValidateUser' => array('balance' => 1));
  3228. $result = $this->Form->input('ValidateUser.balance');
  3229. $expected = array(
  3230. 'div' => array('class' => 'input select'),
  3231. 'label' => array('for' => 'ValidateUserBalance'),
  3232. 'Balance',
  3233. '/label',
  3234. 'select' => array('name' => 'ValidateUser[balance]', 'id' => 'ValidateUserBalance'),
  3235. array('option' => array('value' => '0')),
  3236. 'nothing',
  3237. '/option',
  3238. array('option' => array('value' => '1', 'selected' => 'selected')),
  3239. 'some',
  3240. '/option',
  3241. array('option' => array('value' => '100')),
  3242. 'a lot',
  3243. '/option',
  3244. '/select',
  3245. '/div'
  3246. );
  3247. $this->assertTags($result, $expected);
  3248. }
  3249. /**
  3250. * Test that magic input() selects can easily be converted into radio types without error.
  3251. *
  3252. * @return void
  3253. */
  3254. public function testInputMagicSelectChangeToRadio() {
  3255. $this->markTestIncomplete('Need to revisit once models work again.');
  3256. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3257. $result = $this->Form->input('Model.user_id', array('type' => 'radio'));
  3258. $this->assertRegExp('/input type="radio"/', $result);
  3259. }
  3260. /**
  3261. * fields with the same name as the model should work.
  3262. *
  3263. * @return void
  3264. */
  3265. public function testInputWithMatchingFieldAndModelName() {
  3266. $this->markTestIncomplete('Need to revisit once models work again.');
  3267. $this->Form->create('User');
  3268. $this->Form->fieldset = array(
  3269. 'User' => array(
  3270. 'fields' => array(
  3271. 'User' => array('type' => 'text')
  3272. ),
  3273. 'validates' => array(),
  3274. 'key' => 'id'
  3275. )
  3276. );
  3277. $this->Form->request->data['User']['User'] = 'ABC, Inc.';
  3278. $result = $this->Form->input('User', array('type' => 'text'));
  3279. $expected = array(
  3280. 'div' => array('class' => 'input text'),
  3281. 'label' => array('for' => 'UserUser'), 'User', '/label',
  3282. 'input' => array('name' => 'User[User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
  3283. '/div'
  3284. );
  3285. $this->assertTags($result, $expected);
  3286. }
  3287. /**
  3288. * testFormInputs method
  3289. *
  3290. * test correct results from form::inputs().
  3291. *
  3292. * @return void
  3293. */
  3294. public function testFormInputs() {
  3295. $this->markTestIncomplete('Need to revisit once models work again.');
  3296. $this->Form->create('Cake\Test\TestCase\View\Helper\Contact');
  3297. $result = $this->Form->inputs('The Legend');
  3298. $expected = array(
  3299. '<fieldset',
  3300. '<legend',
  3301. 'The Legend',
  3302. '/legend',
  3303. '*/fieldset',
  3304. );
  3305. $this->assertTags($result, $expected);
  3306. $result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3307. $expected = array(
  3308. 'fieldset' => array('class' => 'classy-stuff'),
  3309. '<legend',
  3310. 'Field of Dreams',
  3311. '/legend',
  3312. '*/fieldset'
  3313. );
  3314. $this->assertTags($result, $expected);
  3315. $result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3316. $this->assertTags($result, $expected);
  3317. $result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
  3318. $this->assertTags($result, $expected);
  3319. $this->Form->create('Contact');
  3320. $this->Form->request['prefix'] = 'admin';
  3321. $this->Form->request['action'] = 'admin_edit';
  3322. $result = $this->Form->inputs();
  3323. $expected = array(
  3324. '<fieldset',
  3325. '<legend',
  3326. 'Edit Contact',
  3327. '/legend',
  3328. '*/fieldset',
  3329. );
  3330. $this->assertTags($result, $expected);
  3331. $this->Form->create('Contact');
  3332. $result = $this->Form->inputs(false);
  3333. $expected = array(
  3334. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3335. array('div' => array('class' => 'input text')),
  3336. '*/div',
  3337. array('div' => array('class' => 'input email')),
  3338. '*/div',
  3339. array('div' => array('class' => 'input tel')),
  3340. '*/div',
  3341. array('div' => array('class' => 'input password')),
  3342. '*/div',
  3343. array('div' => array('class' => 'input date')),
  3344. '*/div',
  3345. array('div' => array('class' => 'input date')),
  3346. '*/div',
  3347. array('div' => array('class' => 'input datetime')),
  3348. '*/div',
  3349. array('div' => array('class' => 'input number')),
  3350. '*/div',
  3351. array('div' => array('class' => 'input select')),
  3352. '*/div',
  3353. );
  3354. $this->assertTags($result, $expected);
  3355. $this->Form->create('Contact');
  3356. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
  3357. $expected = array(
  3358. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3359. array('div' => array('class' => 'input text')),
  3360. '*/div',
  3361. array('div' => array('class' => 'input email')),
  3362. '*/div',
  3363. array('div' => array('class' => 'input tel')),
  3364. '*/div',
  3365. array('div' => array('class' => 'input password')),
  3366. '*/div',
  3367. array('div' => array('class' => 'input date')),
  3368. '*/div',
  3369. array('div' => array('class' => 'input date')),
  3370. '*/div',
  3371. array('div' => array('class' => 'input datetime')),
  3372. '*/div',
  3373. array('div' => array('class' => 'input number')),
  3374. '*/div',
  3375. array('div' => array('class' => 'input select')),
  3376. '*/div',
  3377. );
  3378. $this->assertTags($result, $expected);
  3379. $this->Form->create('Contact');
  3380. $result = $this->Form->inputs(null, null, array('fieldset' => false));
  3381. $this->assertTags($result, $expected);
  3382. $this->Form->create('Contact');
  3383. $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
  3384. $expected = array(
  3385. 'fieldset' => array(),
  3386. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3387. array('div' => array('class' => 'input text')),
  3388. '*/div',
  3389. array('div' => array('class' => 'input email')),
  3390. '*/div',
  3391. array('div' => array('class' => 'input tel')),
  3392. '*/div',
  3393. array('div' => array('class' => 'input password')),
  3394. '*/div',
  3395. array('div' => array('class' => 'input date')),
  3396. '*/div',
  3397. array('div' => array('class' => 'input date')),
  3398. '*/div',
  3399. array('div' => array('class' => 'input datetime')),
  3400. '*/div',
  3401. array('div' => array('class' => 'input number')),
  3402. '*/div',
  3403. array('div' => array('class' => 'input select')),
  3404. '*/div',
  3405. '/fieldset'
  3406. );
  3407. $this->assertTags($result, $expected);
  3408. $this->Form->create('Contact');
  3409. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
  3410. $expected = array(
  3411. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3412. array('div' => array('class' => 'input text')),
  3413. '*/div',
  3414. array('div' => array('class' => 'input email')),
  3415. '*/div',
  3416. array('div' => array('class' => 'input tel')),
  3417. '*/div',
  3418. array('div' => array('class' => 'input password')),
  3419. '*/div',
  3420. array('div' => array('class' => 'input date')),
  3421. '*/div',
  3422. array('div' => array('class' => 'input date')),
  3423. '*/div',
  3424. array('div' => array('class' => 'input datetime')),
  3425. '*/div',
  3426. array('div' => array('class' => 'input number')),
  3427. '*/div',
  3428. array('div' => array('class' => 'input select')),
  3429. '*/div',
  3430. );
  3431. $this->assertTags($result, $expected);
  3432. $this->Form->create('Contact');
  3433. $result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
  3434. $this->assertTags($result, $expected);
  3435. $this->Form->create('Contact');
  3436. $result = $this->Form->inputs('Hello');
  3437. $expected = array(
  3438. 'fieldset' => array(),
  3439. 'legend' => array(),
  3440. 'Hello',
  3441. '/legend',
  3442. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3443. array('div' => array('class' => 'input text')),
  3444. '*/div',
  3445. array('div' => array('class' => 'input email')),
  3446. '*/div',
  3447. array('div' => array('class' => 'input tel')),
  3448. '*/div',
  3449. array('div' => array('class' => 'input password')),
  3450. '*/div',
  3451. array('div' => array('class' => 'input date')),
  3452. '*/div',
  3453. array('div' => array('class' => 'input date')),
  3454. '*/div',
  3455. array('div' => array('class' => 'input datetime')),
  3456. '*/div',
  3457. array('div' => array('class' => 'input number')),
  3458. '*/div',
  3459. array('div' => array('class' => 'input select')),
  3460. '*/div',
  3461. '/fieldset'
  3462. );
  3463. $this->assertTags($result, $expected);
  3464. $this->Form->create('Contact');
  3465. $result = $this->Form->inputs(array('legend' => 'Hello'));
  3466. $expected = array(
  3467. 'fieldset' => array(),
  3468. 'legend' => array(),
  3469. 'Hello',
  3470. '/legend',
  3471. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3472. array('div' => array('class' => 'input text')),
  3473. '*/div',
  3474. array('div' => array('class' => 'input email')),
  3475. '*/div',
  3476. array('div' => array('class' => 'input tel')),
  3477. '*/div',
  3478. array('div' => array('class' => 'input password')),
  3479. '*/div',
  3480. array('div' => array('class' => 'input date')),
  3481. '*/div',
  3482. array('div' => array('class' => 'input date')),
  3483. '*/div',
  3484. array('div' => array('class' => 'input datetime')),
  3485. '*/div',
  3486. array('div' => array('class' => 'input number')),
  3487. '*/div',
  3488. array('div' => array('class' => 'input select')),
  3489. '*/div',
  3490. '/fieldset'
  3491. );
  3492. $this->assertTags($result, $expected);
  3493. $this->Form->create('Contact');
  3494. $result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
  3495. $this->assertTags($result, $expected);
  3496. $this->Form->end();
  3497. $this->Form->create(false);
  3498. $expected = array(
  3499. 'fieldset' => array(),
  3500. array('div' => array('class' => 'input text')),
  3501. 'label' => array('for' => 'foo'),
  3502. 'Foo',
  3503. '/label',
  3504. 'input' => array('type' => 'text', 'name' => 'foo', 'id' => 'foo'),
  3505. '*/div',
  3506. '/fieldset'
  3507. );
  3508. $result = $this->Form->inputs(
  3509. array('foo' => array('type' => 'text')),
  3510. array(),
  3511. array('legend' => false)
  3512. );
  3513. $this->assertTags($result, $expected);
  3514. }
  3515. /**
  3516. * Tests inputs() works with plugin models
  3517. *
  3518. * @return void
  3519. */
  3520. public function testInputsPluginModel() {
  3521. $this->markTestIncomplete('Need to revisit once models work again.');
  3522. $this->loadFixtures('Post');
  3523. Plugin::load('TestPlugin');
  3524. $this->Form->request['models'] = array(
  3525. 'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
  3526. );
  3527. $this->Form->create('TestPlugin.TestPluginPost');
  3528. $result = $this->Form->inputs();
  3529. $this->assertContains('TestPluginPost[id]', $result);
  3530. $this->assertContains('TestPluginPost[author_id]', $result);
  3531. $this->assertContains('TestPluginPost[title]', $result);
  3532. $this->assertEquals('TestPluginPost', $this->Form->model());
  3533. }
  3534. /**
  3535. * testSelectAsCheckbox method
  3536. *
  3537. * test multi-select widget with checkbox formatting.
  3538. *
  3539. * @return void
  3540. */
  3541. public function testSelectAsCheckbox() {
  3542. $this->markTestIncomplete('Need to revisit once models work again.');
  3543. $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
  3544. $expected = array(
  3545. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3546. array('div' => array('class' => 'checkbox')),
  3547. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
  3548. array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
  3549. 'first',
  3550. '/label',
  3551. '/div',
  3552. array('div' => array('class' => 'checkbox')),
  3553. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
  3554. array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
  3555. 'second',
  3556. '/label',
  3557. '/div',
  3558. array('div' => array('class' => 'checkbox')),
  3559. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  3560. array('label' => array('for' => 'ModelMultiField2')),
  3561. 'third',
  3562. '/label',
  3563. '/div',
  3564. );
  3565. $this->assertTags($result, $expected);
  3566. $result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
  3567. $expected = array(
  3568. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3569. array('div' => array('class' => 'checkbox')),
  3570. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField1/22')),
  3571. array('label' => array('for' => 'ModelMultiField1/22')),
  3572. 'half',
  3573. '/label',
  3574. '/div',
  3575. );
  3576. $this->assertTags($result, $expected);
  3577. }
  3578. /**
  3579. * testLabel method
  3580. *
  3581. * test label generation.
  3582. *
  3583. * @return void
  3584. */
  3585. public function testLabel() {
  3586. $result = $this->Form->label('Person.name');
  3587. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3588. $result = $this->Form->label('Person.name');
  3589. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3590. $result = $this->Form->label('Person.first_name');
  3591. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'First Name', '/label'));
  3592. $result = $this->Form->label('Person.first_name', 'Your first name');
  3593. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'Your first name', '/label'));
  3594. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
  3595. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class'), 'Your first name', '/label'));
  3596. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
  3597. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
  3598. $result = $this->Form->label('Person.first_name', '');
  3599. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), '/label'));
  3600. $result = $this->Form->label('Person.2.name', '');
  3601. $this->assertTags($result, array('label' => array('for' => 'person-2-name'), '/label'));
  3602. }
  3603. /**
  3604. * testTextbox method
  3605. *
  3606. * test textbox element generation
  3607. *
  3608. * @return void
  3609. */
  3610. public function testTextbox() {
  3611. $result = $this->Form->text('Model.field');
  3612. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]')));
  3613. $result = $this->Form->text('Model.field', array('type' => 'password'));
  3614. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Model[field]')));
  3615. $result = $this->Form->text('Model.field', array('id' => 'theID'));
  3616. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]', 'id' => 'theID')));
  3617. }
  3618. /**
  3619. * Test that text() hooks up with request data and error fields.
  3620. *
  3621. * @return void
  3622. */
  3623. public function testTextBoxDataAndError() {
  3624. $this->article['errors'] = [
  3625. 'Contact' => ['text' => 'wrong']
  3626. ];
  3627. $this->Form->create($this->article);
  3628. $this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
  3629. $result = $this->Form->text('Model.text');
  3630. $expected = [
  3631. 'input' => [
  3632. 'type' => 'text',
  3633. 'name' => 'Model[text]',
  3634. 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values',
  3635. ]
  3636. ];
  3637. $this->assertTags($result, $expected);
  3638. $this->Form->request->data['Contact']['text'] = 'test';
  3639. $result = $this->Form->text('Contact.text', ['id' => 'theID']);
  3640. $expected = [
  3641. 'input' => [
  3642. 'type' => 'text',
  3643. 'name' => 'Contact[text]',
  3644. 'value' => 'test',
  3645. 'id' => 'theID',
  3646. 'class' => 'form-error'
  3647. ]
  3648. ];
  3649. $this->assertTags($result, $expected);
  3650. }
  3651. /**
  3652. * testDefaultValue method
  3653. *
  3654. * Test default value setting
  3655. *
  3656. * @return void
  3657. */
  3658. public function testTextDefaultValue() {
  3659. $this->Form->request->data['Model']['field'] = 'test';
  3660. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3661. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'test']];
  3662. $this->assertTags($result, $expected);
  3663. unset($this->Form->request->data['Model']['field']);
  3664. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3665. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'default value']];
  3666. $this->assertTags($result, $expected);
  3667. }
  3668. /**
  3669. * testCheckboxDefaultValue method
  3670. *
  3671. * Test default value setting on checkbox() method
  3672. *
  3673. * @return void
  3674. */
  3675. public function testCheckboxDefaultValue() {
  3676. $this->markTestIncomplete('Need to revisit once models work again.');
  3677. $this->Form->request->data['Model']['field'] = false;
  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')));
  3680. unset($this->Form->request->data['Model']['field']);
  3681. $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
  3682. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
  3683. $this->Form->request->data['Model']['field'] = true;
  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', 'checked' => 'checked')));
  3686. unset($this->Form->request->data['Model']['field']);
  3687. $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
  3688. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField')));
  3689. }
  3690. /**
  3691. * testError method
  3692. *
  3693. * Test field error generation
  3694. *
  3695. * @return void
  3696. */
  3697. public function testError() {
  3698. $this->markTestIncomplete('Need to revisit once models work again.');
  3699. $Contact->validationErrors['field'] = array(1);
  3700. $result = $this->Form->error('Contact.field');
  3701. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
  3702. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3703. $this->assertEquals('Error in field Field', $result);
  3704. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3705. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3706. $this->assertEquals('This field contains invalid input', $result);
  3707. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3708. $result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
  3709. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
  3710. $result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
  3711. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
  3712. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
  3713. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3714. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
  3715. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3716. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
  3717. $this->assertEquals('<strong>Badness!</strong>', $result);
  3718. $Contact->validationErrors['field'] = array("email");
  3719. $result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
  3720. $expected = array(
  3721. 'div' => array('class' => 'field-error'),
  3722. 'No good!',
  3723. '/div'
  3724. );
  3725. $this->assertTags($result, $expected);
  3726. $Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
  3727. $result = $this->Form->error('Contact.field', array(
  3728. 'notEmpty' => 'Cannot be empty',
  3729. 'email' => 'No good!'
  3730. ));
  3731. $expected = array(
  3732. 'div' => array('class' => 'error-message'),
  3733. 'ul' => array(),
  3734. '<li', 'Cannot be empty', '/li',
  3735. '<li', 'No good!', '/li',
  3736. '<li', 'Something else', '/li',
  3737. '/ul',
  3738. '/div'
  3739. );
  3740. $this->assertTags($result, $expected);
  3741. // Testing error messages list options
  3742. $Contact->validationErrors['field'] = array('notEmpty', 'email');
  3743. $result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
  3744. $expected = array(
  3745. 'div' => array('class' => 'error-message'),
  3746. 'ol' => array(),
  3747. '<li', 'notEmpty', '/li',
  3748. '<li', 'email', '/li',
  3749. '/ol',
  3750. '/div'
  3751. );
  3752. $this->assertTags($result, $expected);
  3753. $result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
  3754. $expected = array(
  3755. 'div' => array('class' => 'error-message'),
  3756. 'ol' => array(),
  3757. '<li', 'notEmpty', '/li',
  3758. '<li', 'email', '/li',
  3759. '/ol',
  3760. '/div'
  3761. );
  3762. $this->assertTags($result, $expected);
  3763. $result = $this->Form->error('Contact.field', null, array(
  3764. 'listOptions' => array(
  3765. 'class' => 'ul-class',
  3766. 'itemOptions' => array(
  3767. 'class' => 'li-class'
  3768. )
  3769. )
  3770. ));
  3771. $expected = array(
  3772. 'div' => array('class' => 'error-message'),
  3773. 'ul' => array('class' => 'ul-class'),
  3774. array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
  3775. array('li' => array('class' => 'li-class')), 'email', '/li',
  3776. '/ul',
  3777. '/div'
  3778. );
  3779. $this->assertTags($result, $expected);
  3780. }
  3781. /**
  3782. * test error options when using form->input();
  3783. *
  3784. * @return void
  3785. */
  3786. public function testInputErrorEscape() {
  3787. $this->markTestIncomplete('Need to revisit once models work again.');
  3788. $this->Form->create('ValidateProfile');
  3789. $ValidateProfile->validationErrors['city'] = array('required<br>');
  3790. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
  3791. $this->assertRegExp('/required&lt;br&gt;/', $result);
  3792. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
  3793. $this->assertRegExp('/required<br>/', $result);
  3794. }
  3795. /**
  3796. * testPassword method
  3797. *
  3798. * Test password element generation
  3799. *
  3800. * @return void
  3801. */
  3802. public function testPassword() {
  3803. $this->article['errors'] = [
  3804. 'Contact' => [
  3805. 'passwd' => 1
  3806. ]
  3807. ];
  3808. $this->Form->create($this->article);
  3809. $result = $this->Form->password('Contact.field');
  3810. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[field]')));
  3811. $this->Form->request->data['Contact']['passwd'] = 'test';
  3812. $result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
  3813. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
  3814. }
  3815. /**
  3816. * testRadio method
  3817. *
  3818. * Test radio element set generation
  3819. *
  3820. * @return void
  3821. */
  3822. public function testRadio() {
  3823. $result = $this->Form->radio('Model.field', array('option A'));
  3824. $expected = array(
  3825. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3826. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3827. 'label' => array('for' => 'model-field-0'),
  3828. 'option A',
  3829. '/label'
  3830. );
  3831. $this->assertTags($result, $expected);
  3832. $result = $this->Form->radio('Model.field', array('option A', 'option B'));
  3833. $expected = array(
  3834. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3835. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3836. array('label' => array('for' => 'model-field-0')),
  3837. 'option A',
  3838. '/label',
  3839. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1', 'id' => 'model-field-1')),
  3840. array('label' => array('for' => 'model-field-1')),
  3841. 'option B',
  3842. '/label',
  3843. );
  3844. $this->assertTags($result, $expected);
  3845. $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
  3846. $expected = array(
  3847. 'input' => array('type' => 'hidden', 'name' => 'Employee[gender]', 'value' => ''),
  3848. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'male', 'id' => 'employee-gender-male')),
  3849. array('label' => array('for' => 'employee-gender-male')),
  3850. 'Male',
  3851. '/label',
  3852. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'female', 'id' => 'employee-gender-female')),
  3853. array('label' => array('for' => 'employee-gender-female')),
  3854. 'Female',
  3855. '/label',
  3856. );
  3857. $this->assertTags($result, $expected);
  3858. $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'Model[custom]'));
  3859. $expected = array(
  3860. array('input' => array('type' => 'hidden', 'name' => 'Model[custom]', 'value' => '')),
  3861. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '0', 'id' => 'model-custom-0')),
  3862. array('label' => array('for' => 'model-custom-0')),
  3863. 'option A',
  3864. '/label',
  3865. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '1', 'id' => 'model-custom-1')),
  3866. array('label' => array('for' => 'model-custom-1')),
  3867. 'option B',
  3868. '/label',
  3869. );
  3870. $this->assertTags($result, $expected);
  3871. }
  3872. /**
  3873. * test disabling the hidden input for radio buttons
  3874. *
  3875. * @return void
  3876. */
  3877. public function testRadioHiddenInputDisabling() {
  3878. $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
  3879. $expected = array(
  3880. 'input' => array('type' => 'radio', 'name' => 'Model[1][field]', 'value' => '0', 'id' => 'model-1-field-0'),
  3881. 'label' => array('for' => 'model-1-field-0'),
  3882. 'option A',
  3883. '/label'
  3884. );
  3885. $this->assertTags($result, $expected);
  3886. }
  3887. /**
  3888. * testDomIdSuffix method
  3889. *
  3890. * @return void
  3891. */
  3892. public function testDomIdSuffix() {
  3893. $this->markTestIncomplete('Need to revisit once models work again.');
  3894. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs');
  3895. $this->assertEquals('1StringWith1$-dollarSigns', $result);
  3896. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>');
  3897. $this->assertEquals('AbcX=FooY=Bar', $result);
  3898. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs', 'xhtml');
  3899. $this->assertEquals('1StringWith1-dollarSigns', $result);
  3900. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>', 'xhtml');
  3901. $this->assertEquals('AbcXFooYBar', $result);
  3902. }
  3903. /**
  3904. * testDomIdSuffixCollisionResolvement()
  3905. *
  3906. * @return void
  3907. */
  3908. public function testDomIdSuffixCollisionResolvement() {
  3909. $this->markTestIncomplete('Need to revisit once models work again.');
  3910. $result = $this->Form->domIdSuffix('a>b');
  3911. $this->assertEquals('AB', $result);
  3912. $result = $this->Form->domIdSuffix('a<b');
  3913. $this->assertEquals('AB1', $result);
  3914. $result = $this->Form->domIdSuffix('a\'b');
  3915. $this->assertEquals('AB2', $result);
  3916. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3917. $this->assertEquals('1StringWith1-dollar', $result);
  3918. $result = $this->Form->domIdSuffix('1 string with 1€-dollar', 'xhtml');
  3919. $this->assertEquals('1StringWith1-dollar1', $result);
  3920. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3921. $this->assertEquals('1StringWith1-dollar2', $result);
  3922. }
  3923. /**
  3924. * testSelect method
  3925. *
  3926. * Test select element generation.
  3927. *
  3928. * @return void
  3929. */
  3930. public function testSelect() {
  3931. $result = $this->Form->select('Model.field', array());
  3932. $expected = array(
  3933. 'select' => array('name' => 'Model[field]'),
  3934. array('option' => array('value' => '')),
  3935. '/option',
  3936. '/select'
  3937. );
  3938. $this->assertTags($result, $expected);
  3939. $this->Form->request->data = array('Model' => array('field' => 'value'));
  3940. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3941. $expected = array(
  3942. 'select' => array('name' => 'Model[field]'),
  3943. array('option' => array('value' => '')),
  3944. '/option',
  3945. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3946. 'good',
  3947. '/option',
  3948. array('option' => array('value' => 'other')),
  3949. 'bad',
  3950. '/option',
  3951. '/select'
  3952. );
  3953. $this->assertTags($result, $expected);
  3954. $this->Form->request->data = array();
  3955. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3956. $expected = array(
  3957. 'select' => array('name' => 'Model[field]'),
  3958. array('option' => array('value' => '')),
  3959. '/option',
  3960. array('option' => array('value' => 'value')),
  3961. 'good',
  3962. '/option',
  3963. array('option' => array('value' => 'other')),
  3964. 'bad',
  3965. '/option',
  3966. '/select'
  3967. );
  3968. $this->assertTags($result, $expected);
  3969. $result = $this->Form->select(
  3970. 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
  3971. array('empty' => false)
  3972. );
  3973. $expected = array(
  3974. 'select' => array('name' => 'Model[field]'),
  3975. array('option' => array('value' => 'first')),
  3976. 'first &quot;html&quot; &lt;chars&gt;',
  3977. '/option',
  3978. array('option' => array('value' => 'second')),
  3979. 'value',
  3980. '/option',
  3981. '/select'
  3982. );
  3983. $this->assertTags($result, $expected);
  3984. $result = $this->Form->select(
  3985. 'Model.field',
  3986. array('first' => 'first "html" <chars>', 'second' => 'value'),
  3987. array('escape' => false, 'empty' => false)
  3988. );
  3989. $expected = array(
  3990. 'select' => array('name' => 'Model[field]'),
  3991. array('option' => array('value' => 'first')),
  3992. 'first "html" <chars>',
  3993. '/option',
  3994. array('option' => array('value' => 'second')),
  3995. 'value',
  3996. '/option',
  3997. '/select'
  3998. );
  3999. $this->assertTags($result, $expected);
  4000. $options = array(
  4001. array('value' => 'first', 'text' => 'First'),
  4002. array('value' => 'first', 'text' => 'Another First'),
  4003. );
  4004. $result = $this->Form->select(
  4005. 'Model.field',
  4006. $options,
  4007. array('escape' => false, 'empty' => false)
  4008. );
  4009. $expected = array(
  4010. 'select' => array('name' => 'Model[field]'),
  4011. array('option' => array('value' => 'first')),
  4012. 'First',
  4013. '/option',
  4014. array('option' => array('value' => 'first')),
  4015. 'Another First',
  4016. '/option',
  4017. '/select'
  4018. );
  4019. $this->assertTags($result, $expected);
  4020. $this->Form->request->data = array('Model' => array('contact_id' => 228));
  4021. $result = $this->Form->select(
  4022. 'Model.contact_id',
  4023. array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
  4024. array('escape' => false, 'empty' => 'pick something')
  4025. );
  4026. $expected = array(
  4027. 'select' => array('name' => 'Model[contact_id]'),
  4028. array('option' => array('value' => '')), 'pick something', '/option',
  4029. array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
  4030. array('option' => array('value' => '228-1')), '228-1 value', '/option',
  4031. array('option' => array('value' => '228-2')), '228-2 value', '/option',
  4032. '/select'
  4033. );
  4034. $this->assertTags($result, $expected);
  4035. $this->Form->request->data['Model']['field'] = 0;
  4036. $result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
  4037. $expected = array(
  4038. 'select' => array('name' => 'Model[field]'),
  4039. array('option' => array('value' => '')), '/option',
  4040. array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
  4041. array('option' => array('value' => '1')), 'Yes', '/option',
  4042. '/select'
  4043. );
  4044. $this->assertTags($result, $expected);
  4045. }
  4046. /**
  4047. * test select() with required and disabled attributes.
  4048. *
  4049. * @return void
  4050. */
  4051. public function testSelectRequired() {
  4052. $this->article['required'] = [
  4053. 'user_id' => true
  4054. ];
  4055. $this->Form->create($this->article);
  4056. $result = $this->Form->select('user_id', array('option A'));
  4057. $expected = array(
  4058. 'select' => array(
  4059. 'name' => 'user_id',
  4060. 'required' => 'required'
  4061. ),
  4062. array('option' => array('value' => '')), '/option',
  4063. array('option' => array('value' => '0')), 'option A', '/option',
  4064. '/select'
  4065. );
  4066. $this->assertTags($result, $expected);
  4067. $result = $this->Form->select('user_id', array('option A'), array('disabled' => true));
  4068. $expected = array(
  4069. 'select' => array(
  4070. 'name' => 'user_id',
  4071. 'disabled' => 'disabled'
  4072. ),
  4073. array('option' => array('value' => '')), '/option',
  4074. array('option' => array('value' => '0')), 'option A', '/option',
  4075. '/select'
  4076. );
  4077. $this->assertTags($result, $expected);
  4078. }
  4079. /**
  4080. * testNestedSelect method
  4081. *
  4082. * test select element generation with optgroups
  4083. *
  4084. * @return void
  4085. */
  4086. public function testNestedSelect() {
  4087. $result = $this->Form->select(
  4088. 'Model.field',
  4089. array(1 => 'One', 2 => 'Two', 'Three' => array(
  4090. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  4091. )), array('empty' => false)
  4092. );
  4093. $expected = array(
  4094. 'select' => array('name' => 'Model[field]'),
  4095. array('option' => array('value' => 1)),
  4096. 'One',
  4097. '/option',
  4098. array('option' => array('value' => 2)),
  4099. 'Two',
  4100. '/option',
  4101. array('optgroup' => array('label' => 'Three')),
  4102. array('option' => array('value' => 3)),
  4103. 'Three',
  4104. '/option',
  4105. array('option' => array('value' => 4)),
  4106. 'Four',
  4107. '/option',
  4108. array('option' => array('value' => 5)),
  4109. 'Five',
  4110. '/option',
  4111. '/optgroup',
  4112. '/select'
  4113. );
  4114. $this->assertTags($result, $expected);
  4115. }
  4116. /**
  4117. * testSelectMultiple method
  4118. *
  4119. * test generation of multiple select elements
  4120. *
  4121. * @return void
  4122. */
  4123. public function testSelectMultiple() {
  4124. $options = array('first', 'second', 'third');
  4125. $result = $this->Form->select(
  4126. 'Model.multi_field',
  4127. $options,
  4128. array('multiple' => true)
  4129. );
  4130. $expected = array(
  4131. 'input' => array(
  4132. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => ''
  4133. ),
  4134. 'select' => array(
  4135. 'name' => 'Model[multi_field][]',
  4136. 'multiple' => 'multiple'
  4137. ),
  4138. array('option' => array('value' => '0')),
  4139. 'first',
  4140. '/option',
  4141. array('option' => array('value' => '1')),
  4142. 'second',
  4143. '/option',
  4144. array('option' => array('value' => '2')),
  4145. 'third',
  4146. '/option',
  4147. '/select'
  4148. );
  4149. $this->assertTags($result, $expected);
  4150. $result = $this->Form->select(
  4151. 'Model.multi_field',
  4152. $options,
  4153. array('multiple' => 'multiple')
  4154. );
  4155. $this->assertTags($result, $expected);
  4156. }
  4157. /**
  4158. * Test that a checkbox can have 0 for the value and 1 for the hidden input.
  4159. *
  4160. * @return void
  4161. */
  4162. public function testCheckboxZeroValue() {
  4163. $this->markTestIncomplete('Need to revisit once models work again.');
  4164. $result = $this->Form->input('User.get_spam', array(
  4165. 'type' => 'checkbox',
  4166. 'value' => '0',
  4167. 'hiddenField' => '1',
  4168. ));
  4169. $expected = array(
  4170. 'div' => array('class' => 'input checkbox'),
  4171. array('input' => array(
  4172. 'type' => 'hidden', 'name' => 'data[User][get_spam]',
  4173. 'value' => '1', 'id' => 'UserGetSpam_'
  4174. )),
  4175. array('input' => array(
  4176. 'type' => 'checkbox', 'name' => 'data[User][get_spam]',
  4177. 'value' => '0', 'id' => 'UserGetSpam'
  4178. )),
  4179. 'label' => array('for' => 'UserGetSpam'),
  4180. 'Get Spam',
  4181. '/label',
  4182. '/div'
  4183. );
  4184. $this->assertTags($result, $expected);
  4185. }
  4186. /**
  4187. * test generation of habtm select boxes.
  4188. *
  4189. * @return void
  4190. */
  4191. public function testHabtmSelectBox() {
  4192. $this->markTestIncomplete('Need to revisit once models work again.');
  4193. $this->View->viewVars['contactTags'] = array(
  4194. 1 => 'blue',
  4195. 2 => 'red',
  4196. 3 => 'green'
  4197. );
  4198. $this->Form->request->data = array(
  4199. 'Contact' => array(),
  4200. 'ContactTag' => array(
  4201. array(
  4202. 'id' => '1',
  4203. 'name' => 'blue'
  4204. ),
  4205. array(
  4206. 'id' => 3,
  4207. 'name' => 'green'
  4208. )
  4209. )
  4210. );
  4211. $this->Form->create('Contact');
  4212. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4213. $expected = array(
  4214. 'input' => array(
  4215. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4216. ),
  4217. 'select' => array(
  4218. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4219. 'multiple' => 'multiple'
  4220. ),
  4221. array('option' => array('value' => '1', 'selected' => 'selected')),
  4222. 'blue',
  4223. '/option',
  4224. array('option' => array('value' => '2')),
  4225. 'red',
  4226. '/option',
  4227. array('option' => array('value' => '3', 'selected' => 'selected')),
  4228. 'green',
  4229. '/option',
  4230. '/select'
  4231. );
  4232. $this->assertTags($result, $expected);
  4233. // make sure only 50 is selected, and not 50f5c0cf
  4234. $this->View->viewVars['contactTags'] = array(
  4235. '1' => 'blue',
  4236. '50f5c0cf' => 'red',
  4237. '50' => 'green'
  4238. );
  4239. $this->Form->request->data = array(
  4240. 'Contact' => array(),
  4241. 'ContactTag' => array(
  4242. array(
  4243. 'id' => 1,
  4244. 'name' => 'blue'
  4245. ),
  4246. array(
  4247. 'id' => 50,
  4248. 'name' => 'green'
  4249. )
  4250. )
  4251. );
  4252. $this->Form->create('Contact');
  4253. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4254. $expected = array(
  4255. 'input' => array(
  4256. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4257. ),
  4258. 'select' => array(
  4259. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4260. 'multiple' => 'multiple'
  4261. ),
  4262. array('option' => array('value' => '1', 'selected' => 'selected')),
  4263. 'blue',
  4264. '/option',
  4265. array('option' => array('value' => '50f5c0cf')),
  4266. 'red',
  4267. '/option',
  4268. array('option' => array('value' => '50', 'selected' => 'selected')),
  4269. 'green',
  4270. '/option',
  4271. '/select'
  4272. );
  4273. $this->assertTags($result, $expected);
  4274. }
  4275. /**
  4276. * test generation of multi select elements in checkbox format
  4277. *
  4278. * @return void
  4279. */
  4280. public function testSelectMultipleCheckboxes() {
  4281. $this->markTestIncomplete('Need to revisit once models work again.');
  4282. $result = $this->Form->select(
  4283. 'Model.multi_field',
  4284. array('first', 'second', 'third'),
  4285. array('multiple' => 'checkbox')
  4286. );
  4287. $expected = array(
  4288. 'input' => array(
  4289. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4290. ),
  4291. array('div' => array('class' => 'checkbox')),
  4292. array('input' => array(
  4293. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4294. 'value' => '0', 'id' => 'ModelMultiField0'
  4295. )),
  4296. array('label' => array('for' => 'ModelMultiField0')),
  4297. 'first',
  4298. '/label',
  4299. '/div',
  4300. array('div' => array('class' => 'checkbox')),
  4301. array('input' => array(
  4302. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4303. 'value' => '1', 'id' => 'ModelMultiField1'
  4304. )),
  4305. array('label' => array('for' => 'ModelMultiField1')),
  4306. 'second',
  4307. '/label',
  4308. '/div',
  4309. array('div' => array('class' => 'checkbox')),
  4310. array('input' => array(
  4311. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4312. 'value' => '2', 'id' => 'ModelMultiField2'
  4313. )),
  4314. array('label' => array('for' => 'ModelMultiField2')),
  4315. 'third',
  4316. '/label',
  4317. '/div'
  4318. );
  4319. $this->assertTags($result, $expected);
  4320. $result = $this->Form->select(
  4321. 'Model.multi_field',
  4322. array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4323. array('multiple' => 'checkbox')
  4324. );
  4325. $expected = array(
  4326. 'input' => array(
  4327. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4328. ),
  4329. array('div' => array('class' => 'checkbox')),
  4330. array('input' => array(
  4331. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4332. 'value' => 'a', 'id' => 'ModelMultiFieldA'
  4333. )),
  4334. array('label' => array('for' => 'ModelMultiFieldA')),
  4335. 'first',
  4336. '/label',
  4337. '/div',
  4338. array('div' => array('class' => 'checkbox')),
  4339. array('input' => array(
  4340. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4341. 'value' => 'b', 'id' => 'ModelMultiFieldB'
  4342. )),
  4343. array('label' => array('for' => 'ModelMultiFieldB')),
  4344. 'second',
  4345. '/label',
  4346. '/div',
  4347. array('div' => array('class' => 'checkbox')),
  4348. array('input' => array(
  4349. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4350. 'value' => 'c', 'id' => 'ModelMultiFieldC'
  4351. )),
  4352. array('label' => array('for' => 'ModelMultiFieldC')),
  4353. 'third',
  4354. '/label',
  4355. '/div'
  4356. );
  4357. $this->assertTags($result, $expected);
  4358. $result = $this->Form->select(
  4359. 'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
  4360. );
  4361. $expected = array(
  4362. 'input' => array(
  4363. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4364. ),
  4365. array('div' => array('class' => 'checkbox')),
  4366. array('input' => array(
  4367. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4368. 'value' => '1', 'id' => 'ModelMultiField1'
  4369. )),
  4370. array('label' => array('for' => 'ModelMultiField1')),
  4371. 'first',
  4372. '/label',
  4373. '/div'
  4374. );
  4375. $this->assertTags($result, $expected);
  4376. $this->Form->request->data = array('Model' => array('tags' => array(1)));
  4377. $result = $this->Form->select(
  4378. 'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
  4379. );
  4380. $expected = array(
  4381. 'input' => array(
  4382. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4383. ),
  4384. array('div' => array('class' => 'checkbox')),
  4385. array('input' => array(
  4386. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4387. 'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
  4388. )),
  4389. array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
  4390. 'first',
  4391. '/label',
  4392. '/div',
  4393. array('div' => array('class' => 'checkbox')),
  4394. array('input' => array(
  4395. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4396. 'value' => 'Array', 'id' => 'ModelTagsArray'
  4397. )),
  4398. array('label' => array('for' => 'ModelTagsArray')),
  4399. 'Array',
  4400. '/label',
  4401. '/div'
  4402. );
  4403. $this->assertTags($result, $expected);
  4404. $result = $this->Form->select(
  4405. 'Model.multi_field',
  4406. array('a+' => 'first', 'a++' => 'second', 'a+++' => 'third'),
  4407. array('multiple' => 'checkbox')
  4408. );
  4409. $expected = array(
  4410. 'input' => array(
  4411. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4412. ),
  4413. array('div' => array('class' => 'checkbox')),
  4414. array('input' => array(
  4415. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4416. 'value' => 'a+', 'id' => 'ModelMultiFieldA+'
  4417. )),
  4418. array('label' => array('for' => 'ModelMultiFieldA+')),
  4419. 'first',
  4420. '/label',
  4421. '/div',
  4422. array('div' => array('class' => 'checkbox')),
  4423. array('input' => array(
  4424. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4425. 'value' => 'a++', 'id' => 'ModelMultiFieldA++'
  4426. )),
  4427. array('label' => array('for' => 'ModelMultiFieldA++')),
  4428. 'second',
  4429. '/label',
  4430. '/div',
  4431. array('div' => array('class' => 'checkbox')),
  4432. array('input' => array(
  4433. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4434. 'value' => 'a+++', 'id' => 'ModelMultiFieldA+++'
  4435. )),
  4436. array('label' => array('for' => 'ModelMultiFieldA+++')),
  4437. 'third',
  4438. '/label',
  4439. '/div'
  4440. );
  4441. $this->assertTags($result, $expected);
  4442. $result = $this->Form->select(
  4443. 'Model.multi_field',
  4444. array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
  4445. array('multiple' => 'checkbox')
  4446. );
  4447. $expected = array(
  4448. 'input' => array(
  4449. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4450. ),
  4451. array('div' => array('class' => 'checkbox')),
  4452. array('input' => array(
  4453. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4454. 'value' => 'a&gt;b', 'id' => 'ModelMultiFieldAB2'
  4455. )),
  4456. array('label' => array('for' => 'ModelMultiFieldAB2')),
  4457. 'first',
  4458. '/label',
  4459. '/div',
  4460. array('div' => array('class' => 'checkbox')),
  4461. array('input' => array(
  4462. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4463. 'value' => 'a&lt;b', 'id' => 'ModelMultiFieldAB1'
  4464. )),
  4465. array('label' => array('for' => 'ModelMultiFieldAB1')),
  4466. 'second',
  4467. '/label',
  4468. '/div',
  4469. array('div' => array('class' => 'checkbox')),
  4470. array('input' => array(
  4471. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4472. 'value' => 'a&quot;b', 'id' => 'ModelMultiFieldAB'
  4473. )),
  4474. array('label' => array('for' => 'ModelMultiFieldAB')),
  4475. 'third',
  4476. '/label',
  4477. '/div'
  4478. );
  4479. $this->assertTags($result, $expected);
  4480. }
  4481. /**
  4482. * test multiple checkboxes with div styles.
  4483. *
  4484. * @return void
  4485. */
  4486. public function testSelectMultipleCheckboxDiv() {
  4487. $this->markTestIncomplete('Need to revisit once models work again.');
  4488. $result = $this->Form->select(
  4489. 'Model.tags',
  4490. array('first', 'second'),
  4491. array('multiple' => 'checkbox', 'class' => 'my-class')
  4492. );
  4493. $expected = array(
  4494. 'input' => array(
  4495. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4496. ),
  4497. array('div' => array('class' => 'my-class')),
  4498. array('input' => array(
  4499. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4500. 'value' => '0', 'id' => 'ModelTags0'
  4501. )),
  4502. array('label' => array('for' => 'ModelTags0')), 'first', '/label',
  4503. '/div',
  4504. array('div' => array('class' => 'my-class')),
  4505. array('input' => array(
  4506. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4507. 'value' => '1', 'id' => 'ModelTags1'
  4508. )),
  4509. array('label' => array('for' => 'ModelTags1')), 'second', '/label',
  4510. '/div'
  4511. );
  4512. $this->assertTags($result, $expected);
  4513. $result = $this->Form->input('Model.tags', array(
  4514. 'options' => array('first', 'second'),
  4515. 'multiple' => 'checkbox',
  4516. 'class' => 'my-class',
  4517. 'div' => false,
  4518. 'label' => false
  4519. ));
  4520. $this->assertTags($result, $expected);
  4521. $Contact->validationErrors['tags'] = 'Select atleast one option';
  4522. $result = $this->Form->input('Contact.tags', array(
  4523. 'options' => array('one'),
  4524. 'multiple' => 'checkbox',
  4525. 'label' => false,
  4526. 'div' => false
  4527. ));
  4528. $expected = array(
  4529. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4530. array('div' => array('class' => 'checkbox form-error')),
  4531. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4532. array('label' => array('for' => 'ContactTags0')),
  4533. 'one',
  4534. '/label',
  4535. '/div'
  4536. );
  4537. $this->assertTags($result, $expected);
  4538. $result = $this->Form->input('Contact.tags', array(
  4539. 'options' => array('one'),
  4540. 'multiple' => 'checkbox',
  4541. 'class' => 'mycheckbox',
  4542. 'label' => false,
  4543. 'div' => false
  4544. ));
  4545. $expected = array(
  4546. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4547. array('div' => array('class' => 'mycheckbox form-error')),
  4548. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4549. array('label' => array('for' => 'ContactTags0')),
  4550. 'one',
  4551. '/label',
  4552. '/div'
  4553. );
  4554. $this->assertTags($result, $expected);
  4555. }
  4556. /**
  4557. * Checks the security hash array generated for multiple-input checkbox elements
  4558. *
  4559. * @return void
  4560. */
  4561. public function testSelectMultipleCheckboxSecurity() {
  4562. $this->markTestIncomplete('Need to revisit once models work again.');
  4563. $this->Form->request->params['_csrfToken'] = 'testKey';
  4564. $this->assertEquals(array(), $this->Form->fields);
  4565. $result = $this->Form->select(
  4566. 'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
  4567. array('multiple' => 'checkbox')
  4568. );
  4569. $this->assertEquals(array('Model.multi_field'), $this->Form->fields);
  4570. $result = $this->Form->secure($this->Form->fields);
  4571. $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
  4572. $this->assertRegExp('/"' . $key . '"/', $result);
  4573. }
  4574. /**
  4575. * Multiple select elements should always be secured as they always participate
  4576. * in the POST data.
  4577. *
  4578. * @return void
  4579. */
  4580. public function testSelectMultipleSecureWithNoOptions() {
  4581. $this->Form->request->params['_Token'] = 'testkey';
  4582. $this->assertEquals(array(), $this->Form->fields);
  4583. $this->Form->select(
  4584. 'Model.select',
  4585. array(),
  4586. array('multiple' => true)
  4587. );
  4588. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4589. }
  4590. /**
  4591. * When a select box has no options it should not be added to the fields list
  4592. * as it always fail post validation.
  4593. *
  4594. * @return void
  4595. */
  4596. public function testSelectNoSecureWithNoOptions() {
  4597. $this->markTestIncomplete('Need to revisit once models work again.');
  4598. $this->Form->request->params['_csrfToken'] = 'testkey';
  4599. $this->assertEquals(array(), $this->Form->fields);
  4600. $this->Form->select(
  4601. 'Model.select',
  4602. array()
  4603. );
  4604. $this->assertEquals(array(), $this->Form->fields);
  4605. $this->Form->select(
  4606. 'Model.select',
  4607. array(),
  4608. array('empty' => true)
  4609. );
  4610. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4611. }
  4612. /**
  4613. * testInputMultipleCheckboxes method
  4614. *
  4615. * test input() resulting in multi select elements being generated.
  4616. *
  4617. * @return void
  4618. */
  4619. public function testInputMultipleCheckboxes() {
  4620. $this->markTestIncomplete('Need to revisit once models work again.');
  4621. $result = $this->Form->input('Model.multi_field', array(
  4622. 'options' => array('first', 'second', 'third'),
  4623. 'multiple' => 'checkbox'
  4624. ));
  4625. $expected = array(
  4626. array('div' => array('class' => 'input select')),
  4627. array('label' => array('for' => 'ModelMultiField')),
  4628. 'Multi Field',
  4629. '/label',
  4630. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4631. array('div' => array('class' => 'checkbox')),
  4632. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4633. array('label' => array('for' => 'ModelMultiField0')),
  4634. 'first',
  4635. '/label',
  4636. '/div',
  4637. array('div' => array('class' => 'checkbox')),
  4638. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4639. array('label' => array('for' => 'ModelMultiField1')),
  4640. 'second',
  4641. '/label',
  4642. '/div',
  4643. array('div' => array('class' => 'checkbox')),
  4644. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4645. array('label' => array('for' => 'ModelMultiField2')),
  4646. 'third',
  4647. '/label',
  4648. '/div',
  4649. '/div'
  4650. );
  4651. $this->assertTags($result, $expected);
  4652. $result = $this->Form->input('Model.multi_field', array(
  4653. 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4654. 'multiple' => 'checkbox'
  4655. ));
  4656. $expected = array(
  4657. array('div' => array('class' => 'input select')),
  4658. array('label' => array('for' => 'ModelMultiField')),
  4659. 'Multi Field',
  4660. '/label',
  4661. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4662. array('div' => array('class' => 'checkbox')),
  4663. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
  4664. array('label' => array('for' => 'ModelMultiFieldA')),
  4665. 'first',
  4666. '/label',
  4667. '/div',
  4668. array('div' => array('class' => 'checkbox')),
  4669. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
  4670. array('label' => array('for' => 'ModelMultiFieldB')),
  4671. 'second',
  4672. '/label',
  4673. '/div',
  4674. array('div' => array('class' => 'checkbox')),
  4675. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
  4676. array('label' => array('for' => 'ModelMultiFieldC')),
  4677. 'third',
  4678. '/label',
  4679. '/div',
  4680. '/div'
  4681. );
  4682. $this->assertTags($result, $expected);
  4683. $result = $this->Form->input('Model.multi_field', array(
  4684. 'options' => array('1' => 'first'),
  4685. 'multiple' => 'checkbox',
  4686. 'label' => false,
  4687. 'div' => false
  4688. ));
  4689. $expected = array(
  4690. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4691. array('div' => array('class' => 'checkbox')),
  4692. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4693. array('label' => array('for' => 'ModelMultiField1')),
  4694. 'first',
  4695. '/label',
  4696. '/div'
  4697. );
  4698. $this->assertTags($result, $expected);
  4699. $result = $this->Form->input('Model.multi_field', array(
  4700. 'options' => array('2' => 'second'),
  4701. 'multiple' => 'checkbox',
  4702. 'label' => false,
  4703. 'div' => false
  4704. ));
  4705. $expected = array(
  4706. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4707. array('div' => array('class' => 'checkbox')),
  4708. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4709. array('label' => array('for' => 'ModelMultiField2')),
  4710. 'second',
  4711. '/label',
  4712. '/div'
  4713. );
  4714. $this->assertTags($result, $expected);
  4715. }
  4716. /**
  4717. * testSelectHiddenFieldOmission method
  4718. *
  4719. * test that select() with 'hiddenField' => false omits the hidden field
  4720. *
  4721. * @return void
  4722. */
  4723. public function testSelectHiddenFieldOmission() {
  4724. $this->markTestIncomplete('Need to revisit once models work again.');
  4725. $result = $this->Form->select('Model.multi_field',
  4726. array('first', 'second'),
  4727. array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
  4728. );
  4729. $expected = array(
  4730. array('div' => array('class' => 'checkbox')),
  4731. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4732. array('label' => array('for' => 'ModelMultiField0')),
  4733. 'first',
  4734. '/label',
  4735. '/div',
  4736. array('div' => array('class' => 'checkbox')),
  4737. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4738. array('label' => array('for' => 'ModelMultiField1')),
  4739. 'second',
  4740. '/label',
  4741. '/div'
  4742. );
  4743. $this->assertTags($result, $expected);
  4744. $result = $this->Form->input('Model.multi_field', array(
  4745. 'options' => array('first', 'second'),
  4746. 'multiple' => 'checkbox',
  4747. 'hiddenField' => false
  4748. ));
  4749. $expected = array(
  4750. array('div' => array('class' => 'input select')),
  4751. array('label' => array('for' => 'ModelMultiField')),
  4752. 'Multi Field',
  4753. '/label',
  4754. array('div' => array('class' => 'checkbox')),
  4755. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4756. array('label' => array('for' => 'ModelMultiField0')),
  4757. 'first',
  4758. '/label',
  4759. '/div',
  4760. array('div' => array('class' => 'checkbox')),
  4761. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4762. array('label' => array('for' => 'ModelMultiField1')),
  4763. 'second',
  4764. '/label',
  4765. '/div',
  4766. '/div'
  4767. );
  4768. $this->assertTags($result, $expected);
  4769. }
  4770. /**
  4771. * test that select() with multiple = checkbox works with overriding name attribute.
  4772. *
  4773. * @return void
  4774. */
  4775. public function testSelectCheckboxMultipleOverrideName() {
  4776. $this->markTestIncomplete('Need to revisit once models work again.');
  4777. $result = $this->Form->input('category', array(
  4778. 'type' => 'select',
  4779. 'multiple' => 'checkbox',
  4780. 'name' => 'fish',
  4781. 'options' => array('1', '2'),
  4782. 'div' => false,
  4783. 'label' => false,
  4784. ));
  4785. $expected = array(
  4786. 'input' => array('type' => 'hidden', 'name' => 'fish', 'value' => '', 'id' => 'category'),
  4787. array('div' => array('class' => 'checkbox')),
  4788. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '0', 'id' => 'Category0')),
  4789. array('label' => array('for' => 'Category0')), '1', '/label',
  4790. '/div',
  4791. array('div' => array('class' => 'checkbox')),
  4792. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '1', 'id' => 'Category1')),
  4793. array('label' => array('for' => 'Category1')), '2', '/label',
  4794. '/div'
  4795. );
  4796. $this->assertTags($result, $expected);
  4797. }
  4798. /**
  4799. * Test that 'id' overrides all the checkbox id's as well.
  4800. *
  4801. * @return void
  4802. */
  4803. public function testSelectCheckboxMultipleId() {
  4804. $this->markTestIncomplete('Need to revisit once models work again.');
  4805. $result = $this->Form->select(
  4806. 'Model.multi_field',
  4807. array('first', 'second', 'third'),
  4808. array('multiple' => 'checkbox', 'id' => 'CustomId')
  4809. );
  4810. $expected = array(
  4811. 'input' => array(
  4812. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'CustomId'
  4813. ),
  4814. array('div' => array('class' => 'checkbox')),
  4815. array('input' => array(
  4816. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4817. 'value' => '0', 'id' => 'CustomId0'
  4818. )),
  4819. array('label' => array('for' => 'CustomId0')),
  4820. 'first',
  4821. '/label',
  4822. '/div',
  4823. array('div' => array('class' => 'checkbox')),
  4824. array('input' => array(
  4825. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4826. 'value' => '1', 'id' => 'CustomId1'
  4827. )),
  4828. array('label' => array('for' => 'CustomId1')),
  4829. 'second',
  4830. '/label',
  4831. '/div',
  4832. array('div' => array('class' => 'checkbox')),
  4833. array('input' => array(
  4834. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4835. 'value' => '2', 'id' => 'CustomId2'
  4836. )),
  4837. array('label' => array('for' => 'CustomId2')),
  4838. 'third',
  4839. '/label',
  4840. '/div'
  4841. );
  4842. $this->assertTags($result, $expected);
  4843. }
  4844. /**
  4845. * testCheckbox method
  4846. *
  4847. * Test generation of checkboxes
  4848. *
  4849. * @return void
  4850. */
  4851. public function testCheckbox() {
  4852. $result = $this->Form->checkbox('Model.field');
  4853. $expected = array(
  4854. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4855. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1'))
  4856. );
  4857. $this->assertTags($result, $expected);
  4858. $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
  4859. $expected = array(
  4860. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4861. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => 'myvalue', 'id' => 'theID'))
  4862. );
  4863. $this->assertTags($result, $expected);
  4864. }
  4865. /**
  4866. * Test checkbox being checked or having errors.
  4867. *
  4868. * @return void
  4869. */
  4870. public function testCheckboxCheckedAndError() {
  4871. $this->article['errors'] = [
  4872. 'published' => true
  4873. ];
  4874. $this->Form->request->data['published'] = 'myvalue';
  4875. $this->Form->create($this->article);
  4876. $result = $this->Form->checkbox('published', array('id' => 'theID', 'value' => 'myvalue'));
  4877. $expected = array(
  4878. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4879. array('input' => array(
  4880. 'type' => 'checkbox',
  4881. 'name' => 'published',
  4882. 'value' => 'myvalue',
  4883. 'id' => 'theID',
  4884. 'checked' => 'checked',
  4885. 'class' => 'form-error'
  4886. ))
  4887. );
  4888. $this->assertTags($result, $expected);
  4889. $this->Form->request->data['published'] = '';
  4890. $result = $this->Form->checkbox('published');
  4891. $expected = array(
  4892. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4893. array('input' => array('type' => 'checkbox', 'name' => 'published', 'value' => '1', 'class' => 'form-error'))
  4894. );
  4895. $this->assertTags($result, $expected);
  4896. }
  4897. /**
  4898. * test checkbox() with a custom name attribute
  4899. *
  4900. * @return void
  4901. */
  4902. public function testCheckboxCustomNameAttribute() {
  4903. $result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
  4904. $expected = array(
  4905. 'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0'),
  4906. array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1'))
  4907. );
  4908. $this->assertTags($result, $expected);
  4909. }
  4910. /**
  4911. * Test that the hidden input for checkboxes can be omitted or set to a
  4912. * specific value.
  4913. *
  4914. * @return void
  4915. */
  4916. public function testCheckboxHiddenField() {
  4917. $result = $this->Form->checkbox('UserForm.something', array(
  4918. 'hiddenField' => false
  4919. ));
  4920. $expected = array(
  4921. 'input' => array(
  4922. 'type' => 'checkbox',
  4923. 'name' => 'UserForm[something]',
  4924. 'value' => '1'
  4925. ),
  4926. );
  4927. $this->assertTags($result, $expected);
  4928. $result = $this->Form->checkbox('UserForm.something', array(
  4929. 'value' => 'Y',
  4930. 'hiddenField' => 'N',
  4931. ));
  4932. $expected = array(
  4933. array('input' => array(
  4934. 'type' => 'hidden', 'name' => 'UserForm[something]',
  4935. 'value' => 'N'
  4936. )),
  4937. array('input' => array(
  4938. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  4939. 'value' => 'Y'
  4940. )),
  4941. );
  4942. $this->assertTags($result, $expected);
  4943. }
  4944. /**
  4945. * testDateTime method
  4946. *
  4947. * Test generation of date/time select elements
  4948. *
  4949. * @return void
  4950. */
  4951. public function testDateTime() {
  4952. $this->markTestIncomplete('Need to revisit once models work again.');
  4953. extract($this->dateRegex);
  4954. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  4955. $now = strtotime('now');
  4956. $expected = array(
  4957. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  4958. $daysRegex,
  4959. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  4960. date('j', $now),
  4961. '/option',
  4962. '*/select',
  4963. '-',
  4964. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  4965. $monthsRegex,
  4966. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  4967. date('F', $now),
  4968. '/option',
  4969. '*/select',
  4970. '-',
  4971. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  4972. $yearsRegex,
  4973. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  4974. date('Y', $now),
  4975. '/option',
  4976. '*/select',
  4977. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  4978. $hoursRegex,
  4979. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  4980. date('g', $now),
  4981. '/option',
  4982. '*/select',
  4983. ':',
  4984. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  4985. $minutesRegex,
  4986. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  4987. date('i', $now),
  4988. '/option',
  4989. '*/select',
  4990. ' ',
  4991. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  4992. $meridianRegex,
  4993. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  4994. date('a', $now),
  4995. '/option',
  4996. '*/select'
  4997. );
  4998. $this->assertTags($result, $expected);
  4999. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  5000. $expected = array(
  5001. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5002. $daysRegex,
  5003. array('option' => array('value' => '')),
  5004. '/option',
  5005. '*/select',
  5006. '-',
  5007. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5008. $monthsRegex,
  5009. array('option' => array('value' => '')),
  5010. '/option',
  5011. '*/select',
  5012. '-',
  5013. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5014. $yearsRegex,
  5015. array('option' => array('value' => '')),
  5016. '/option',
  5017. '*/select',
  5018. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5019. $hoursRegex,
  5020. array('option' => array('value' => '')),
  5021. '/option',
  5022. '*/select',
  5023. ':',
  5024. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5025. $minutesRegex,
  5026. array('option' => array('value' => '')),
  5027. '/option',
  5028. '*/select',
  5029. ' ',
  5030. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5031. $meridianRegex,
  5032. array('option' => array('value' => '')),
  5033. '/option',
  5034. '*/select'
  5035. );
  5036. $this->assertTags($result, $expected);
  5037. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5038. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
  5039. $this->assertTags($result, $expected);
  5040. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5041. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
  5042. $this->assertTags($result, $expected);
  5043. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5044. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
  5045. $expected = array(
  5046. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5047. $daysRegex,
  5048. array('option' => array('value' => '')),
  5049. '/option',
  5050. '*/select',
  5051. '-',
  5052. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5053. $monthsRegex,
  5054. array('option' => array('value' => '')),
  5055. '/option',
  5056. '*/select',
  5057. '-',
  5058. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5059. $yearsRegex,
  5060. array('option' => array('value' => '')),
  5061. '/option',
  5062. '*/select',
  5063. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5064. $hoursRegex,
  5065. array('option' => array('value' => '')),
  5066. '/option',
  5067. '*/select',
  5068. ':',
  5069. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5070. $minutesRegex,
  5071. array('option' => array('value' => '')),
  5072. '/option',
  5073. array('option' => array('value' => '00')),
  5074. '00',
  5075. '/option',
  5076. array('option' => array('value' => '05')),
  5077. '05',
  5078. '/option',
  5079. array('option' => array('value' => '10')),
  5080. '10',
  5081. '/option',
  5082. '*/select',
  5083. ' ',
  5084. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5085. $meridianRegex,
  5086. array('option' => array('value' => '')),
  5087. '/option',
  5088. '*/select'
  5089. );
  5090. $this->assertTags($result, $expected);
  5091. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5092. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5093. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5094. $this->Form->request->data['Contact']['data'] = null;
  5095. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  5096. $expected = array(
  5097. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5098. $daysRegex,
  5099. array('option' => array('value' => '')),
  5100. '/option',
  5101. '*/select',
  5102. '-',
  5103. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5104. $monthsRegex,
  5105. array('option' => array('value' => '')),
  5106. '/option',
  5107. '*/select',
  5108. '-',
  5109. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5110. $yearsRegex,
  5111. array('option' => array('value' => '')),
  5112. '/option',
  5113. '*/select',
  5114. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5115. $hoursRegex,
  5116. array('option' => array('value' => '')),
  5117. '/option',
  5118. '*/select',
  5119. ':',
  5120. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5121. $minutesRegex,
  5122. array('option' => array('value' => '')),
  5123. '/option',
  5124. '*/select',
  5125. ' ',
  5126. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5127. $meridianRegex,
  5128. array('option' => array('value' => '')),
  5129. '/option',
  5130. '*/select'
  5131. );
  5132. $this->assertTags($result, $expected);
  5133. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5134. $this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
  5135. $now = strtotime($this->Form->data['Model']['field']);
  5136. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
  5137. $expected = array(
  5138. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5139. $daysRegex,
  5140. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5141. date('j', $now),
  5142. '/option',
  5143. '*/select',
  5144. '-',
  5145. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5146. $monthsRegex,
  5147. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5148. date('F', $now),
  5149. '/option',
  5150. '*/select',
  5151. '-',
  5152. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5153. $yearsRegex,
  5154. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5155. date('Y', $now),
  5156. '/option',
  5157. '*/select',
  5158. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5159. $hoursRegex,
  5160. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5161. date('g', $now),
  5162. '/option',
  5163. '*/select',
  5164. ':',
  5165. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5166. $minutesRegex,
  5167. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  5168. date('i', $now),
  5169. '/option',
  5170. '*/select',
  5171. ' ',
  5172. array('select' => array('name' => 'Model[field][meridian]', 'id' => 'ModelFieldMeridian')),
  5173. $meridianRegex,
  5174. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  5175. date('a', $now),
  5176. '/option',
  5177. '*/select'
  5178. );
  5179. $this->assertTags($result, $expected);
  5180. $selected = strtotime('2008-10-26 12:33:00');
  5181. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
  5182. $this->assertRegExp('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
  5183. $this->assertRegExp('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
  5184. $this->assertRegExp('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
  5185. $this->assertRegExp('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
  5186. $this->assertRegExp('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
  5187. $this->assertRegExp('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
  5188. $this->Form->create('Contact');
  5189. $result = $this->Form->input('published');
  5190. $now = strtotime('now');
  5191. $expected = array(
  5192. 'div' => array('class' => 'input date'),
  5193. 'label' => array('for' => 'ContactPublishedMonth'),
  5194. 'Published',
  5195. '/label',
  5196. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5197. $monthsRegex,
  5198. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5199. date('F', $now),
  5200. '/option',
  5201. '*/select',
  5202. '-',
  5203. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5204. $daysRegex,
  5205. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5206. date('j', $now),
  5207. '/option',
  5208. '*/select',
  5209. '-',
  5210. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5211. $yearsRegex,
  5212. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5213. date('Y', $now),
  5214. '/option',
  5215. '*/select',
  5216. '/div'
  5217. );
  5218. $this->assertTags($result, $expected);
  5219. $result = $this->Form->input('published2', array('type' => 'date'));
  5220. $now = strtotime('now');
  5221. $expected = array(
  5222. 'div' => array('class' => 'input date'),
  5223. 'label' => array('for' => 'ContactPublished2Month'),
  5224. 'Published2',
  5225. '/label',
  5226. array('select' => array('name' => 'Contact[published2][month]', 'id' => 'ContactPublished2Month')),
  5227. $monthsRegex,
  5228. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5229. date('F', $now),
  5230. '/option',
  5231. '*/select',
  5232. '-',
  5233. array('select' => array('name' => 'Contact[published2][day]', 'id' => 'ContactPublished2Day')),
  5234. $daysRegex,
  5235. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5236. date('j', $now),
  5237. '/option',
  5238. '*/select',
  5239. '-',
  5240. array('select' => array('name' => 'Contact[published2][year]', 'id' => 'ContactPublished2Year')),
  5241. $yearsRegex,
  5242. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5243. date('Y', $now),
  5244. '/option',
  5245. '*/select',
  5246. '/div'
  5247. );
  5248. $this->assertTags($result, $expected);
  5249. $this->Form->create('Contact');
  5250. $result = $this->Form->input('published', array('monthNames' => false));
  5251. $now = strtotime('now');
  5252. $expected = array(
  5253. 'div' => array('class' => 'input date'),
  5254. 'label' => array('for' => 'ContactPublishedMonth'),
  5255. 'Published',
  5256. '/label',
  5257. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5258. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5259. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5260. date('m', $now),
  5261. '/option',
  5262. '*/select',
  5263. '-',
  5264. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5265. $daysRegex,
  5266. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5267. date('j', $now),
  5268. '/option',
  5269. '*/select',
  5270. '-',
  5271. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5272. $yearsRegex,
  5273. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5274. date('Y', $now),
  5275. '/option',
  5276. '*/select',
  5277. '/div'
  5278. );
  5279. $this->assertTags($result, $expected);
  5280. $result = $this->Form->input('published', array('type' => 'time'));
  5281. $now = strtotime('now');
  5282. $expected = array(
  5283. 'div' => array('class' => 'input time'),
  5284. 'label' => array('for' => 'ContactPublishedHour'),
  5285. 'Published',
  5286. '/label',
  5287. array('select' => array('name' => 'Contact[published][hour]', 'id' => 'ContactPublishedHour')),
  5288. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5289. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5290. date('g', $now),
  5291. '/option',
  5292. '*/select',
  5293. ':',
  5294. );
  5295. $this->assertTags($result, $expected);
  5296. $result = $this->Form->input('published', array(
  5297. 'timeFormat' => 24,
  5298. 'interval' => 5,
  5299. 'selected' => strtotime('2009-09-03 13:37:00'),
  5300. 'type' => 'datetime'
  5301. ));
  5302. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5303. $this->assertRegExp('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
  5304. $this->assertRegExp('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
  5305. $this->assertRegExp('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
  5306. $this->assertRegExp('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
  5307. }
  5308. /**
  5309. * Test dateTime with rounding
  5310. *
  5311. * @return void
  5312. */
  5313. public function testDateTimeRounding() {
  5314. $this->markTestIncomplete('Need to revisit once models work again.');
  5315. $this->Form->request->data['Contact'] = array(
  5316. 'date' => array(
  5317. 'day' => '13',
  5318. 'month' => '12',
  5319. 'year' => '2010',
  5320. 'hour' => '04',
  5321. 'min' => '19',
  5322. 'meridian' => 'AM'
  5323. )
  5324. );
  5325. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
  5326. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5327. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
  5328. $this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
  5329. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
  5330. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5331. }
  5332. /**
  5333. * Test that empty values don't trigger errors.
  5334. *
  5335. * @return void
  5336. */
  5337. public function testDateTimeNoErrorsOnEmptyData() {
  5338. $this->markTestIncomplete('Need to revisit once models work again.');
  5339. $this->Form->request->data['Contact'] = array(
  5340. 'date' => array(
  5341. 'day' => '',
  5342. 'month' => '',
  5343. 'year' => '',
  5344. 'hour' => '',
  5345. 'min' => '',
  5346. 'meridian' => ''
  5347. )
  5348. );
  5349. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  5350. $this->assertNotEmpty($result);
  5351. }
  5352. /**
  5353. * test that datetime() and default values work.
  5354. *
  5355. * @return void
  5356. */
  5357. public function testDatetimeWithDefault() {
  5358. $this->markTestIncomplete('Need to revisit once models work again.');
  5359. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
  5360. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5361. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5362. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5363. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
  5364. 'default' => '2009-06-01 11:15:30'
  5365. ));
  5366. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5367. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5368. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5369. }
  5370. /**
  5371. * test that bogus non-date time data doesn't cause errors.
  5372. *
  5373. * @return void
  5374. */
  5375. public function testDateTimeWithBogusData() {
  5376. $this->markTestIncomplete('Need to revisit once models work again.');
  5377. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
  5378. $this->assertNotRegExp('/selected="selected">\d/', $result);
  5379. }
  5380. /**
  5381. * testDateTime all zeros
  5382. *
  5383. * @return void
  5384. */
  5385. public function testDateTimeAllZeros() {
  5386. $this->markTestIncomplete('Need to revisit once models work again.');
  5387. $result = $this->Form->dateTime('Contact.date',
  5388. 'DMY',
  5389. false,
  5390. array(
  5391. 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
  5392. 'value' => '0000-00-00'
  5393. )
  5394. );
  5395. $this->assertRegExp('/<option value="">-<\/option>/', $result);
  5396. $this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
  5397. }
  5398. /**
  5399. * testDateTimeEmptyAsArray
  5400. *
  5401. * @return void
  5402. */
  5403. public function testDateTimeEmptyAsArray() {
  5404. $this->markTestIncomplete('Need to revisit once models work again.');
  5405. $result = $this->Form->dateTime('Contact.date',
  5406. 'DMY',
  5407. '12',
  5408. array(
  5409. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
  5410. 'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
  5411. )
  5412. )
  5413. );
  5414. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5415. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5416. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5417. $this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
  5418. $this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
  5419. $this->assertNotRegExp('/<option value=""><\/option>/', $result);
  5420. $result = $this->Form->dateTime('Contact.date',
  5421. 'DMY',
  5422. '12',
  5423. array(
  5424. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
  5425. )
  5426. );
  5427. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5428. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5429. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5430. $this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
  5431. $this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
  5432. $this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
  5433. }
  5434. /**
  5435. * testFormDateTimeMulti method
  5436. *
  5437. * test multiple datetime element generation
  5438. *
  5439. * @return void
  5440. */
  5441. public function testFormDateTimeMulti() {
  5442. $this->markTestIncomplete('Need to revisit once models work again.');
  5443. extract($this->dateRegex);
  5444. $result = $this->Form->dateTime('Contact.1.updated');
  5445. $expected = array(
  5446. array('select' => array('name' => 'Contact[1][updated][day]', 'id' => 'Contact1UpdatedDay')),
  5447. $daysRegex,
  5448. array('option' => array('value' => '')),
  5449. '/option',
  5450. '*/select',
  5451. '-',
  5452. array('select' => array('name' => 'Contact[1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
  5453. $monthsRegex,
  5454. array('option' => array('value' => '')),
  5455. '/option',
  5456. '*/select',
  5457. '-',
  5458. array('select' => array('name' => 'Contact[1][updated][year]', 'id' => 'Contact1UpdatedYear')),
  5459. $yearsRegex,
  5460. array('option' => array('value' => '')),
  5461. '/option',
  5462. '*/select',
  5463. array('select' => array('name' => 'Contact[1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
  5464. $hoursRegex,
  5465. array('option' => array('value' => '')),
  5466. '/option',
  5467. '*/select',
  5468. ':',
  5469. array('select' => array('name' => 'Contact[1][updated][min]', 'id' => 'Contact1UpdatedMin')),
  5470. $minutesRegex,
  5471. array('option' => array('value' => '')),
  5472. '/option',
  5473. '*/select',
  5474. ' ',
  5475. array('select' => array('name' => 'Contact[1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
  5476. $meridianRegex,
  5477. array('option' => array('value' => '')),
  5478. '/option',
  5479. '*/select'
  5480. );
  5481. $this->assertTags($result, $expected);
  5482. $result = $this->Form->dateTime('Contact.2.updated');
  5483. $expected = array(
  5484. array('select' => array('name' => 'Contact[2][updated][day]', 'id' => 'Contact2UpdatedDay')),
  5485. $daysRegex,
  5486. array('option' => array('value' => '')),
  5487. '/option',
  5488. '*/select',
  5489. '-',
  5490. array('select' => array('name' => 'Contact[2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
  5491. $monthsRegex,
  5492. array('option' => array('value' => '')),
  5493. '/option',
  5494. '*/select',
  5495. '-',
  5496. array('select' => array('name' => 'Contact[2][updated][year]', 'id' => 'Contact2UpdatedYear')),
  5497. $yearsRegex,
  5498. array('option' => array('value' => '')),
  5499. '/option',
  5500. '*/select',
  5501. array('select' => array('name' => 'Contact[2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
  5502. $hoursRegex,
  5503. array('option' => array('value' => '')),
  5504. '/option',
  5505. '*/select',
  5506. ':',
  5507. array('select' => array('name' => 'Contact[2][updated][min]', 'id' => 'Contact2UpdatedMin')),
  5508. $minutesRegex,
  5509. array('option' => array('value' => '')),
  5510. '/option',
  5511. '*/select',
  5512. ' ',
  5513. array('select' => array('name' => 'Contact[2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
  5514. $meridianRegex,
  5515. array('option' => array('value' => '')),
  5516. '/option',
  5517. '*/select'
  5518. );
  5519. $this->assertTags($result, $expected);
  5520. }
  5521. /**
  5522. * When changing the date format, the label should always focus the first select box when
  5523. * clicked.
  5524. *
  5525. * @return void
  5526. */
  5527. public function testDateTimeLabelIdMatchesFirstInput() {
  5528. $this->markTestIncomplete('Need to revisit once models work again.');
  5529. $result = $this->Form->input('Model.date', array('type' => 'date'));
  5530. $this->assertContains('label for="ModelDateMonth"', $result);
  5531. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
  5532. $this->assertContains('label for="ModelDateDay"', $result);
  5533. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
  5534. $this->assertContains('label for="ModelDateYear"', $result);
  5535. }
  5536. /**
  5537. * testMonth method
  5538. *
  5539. * @return void
  5540. */
  5541. public function testMonth() {
  5542. $this->markTestIncomplete('Need to revisit once models work again.');
  5543. $result = $this->Form->month('Model.field');
  5544. $expected = array(
  5545. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5546. array('option' => array('value' => '')),
  5547. '/option',
  5548. array('option' => array('value' => '01')),
  5549. date('F', strtotime('2008-01-01 00:00:00')),
  5550. '/option',
  5551. array('option' => array('value' => '02')),
  5552. date('F', strtotime('2008-02-01 00:00:00')),
  5553. '/option',
  5554. '*/select',
  5555. );
  5556. $this->assertTags($result, $expected);
  5557. $result = $this->Form->month('Model.field', array('empty' => true));
  5558. $expected = array(
  5559. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5560. array('option' => array('value' => '')),
  5561. '/option',
  5562. array('option' => array('value' => '01')),
  5563. date('F', strtotime('2008-01-01 00:00:00')),
  5564. '/option',
  5565. array('option' => array('value' => '02')),
  5566. date('F', strtotime('2008-02-01 00:00:00')),
  5567. '/option',
  5568. '*/select',
  5569. );
  5570. $this->assertTags($result, $expected);
  5571. $result = $this->Form->month('Model.field', array('monthNames' => false));
  5572. $expected = array(
  5573. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5574. array('option' => array('value' => '')),
  5575. '/option',
  5576. array('option' => array('value' => '01')),
  5577. '01',
  5578. '/option',
  5579. array('option' => array('value' => '02')),
  5580. '02',
  5581. '/option',
  5582. '*/select',
  5583. );
  5584. $this->assertTags($result, $expected);
  5585. $monthNames = array(
  5586. '01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
  5587. '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
  5588. $result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
  5589. $expected = array(
  5590. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5591. array('option' => array('value' => '')),
  5592. '/option',
  5593. array('option' => array('value' => '01')),
  5594. 'Jan',
  5595. '/option',
  5596. array('option' => array('value' => '02')),
  5597. 'Feb',
  5598. '/option',
  5599. '*/select',
  5600. );
  5601. $this->assertTags($result, $expected);
  5602. $this->Form->request->data['Project']['release'] = '2050-02-10';
  5603. $result = $this->Form->month('Project.release');
  5604. $expected = array(
  5605. array('select' => array('name' => 'Project[release][month]', 'id' => 'ProjectReleaseMonth')),
  5606. array('option' => array('value' => '')),
  5607. '/option',
  5608. array('option' => array('value' => '01')),
  5609. 'January',
  5610. '/option',
  5611. array('option' => array('value' => '02', 'selected' => 'selected')),
  5612. 'February',
  5613. '/option',
  5614. '*/select',
  5615. );
  5616. $this->assertTags($result, $expected);
  5617. }
  5618. /**
  5619. * testDay method
  5620. *
  5621. * @return void
  5622. */
  5623. public function testDay() {
  5624. $this->markTestIncomplete('Need to revisit once models work again.');
  5625. extract($this->dateRegex);
  5626. $result = $this->Form->day('Model.field', array('value' => false));
  5627. $expected = array(
  5628. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5629. array('option' => array('value' => '')),
  5630. '/option',
  5631. array('option' => array('value' => '01')),
  5632. '1',
  5633. '/option',
  5634. array('option' => array('value' => '02')),
  5635. '2',
  5636. '/option',
  5637. $daysRegex,
  5638. '/select',
  5639. );
  5640. $this->assertTags($result, $expected);
  5641. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5642. $result = $this->Form->day('Model.field');
  5643. $expected = array(
  5644. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5645. array('option' => array('value' => '')),
  5646. '/option',
  5647. array('option' => array('value' => '01')),
  5648. '1',
  5649. '/option',
  5650. array('option' => array('value' => '02')),
  5651. '2',
  5652. '/option',
  5653. $daysRegex,
  5654. array('option' => array('value' => '10', 'selected' => 'selected')),
  5655. '10',
  5656. '/option',
  5657. $daysRegex,
  5658. '/select',
  5659. );
  5660. $this->assertTags($result, $expected);
  5661. $this->Form->request->data['Model']['field'] = '';
  5662. $result = $this->Form->day('Model.field', array('value' => '10'));
  5663. $expected = array(
  5664. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5665. array('option' => array('value' => '')),
  5666. '/option',
  5667. array('option' => array('value' => '01')),
  5668. '1',
  5669. '/option',
  5670. array('option' => array('value' => '02')),
  5671. '2',
  5672. '/option',
  5673. $daysRegex,
  5674. array('option' => array('value' => '10', 'selected' => 'selected')),
  5675. '10',
  5676. '/option',
  5677. $daysRegex,
  5678. '/select',
  5679. );
  5680. $this->assertTags($result, $expected);
  5681. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5682. $result = $this->Form->day('Model.field', array('value' => true));
  5683. $expected = array(
  5684. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5685. array('option' => array('value' => '')),
  5686. '/option',
  5687. array('option' => array('value' => '01')),
  5688. '1',
  5689. '/option',
  5690. array('option' => array('value' => '02')),
  5691. '2',
  5692. '/option',
  5693. $daysRegex,
  5694. array('option' => array('value' => '10', 'selected' => 'selected')),
  5695. '10',
  5696. '/option',
  5697. $daysRegex,
  5698. '/select',
  5699. );
  5700. $this->assertTags($result, $expected);
  5701. $this->Form->request->data['Project']['release'] = '2050-10-10';
  5702. $result = $this->Form->day('Project.release');
  5703. $expected = array(
  5704. array('select' => array('name' => 'Project[release][day]', 'id' => 'ProjectReleaseDay')),
  5705. array('option' => array('value' => '')),
  5706. '/option',
  5707. array('option' => array('value' => '01')),
  5708. '1',
  5709. '/option',
  5710. array('option' => array('value' => '02')),
  5711. '2',
  5712. '/option',
  5713. $daysRegex,
  5714. array('option' => array('value' => '10', 'selected' => 'selected')),
  5715. '10',
  5716. '/option',
  5717. $daysRegex,
  5718. '/select',
  5719. );
  5720. $this->assertTags($result, $expected);
  5721. }
  5722. /**
  5723. * testMinute method
  5724. *
  5725. * @return void
  5726. */
  5727. public function testMinute() {
  5728. $this->markTestIncomplete('Need to revisit once models work again.');
  5729. extract($this->dateRegex);
  5730. $result = $this->Form->minute('Model.field');
  5731. $expected = array(
  5732. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5733. array('option' => array('value' => '')),
  5734. '/option',
  5735. array('option' => array('value' => '00')),
  5736. '00',
  5737. '/option',
  5738. array('option' => array('value' => '01')),
  5739. '01',
  5740. '/option',
  5741. array('option' => array('value' => '02')),
  5742. '02',
  5743. '/option',
  5744. $minutesRegex,
  5745. '/select',
  5746. );
  5747. $this->assertTags($result, $expected);
  5748. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5749. $result = $this->Form->minute('Model.field');
  5750. $expected = array(
  5751. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5752. array('option' => array('value' => '')),
  5753. '/option',
  5754. array('option' => array('value' => '00')),
  5755. '00',
  5756. '/option',
  5757. array('option' => array('value' => '01')),
  5758. '01',
  5759. '/option',
  5760. array('option' => array('value' => '02')),
  5761. '02',
  5762. '/option',
  5763. $minutesRegex,
  5764. array('option' => array('value' => '12', 'selected' => 'selected')),
  5765. '12',
  5766. '/option',
  5767. $minutesRegex,
  5768. '/select',
  5769. );
  5770. $this->assertTags($result, $expected);
  5771. $this->Form->request->data['Model']['field'] = '';
  5772. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5773. $expected = array(
  5774. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5775. array('option' => array('value' => '')),
  5776. '/option',
  5777. array('option' => array('value' => '00')),
  5778. '00',
  5779. '/option',
  5780. array('option' => array('value' => '05')),
  5781. '05',
  5782. '/option',
  5783. array('option' => array('value' => '10')),
  5784. '10',
  5785. '/option',
  5786. $minutesRegex,
  5787. '/select',
  5788. );
  5789. $this->assertTags($result, $expected);
  5790. $this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
  5791. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5792. $expected = array(
  5793. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5794. array('option' => array('value' => '')),
  5795. '/option',
  5796. array('option' => array('value' => '00')),
  5797. '00',
  5798. '/option',
  5799. array('option' => array('value' => '05')),
  5800. '05',
  5801. '/option',
  5802. array('option' => array('value' => '10', 'selected' => 'selected')),
  5803. '10',
  5804. '/option',
  5805. $minutesRegex,
  5806. '/select',
  5807. );
  5808. $this->assertTags($result, $expected);
  5809. }
  5810. /**
  5811. * testHour method
  5812. *
  5813. * @return void
  5814. */
  5815. public function testHour() {
  5816. $this->markTestIncomplete('Need to revisit once models work again.');
  5817. extract($this->dateRegex);
  5818. $result = $this->Form->hour('Model.field', false);
  5819. $expected = array(
  5820. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5821. array('option' => array('value' => '')),
  5822. '/option',
  5823. array('option' => array('value' => '01')),
  5824. '1',
  5825. '/option',
  5826. array('option' => array('value' => '02')),
  5827. '2',
  5828. '/option',
  5829. $hoursRegex,
  5830. '/select',
  5831. );
  5832. $this->assertTags($result, $expected);
  5833. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5834. $result = $this->Form->hour('Model.field', false);
  5835. $expected = array(
  5836. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5837. array('option' => array('value' => '')),
  5838. '/option',
  5839. array('option' => array('value' => '01')),
  5840. '1',
  5841. '/option',
  5842. array('option' => array('value' => '02')),
  5843. '2',
  5844. '/option',
  5845. $hoursRegex,
  5846. array('option' => array('value' => '12', 'selected' => 'selected')),
  5847. '12',
  5848. '/option',
  5849. '/select',
  5850. );
  5851. $this->assertTags($result, $expected);
  5852. $this->Form->request->data['Model']['field'] = '';
  5853. $result = $this->Form->hour('Model.field', true, array('value' => '23'));
  5854. $this->assertContains('<option value="23" selected="selected">23</option>', $result);
  5855. $result = $this->Form->hour('Model.field', false, array('value' => '23'));
  5856. $this->assertContains('<option value="11" selected="selected">11</option>', $result);
  5857. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5858. $result = $this->Form->hour('Model.field', true);
  5859. $expected = array(
  5860. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5861. array('option' => array('value' => '')),
  5862. '/option',
  5863. array('option' => array('value' => '00', 'selected' => 'selected')),
  5864. '0',
  5865. '/option',
  5866. array('option' => array('value' => '01')),
  5867. '1',
  5868. '/option',
  5869. array('option' => array('value' => '02')),
  5870. '2',
  5871. '/option',
  5872. $hoursRegex,
  5873. '/select',
  5874. );
  5875. $this->assertTags($result, $expected);
  5876. unset($this->Form->request->data['Model']['field']);
  5877. $result = $this->Form->hour('Model.field', true, array('value' => 'now'));
  5878. $thisHour = date('H');
  5879. $optValue = date('G');
  5880. $this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
  5881. $this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
  5882. $result = $this->Form->hour('Model.field', true);
  5883. $expected = array(
  5884. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5885. array('option' => array('value' => '')),
  5886. '/option',
  5887. array('option' => array('value' => '00')),
  5888. '0',
  5889. '/option',
  5890. array('option' => array('value' => '01', 'selected' => 'selected')),
  5891. '1',
  5892. '/option',
  5893. array('option' => array('value' => '02')),
  5894. '2',
  5895. '/option',
  5896. $hoursRegex,
  5897. '/select',
  5898. );
  5899. $this->assertTags($result, $expected);
  5900. }
  5901. /**
  5902. * testYear method
  5903. *
  5904. * @return void
  5905. */
  5906. public function testYear() {
  5907. $this->markTestIncomplete('Need to revisit once models work again.');
  5908. $result = $this->Form->year('Model.field', 2006, 2007);
  5909. $expected = array(
  5910. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5911. array('option' => array('value' => '')),
  5912. '/option',
  5913. array('option' => array('value' => '2007')),
  5914. '2007',
  5915. '/option',
  5916. array('option' => array('value' => '2006')),
  5917. '2006',
  5918. '/option',
  5919. '/select',
  5920. );
  5921. $this->assertTags($result, $expected);
  5922. $result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
  5923. $expected = array(
  5924. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5925. array('option' => array('value' => '')),
  5926. '/option',
  5927. array('option' => array('value' => '2006')),
  5928. '2006',
  5929. '/option',
  5930. array('option' => array('value' => '2007')),
  5931. '2007',
  5932. '/option',
  5933. '/select',
  5934. );
  5935. $this->assertTags($result, $expected);
  5936. $this->request->data['Contact']['published'] = '';
  5937. $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
  5938. $expected = array(
  5939. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
  5940. array('option' => array('value' => '')),
  5941. '/option',
  5942. array('option' => array('value' => '2007')),
  5943. '2007',
  5944. '/option',
  5945. array('option' => array('value' => '2006')),
  5946. '2006',
  5947. '/option',
  5948. '/select',
  5949. );
  5950. $this->assertTags($result, $expected);
  5951. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  5952. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
  5953. $expected = array(
  5954. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5955. array('option' => array('value' => '2007')),
  5956. '2007',
  5957. '/option',
  5958. array('option' => array('value' => '2006', 'selected' => 'selected')),
  5959. '2006',
  5960. '/option',
  5961. '/select',
  5962. );
  5963. $this->assertTags($result, $expected);
  5964. $this->Form->request->data['Contact']['published'] = '';
  5965. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
  5966. $expected = array(
  5967. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5968. array('option' => array('value' => '')),
  5969. '/option',
  5970. array('option' => array('value' => '2007')),
  5971. '2007',
  5972. '/option',
  5973. array('option' => array('value' => '2006')),
  5974. '2006',
  5975. '/option',
  5976. '/select',
  5977. );
  5978. $this->assertTags($result, $expected);
  5979. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  5980. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
  5981. $expected = array(
  5982. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5983. array('option' => array('value' => '2007')),
  5984. '2007',
  5985. '/option',
  5986. array('option' => array('value' => '2006', 'selected' => 'selected')),
  5987. '2006',
  5988. '/option',
  5989. '/select',
  5990. );
  5991. $this->assertTags($result, $expected);
  5992. $this->Form->request->data['Contact']['published'] = '';
  5993. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
  5994. $expected = array(
  5995. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5996. array('option' => array('value' => '')),
  5997. '/option',
  5998. array('option' => array('value' => '2007', 'selected' => 'selected')),
  5999. '2007',
  6000. '/option',
  6001. array('option' => array('value' => '2006')),
  6002. '2006',
  6003. '/option',
  6004. '/select',
  6005. );
  6006. $this->assertTags($result, $expected);
  6007. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6008. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
  6009. $expected = array(
  6010. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6011. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6012. '2007',
  6013. '/option',
  6014. array('option' => array('value' => '2006')),
  6015. '2006',
  6016. '/option',
  6017. '/select',
  6018. );
  6019. $this->assertTags($result, $expected);
  6020. $this->Form->request->data['Contact']['published'] = '';
  6021. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
  6022. $expected = array(
  6023. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6024. array('option' => array('value' => '2008')),
  6025. '2008',
  6026. '/option',
  6027. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6028. '2007',
  6029. '/option',
  6030. array('option' => array('value' => '2006')),
  6031. '2006',
  6032. '/option',
  6033. '/select',
  6034. );
  6035. $this->assertTags($result, $expected);
  6036. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6037. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
  6038. $expected = array(
  6039. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6040. array('option' => array('value' => '2008')),
  6041. '2008',
  6042. '/option',
  6043. array('option' => array('value' => '2007')),
  6044. '2007',
  6045. '/option',
  6046. array('option' => array('value' => '2006', 'selected' => 'selected')),
  6047. '2006',
  6048. '/option',
  6049. '/select',
  6050. );
  6051. $this->assertTags($result, $expected);
  6052. $this->Form->request->data = array();
  6053. $this->Form->create('Contact');
  6054. $result = $this->Form->year('published', 2006, 2008, array('empty' => false));
  6055. $expected = array(
  6056. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6057. array('option' => array('value' => '2008')),
  6058. '2008',
  6059. '/option',
  6060. array('option' => array('value' => '2007')),
  6061. '2007',
  6062. '/option',
  6063. array('option' => array('value' => '2006')),
  6064. '2006',
  6065. '/option',
  6066. '/select',
  6067. );
  6068. $this->assertTags($result, $expected);
  6069. $result = $this->Form->year('published', array(), array(), array('empty' => false));
  6070. $this->assertContains('Contact[published][year]', $result);
  6071. }
  6072. /**
  6073. * testYearAutoExpandRange method
  6074. *
  6075. * @return void
  6076. */
  6077. public function testYearAutoExpandRange() {
  6078. $this->markTestIncomplete('Need to revisit once models work again.');
  6079. $this->Form->request->data['User']['birthday'] = '1930-10-10';
  6080. $result = $this->Form->year('User.birthday');
  6081. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6082. $result = $matches[1];
  6083. $expected = range(date('Y') + 20, 1930);
  6084. $this->assertEquals($expected, $result);
  6085. $this->Form->request->data['Project']['release'] = '2050-10-10';
  6086. $result = $this->Form->year('Project.release');
  6087. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6088. $result = $matches[1];
  6089. $expected = range(2050, date('Y') - 20);
  6090. $this->assertEquals($expected, $result);
  6091. $this->Form->request->data['Project']['release'] = '1881-10-10';
  6092. $result = $this->Form->year('Project.release', 1890, 1900);
  6093. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6094. $result = $matches[1];
  6095. $expected = range(1900, 1881);
  6096. $this->assertEquals($expected, $result);
  6097. }
  6098. /**
  6099. * testInputDate method
  6100. *
  6101. * Test various inputs with type date and different dateFormat values.
  6102. * Failing to provide a dateFormat key should not error.
  6103. * It should simply not pre-select any value then.
  6104. *
  6105. * @return void
  6106. */
  6107. public function testInputDate() {
  6108. $this->markTestIncomplete('Need to revisit once models work again.');
  6109. $this->Form->request->data = array(
  6110. 'User' => array(
  6111. 'month_year' => array('month' => date('m')),
  6112. 'just_year' => array('month' => date('m')),
  6113. 'just_month' => array('year' => date('Y')),
  6114. 'just_day' => array('month' => date('m')),
  6115. )
  6116. );
  6117. $this->Form->create('User');
  6118. $result = $this->Form->input('month_year',
  6119. array(
  6120. 'label' => false,
  6121. 'div' => false,
  6122. 'type' => 'date',
  6123. 'dateFormat' => 'MY',
  6124. 'minYear' => 2006,
  6125. 'maxYear' => 2008
  6126. )
  6127. );
  6128. $this->assertContains('value="' . date('m') . '" selected="selected"', $result);
  6129. $this->assertNotContains('value="2008" selected="selected"', $result);
  6130. $result = $this->Form->input('just_year',
  6131. array(
  6132. 'type' => 'date',
  6133. 'label' => false,
  6134. 'dateFormat' => 'Y',
  6135. 'minYear' => date('Y'),
  6136. 'maxYear' => date('Y', strtotime('+20 years'))
  6137. )
  6138. );
  6139. $this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
  6140. $result = $this->Form->input('just_month',
  6141. array(
  6142. 'type' => 'date',
  6143. 'label' => false,
  6144. 'dateFormat' => 'M',
  6145. 'empty' => false,
  6146. )
  6147. );
  6148. $this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
  6149. $result = $this->Form->input('just_day',
  6150. array(
  6151. 'type' => 'date',
  6152. 'label' => false,
  6153. 'dateFormat' => 'D',
  6154. 'empty' => false,
  6155. )
  6156. );
  6157. $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
  6158. }
  6159. /**
  6160. * testInputDateMaxYear method
  6161. *
  6162. * Let's say we want to only allow users born from 2006 to 2008 to register
  6163. * This being the first singup page, we still don't have any data
  6164. *
  6165. * @return void
  6166. */
  6167. public function testInputDateMaxYear() {
  6168. $this->markTestIncomplete('Need to revisit once models work again.');
  6169. $this->Form->request->data = array();
  6170. $this->Form->create('User');
  6171. $result = $this->Form->input('birthday',
  6172. array(
  6173. 'label' => false,
  6174. 'div' => false,
  6175. 'type' => 'date',
  6176. 'dateFormat' => 'DMY',
  6177. 'minYear' => 2006,
  6178. 'maxYear' => 2008
  6179. )
  6180. );
  6181. $this->assertContains('value="2008" selected="selected"', $result);
  6182. }
  6183. /**
  6184. * testTextArea method
  6185. *
  6186. * @return void
  6187. */
  6188. public function testTextArea() {
  6189. $this->Form->request->data = array('field' => 'some test data');
  6190. $result = $this->Form->textarea('field');
  6191. $expected = array(
  6192. 'textarea' => array('name' => 'field'),
  6193. 'some test data',
  6194. '/textarea',
  6195. );
  6196. $this->assertTags($result, $expected);
  6197. $result = $this->Form->textarea('user.bio');
  6198. $expected = array(
  6199. 'textarea' => array('name' => 'user[bio]'),
  6200. '/textarea',
  6201. );
  6202. $this->assertTags($result, $expected);
  6203. $this->Form->request->data = array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars');
  6204. $result = $this->Form->textarea('field');
  6205. $expected = array(
  6206. 'textarea' => array('name' => 'field'),
  6207. htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
  6208. '/textarea',
  6209. );
  6210. $this->assertTags($result, $expected);
  6211. $this->Form->request->data = [
  6212. 'Model' => ['field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars']
  6213. ];
  6214. $result = $this->Form->textarea('Model.field', ['escape' => false]);
  6215. $expected = array(
  6216. 'textarea' => array('name' => 'Model[field]'),
  6217. 'some <strong>test</strong> data with <a href="#">HTML</a> chars',
  6218. '/textarea',
  6219. );
  6220. $this->assertTags($result, $expected);
  6221. $result = $this->Form->textarea('0.OtherModel.field');
  6222. $expected = array(
  6223. 'textarea' => array('name' => '0[OtherModel][field]'),
  6224. '/textarea'
  6225. );
  6226. $this->assertTags($result, $expected);
  6227. }
  6228. /**
  6229. * testTextAreaWithStupidCharacters method
  6230. *
  6231. * test text area with non-ascii characters
  6232. *
  6233. * @return void
  6234. */
  6235. public function testTextAreaWithStupidCharacters() {
  6236. $result = $this->Form->textarea('Post.content', [
  6237. 'value' => "GREAT®",
  6238. 'rows' => '15',
  6239. 'cols' => '75'
  6240. ]);
  6241. $expected = [
  6242. 'textarea' => ['name' => 'Post[content]', 'rows' => '15', 'cols' => '75'],
  6243. 'GREAT®',
  6244. '/textarea',
  6245. ];
  6246. $this->assertTags($result, $expected);
  6247. }
  6248. /**
  6249. * testHiddenField method
  6250. *
  6251. * @return void
  6252. */
  6253. public function testHiddenField() {
  6254. $this->article['errors'] = [
  6255. 'field' => true
  6256. ];
  6257. $this->Form->request->data['field'] = 'test';
  6258. $this->Form->create($this->article);
  6259. $result = $this->Form->hidden('field', array('id' => 'theID'));
  6260. $this->assertTags($result, array(
  6261. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'id' => 'theID', 'value' => 'test'))
  6262. );
  6263. $result = $this->Form->hidden('field', ['value' => 'my value']);
  6264. $expected = [
  6265. 'input' => ['type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'value' => 'my value']
  6266. ];
  6267. $this->assertTags($result, $expected);
  6268. }
  6269. /**
  6270. * testFileUploadField method
  6271. *
  6272. * @return void
  6273. */
  6274. public function testFileUploadField() {
  6275. $expected = ['input' => ['type' => 'file', 'name' => 'Model[upload]']];
  6276. $result = $this->Form->file('Model.upload');
  6277. $this->assertTags($result, $expected);
  6278. $this->Form->request->data['Model']['upload'] = [
  6279. 'name' => '', 'type' => '', 'tmp_name' => '',
  6280. 'error' => 4, 'size' => 0
  6281. ];
  6282. $result = $this->Form->file('Model.upload');
  6283. $this->assertTags($result, $expected);
  6284. $this->Form->request->data['Model']['upload'] = 'no data should be set in value';
  6285. $result = $this->Form->file('Model.upload');
  6286. $this->assertTags($result, $expected);
  6287. }
  6288. /**
  6289. * test File upload input on a model not used in create();
  6290. *
  6291. * @return void
  6292. */
  6293. public function testFileUploadOnOtherModel() {
  6294. $this->Form->create($this->article, array('type' => 'file'));
  6295. $result = $this->Form->file('ValidateProfile.city');
  6296. $expected = array(
  6297. 'input' => array('type' => 'file', 'name' => 'ValidateProfile[city]')
  6298. );
  6299. $this->assertTags($result, $expected);
  6300. }
  6301. /**
  6302. * testButton method
  6303. *
  6304. * @return void
  6305. */
  6306. public function testButton() {
  6307. $result = $this->Form->button('Hi');
  6308. $this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
  6309. $result = $this->Form->button('Clear Form >', array('type' => 'reset'));
  6310. $this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
  6311. $result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
  6312. $this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
  6313. $result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
  6314. $this->assertTags($result, array('button' => array('type' => 'reset'), '&lt;Clear Form&gt;', '/button'));
  6315. $result = $this->Form->button('No type', array('type' => false));
  6316. $this->assertTags($result, array('button' => array(), 'No type', '/button'));
  6317. $result = $this->Form->button('Upload Text', array(
  6318. 'onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'",
  6319. 'escape' => false
  6320. ));
  6321. $this->assertNotRegExp('/\&039/', $result);
  6322. }
  6323. /**
  6324. * Test that button() makes unlocked fields by default.
  6325. *
  6326. * @return void
  6327. */
  6328. public function testButtonUnlockedByDefault() {
  6329. $this->Form->request->params['_csrfToken'] = 'secured';
  6330. $this->Form->button('Save', array('name' => 'save'));
  6331. $this->Form->button('Clear');
  6332. $result = $this->Form->unlockField();
  6333. $this->assertEquals(array('save'), $result);
  6334. }
  6335. /**
  6336. * testPostButton method
  6337. *
  6338. * @return void
  6339. */
  6340. public function testPostButton() {
  6341. $result = $this->Form->postButton('Hi', '/controller/action');
  6342. $this->assertTags($result, array(
  6343. 'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
  6344. 'div' => array('style' => 'display:none;'),
  6345. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6346. '/div',
  6347. 'button' => array('type' => 'submit'),
  6348. 'Hi',
  6349. '/button',
  6350. '/form'
  6351. ));
  6352. $result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
  6353. $this->assertTrue(strpos($result, '<input type="hidden" name="extra" value="value"') !== false);
  6354. }
  6355. /**
  6356. * Test that postButton adds _Token fields.
  6357. *
  6358. * @return void
  6359. */
  6360. public function testSecurePostButton() {
  6361. $this->Form->request->params['_csrfToken'] = 'testkey';
  6362. $this->Form->request->params['_Token'] = ['unlockedFields' => []];
  6363. $result = $this->Form->postButton('Delete', '/posts/delete/1');
  6364. $expected = array(
  6365. 'form' => array(
  6366. 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
  6367. ),
  6368. array('div' => array('style' => 'display:none;')),
  6369. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6370. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6371. '/div',
  6372. 'button' => array('type' => 'submit'),
  6373. 'Delete',
  6374. '/button',
  6375. array('div' => array('style' => 'display:none;')),
  6376. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6377. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6378. '/div',
  6379. '/form',
  6380. );
  6381. $this->assertTags($result, $expected);
  6382. }
  6383. /**
  6384. * testPostLink method
  6385. *
  6386. * @return void
  6387. */
  6388. public function testPostLink() {
  6389. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6390. $this->assertTags($result, array(
  6391. 'form' => array(
  6392. 'method' => 'post', 'action' => '/posts/delete/1',
  6393. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6394. ),
  6395. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6396. '/form',
  6397. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6398. 'Delete',
  6399. '/a'
  6400. ));
  6401. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
  6402. $this->assertTags($result, array(
  6403. 'form' => array(
  6404. 'method' => 'post', 'action' => '/posts/delete/1',
  6405. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6406. ),
  6407. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
  6408. '/form',
  6409. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6410. 'Delete',
  6411. '/a'
  6412. ));
  6413. $result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
  6414. $this->assertTags($result, array(
  6415. 'form' => array(
  6416. 'method' => 'post', 'action' => '/posts/delete/1',
  6417. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6418. ),
  6419. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6420. '/form',
  6421. 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\(&quot;Confirm\?&quot;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6422. 'Delete',
  6423. '/a'
  6424. ));
  6425. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
  6426. $this->assertTags($result, array(
  6427. 'form' => array(
  6428. 'method' => 'post', 'action' => '/posts/delete/1',
  6429. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6430. ),
  6431. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6432. '/form',
  6433. '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;/'),
  6434. 'Delete',
  6435. '/a'
  6436. ));
  6437. $result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
  6438. $this->assertContains('<input type="hidden" name="id" value="1"', $result);
  6439. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
  6440. $this->assertTags($result, array(
  6441. 'form' => array(
  6442. 'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
  6443. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6444. ),
  6445. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6446. '/form',
  6447. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6448. 'Delete',
  6449. '/a'
  6450. ));
  6451. $result = $this->Form->postLink(
  6452. '',
  6453. array('controller' => 'items', 'action' => 'delete', 10),
  6454. array('class' => 'btn btn-danger', 'escape' => false),
  6455. 'Confirm thing'
  6456. );
  6457. $this->assertTags($result, array(
  6458. 'form' => array(
  6459. 'method' => 'post', 'action' => '/items/delete/10',
  6460. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6461. ),
  6462. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6463. '/form',
  6464. 'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\&quot\;Confirm thing\&quot\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6465. '/a'
  6466. ));
  6467. }
  6468. /**
  6469. * test creating postLinks after a GET form.
  6470. *
  6471. * @return void
  6472. */
  6473. public function testPostLinkAfterGetForm() {
  6474. $this->Form->request->params['_csrfToken'] = 'testkey';
  6475. $this->Form->request->params['_Token'] = 'val';
  6476. $this->Form->create($this->article, array('type' => 'get'));
  6477. $this->Form->end();
  6478. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6479. $this->assertTags($result, array(
  6480. 'form' => array(
  6481. 'method' => 'post', 'action' => '/posts/delete/1',
  6482. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6483. ),
  6484. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6485. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6486. 'div' => array('style' => 'display:none;'),
  6487. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6488. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6489. '/div',
  6490. '/form',
  6491. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6492. 'Delete',
  6493. '/a'
  6494. ));
  6495. }
  6496. /**
  6497. * Test that postLink adds form tags to view block
  6498. *
  6499. * @return void
  6500. */
  6501. public function testPostLinkFormBuffer() {
  6502. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
  6503. $this->assertTags($result, array(
  6504. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6505. 'Delete',
  6506. '/a'
  6507. ));
  6508. $result = $this->View->fetch('postLink');
  6509. $this->assertTags($result, array(
  6510. 'form' => array(
  6511. 'method' => 'post', 'action' => '/posts/delete/1',
  6512. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6513. ),
  6514. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6515. '/form'
  6516. ));
  6517. $result = $this->Form->postLink('Delete', '/posts/delete/2',
  6518. array('inline' => false, 'method' => 'DELETE')
  6519. );
  6520. $this->assertTags($result, array(
  6521. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6522. 'Delete',
  6523. '/a'
  6524. ));
  6525. $result = $this->View->fetch('postLink');
  6526. $this->assertTags($result, array(
  6527. 'form' => array(
  6528. 'method' => 'post', 'action' => '/posts/delete/1',
  6529. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6530. ),
  6531. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6532. '/form',
  6533. array(
  6534. 'form' => array(
  6535. 'method' => 'post', 'action' => '/posts/delete/2',
  6536. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6537. ),
  6538. ),
  6539. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
  6540. '/form'
  6541. ));
  6542. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'foobar'));
  6543. $this->assertTags($result, array(
  6544. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6545. 'Delete',
  6546. '/a'
  6547. ));
  6548. $result = $this->View->fetch('foobar');
  6549. $this->assertTags($result, array(
  6550. 'form' => array(
  6551. 'method' => 'post', 'action' => '/posts/delete/1',
  6552. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6553. ),
  6554. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6555. '/form'
  6556. ));
  6557. }
  6558. /**
  6559. * testSubmitButton method
  6560. *
  6561. * @return void
  6562. */
  6563. public function testSubmitButton() {
  6564. $this->markTestIncomplete('Need to revisit once models work again.');
  6565. $result = $this->Form->submit('');
  6566. $expected = array(
  6567. 'div' => array('class' => 'submit'),
  6568. 'input' => array('type' => 'submit', 'value' => ''),
  6569. '/div'
  6570. );
  6571. $this->assertTags($result, $expected);
  6572. $result = $this->Form->submit('Test Submit');
  6573. $expected = array(
  6574. 'div' => array('class' => 'submit'),
  6575. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6576. '/div'
  6577. );
  6578. $this->assertTags($result, $expected);
  6579. $result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
  6580. $expected = array(
  6581. 'span' => array('class' => 'submit'),
  6582. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6583. '/span'
  6584. );
  6585. $this->assertTags($result, $expected);
  6586. $result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
  6587. $expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
  6588. $this->assertTags($result, $expected);
  6589. $result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
  6590. $expected = array(
  6591. 'div' => array('class' => 'submit', 'id' => 'SaveButton'),
  6592. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6593. '/div'
  6594. );
  6595. $this->assertTags($result, $expected);
  6596. $result = $this->Form->submit('Next >');
  6597. $expected = array(
  6598. 'div' => array('class' => 'submit'),
  6599. 'input' => array('type' => 'submit', 'value' => 'Next &gt;'),
  6600. '/div'
  6601. );
  6602. $this->assertTags($result, $expected);
  6603. $result = $this->Form->submit('Next >', array('escape' => false));
  6604. $expected = array(
  6605. 'div' => array('class' => 'submit'),
  6606. 'input' => array('type' => 'submit', 'value' => 'Next >'),
  6607. '/div'
  6608. );
  6609. $this->assertTags($result, $expected);
  6610. $result = $this->Form->submit('Reset!', array('type' => 'reset'));
  6611. $expected = array(
  6612. 'div' => array('class' => 'submit'),
  6613. 'input' => array('type' => 'reset', 'value' => 'Reset!'),
  6614. '/div'
  6615. );
  6616. $this->assertTags($result, $expected);
  6617. $before = '--before--';
  6618. $after = '--after--';
  6619. $result = $this->Form->submit('Test', array('before' => $before));
  6620. $expected = array(
  6621. 'div' => array('class' => 'submit'),
  6622. '--before--',
  6623. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6624. '/div'
  6625. );
  6626. $this->assertTags($result, $expected);
  6627. $result = $this->Form->submit('Test', array('after' => $after));
  6628. $expected = array(
  6629. 'div' => array('class' => 'submit'),
  6630. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6631. '--after--',
  6632. '/div'
  6633. );
  6634. $this->assertTags($result, $expected);
  6635. $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
  6636. $expected = array(
  6637. 'div' => array('class' => 'submit'),
  6638. '--before--',
  6639. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6640. '--after--',
  6641. '/div'
  6642. );
  6643. $this->assertTags($result, $expected);
  6644. }
  6645. /**
  6646. * test image submit types.
  6647. *
  6648. * @return void
  6649. */
  6650. public function testSubmitImage() {
  6651. $this->markTestIncomplete('Need to revisit once models work again.');
  6652. $result = $this->Form->submit('http://example.com/cake.power.gif');
  6653. $expected = array(
  6654. 'div' => array('class' => 'submit'),
  6655. 'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
  6656. '/div'
  6657. );
  6658. $this->assertTags($result, $expected);
  6659. $result = $this->Form->submit('/relative/cake.power.gif');
  6660. $expected = array(
  6661. 'div' => array('class' => 'submit'),
  6662. 'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
  6663. '/div'
  6664. );
  6665. $this->assertTags($result, $expected);
  6666. $result = $this->Form->submit('cake.power.gif');
  6667. $expected = array(
  6668. 'div' => array('class' => 'submit'),
  6669. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6670. '/div'
  6671. );
  6672. $this->assertTags($result, $expected);
  6673. $result = $this->Form->submit('Not.an.image');
  6674. $expected = array(
  6675. 'div' => array('class' => 'submit'),
  6676. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6677. '/div'
  6678. );
  6679. $this->assertTags($result, $expected);
  6680. $after = '--after--';
  6681. $before = '--before--';
  6682. $result = $this->Form->submit('cake.power.gif', array('after' => $after));
  6683. $expected = array(
  6684. 'div' => array('class' => 'submit'),
  6685. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6686. '--after--',
  6687. '/div'
  6688. );
  6689. $this->assertTags($result, $expected);
  6690. $result = $this->Form->submit('cake.power.gif', array('before' => $before));
  6691. $expected = array(
  6692. 'div' => array('class' => 'submit'),
  6693. '--before--',
  6694. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6695. '/div'
  6696. );
  6697. $this->assertTags($result, $expected);
  6698. $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
  6699. $expected = array(
  6700. 'div' => array('class' => 'submit'),
  6701. '--before--',
  6702. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6703. '--after--',
  6704. '/div'
  6705. );
  6706. $this->assertTags($result, $expected);
  6707. $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
  6708. $expected = array(
  6709. 'div' => array('class' => 'submit'),
  6710. '--before--',
  6711. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6712. '--after--',
  6713. '/div'
  6714. );
  6715. $this->assertTags($result, $expected);
  6716. }
  6717. /**
  6718. * Submit buttons should be unlocked by default as there could be multiples, and only one will
  6719. * be submitted at a time.
  6720. *
  6721. * @return void
  6722. */
  6723. public function testSubmitUnlockedByDefault() {
  6724. $this->markTestIncomplete('Need to revisit once models work again.');
  6725. $this->Form->request->params['_csrfToken'] = 'secured';
  6726. $this->Form->submit('Go go');
  6727. $this->Form->submit('Save', array('name' => 'save'));
  6728. $result = $this->Form->unlockField();
  6729. $this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
  6730. }
  6731. /**
  6732. * Test submit image with timestamps.
  6733. *
  6734. * @return void
  6735. */
  6736. public function testSubmitImageTimestamp() {
  6737. $this->markTestIncomplete('Need to revisit once models work again.');
  6738. Configure::write('Asset.timestamp', 'force');
  6739. $result = $this->Form->submit('cake.power.gif');
  6740. $expected = array(
  6741. 'div' => array('class' => 'submit'),
  6742. 'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
  6743. '/div'
  6744. );
  6745. $this->assertTags($result, $expected);
  6746. }
  6747. /**
  6748. * test that datetime() works with GET style forms.
  6749. *
  6750. * @return void
  6751. */
  6752. public function testDateTimeWithGetForms() {
  6753. $this->markTestIncomplete('Need to revisit once models work again.');
  6754. extract($this->dateRegex);
  6755. $this->Form->create('Contact', array('type' => 'get'));
  6756. $result = $this->Form->datetime('created');
  6757. $this->assertRegExp('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
  6758. $this->assertRegExp('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
  6759. $this->assertRegExp('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
  6760. $this->assertRegExp('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
  6761. $this->assertRegExp('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
  6762. $this->assertRegExp('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
  6763. }
  6764. /**
  6765. * testEditFormWithData method
  6766. *
  6767. * test auto populating form elements from submitted data.
  6768. *
  6769. * @return void
  6770. */
  6771. public function testEditFormWithData() {
  6772. $this->markTestIncomplete('Need to revisit once models work again.');
  6773. $this->Form->request->data = array('Person' => array(
  6774. 'id' => 1,
  6775. 'first_name' => 'Nate',
  6776. 'last_name' => 'Abele',
  6777. 'email' => 'nate@example.com'
  6778. ));
  6779. $this->Form->request->addParams(array(
  6780. 'models' => array('Person'),
  6781. 'controller' => 'people',
  6782. 'action' => 'add'
  6783. ));
  6784. $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
  6785. $this->Form->create();
  6786. $result = $this->Form->select('People.People', $options, array('multiple' => true));
  6787. $expected = array(
  6788. 'input' => array('type' => 'hidden', 'name' => 'People[People]', 'value' => '', 'id' => 'PeoplePeople_'),
  6789. 'select' => array(
  6790. 'name' => 'People[People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
  6791. ),
  6792. array('option' => array('value' => 1)), 'Nate', '/option',
  6793. array('option' => array('value' => 2)), 'Garrett', '/option',
  6794. array('option' => array('value' => 3)), 'Larry', '/option',
  6795. '/select'
  6796. );
  6797. $this->assertTags($result, $expected);
  6798. }
  6799. /**
  6800. * Test that required fields are created for various types of validation.
  6801. *
  6802. * @return void
  6803. */
  6804. public function testFormInputRequiredDetection() {
  6805. $this->markTestIncomplete('Need to revisit once models work again.');
  6806. $this->Form->create('Contact');
  6807. $result = $this->Form->input('Contact.non_existing');
  6808. $expected = array(
  6809. 'div' => array('class' => 'input text'),
  6810. 'label' => array('for' => 'ContactNonExisting'),
  6811. 'Non Existing',
  6812. '/label',
  6813. 'input' => array(
  6814. 'type' => 'text', 'name' => 'Contact[non_existing]',
  6815. 'id' => 'ContactNonExisting'
  6816. ),
  6817. '/div'
  6818. );
  6819. $this->assertTags($result, $expected);
  6820. $result = $this->Form->input('Contact.imrequired');
  6821. $expected = array(
  6822. 'div' => array('class' => 'input text required'),
  6823. 'label' => array('for' => 'ContactImrequired'),
  6824. 'Imrequired',
  6825. '/label',
  6826. 'input' => array(
  6827. 'type' => 'text', 'name' => 'Contact[imrequired]',
  6828. 'id' => 'ContactImrequired',
  6829. 'required' => 'required'
  6830. ),
  6831. '/div'
  6832. );
  6833. $this->assertTags($result, $expected);
  6834. $result = $this->Form->input('Contact.imalsorequired');
  6835. $expected = array(
  6836. 'div' => array('class' => 'input text required'),
  6837. 'label' => array('for' => 'ContactImalsorequired'),
  6838. 'Imalsorequired',
  6839. '/label',
  6840. 'input' => array(
  6841. 'type' => 'text', 'name' => 'Contact[imalsorequired]',
  6842. 'id' => 'ContactImalsorequired',
  6843. 'required' => 'required'
  6844. ),
  6845. '/div'
  6846. );
  6847. $this->assertTags($result, $expected);
  6848. $result = $this->Form->input('Contact.imrequiredtoo');
  6849. $expected = array(
  6850. 'div' => array('class' => 'input text required'),
  6851. 'label' => array('for' => 'ContactImrequiredtoo'),
  6852. 'Imrequiredtoo',
  6853. '/label',
  6854. 'input' => array(
  6855. 'type' => 'text', 'name' => 'Contact[imrequiredtoo]',
  6856. 'id' => 'ContactImrequiredtoo',
  6857. 'required' => 'required'
  6858. ),
  6859. '/div'
  6860. );
  6861. $this->assertTags($result, $expected);
  6862. $result = $this->Form->input('Contact.required_one');
  6863. $expected = array(
  6864. 'div' => array('class' => 'input text required'),
  6865. 'label' => array('for' => 'ContactRequiredOne'),
  6866. 'Required One',
  6867. '/label',
  6868. 'input' => array(
  6869. 'type' => 'text', 'name' => 'Contact[required_one]',
  6870. 'id' => 'ContactRequiredOne',
  6871. 'required' => 'required'
  6872. ),
  6873. '/div'
  6874. );
  6875. $this->assertTags($result, $expected);
  6876. $result = $this->Form->input('Contact.string_required');
  6877. $expected = array(
  6878. 'div' => array('class' => 'input text required'),
  6879. 'label' => array('for' => 'ContactStringRequired'),
  6880. 'String Required',
  6881. '/label',
  6882. 'input' => array(
  6883. 'type' => 'text', 'name' => 'Contact[string_required]',
  6884. 'id' => 'ContactStringRequired',
  6885. 'required' => 'required'
  6886. ),
  6887. '/div'
  6888. );
  6889. $this->assertTags($result, $expected);
  6890. $result = $this->Form->input('Contact.imnotrequired');
  6891. $expected = array(
  6892. 'div' => array('class' => 'input text'),
  6893. 'label' => array('for' => 'ContactImnotrequired'),
  6894. 'Imnotrequired',
  6895. '/label',
  6896. 'input' => array(
  6897. 'type' => 'text', 'name' => 'Contact[imnotrequired]',
  6898. 'id' => 'ContactImnotrequired'
  6899. ),
  6900. '/div'
  6901. );
  6902. $this->assertTags($result, $expected);
  6903. $result = $this->Form->input('Contact.imalsonotrequired');
  6904. $expected = array(
  6905. 'div' => array('class' => 'input text'),
  6906. 'label' => array('for' => 'ContactImalsonotrequired'),
  6907. 'Imalsonotrequired',
  6908. '/label',
  6909. 'input' => array(
  6910. 'type' => 'text', 'name' => 'Contact[imalsonotrequired]',
  6911. 'id' => 'ContactImalsonotrequired'
  6912. ),
  6913. '/div'
  6914. );
  6915. $this->assertTags($result, $expected);
  6916. $result = $this->Form->input('Contact.imalsonotrequired2');
  6917. $expected = array(
  6918. 'div' => array('class' => 'input text'),
  6919. 'label' => array('for' => 'ContactImalsonotrequired2'),
  6920. 'Imalsonotrequired2',
  6921. '/label',
  6922. 'input' => array(
  6923. 'type' => 'text', 'name' => 'Contact[imalsonotrequired2]',
  6924. 'id' => 'ContactImalsonotrequired2'
  6925. ),
  6926. '/div'
  6927. );
  6928. $this->assertTags($result, $expected);
  6929. $result = $this->Form->input('Contact.imnotrequiredeither');
  6930. $expected = array(
  6931. 'div' => array('class' => 'input text'),
  6932. 'label' => array('for' => 'ContactImnotrequiredeither'),
  6933. 'Imnotrequiredeither',
  6934. '/label',
  6935. 'input' => array(
  6936. 'type' => 'text', 'name' => 'Contact[imnotrequiredeither]',
  6937. 'id' => 'ContactImnotrequiredeither'
  6938. ),
  6939. '/div'
  6940. );
  6941. $this->assertTags($result, $expected);
  6942. $result = $this->Form->input('Contact.iamrequiredalways');
  6943. $expected = array(
  6944. 'div' => array('class' => 'input text required'),
  6945. 'label' => array('for' => 'ContactIamrequiredalways'),
  6946. 'Iamrequiredalways',
  6947. '/label',
  6948. 'input' => array(
  6949. 'type' => 'text', 'name' => 'Contact[iamrequiredalways]',
  6950. 'id' => 'ContactIamrequiredalways',
  6951. 'required' => 'required'
  6952. ),
  6953. '/div'
  6954. );
  6955. $this->assertTags($result, $expected);
  6956. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
  6957. $expected = array(
  6958. 'div' => array('class' => 'input checkbox required'),
  6959. array('input' => array(
  6960. 'type' => 'hidden',
  6961. 'name' => 'Contact[boolean_field]',
  6962. 'id' => 'ContactBooleanField_',
  6963. 'value' => '0'
  6964. )),
  6965. array('input' => array(
  6966. 'type' => 'checkbox',
  6967. 'name' => 'Contact[boolean_field]',
  6968. 'value' => '1',
  6969. 'id' => 'ContactBooleanField'
  6970. )),
  6971. 'label' => array('for' => 'ContactBooleanField'),
  6972. 'Boolean Field',
  6973. '/label',
  6974. '/div'
  6975. );
  6976. $this->assertTags($result, $expected);
  6977. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
  6978. $expected = array(
  6979. 'div' => array('class' => 'input checkbox required'),
  6980. array('input' => array(
  6981. 'type' => 'hidden',
  6982. 'name' => 'Contact[boolean_field]',
  6983. 'id' => 'ContactBooleanField_',
  6984. 'value' => '0'
  6985. )),
  6986. array('input' => array(
  6987. 'type' => 'checkbox',
  6988. 'name' => 'Contact[boolean_field]',
  6989. 'value' => '1',
  6990. 'id' => 'ContactBooleanField',
  6991. 'required' => 'required'
  6992. )),
  6993. 'label' => array('for' => 'ContactBooleanField'),
  6994. 'Boolean Field',
  6995. '/label',
  6996. '/div'
  6997. );
  6998. $this->assertTags($result, $expected);
  6999. $result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
  7000. $expected = array(
  7001. 'div' => array('class' => 'input file required'),
  7002. 'label' => array('for' => 'ContactIamrequiredalways'),
  7003. 'Iamrequiredalways',
  7004. '/label',
  7005. 'input' => array(
  7006. 'type' => 'file',
  7007. 'name' => 'data[Contact][iamrequiredalways]',
  7008. 'id' => 'ContactIamrequiredalways',
  7009. 'required' => 'required'
  7010. ),
  7011. '/div'
  7012. );
  7013. $this->assertTags($result, $expected);
  7014. }
  7015. /**
  7016. * Test that required fields are created when only using ModelValidator::add().
  7017. *
  7018. * @return void
  7019. */
  7020. public function testFormInputRequiredDetectionModelValidator() {
  7021. $this->markTestIncomplete('Need to revisit once models work again.');
  7022. $this->Form->create('ContactTag');
  7023. $result = $this->Form->input('ContactTag.iwillberequired');
  7024. $expected = array(
  7025. 'div' => array('class' => 'input text required'),
  7026. 'label' => array('for' => 'ContactTagIwillberequired'),
  7027. 'Iwillberequired',
  7028. '/label',
  7029. 'input' => array(
  7030. 'name' => 'data[ContactTag][iwillberequired]',
  7031. 'type' => 'text',
  7032. 'id' => 'ContactTagIwillberequired',
  7033. 'required' => 'required'
  7034. ),
  7035. '/div'
  7036. );
  7037. $this->assertTags($result, $expected);
  7038. }
  7039. /**
  7040. * testFormMagicInput method
  7041. *
  7042. * @return void
  7043. */
  7044. public function testFormMagicInput() {
  7045. $this->markTestIncomplete('Need to revisit once models work again.');
  7046. $encoding = strtolower(Configure::read('App.encoding'));
  7047. $result = $this->Form->create('Contact');
  7048. $expected = array(
  7049. 'form' => array(
  7050. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7051. 'accept-charset' => $encoding
  7052. ),
  7053. 'div' => array('style' => 'display:none;'),
  7054. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7055. '/div'
  7056. );
  7057. $this->assertTags($result, $expected);
  7058. $result = $this->Form->input('name');
  7059. $expected = array(
  7060. 'div' => array('class' => 'input text'),
  7061. 'label' => array('for' => 'ContactName'),
  7062. 'Name',
  7063. '/label',
  7064. 'input' => array(
  7065. 'type' => 'text', 'name' => 'Contact[name]',
  7066. 'id' => 'ContactName', 'maxlength' => '255'
  7067. ),
  7068. '/div'
  7069. );
  7070. $this->assertTags($result, $expected);
  7071. $result = $this->Form->input('non_existing_field_in_contact_model');
  7072. $expected = array(
  7073. 'div' => array('class' => 'input text'),
  7074. 'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
  7075. 'Non Existing Field In Contact Model',
  7076. '/label',
  7077. 'input' => array(
  7078. 'type' => 'text', 'name' => 'Contact[non_existing_field_in_contact_model]',
  7079. 'id' => 'ContactNonExistingFieldInContactModel'
  7080. ),
  7081. '/div'
  7082. );
  7083. $this->assertTags($result, $expected);
  7084. $result = $this->Form->input('Address.street');
  7085. $expected = array(
  7086. 'div' => array('class' => 'input text'),
  7087. 'label' => array('for' => 'AddressStreet'),
  7088. 'Street',
  7089. '/label',
  7090. 'input' => array(
  7091. 'type' => 'text', 'name' => 'Address[street]',
  7092. 'id' => 'AddressStreet'
  7093. ),
  7094. '/div'
  7095. );
  7096. $this->assertTags($result, $expected);
  7097. $result = $this->Form->input('Address.non_existing_field_in_model');
  7098. $expected = array(
  7099. 'div' => array('class' => 'input text'),
  7100. 'label' => array('for' => 'AddressNonExistingFieldInModel'),
  7101. 'Non Existing Field In Model',
  7102. '/label',
  7103. 'input' => array(
  7104. 'type' => 'text', 'name' => 'Address[non_existing_field_in_model]',
  7105. 'id' => 'AddressNonExistingFieldInModel'
  7106. ),
  7107. '/div'
  7108. );
  7109. $this->assertTags($result, $expected);
  7110. $result = $this->Form->input('name', array('div' => false));
  7111. $expected = array(
  7112. 'label' => array('for' => 'ContactName'),
  7113. 'Name',
  7114. '/label',
  7115. 'input' => array(
  7116. 'type' => 'text', 'name' => 'Contact[name]',
  7117. 'id' => 'ContactName', 'maxlength' => '255'
  7118. )
  7119. );
  7120. $this->assertTags($result, $expected);
  7121. extract($this->dateRegex);
  7122. $now = strtotime('now');
  7123. $result = $this->Form->input('Contact.published', array('div' => false));
  7124. $expected = array(
  7125. 'label' => array('for' => 'ContactPublishedMonth'),
  7126. 'Published',
  7127. '/label',
  7128. array('select' => array(
  7129. 'name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth'
  7130. )),
  7131. $monthsRegex,
  7132. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7133. date('F', $now),
  7134. '/option',
  7135. '*/select',
  7136. '-',
  7137. array('select' => array(
  7138. 'name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay'
  7139. )),
  7140. $daysRegex,
  7141. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7142. date('j', $now),
  7143. '/option',
  7144. '*/select',
  7145. '-',
  7146. array('select' => array(
  7147. 'name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear'
  7148. )),
  7149. $yearsRegex,
  7150. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7151. date('Y', $now),
  7152. '*/select'
  7153. );
  7154. $this->assertTags($result, $expected);
  7155. $result = $this->Form->input('Contact.updated', array('div' => false));
  7156. $expected = array(
  7157. 'label' => array('for' => 'ContactUpdatedMonth'),
  7158. 'Updated',
  7159. '/label',
  7160. array('select' => array(
  7161. 'name' => 'Contact[updated][month]', 'id' => 'ContactUpdatedMonth'
  7162. )),
  7163. $monthsRegex,
  7164. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7165. date('F', $now),
  7166. '/option',
  7167. '*/select',
  7168. '-',
  7169. array('select' => array(
  7170. 'name' => 'Contact[updated][day]', 'id' => 'ContactUpdatedDay'
  7171. )),
  7172. $daysRegex,
  7173. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7174. date('j', $now),
  7175. '/option',
  7176. '*/select',
  7177. '-',
  7178. array('select' => array(
  7179. 'name' => 'Contact[updated][year]', 'id' => 'ContactUpdatedYear'
  7180. )),
  7181. $yearsRegex,
  7182. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7183. date('Y', $now),
  7184. '*/select'
  7185. );
  7186. $this->assertTags($result, $expected);
  7187. $result = $this->Form->input('UserForm.stuff');
  7188. $expected = array(
  7189. 'div' => array('class' => 'input text'),
  7190. 'label' => array('for' => 'UserFormStuff'),
  7191. 'Stuff',
  7192. '/label',
  7193. 'input' => array(
  7194. 'type' => 'text', 'name' => 'UserForm[stuff]',
  7195. 'id' => 'UserFormStuff', 'maxlength' => 10
  7196. ),
  7197. '/div'
  7198. );
  7199. $this->assertTags($result, $expected);
  7200. }
  7201. /**
  7202. * testForMagicInputNonExistingNorValidated method
  7203. *
  7204. * @return void
  7205. */
  7206. public function testForMagicInputNonExistingNorValidated() {
  7207. $this->markTestIncomplete('Need to revisit once models work again.');
  7208. $encoding = strtolower(Configure::read('App.encoding'));
  7209. $result = $this->Form->create('Contact');
  7210. $expected = array(
  7211. 'form' => array(
  7212. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7213. 'accept-charset' => $encoding
  7214. ),
  7215. 'div' => array('style' => 'display:none;'),
  7216. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7217. '/div'
  7218. );
  7219. $this->assertTags($result, $expected);
  7220. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7221. $expected = array(
  7222. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7223. 'Non Existing Nor Validated',
  7224. '/label',
  7225. 'input' => array(
  7226. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7227. 'id' => 'ContactNonExistingNorValidated'
  7228. )
  7229. );
  7230. $this->assertTags($result, $expected);
  7231. $result = $this->Form->input('Contact.non_existing_nor_validated', array(
  7232. 'div' => false, 'value' => 'my value'
  7233. ));
  7234. $expected = array(
  7235. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7236. 'Non Existing Nor Validated',
  7237. '/label',
  7238. 'input' => array(
  7239. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7240. 'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
  7241. )
  7242. );
  7243. $this->assertTags($result, $expected);
  7244. $this->Form->request->data = array(
  7245. 'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
  7246. ));
  7247. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7248. $expected = array(
  7249. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7250. 'Non Existing Nor Validated',
  7251. '/label',
  7252. 'input' => array(
  7253. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7254. 'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
  7255. )
  7256. );
  7257. $this->assertTags($result, $expected);
  7258. }
  7259. /**
  7260. * testFormMagicInputLabel method
  7261. *
  7262. * @return void
  7263. */
  7264. public function testFormMagicInputLabel() {
  7265. $this->markTestIncomplete('Need to revisit once models work again.');
  7266. $encoding = strtolower(Configure::read('App.encoding'));
  7267. $result = $this->Form->create('Contact');
  7268. $expected = array(
  7269. 'form' => array(
  7270. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7271. 'accept-charset' => $encoding
  7272. ),
  7273. 'div' => array('style' => 'display:none;'),
  7274. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7275. '/div'
  7276. );
  7277. $this->assertTags($result, $expected);
  7278. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
  7279. $this->assertTags($result, array('input' => array(
  7280. 'name' => 'Contact[name]', 'type' => 'text',
  7281. 'id' => 'ContactName', 'maxlength' => '255')
  7282. ));
  7283. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
  7284. $expected = array(
  7285. 'label' => array('for' => 'ContactName'),
  7286. 'My label',
  7287. '/label',
  7288. 'input' => array(
  7289. 'type' => 'text', 'name' => 'Contact[name]',
  7290. 'id' => 'ContactName', 'maxlength' => '255'
  7291. )
  7292. );
  7293. $this->assertTags($result, $expected);
  7294. $result = $this->Form->input('Contact.name', array(
  7295. 'div' => false, 'label' => array('class' => 'mandatory')
  7296. ));
  7297. $expected = array(
  7298. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7299. 'Name',
  7300. '/label',
  7301. 'input' => array(
  7302. 'type' => 'text', 'name' => 'Contact[name]',
  7303. 'id' => 'ContactName', 'maxlength' => '255'
  7304. )
  7305. );
  7306. $this->assertTags($result, $expected);
  7307. $result = $this->Form->input('Contact.name', array(
  7308. 'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
  7309. ));
  7310. $expected = array(
  7311. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7312. 'My label',
  7313. '/label',
  7314. 'input' => array(
  7315. 'type' => 'text', 'name' => 'Contact[name]',
  7316. 'id' => 'ContactName', 'maxlength' => '255'
  7317. )
  7318. );
  7319. $this->assertTags($result, $expected);
  7320. $result = $this->Form->input('Contact.name', array(
  7321. 'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
  7322. ));
  7323. $expected = array(
  7324. 'label' => array('for' => 'my_id'),
  7325. 'Name',
  7326. '/label',
  7327. 'input' => array(
  7328. 'type' => 'text', 'name' => 'Contact[name]',
  7329. 'id' => 'my_id', 'maxlength' => '255'
  7330. )
  7331. );
  7332. $this->assertTags($result, $expected);
  7333. $result = $this->Form->input('1.id');
  7334. $this->assertTags($result, array('input' => array(
  7335. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7336. 'id' => 'Contact1Id'
  7337. )));
  7338. $result = $this->Form->input("1.name");
  7339. $expected = array(
  7340. 'div' => array('class' => 'input text'),
  7341. 'label' => array('for' => 'Contact1Name'),
  7342. 'Name',
  7343. '/label',
  7344. 'input' => array(
  7345. 'type' => 'text', 'name' => 'Contact[1][name]',
  7346. 'id' => 'Contact1Name', 'maxlength' => '255'
  7347. ),
  7348. '/div'
  7349. );
  7350. $this->assertTags($result, $expected);
  7351. $result = $this->Form->input('Contact.1.id');
  7352. $this->assertTags($result, array(
  7353. 'input' => array(
  7354. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7355. 'id' => 'Contact1Id'
  7356. )
  7357. ));
  7358. $result = $this->Form->input("Model.1.name");
  7359. $expected = array(
  7360. 'div' => array('class' => 'input text'),
  7361. 'label' => array('for' => 'Model1Name'),
  7362. 'Name',
  7363. '/label',
  7364. 'input' => array(
  7365. 'type' => 'text', 'name' => 'Model[1][name]',
  7366. 'id' => 'Model1Name'
  7367. ),
  7368. '/div'
  7369. );
  7370. $this->assertTags($result, $expected);
  7371. }
  7372. /**
  7373. * testFormEnd method
  7374. *
  7375. * @return void
  7376. */
  7377. public function testFormEnd() {
  7378. $this->assertEquals('</form>', $this->Form->end());
  7379. }
  7380. /**
  7381. * testMultipleFormWithIdFields method
  7382. *
  7383. * @return void
  7384. */
  7385. public function testMultipleFormWithIdFields() {
  7386. $this->markTestIncomplete('Need to revisit once models work again.');
  7387. $this->Form->create('UserForm');
  7388. $result = $this->Form->input('id');
  7389. $this->assertTags($result, array('input' => array(
  7390. 'type' => 'hidden', 'name' => 'UserForm[id]', 'id' => 'UserFormId'
  7391. )));
  7392. $result = $this->Form->input('ValidateItem.id');
  7393. $this->assertTags($result, array('input' => array(
  7394. 'type' => 'hidden', 'name' => 'ValidateItem[id]',
  7395. 'id' => 'ValidateItemId'
  7396. )));
  7397. $result = $this->Form->input('ValidateUser.id');
  7398. $this->assertTags($result, array('input' => array(
  7399. 'type' => 'hidden', 'name' => 'ValidateUser[id]',
  7400. 'id' => 'ValidateUserId'
  7401. )));
  7402. }
  7403. /**
  7404. * testDbLessModel method
  7405. *
  7406. * @return void
  7407. */
  7408. public function testDbLessModel() {
  7409. $this->markTestIncomplete('Need to revisit once models work again.');
  7410. $this->Form->create('TestMail');
  7411. $result = $this->Form->input('name');
  7412. $expected = array(
  7413. 'div' => array('class' => 'input text'),
  7414. 'label' => array('for' => 'TestMailName'),
  7415. 'Name',
  7416. '/label',
  7417. 'input' => array(
  7418. 'name' => 'TestMail[name]', 'type' => 'text',
  7419. 'id' => 'TestMailName'
  7420. ),
  7421. '/div'
  7422. );
  7423. $this->assertTags($result, $expected);
  7424. $this->Form->create('TestMail');
  7425. $result = $this->Form->input('name');
  7426. $expected = array(
  7427. 'div' => array('class' => 'input text'),
  7428. 'label' => array('for' => 'TestMailName'),
  7429. 'Name',
  7430. '/label',
  7431. 'input' => array(
  7432. 'name' => 'TestMail[name]', 'type' => 'text',
  7433. 'id' => 'TestMailName'
  7434. ),
  7435. '/div'
  7436. );
  7437. $this->assertTags($result, $expected);
  7438. }
  7439. /**
  7440. * testBrokenness method
  7441. *
  7442. * @return void
  7443. */
  7444. public function testBrokenness() {
  7445. $this->markTestIncomplete('Need to revisit once models work again.');
  7446. /*
  7447. * #4 This test has two parents and four children. By default (as of r7117) both
  7448. * parents are show but the first parent is missing a child. This is the inconsistency
  7449. * in the default behaviour - one parent has all children, the other does not - dependent
  7450. * on the data values.
  7451. */
  7452. $result = $this->Form->select('Model.field', array(
  7453. 'Fred' => array(
  7454. 'freds_son_1' => 'Fred',
  7455. 'freds_son_2' => 'Freddie'
  7456. ),
  7457. 'Bert' => array(
  7458. 'berts_son_1' => 'Albert',
  7459. 'berts_son_2' => 'Bertie')
  7460. ),
  7461. array('showParents' => true, 'empty' => false)
  7462. );
  7463. $expected = array(
  7464. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7465. array('optgroup' => array('label' => 'Fred')),
  7466. array('option' => array('value' => 'freds_son_1')),
  7467. 'Fred',
  7468. '/option',
  7469. array('option' => array('value' => 'freds_son_2')),
  7470. 'Freddie',
  7471. '/option',
  7472. '/optgroup',
  7473. array('optgroup' => array('label' => 'Bert')),
  7474. array('option' => array('value' => 'berts_son_1')),
  7475. 'Albert',
  7476. '/option',
  7477. array('option' => array('value' => 'berts_son_2')),
  7478. 'Bertie',
  7479. '/option',
  7480. '/optgroup',
  7481. '/select'
  7482. );
  7483. $this->assertTags($result, $expected);
  7484. /*
  7485. * #2 This is structurally identical to the test above (#1) - only the parent name has
  7486. * changed, so we should expect the same select list data, just with a different name
  7487. * for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
  7488. * This is where data corruption can occur, because when a select value is missing from
  7489. * a list a form will substitute the first value in the list - without the user knowing.
  7490. * If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
  7491. * affect the availability of 3 => 'Three' as a valid option.
  7492. */
  7493. $options = array(1 => 'One', 2 => 'Two', 'Three' => array(
  7494. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  7495. ));
  7496. $result = $this->Form->select(
  7497. 'Model.field', $options, array('showParents' => true, 'empty' => false)
  7498. );
  7499. $expected = array(
  7500. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7501. array('option' => array('value' => 1)),
  7502. 'One',
  7503. '/option',
  7504. array('option' => array('value' => 2)),
  7505. 'Two',
  7506. '/option',
  7507. array('optgroup' => array('label' => 'Three')),
  7508. array('option' => array('value' => 3)),
  7509. 'Three',
  7510. '/option',
  7511. array('option' => array('value' => 4)),
  7512. 'Four',
  7513. '/option',
  7514. array('option' => array('value' => 5)),
  7515. 'Five',
  7516. '/option',
  7517. '/optgroup',
  7518. '/select'
  7519. );
  7520. $this->assertTags($result, $expected);
  7521. }
  7522. /**
  7523. * Test the generation of fields for a multi record form.
  7524. *
  7525. * @return void
  7526. */
  7527. public function testMultiRecordForm() {
  7528. $this->markTestIncomplete('Need to revisit once models work again.');
  7529. $this->Form->create('ValidateProfile');
  7530. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
  7531. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
  7532. $expected = array(
  7533. 'div' => array('class' => 'input textarea'),
  7534. 'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
  7535. 'Name',
  7536. '/label',
  7537. 'textarea' => array(
  7538. 'id' => 'ValidateProfile1ValidateItem2Name',
  7539. 'name' => 'ValidateProfile[1][ValidateItem][2][name]',
  7540. 'cols' => 30,
  7541. 'rows' => 6
  7542. ),
  7543. 'Value',
  7544. '/textarea',
  7545. '/div'
  7546. );
  7547. $this->assertTags($result, $expected);
  7548. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
  7549. $expected = array(
  7550. 'div' => array('class' => 'input date'),
  7551. 'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
  7552. 'Created',
  7553. '/label',
  7554. array('select' => array(
  7555. 'name' => 'ValidateProfile[1][ValidateItem][2][created][month]',
  7556. 'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
  7557. )
  7558. ),
  7559. array('option' => array('value' => '')), '/option',
  7560. $this->dateRegex['monthsRegex'],
  7561. '/select', '-',
  7562. array('select' => array(
  7563. 'name' => 'ValidateProfile[1][ValidateItem][2][created][day]',
  7564. 'id' => 'ValidateProfile1ValidateItem2CreatedDay'
  7565. )
  7566. ),
  7567. array('option' => array('value' => '')), '/option',
  7568. $this->dateRegex['daysRegex'],
  7569. '/select', '-',
  7570. array('select' => array(
  7571. 'name' => 'ValidateProfile[1][ValidateItem][2][created][year]',
  7572. 'id' => 'ValidateProfile1ValidateItem2CreatedYear'
  7573. )
  7574. ),
  7575. array('option' => array('value' => '')), '/option',
  7576. $this->dateRegex['yearsRegex'],
  7577. '/select',
  7578. '/div'
  7579. );
  7580. $this->assertTags($result, $expected);
  7581. $ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
  7582. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
  7583. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
  7584. $expected = array(
  7585. 'div' => array('class' => 'input select error'),
  7586. 'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
  7587. 'Profile',
  7588. '/label',
  7589. 'select' => array(
  7590. 'name' => 'ValidateProfile[1][ValidateItem][2][profile_id]',
  7591. 'id' => 'ValidateProfile1ValidateItem2ProfileId',
  7592. 'class' => 'form-error'
  7593. ),
  7594. '/select',
  7595. array('div' => array('class' => 'error-message')),
  7596. 'Error',
  7597. '/div',
  7598. '/div'
  7599. );
  7600. $this->assertTags($result, $expected);
  7601. }
  7602. /**
  7603. * test the correct display of multi-record form validation errors.
  7604. *
  7605. * @return void
  7606. */
  7607. public function testMultiRecordFormValidationErrors() {
  7608. $this->markTestIncomplete('Need to revisit once models work again.');
  7609. $this->Form->create('ValidateProfile');
  7610. $ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
  7611. $result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
  7612. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7613. $ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
  7614. $result = $this->Form->error('ValidateProfile.2.city');
  7615. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7616. $result = $this->Form->error('2.city');
  7617. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7618. }
  7619. /**
  7620. * test the correct display of multi-record form validation errors.
  7621. *
  7622. * @return void
  7623. */
  7624. public function testSaveManyRecordFormValidationErrors() {
  7625. $this->markTestIncomplete('Need to revisit once models work again.');
  7626. $this->Form->create('ValidateUser');
  7627. $ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
  7628. $result = $this->Form->error('0.ValidateUser.ValidateItem.name');
  7629. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7630. $ValidateUser->validationErrors[0]['city'] = array('Error in field city');
  7631. $result = $this->Form->error('ValidateUser.0.city');
  7632. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7633. }
  7634. /**
  7635. * tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
  7636. *
  7637. * @return void
  7638. */
  7639. public function testInputTemplate() {
  7640. $this->markTestIncomplete('Need to revisit once models work again.');
  7641. $result = $this->Form->input('Contact.email', array(
  7642. 'type' => 'text', 'format' => array('input')
  7643. ));
  7644. $expected = array(
  7645. 'div' => array('class' => 'input text'),
  7646. 'input' => array(
  7647. 'type' => 'text', 'name' => 'Contact[email]',
  7648. 'id' => 'ContactEmail'
  7649. ),
  7650. '/div'
  7651. );
  7652. $this->assertTags($result, $expected);
  7653. $result = $this->Form->input('Contact.email', array(
  7654. 'type' => 'text', 'format' => array('input', 'label'),
  7655. 'label' => '<em>Email (required)</em>'
  7656. ));
  7657. $expected = array(
  7658. 'div' => array('class' => 'input text'),
  7659. array('input' => array(
  7660. 'type' => 'text', 'name' => 'Contact[email]',
  7661. 'id' => 'ContactEmail'
  7662. )),
  7663. 'label' => array('for' => 'ContactEmail'),
  7664. 'em' => array(),
  7665. 'Email (required)',
  7666. '/em',
  7667. '/label',
  7668. '/div'
  7669. );
  7670. $this->assertTags($result, $expected);
  7671. $result = $this->Form->input('Contact.email', array(
  7672. 'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
  7673. 'between' => '<div>Something in the middle</div>',
  7674. 'after' => '<span>Some text at the end</span>'
  7675. ));
  7676. $expected = array(
  7677. 'div' => array('class' => 'input text'),
  7678. array('input' => array(
  7679. 'type' => 'text', 'name' => 'Contact[email]',
  7680. 'id' => 'ContactEmail'
  7681. )),
  7682. array('div' => array()),
  7683. 'Something in the middle',
  7684. '/div',
  7685. 'label' => array('for' => 'ContactEmail'),
  7686. 'Email',
  7687. '/label',
  7688. 'span' => array(),
  7689. 'Some text at the end',
  7690. '/span',
  7691. '/div'
  7692. );
  7693. $this->assertTags($result, $expected);
  7694. $result = $this->Form->input('Contact.method', array(
  7695. 'type' => 'radio',
  7696. 'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
  7697. 'between' => 'I am between',
  7698. ));
  7699. $expected = array(
  7700. 'div' => array('class' => 'input radio'),
  7701. 'fieldset' => array(),
  7702. 'legend' => array(),
  7703. 'Method',
  7704. '/legend',
  7705. 'I am between',
  7706. 'input' => array(
  7707. 'type' => 'hidden', 'name' => 'Contact[method]',
  7708. 'value' => '', 'id' => 'ContactMethod_'
  7709. ),
  7710. array('input' => array(
  7711. 'type' => 'radio', 'name' => 'Contact[method]',
  7712. 'value' => 'email', 'id' => 'ContactMethodEmail'
  7713. )),
  7714. array('label' => array('for' => 'ContactMethodEmail')),
  7715. 'Email',
  7716. '/label',
  7717. array('input' => array(
  7718. 'type' => 'radio', 'name' => 'Contact[method]',
  7719. 'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
  7720. )),
  7721. array('label' => array('for' => 'ContactMethodPigeon')),
  7722. 'Pigeon',
  7723. '/label',
  7724. '/fieldset',
  7725. '/div',
  7726. );
  7727. $this->assertTags($result, $expected);
  7728. }
  7729. /**
  7730. * test that some html5 inputs + FormHelper::__call() work
  7731. *
  7732. * @return void
  7733. */
  7734. public function testHtml5Inputs() {
  7735. $result = $this->Form->email('User.email');
  7736. $expected = array(
  7737. 'input' => array('type' => 'email', 'name' => 'User[email]')
  7738. );
  7739. $this->assertTags($result, $expected);
  7740. $result = $this->Form->search('User.query');
  7741. $expected = array(
  7742. 'input' => array('type' => 'search', 'name' => 'User[query]')
  7743. );
  7744. $this->assertTags($result, $expected);
  7745. $result = $this->Form->search('User.query', array('value' => 'test'));
  7746. $expected = array(
  7747. 'input' => array('type' => 'search', 'name' => 'User[query]', 'value' => 'test')
  7748. );
  7749. $this->assertTags($result, $expected);
  7750. $result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
  7751. $expected = array(
  7752. 'input' => array('type' => 'text', 'name' => 'User[query]', 'value' => 'test')
  7753. );
  7754. $this->assertTags($result, $expected);
  7755. }
  7756. /**
  7757. * Test accessing html5 inputs through input().
  7758. *
  7759. * @return void
  7760. */
  7761. public function testHtml5InputWithInput() {
  7762. $this->markTestIncomplete('Need to revisit once models work again.');
  7763. $result = $this->Form->input('User.website', array(
  7764. 'type' => 'url',
  7765. 'value' => 'http://domain.tld',
  7766. 'div' => false,
  7767. 'label' => false));
  7768. $expected = array(
  7769. 'input' => array('type' => 'url', 'name' => 'User[website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
  7770. );
  7771. $this->assertTags($result, $expected);
  7772. }
  7773. /**
  7774. * Test errors when field name is missing.
  7775. *
  7776. * @expectedException Cake\Error\Exception
  7777. * @return void
  7778. */
  7779. public function testHtml5InputException() {
  7780. $this->Form->email();
  7781. }
  7782. /**
  7783. * Tests that a model can be loaded from the model names passed in the request object
  7784. *
  7785. * @return void
  7786. */
  7787. public function testIntrospectModelFromRequest() {
  7788. $this->markTestIncomplete('Need to revisit once models work again.');
  7789. $this->loadFixtures('Post');
  7790. App::build(array(
  7791. 'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
  7792. ));
  7793. Plugin::load('TestPlugin');
  7794. $this->Form->request['models'] = array(
  7795. 'TestPluginPost' => array(
  7796. 'plugin' => 'TestPlugin',
  7797. 'className' => 'TestPluginPost'
  7798. )
  7799. );
  7800. $this->Form->create('TestPluginPost');
  7801. Plugin::unload();
  7802. }
  7803. /**
  7804. * Tests that it is possible to set the validation errors directly in the helper for a field
  7805. *
  7806. * @return void
  7807. */
  7808. public function testCustomValidationErrors() {
  7809. $this->markTestIncomplete('Need to revisit once models work again.');
  7810. $this->Form->validationErrors['Thing']['field'] = 'Badness!';
  7811. $result = $this->Form->error('Thing.field', null, array('wrap' => false));
  7812. $this->assertEquals('Badness!', $result);
  7813. }
  7814. /**
  7815. * Tests that the 'on' key validates as expected on create
  7816. *
  7817. * @return void
  7818. */
  7819. public function testRequiredOnCreate() {
  7820. $this->markTestIncomplete('Need to revisit once models work again.');
  7821. $this->Form->create('Contact');
  7822. $result = $this->Form->input('Contact.imrequiredonupdate');
  7823. $expected = array(
  7824. 'div' => array('class' => 'input text'),
  7825. 'label' => array('for' => 'ContactImrequiredonupdate'),
  7826. 'Imrequiredonupdate',
  7827. '/label',
  7828. 'input' => array(
  7829. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  7830. 'id' => 'ContactImrequiredonupdate'
  7831. ),
  7832. '/div'
  7833. );
  7834. $this->assertTags($result, $expected);
  7835. $result = $this->Form->input('Contact.imrequiredoncreate');
  7836. $expected = array(
  7837. 'div' => array('class' => 'input text required'),
  7838. 'label' => array('for' => 'ContactImrequiredoncreate'),
  7839. 'Imrequiredoncreate',
  7840. '/label',
  7841. 'input' => array(
  7842. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  7843. 'id' => 'ContactImrequiredoncreate',
  7844. 'required' => 'required'
  7845. ),
  7846. '/div'
  7847. );
  7848. $this->assertTags($result, $expected);
  7849. $result = $this->Form->input('Contact.imrequiredonboth');
  7850. $expected = array(
  7851. 'div' => array('class' => 'input text required'),
  7852. 'label' => array('for' => 'ContactImrequiredonboth'),
  7853. 'Imrequiredonboth',
  7854. '/label',
  7855. 'input' => array(
  7856. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  7857. 'id' => 'ContactImrequiredonboth',
  7858. 'required' => 'required'
  7859. ),
  7860. '/div'
  7861. );
  7862. $this->assertTags($result, $expected);
  7863. $this->Form->inputDefaults(array('required' => false));
  7864. $result = $this->Form->input('Contact.imrequired');
  7865. $expected = array(
  7866. 'div' => array('class' => 'input text'),
  7867. 'label' => array('for' => 'ContactImrequired'),
  7868. 'Imrequired',
  7869. '/label',
  7870. 'input' => array(
  7871. 'type' => 'text', 'name' => 'Contact[imrequired]',
  7872. 'id' => 'ContactImrequired'
  7873. ),
  7874. '/div'
  7875. );
  7876. $this->assertTags($result, $expected);
  7877. $result = $this->Form->input('Contact.imrequired', array('required' => false));
  7878. $this->assertTags($result, $expected);
  7879. $result = $this->Form->input('Contact.imrequired', array('required' => true));
  7880. $expected = array(
  7881. 'div' => array('class' => 'input text required'),
  7882. 'label' => array('for' => 'ContactImrequired'),
  7883. 'Imrequired',
  7884. '/label',
  7885. 'input' => array(
  7886. 'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
  7887. 'id' => 'ContactImrequired'
  7888. ),
  7889. '/div'
  7890. );
  7891. $this->assertTags($result, $expected);
  7892. $result = $this->Form->input('Contact.imrequired', array('required' => null));
  7893. $this->assertTags($result, $expected);
  7894. }
  7895. /**
  7896. * Tests that the 'on' key validates as expected on update
  7897. *
  7898. * @return void
  7899. */
  7900. public function testRequiredOnUpdate() {
  7901. $this->markTestIncomplete('Need to revisit once models work again.');
  7902. $this->Form->request->data['Contact']['id'] = 1;
  7903. $this->Form->create('Contact');
  7904. $result = $this->Form->input('Contact.imrequiredonupdate');
  7905. $expected = array(
  7906. 'div' => array('class' => 'input text required'),
  7907. 'label' => array('for' => 'ContactImrequiredonupdate'),
  7908. 'Imrequiredonupdate',
  7909. '/label',
  7910. 'input' => array(
  7911. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  7912. 'id' => 'ContactImrequiredonupdate',
  7913. 'required' => 'required'
  7914. ),
  7915. '/div'
  7916. );
  7917. $this->assertTags($result, $expected);
  7918. $result = $this->Form->input('Contact.imrequiredoncreate');
  7919. $expected = array(
  7920. 'div' => array('class' => 'input text'),
  7921. 'label' => array('for' => 'ContactImrequiredoncreate'),
  7922. 'Imrequiredoncreate',
  7923. '/label',
  7924. 'input' => array(
  7925. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  7926. 'id' => 'ContactImrequiredoncreate'
  7927. ),
  7928. '/div'
  7929. );
  7930. $this->assertTags($result, $expected);
  7931. $result = $this->Form->input('Contact.imrequiredonboth');
  7932. $expected = array(
  7933. 'div' => array('class' => 'input text required'),
  7934. 'label' => array('for' => 'ContactImrequiredonboth'),
  7935. 'Imrequiredonboth',
  7936. '/label',
  7937. 'input' => array(
  7938. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  7939. 'id' => 'ContactImrequiredonboth',
  7940. 'required' => 'required'
  7941. ),
  7942. '/div'
  7943. );
  7944. $this->assertTags($result, $expected);
  7945. $result = $this->Form->input('Contact.imrequired');
  7946. $expected = array(
  7947. 'div' => array('class' => 'input text required'),
  7948. 'label' => array('for' => 'ContactImrequired'),
  7949. 'Imrequired',
  7950. '/label',
  7951. 'input' => array(
  7952. 'type' => 'text', 'name' => 'Contact[imrequired]',
  7953. 'id' => 'ContactImrequired',
  7954. 'required' => 'required'
  7955. ),
  7956. '/div'
  7957. );
  7958. $this->assertTags($result, $expected);
  7959. }
  7960. /**
  7961. * Test inputDefaults setter and getter
  7962. *
  7963. * @return void
  7964. */
  7965. public function testInputDefaults() {
  7966. $this->markTestIncomplete('Need to revisit once models work again.');
  7967. $this->Form->create('Contact');
  7968. $this->Form->inputDefaults(array(
  7969. 'label' => false,
  7970. 'div' => array(
  7971. 'style' => 'color: #000;'
  7972. )
  7973. ));
  7974. $result = $this->Form->input('Contact.field1');
  7975. $expected = array(
  7976. 'div' => array('class' => 'input text', 'style' => 'color: #000;'),
  7977. 'input' => array(
  7978. 'type' => 'text', 'name' => 'Contact[field1]',
  7979. 'id' => 'ContactField1'
  7980. ),
  7981. '/div'
  7982. );
  7983. $this->assertTags($result, $expected);
  7984. $this->Form->inputDefaults(array(
  7985. 'div' => false,
  7986. 'label' => 'Label',
  7987. ));
  7988. $result = $this->Form->input('Contact.field1');
  7989. $expected = array(
  7990. 'label' => array('for' => 'ContactField1'),
  7991. 'Label',
  7992. '/label',
  7993. 'input' => array(
  7994. 'type' => 'text', 'name' => 'Contact[field1]',
  7995. 'id' => 'ContactField1'
  7996. ),
  7997. );
  7998. $this->assertTags($result, $expected);
  7999. $this->Form->inputDefaults(array(
  8000. 'label' => false,
  8001. ), true);
  8002. $result = $this->Form->input('Contact.field1');
  8003. $expected = array(
  8004. 'input' => array(
  8005. 'type' => 'text', 'name' => 'Contact[field1]',
  8006. 'id' => 'ContactField1'
  8007. ),
  8008. );
  8009. $this->assertTags($result, $expected);
  8010. $result = $this->Form->inputDefaults();
  8011. $expected = array(
  8012. 'div' => false,
  8013. 'label' => false,
  8014. );
  8015. $this->assertEquals($expected, $result);
  8016. }
  8017. }