| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038 |
- <?php
- /**
- * FormHelperTest file
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @package Cake.Test.Case.View.Helper
- * @since CakePHP(tm) v 1.2.0.4206
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- App::uses('ClassRegistry', 'Utility');
- App::uses('Controller', 'Controller');
- App::uses('View', 'View');
- App::uses('Model', 'Model');
- App::uses('Security', 'Utility');
- App::uses('CakeRequest', 'Network');
- App::uses('HtmlHelper', 'View/Helper');
- App::uses('FormHelper', 'View/Helper');
- App::uses('Router', 'Routing');
- /**
- * ContactTestController class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTestController extends Controller {
- /**
- * uses property
- *
- * @var mixed null
- */
- public $uses = null;
- }
- /**
- * Contact class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class Contact extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * Default schema
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
- 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
- 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
- 'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
- );
- /**
- * validate property
- *
- * @var array
- */
- public $validate = array(
- 'non_existing' => array(),
- 'idontexist' => array(),
- 'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false),
- 'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
- 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
- 'imrequiredonboth' => array(
- 'required' => array('rule' => 'alphaNumeric'),
- ),
- 'string_required' => 'notEmpty',
- 'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
- 'imrequiredtoo' => array('rule' => 'notEmpty'),
- 'required_one' => array('required' => array('rule' => array('notEmpty'))),
- 'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
- 'imalsonotrequired' => array(
- 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
- 'between' => array('rule' => array('between', 5, 30)),
- ),
- 'imalsonotrequired2' => array(
- 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
- 'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
- ),
- 'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true),
- 'iamrequiredalways' => array(
- 'email' => array('rule' => 'email'),
- 'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
- 'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
- ),
- 'boolean_field' => array('rule' => 'boolean')
- );
- /**
- * schema method
- *
- * @return void
- */
- public function setSchema($schema) {
- $this->_schema = $schema;
- }
- /**
- * hasAndBelongsToMany property
- *
- * @var array
- */
- public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact'));
- /**
- * hasAndBelongsToMany property
- *
- * @var array
- */
- public $belongsTo = array('User' => array('className' => 'UserForm'));
- }
- /**
- * ContactTagsContact class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTagsContact extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * Default schema
- *
- * @var array
- */
- protected $_schema = array(
- 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'contact_tag_id' => array(
- 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
- )
- );
- /**
- * schema method
- *
- * @return void
- */
- public function setSchema($schema) {
- $this->_schema = $schema;
- }
- }
- /**
- * ContactNonStandardPk class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ContactNonStandardPk extends Contact {
- /**
- * primaryKey property
- *
- * @var string
- */
- public $primaryKey = 'pk';
- /**
- * schema method
- *
- * @return void
- */
- public function schema($field = false) {
- $this->_schema = parent::schema();
- $this->_schema['pk'] = $this->_schema['id'];
- unset($this->_schema['id']);
- return $this->_schema;
- }
- }
- /**
- * ContactTag class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTag extends Model {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * schema definition
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
- 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
- 'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
- 'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
- );
- }
- /**
- * UserForm class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class UserForm extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * hasMany property
- *
- * @var array
- */
- public $hasMany = array(
- 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
- ));
- /**
- * schema definition
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
- 'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
- 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
- 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
- 'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
- 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
- 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
- );
- }
- /**
- * OpenidUrl class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class OpenidUrl extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * belongsTo property
- *
- * @var array
- */
- public $belongsTo = array('UserForm' => array(
- 'className' => 'UserForm', 'foreignKey' => 'user_form_id'
- ));
- /**
- * validate property
- *
- * @var array
- */
- public $validate = array('openid_not_registered' => array());
- /**
- * schema method
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'user_form_id' => array(
- 'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
- ),
- 'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- );
- /**
- * beforeValidate method
- *
- * @return void
- */
- public function beforeValidate($options = array()) {
- $this->invalidate('openid_not_registered');
- return true;
- }
- }
- /**
- * ValidateUser class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateUser extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * hasOne property
- *
- * @var array
- */
- public $hasOne = array('ValidateProfile' => array(
- 'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
- ));
- /**
- * schema method
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
- 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'),
- 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'),
- 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'),
- 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
- 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
- );
- /**
- * beforeValidate method
- *
- * @return void
- */
- public function beforeValidate($options = array()) {
- $this->invalidate('email');
- return false;
- }
- }
- /**
- * ValidateProfile class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateProfile extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * schema property
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
- 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
- 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
- );
- /**
- * hasOne property
- *
- * @var array
- */
- public $hasOne = array('ValidateItem' => array(
- 'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
- ));
- /**
- * belongsTo property
- *
- * @var array
- */
- public $belongsTo = array('ValidateUser' => array(
- 'className' => 'ValidateUser', 'foreignKey' => 'user_id'
- ));
- /**
- * beforeValidate method
- *
- * @return void
- */
- public function beforeValidate($options = array()) {
- $this->invalidate('full_name');
- $this->invalidate('city');
- return false;
- }
- }
- /**
- * ValidateItem class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateItem extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- /**
- * schema property
- *
- * @var array
- */
- protected $_schema = array(
- 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
- 'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
- 'description' => array(
- 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
- ),
- 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
- 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
- );
- /**
- * belongsTo property
- *
- * @var array
- */
- public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
- /**
- * beforeValidate method
- *
- * @return void
- */
- public function beforeValidate($options = array()) {
- $this->invalidate('description');
- return false;
- }
- }
- /**
- * TestMail class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class TestMail extends CakeTestModel {
- /**
- * useTable property
- *
- * @var boolean
- */
- public $useTable = false;
- }
- /**
- * FormHelperTest class
- *
- * @package Cake.Test.Case.View.Helper
- * @property FormHelper $Form
- */
- class FormHelperTest extends CakeTestCase {
- /**
- * Fixtures to be used
- *
- * @var array
- */
- public $fixtures = array('core.post');
- /**
- * Do not load the fixtures by default
- *
- * @var boolean
- */
- public $autoFixtures = false;
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- Configure::write('Config.language', 'eng');
- Configure::write('App.base', '');
- Configure::delete('Asset');
- $this->Controller = new ContactTestController();
- $this->View = new View($this->Controller);
- $this->Form = new FormHelper($this->View);
- $this->Form->Html = new HtmlHelper($this->View);
- $this->Form->request = new CakeRequest('contacts/add', false);
- $this->Form->request->here = '/contacts/add';
- $this->Form->request['action'] = 'add';
- $this->Form->request->webroot = '';
- $this->Form->request->base = '';
- ClassRegistry::addObject('Contact', new Contact());
- ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk());
- ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
- ClassRegistry::addObject('User', new UserForm());
- ClassRegistry::addObject('ValidateItem', new ValidateItem());
- ClassRegistry::addObject('ValidateUser', new ValidateUser());
- ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
- $this->oldSalt = Configure::read('Security.salt');
- $this->dateRegex = array(
- 'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
- 'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
- 'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
- 'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
- 'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
- 'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
- );
- Configure::write('Security.salt', 'foo!');
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
- Configure::write('Security.salt', $this->oldSalt);
- }
- /**
- * testFormCreateWithSecurity method
- *
- * Test form->create() with security key.
- *
- * @return void
- */
- public function testCreateWithSecurity() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
- $expected = array(
- 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
- 'div' => array('style' => 'display:none;'),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
- $expected['form']['id'] = 'MyForm';
- $this->assertTags($result, $expected);
- }
- /**
- * testFormCreateGetNoSecurity method
- *
- * Test form->create() with no security key as its a get form
- *
- * @return void
- */
- public function testCreateEndGetNoSecurity() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact', array('type' => 'get', 'url' => '/contacts/add'));
- $this->assertNotContains('Token', $result);
- $result = $this->Form->end('Save');
- $this->assertNotContains('Token', $result);
- }
- /**
- * test that create() clears the fields property so it starts fresh
- *
- * @return void
- */
- public function testCreateClearingFields() {
- $this->Form->fields = array('model_id');
- $this->Form->create('Contact');
- $this->assertEquals(array(), $this->Form->fields);
- }
- /**
- * Tests form hash generation with model-less data
- *
- * @return void
- */
- public function testValidateHashNoModel() {
- $this->Form->request['_Token'] = array('key' => 'foo');
- $result = $this->Form->secure(array('anything'));
- $this->assertRegExp('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
- }
- /**
- * Tests that models with identical field names get resolved properly
- *
- * @return void
- */
- public function testDuplicateFieldNameResolution() {
- $result = $this->Form->create('ValidateUser');
- $this->assertEquals(array('ValidateUser'), $this->Form->entity());
- $result = $this->Form->input('ValidateItem.name');
- $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
- $result = $this->Form->input('ValidateUser.name');
- $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
- $this->assertRegExp('/name="data\[ValidateUser\]\[name\]"/', $result);
- $this->assertRegExp('/type="text"/', $result);
- $result = $this->Form->input('ValidateItem.name');
- $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
- $this->assertRegExp('/name="data\[ValidateItem\]\[name\]"/', $result);
- $this->assertRegExp('/<textarea/', $result);
- $result = $this->Form->input('name');
- $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
- $this->assertRegExp('/name="data\[ValidateUser\]\[name\]"/', $result);
- $this->assertRegExp('/type="text"/', $result);
- }
- /**
- * Tests that hidden fields generated for checkboxes don't get locked
- *
- * @return void
- */
- public function testNoCheckboxLocking() {
- $this->Form->request['_Token'] = array('key' => 'foo');
- $this->assertSame(array(), $this->Form->fields);
- $this->Form->checkbox('check', array('value' => '1'));
- $this->assertSame($this->Form->fields, array('check'));
- }
- /**
- * testFormSecurityFields method
- *
- * Test generation of secure form hash generation.
- *
- * @return void
- */
- public function testFormSecurityFields() {
- $key = 'testKey';
- $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
- $secureAttributes = array('form' => 'MyTestForm');
- $this->Form->request['_Token'] = array('key' => $key);
- $result = $this->Form->secure($fields, $secureAttributes);
- $hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
- $hash .= ':' . 'Model.valid';
- $hash = urlencode($hash);
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/',
- 'form' => 'MyTestForm',
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/',
- 'form' => 'MyTestForm',
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Tests correct generation of number fields for double and float fields
- *
- * @return void
- */
- public function testTextFieldGenerationForFloats() {
- $model = ClassRegistry::getObject('Contact');
- $model->setSchema(array('foo' => array(
- 'type' => 'float',
- 'null' => false,
- 'default' => null,
- 'length' => 10
- )));
- $this->Form->create('Contact');
- $result = $this->Form->input('foo');
- $expected = array(
- 'div' => array('class' => 'input number'),
- 'label' => array('for' => 'ContactFoo'),
- 'Foo',
- '/label',
- array('input' => array(
- 'type' => 'number',
- 'name' => 'data[Contact][foo]',
- 'id' => 'ContactFoo',
- 'step' => 'any'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('foo', array('step' => 0.5));
- $expected = array(
- 'div' => array('class' => 'input number'),
- 'label' => array('for' => 'ContactFoo'),
- 'Foo',
- '/label',
- array('input' => array(
- 'type' => 'number',
- 'name' => 'data[Contact][foo]',
- 'id' => 'ContactFoo',
- 'step' => '0.5'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Tests correct generation of number fields for integer fields
- *
- * @return void
- */
- public function testTextFieldTypeNumberGenerationForIntegers() {
- $model = ClassRegistry::getObject('Contact');
- $model->setSchema(array('foo' => array(
- 'type' => 'integer',
- 'null' => false,
- 'default' => null,
- 'length' => null
- )));
- $this->Form->create('Contact');
- $result = $this->Form->input('foo');
- $expected = array(
- 'div' => array('class' => 'input number'),
- 'label' => array('for' => 'ContactFoo'),
- 'Foo',
- '/label',
- array('input' => array(
- 'type' => 'number', 'name' => 'data[Contact][foo]',
- 'id' => 'ContactFoo'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Tests correct generation of file upload fields for binary fields
- *
- * @return void
- */
- public function testFileUploadFieldTypeGenerationForBinaries() {
- $model = ClassRegistry::getObject('Contact');
- $model->setSchema(array('foo' => array(
- 'type' => 'binary',
- 'null' => false,
- 'default' => null,
- 'length' => 1024
- )));
- $this->Form->create('Contact');
- $result = $this->Form->input('foo');
- $expected = array(
- 'div' => array('class' => 'input file'),
- 'label' => array('for' => 'ContactFoo'),
- 'Foo',
- '/label',
- array('input' => array(
- 'type' => 'file', 'name' => 'data[Contact][foo]',
- 'id' => 'ContactFoo'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormSecurityMultipleFields method
- *
- * Test secure() with multiple row form. Ensure hash is correct.
- *
- * @return void
- */
- public function testFormSecurityMultipleFields() {
- $key = 'testKey';
- $fields = array(
- 'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
- 'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
- 'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
- );
- $this->Form->request['_Token'] = array('key' => $key);
- $result = $this->Form->secure($fields);
- $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
- $hash .= '%7CModel.1.hidden%7CModel.1.valid';
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormSecurityMultipleSubmitButtons
- *
- * test form submit generation and ensure that _Token is only created on end()
- *
- * @return void
- */
- public function testFormSecurityMultipleSubmitButtons() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('Addresses');
- $this->Form->input('Address.title');
- $this->Form->input('Address.first_name');
- $result = $this->Form->submit('Save', array('name' => 'save'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Cancel', array('name' => 'cancel'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(null);
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => 'preg:/.+/', 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that buttons created with foo[bar] name attributes are unlocked correctly.
- *
- * @return void
- */
- public function testSecurityButtonNestedNamed() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('Addresses');
- $this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
- $result = $this->Form->unlockField();
- $this->assertEquals(array('Address.button'), $result);
- }
- /**
- * Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
- *
- * @return void
- */
- public function testSecuritySubmitNestedNamed() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('Addresses');
- $this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
- $result = $this->Form->unlockField();
- $this->assertEquals(array('Address.button'), $result);
- }
- /**
- * Test that the correct fields are unlocked for image submits with no names.
- *
- * @return void
- */
- public function testSecuritySubmitImageNoName() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('User');
- $result = $this->Form->submit('save.png');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'img/save.png'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->assertEquals(array('x', 'y'), $this->Form->unlockField());
- }
- /**
- * Test that the correct fields are unlocked for image submits with names.
- *
- * @return void
- */
- public function testSecuritySubmitImageName() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('User');
- $result = $this->Form->submit('save.png', array('name' => 'test'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
- }
- /**
- * testFormSecurityMultipleInputFields method
- *
- * Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
- *
- * @return void
- */
- public function testFormSecurityMultipleInputFields() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array('key' => $key);
- $this->Form->create('Addresses');
- $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
- $this->Form->input('Addresses.0.title');
- $this->Form->input('Addresses.0.first_name');
- $this->Form->input('Addresses.0.last_name');
- $this->Form->input('Addresses.0.address');
- $this->Form->input('Addresses.0.city');
- $this->Form->input('Addresses.0.phone');
- $this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
- $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
- $this->Form->input('Addresses.1.title');
- $this->Form->input('Addresses.1.first_name');
- $this->Form->input('Addresses.1.last_name');
- $this->Form->input('Addresses.1.address');
- $this->Form->input('Addresses.1.city');
- $this->Form->input('Addresses.1.phone');
- $this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
- $result = $this->Form->secure($this->Form->fields);
- $hash = 'a3b9b2ba1cb688838f92818a5970e17dd7943a78%3AAddresses.0.id%7CAddresses.1.id';
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test form security with Model.field.0 style inputs
- *
- * @return void
- */
- public function testFormSecurityArrayFields() {
- $key = 'testKey';
- $this->Form->request->params['_Token']['key'] = $key;
- $this->Form->create('Address');
- $this->Form->input('Address.primary.1');
- $this->assertEquals('Address.primary', $this->Form->fields[0]);
- $this->Form->input('Address.secondary.1.0');
- $this->assertEquals('Address.secondary', $this->Form->fields[1]);
- }
- /**
- * testFormSecurityMultipleInputDisabledFields method
- *
- * test secure form generation with multiple records and disabled fields.
- *
- * @return void
- */
- public function testFormSecurityMultipleInputDisabledFields() {
- $key = 'testKey';
- $this->Form->request->params['_Token'] = array(
- 'key' => $key,
- 'unlockedFields' => array('first_name', 'address')
- );
- $this->Form->create();
- $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
- $this->Form->input('Addresses.0.title');
- $this->Form->input('Addresses.0.first_name');
- $this->Form->input('Addresses.0.last_name');
- $this->Form->input('Addresses.0.address');
- $this->Form->input('Addresses.0.city');
- $this->Form->input('Addresses.0.phone');
- $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
- $this->Form->input('Addresses.1.title');
- $this->Form->input('Addresses.1.first_name');
- $this->Form->input('Addresses.1.last_name');
- $this->Form->input('Addresses.1.address');
- $this->Form->input('Addresses.1.city');
- $this->Form->input('Addresses.1.phone');
- $result = $this->Form->secure($this->Form->fields);
- $hash = '5c9cadf9da008cc444d3960b481391a425a5d979%3AAddresses.0.id%7CAddresses.1.id';
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormSecurityInputDisabledFields method
- *
- * Test single record form with disabled fields.
- *
- * @return void
- */
- public function testFormSecurityInputUnlockedFields() {
- $key = 'testKey';
- $this->Form->request['_Token'] = array(
- 'key' => $key,
- 'unlockedFields' => array('first_name', 'address')
- );
- $this->Form->create();
- $this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
- $this->Form->hidden('Addresses.id', array('value' => '123456'));
- $this->Form->input('Addresses.title');
- $this->Form->input('Addresses.first_name');
- $this->Form->input('Addresses.last_name');
- $this->Form->input('Addresses.address');
- $this->Form->input('Addresses.city');
- $this->Form->input('Addresses.phone');
- $result = $this->Form->fields;
- $expected = array(
- 'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
- 'Addresses.city', 'Addresses.phone'
- );
- $this->assertEquals($expected, $result);
- $result = $this->Form->secure($expected);
- $hash = '40289bd07811587887ff56585a8526ff9da59d7a%3AAddresses.id';
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test securing inputs with custom name attributes.
- *
- * @return void
- */
- public function testFormSecureWithCustomNameAttribute() {
- $this->Form->request->params['_Token']['key'] = 'testKey';
- $this->Form->text('UserForm.published', array('name' => 'data[User][custom]'));
- $this->assertEquals('User.custom', $this->Form->fields[0]);
- $this->Form->text('UserForm.published', array('name' => 'data[User][custom][another][value]'));
- $this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
- }
- /**
- * testFormSecuredInput method
- *
- * Test generation of entire secure form, assertions made on input() output.
- *
- * @return void
- */
- public function testFormSecuredInput() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
- $encoding = strtolower(Configure::read('App.encoding'));
- $expected = array(
- 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
- 'div' => array('style' => 'display:none;'),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][key]',
- 'value' => 'testKey', 'id' => 'preg:/Token\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('UserForm.published', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'UserFormPublished'),
- 'Published',
- '/label',
- array('input' => array(
- 'type' => 'text', 'name' => 'data[UserForm][published]',
- 'id' => 'UserFormPublished'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('UserForm.other', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'UserFormOther'),
- 'Other',
- '/label',
- array('input' => array(
- 'type' => 'text', 'name' => 'data[UserForm][other]',
- 'id' => 'UserFormOther'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->hidden('UserForm.stuff');
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[UserForm][stuff]',
- 'id' => 'UserFormStuff'
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
- $expected = array('input' => array(
- 'type' => 'hidden', 'name' => 'data[UserForm][hidden]',
- 'value' => '0', 'id' => 'UserFormHidden'
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[UserForm][something]',
- 'value' => '0', 'id' => 'UserFormSomething_'
- )),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[UserForm][something]',
- 'value' => '1', 'id' => 'UserFormSomething'
- )),
- 'label' => array('for' => 'UserFormSomething'),
- 'Something',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->fields;
- $expected = array(
- 'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
- 'UserForm.hidden' => '0', 'UserForm.something'
- );
- $this->assertEquals($expected, $result);
- $hash = '6014b4e1c4f39eb62389712111dbe6435bec66cb%3AUserForm.hidden%7CUserForm.stuff';
- $result = $this->Form->secure($this->Form->fields);
- $expected = array(
- 'div' => array('style' => 'display:none;'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][fields]',
- 'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test secured inputs with custom names.
- *
- * @return void
- */
- public function testSecuredInputCustomName() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->assertEquals(array(), $this->Form->fields);
- $this->Form->input('text_input', array(
- 'name' => 'data[Option][General.default_role]',
- ));
- $expected = array('Option.General.default_role');
- $this->assertEquals($expected, $this->Form->fields);
- $this->Form->input('select_box', array(
- 'name' => 'data[Option][General.select_role]',
- 'type' => 'select',
- 'options' => array(1, 2),
- ));
- $expected = array('Option.General.default_role', 'Option.General.select_role');
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * Tests that the correct keys are added to the field hash index
- *
- * @return void
- */
- public function testSecuredFileInput() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->assertEquals(array(), $this->Form->fields);
- $this->Form->file('Attachment.file');
- $expected = array(
- 'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
- 'Attachment.file.error', 'Attachment.file.size'
- );
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * test that multiple selects keys are added to field hash
- *
- * @return void
- */
- public function testSecuredMultipleSelect() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->assertEquals(array(), $this->Form->fields);
- $options = array('1' => 'one', '2' => 'two');
- $this->Form->select('Model.select', $options);
- $expected = array('Model.select');
- $this->assertEquals($expected, $this->Form->fields);
- $this->Form->fields = array();
- $this->Form->select('Model.select', $options, array('multiple' => true));
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * testFormSecuredRadio method
- *
- * @return void
- */
- public function testSecuredRadio() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->assertEquals(array(), $this->Form->fields);
- $options = array('1' => 'option1', '2' => 'option2');
- $this->Form->radio('Test.test', $options);
- $expected = array('Test.test');
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * Test that when disabled is in a list based attribute array it works.
- *
- * @return void
- */
- public function testSecuredAndDisabledNotAssoc() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->Form->select('Model.select', array(1, 2), array('disabled'));
- $this->Form->checkbox('Model.checkbox', array('disabled'));
- $this->Form->text('Model.text', array('disabled'));
- $this->Form->textarea('Model.textarea', array('disabled'));
- $this->Form->password('Model.password', array('disabled'));
- $this->Form->radio('Model.radio', array(1, 2), array('disabled'));
- $expected = array(
- 'Model.radio' => ''
- );
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * test that forms with disabled inputs + secured forms leave off the inputs from the form
- * hashing.
- *
- * @return void
- */
- public function testSecuredAndDisabled() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->Form->checkbox('Model.checkbox', array('disabled' => true));
- $this->Form->text('Model.text', array('disabled' => true));
- $this->Form->password('Model.text', array('disabled' => true));
- $this->Form->textarea('Model.textarea', array('disabled' => true));
- $this->Form->select('Model.select', array(1, 2), array('disabled' => true));
- $this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
- $this->Form->year('Model.year', null, null, array('disabled' => true));
- $this->Form->month('Model.month', array('disabled' => true));
- $this->Form->day('Model.day', array('disabled' => true));
- $this->Form->hour('Model.hour', false, array('disabled' => true));
- $this->Form->minute('Model.minute', array('disabled' => true));
- $this->Form->meridian('Model.meridian', array('disabled' => true));
- $expected = array(
- 'Model.radio' => ''
- );
- $this->assertEquals($expected, $this->Form->fields);
- }
- /**
- * Test that only the path + query elements of a form's URL show up in their hash.
- *
- * @return void
- */
- public function testSecuredFormUrlIgnoresHost() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $expected = '0ff0c85cd70584d8fd18fa136846d22c66c21e2d%3A';
- $this->Form->create('Address', array(
- 'url' => array('controller' => 'articles', 'action' => 'view', 1, '?' => array('page' => 1))
- ));
- $result = $this->Form->secure();
- $this->assertContains($expected, $result);
- $this->Form->create('Address', array('url' => 'http://localhost/articles/view/1?page=1'));
- $result = $this->Form->secure();
- $this->assertContains($expected, $result, 'Full URL should only use path and query.');
- $this->Form->create('Address', array('url' => '/articles/view/1?page=1'));
- $result = $this->Form->secure();
- $this->assertContains($expected, $result, 'URL path + query should work.');
- $this->Form->create('Address', array('url' => '/articles/view/1'));
- $result = $this->Form->secure();
- $this->assertNotContains($expected, $result, 'URL is different');
- }
- /**
- * testDisableSecurityUsingForm method
- *
- * @return void
- */
- public function testDisableSecurityUsingForm() {
- $this->Form->request['_Token'] = array(
- 'key' => 'testKey',
- 'disabledFields' => array()
- );
- $this->Form->create();
- $this->Form->hidden('Addresses.id', array('value' => '123456'));
- $this->Form->input('Addresses.title');
- $this->Form->input('Addresses.first_name', array('secure' => false));
- $this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
- $this->Form->input('Addresses.zip', array(
- 'type' => 'select', 'options' => array(1, 2), 'secure' => false
- ));
- $result = $this->Form->fields;
- $expected = array(
- 'Addresses.id' => '123456', 'Addresses.title',
- );
- $this->assertEquals($expected, $result);
- }
- /**
- * test disableField
- *
- * @return void
- */
- public function testUnlockFieldAddsToList() {
- $this->Form->request['_Token'] = array(
- 'key' => 'testKey',
- 'unlockedFields' => array()
- );
- $this->Form->create('Contact');
- $this->Form->unlockField('Contact.name');
- $this->Form->text('Contact.name');
- $this->assertEquals(array('Contact.name'), $this->Form->unlockField());
- $this->assertEquals(array(), $this->Form->fields);
- }
- /**
- * test unlockField removing from fields array.
- *
- * @return void
- */
- public function testUnlockFieldRemovingFromFields() {
- $this->Form->request['_Token'] = array(
- 'key' => 'testKey',
- 'unlockedFields' => array()
- );
- $this->Form->create('Contact');
- $this->Form->hidden('Contact.id', array('value' => 1));
- $this->Form->text('Contact.name');
- $this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
- $this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
- $this->Form->unlockField('Contact.name');
- $this->Form->unlockField('Contact.id');
- $this->assertEquals(array(), $this->Form->fields);
- }
- /**
- * testTagIsInvalid method
- *
- * @return void
- */
- public function testTagIsInvalid() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
- $this->Form->setEntity('Contact.0.email');
- $result = $this->Form->tagIsInvalid();
- $this->assertEquals($expected, $result);
- $this->Form->setEntity('Contact.1.email');
- $result = $this->Form->tagIsInvalid();
- $this->assertFalse($result);
- $this->Form->setEntity('Contact.0.name');
- $result = $this->Form->tagIsInvalid();
- $this->assertFalse($result);
- }
- /**
- * Test tagIsInvalid with validation errors from a saveMany
- *
- * @return void
- */
- public function testTagIsInvalidSaveMany() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
- $this->Form->create('Contact');
- $this->Form->setEntity('0.email');
- $result = $this->Form->tagIsInvalid();
- $this->assertEquals($expected, $result);
- $this->Form->setEntity('0.Contact.email');
- $result = $this->Form->tagIsInvalid();
- $this->assertEquals($expected, $result);
- }
- /**
- * Test validation errors.
- *
- * @return void
- */
- public function testPasswordValidation() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['password'] = array('Please provide a password');
- $result = $this->Form->input('Contact.password');
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- 'Please provide a password',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.password', array('errorMessage' => false));
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test validation errors, when validation message is an empty string.
- *
- * @return void
- */
- public function testEmptyErrorValidation() {
- $this->Form->validationErrors['Contact']['password'] = '';
- $result = $this->Form->input('Contact.password');
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- array(),
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.password', array('errorMessage' => false));
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test validation errors, when calling input() overriding validation message by an empty string.
- *
- * @return void
- */
- public function testEmptyInputErrorValidation() {
- $this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
- $result = $this->Form->input('Contact.password', array('error' => ''));
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- array(),
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
- $expected = array(
- 'div' => array('class' => 'input password error'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- 'input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword', 'class' => 'form-error'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormValidationAssociated method
- *
- * test display of form errors in conjunction with model::validates.
- *
- * @return void
- */
- public function testFormValidationAssociated() {
- $this->UserForm = ClassRegistry::getObject('UserForm');
- $this->UserForm->OpenidUrl = ClassRegistry::getObject('OpenidUrl');
- $data = array(
- 'UserForm' => array('name' => 'user'),
- 'OpenidUrl' => array('url' => 'http://www.cakephp.org')
- );
- $result = $this->UserForm->OpenidUrl->create($data);
- $this->assertFalse(empty($result));
- $this->assertFalse($this->UserForm->OpenidUrl->validates());
- $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
- $encoding = strtolower(Configure::read('App.encoding'));
- $expected = array(
- 'form' => array(
- 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->error(
- 'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
- );
- $this->assertEquals('Error, not registered', $result);
- unset($this->UserForm->OpenidUrl, $this->UserForm);
- }
- /**
- * testFormValidationAssociatedFirstLevel method
- *
- * test form error display with associated model.
- *
- * @return void
- */
- public function testFormValidationAssociatedFirstLevel() {
- $this->ValidateUser = ClassRegistry::getObject('ValidateUser');
- $this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
- $data = array(
- 'ValidateUser' => array('name' => 'mariano'),
- 'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
- );
- $result = $this->ValidateUser->create($data);
- $this->assertFalse(empty($result));
- $this->assertFalse($this->ValidateUser->validates());
- $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
- $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
- $encoding = strtolower(Configure::read('App.encoding'));
- $expected = array(
- 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->error(
- 'ValidateUser.email', 'Invalid email', array('wrap' => false)
- );
- $this->assertEquals('Invalid email', $result);
- $result = $this->Form->error(
- 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
- );
- $this->assertEquals('Invalid name', $result);
- $result = $this->Form->error(
- 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
- );
- $this->assertEquals('Invalid city', $result);
- unset($this->ValidateUser->ValidateProfile);
- unset($this->ValidateUser);
- }
- /**
- * testFormValidationAssociatedSecondLevel method
- *
- * test form error display with associated model.
- *
- * @return void
- */
- public function testFormValidationAssociatedSecondLevel() {
- $this->ValidateUser = ClassRegistry::getObject('ValidateUser');
- $this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
- $this->ValidateUser->ValidateProfile->ValidateItem = ClassRegistry::getObject('ValidateItem');
- $data = array(
- 'ValidateUser' => array('name' => 'mariano'),
- 'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
- 'ValidateItem' => array('name' => 'Item')
- );
- $result = $this->ValidateUser->create($data);
- $this->assertFalse(empty($result));
- $this->assertFalse($this->ValidateUser->validates());
- $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
- $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
- $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
- $encoding = strtolower(Configure::read('App.encoding'));
- $expected = array(
- 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->error(
- 'ValidateUser.email', 'Invalid email', array('wrap' => false)
- );
- $this->assertEquals('Invalid email', $result);
- $result = $this->Form->error(
- 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
- );
- $this->assertEquals('Invalid name', $result);
- $result = $this->Form->error(
- 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
- );
- $result = $this->Form->error(
- 'ValidateItem.description', 'Invalid description', array('wrap' => false)
- );
- $this->assertEquals('Invalid description', $result);
- unset($this->ValidateUser->ValidateProfile->ValidateItem);
- unset($this->ValidateUser->ValidateProfile);
- unset($this->ValidateUser);
- }
- /**
- * testFormValidationMultiRecord method
- *
- * test form error display with multiple records.
- *
- * @return void
- */
- public function testFormValidationMultiRecord() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors[2] = array(
- 'name' => array('This field cannot be left blank')
- );
- $result = $this->Form->input('Contact.2.name');
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'Contact2Name'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][2][name]', 'id' => 'Contact2Name',
- 'class' => 'form-error', 'maxlength' => 255
- ),
- array('div' => array('class' => 'error-message')),
- 'This field cannot be left blank',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testMultipleInputValidation method
- *
- * test multiple record form validation error display.
- *
- * @return void
- */
- public function testMultipleInputValidation() {
- $Address = ClassRegistry::init(array('class' => 'Address', 'table' => false, 'ds' => 'test'));
- $Address->validationErrors[0] = array(
- 'title' => array('This field cannot be empty'),
- 'first_name' => array('This field cannot be empty')
- );
- $Address->validationErrors[1] = array(
- 'last_name' => array('You must have a last name')
- );
- $this->Form->create();
- $result = $this->Form->input('Address.0.title');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'preg:/[^<]+/',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name', 'id', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- 'This field cannot be empty',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Address.0.first_name');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'preg:/[^<]+/',
- '/label',
- 'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
- array('div' => array('class' => 'error-message')),
- 'This field cannot be empty',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Address.0.last_name');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'preg:/[^<]+/',
- '/label',
- 'input' => array('type' => 'text', 'name', 'id'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Address.1.last_name');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'preg:/[^<]+/',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name', 'id',
- 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- 'You must have a last name',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testInput method
- *
- * Test various incarnations of input().
- *
- * @return void
- */
- public function testInput() {
- $result = $this->Form->input('ValidateUser.balance');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'Balance',
- '/label',
- 'input' => array('name', 'type' => 'number', 'id', 'step'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('ValidateUser.cost_decimal');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'Cost Decimal',
- '/label',
- 'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('ValidateUser.ratio');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'Ratio',
- '/label',
- 'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('ValidateUser.population');
- $expected = array(
- 'div' => array('class'),
- 'label' => array('for'),
- 'Population',
- '/label',
- 'input' => array('name', 'type' => 'number', 'step' => '1', 'id'),
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array('id' => 'custom'));
- $expected = array(
- 'div' => array('class' => 'input email'),
- 'label' => array('for' => 'custom'),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'email', 'name' => 'data[Contact][email]',
- 'id' => 'custom', 'maxlength' => 255
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
- $expected = array(
- '<div',
- 'label' => array('for' => 'ContactEmail'),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'email', 'name' => 'data[Contact][email]',
- 'id' => 'ContactEmail', 'maxlength' => 255
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->hidden('Contact.idontexist');
- $expected = array('input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][idontexist]',
- 'id' => 'ContactIdontexist'
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactEmail'),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
- 'id' => 'ContactEmail'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.5.email', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'Contact5Email'),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][5][email]',
- 'id' => 'Contact5Email'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.password');
- $expected = array(
- 'div' => array('class' => 'input password'),
- 'label' => array('for' => 'ContactPassword'),
- 'Password',
- '/label',
- array('input' => array(
- 'type' => 'password', 'name' => 'data[Contact][password]',
- 'id' => 'ContactPassword'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array(
- 'type' => 'file', 'class' => 'textbox'
- ));
- $expected = array(
- 'div' => array('class' => 'input file'),
- 'label' => array('for' => 'ContactEmail'),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox',
- 'id' => 'ContactEmail'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
- $result = $this->Form->input('Contact.phone');
- $expected = array(
- 'div' => array('class' => 'input tel'),
- 'label' => array('for' => 'ContactPhone'),
- 'Phone',
- '/label',
- array('input' => array(
- 'type' => 'tel', 'name' => 'data[Contact][phone]',
- 'value' => 'Hello & World > weird chars',
- 'id' => 'ContactPhone', 'maxlength' => 255
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
- $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'myId'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Model][0][OtherModel][field]',
- 'value' => 'My value', 'id' => 'myId'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- unset($this->Form->request->data);
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['field'] = array('Badness!');
- $result = $this->Form->input('Contact.field');
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field]',
- 'id' => 'ContactField', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error-message')),
- 'Badness!',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.field', array(
- 'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
- ));
- $expected = array(
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field]',
- 'id' => 'ContactField', 'class' => 'form-error'
- ),
- array('span' => array('class' => 'error-message')),
- 'Badness!',
- '/span'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.field', array(
- 'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
- ));
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field]',
- 'id' => 'ContactField', 'class' => 'form-error'
- ),
- array('div' => array('class' => 'error')),
- 'Badness!',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.field', array(
- 'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
- ));
- $expected = array(
- 'span' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field]',
- 'id' => 'ContactField', 'class' => 'form-error'
- ),
- 'Badness!',
- '/span'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field]',
- 'id' => 'ContactField', 'class' => 'form-error'
- ),
- 'A message to you, Rudy',
- array('div' => array('class' => 'error-message')),
- 'Badness!',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->setEntity(null);
- $this->Form->setEntity('Contact.field');
- $result = $this->Form->input('Contact.field', array(
- 'after' => 'A message to you, Rudy', 'error' => false
- ));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
- 'A message to you, Rudy',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ObjectField'),
- 'Field',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
- 'A message to you, Rudy',
- '/div'
- );
- $this->assertTags($result, $expected);
- $Contact->validationErrors['field'] = array('minLength');
- $result = $this->Form->input('Contact.field', array(
- 'error' => array(
- 'minLength' => 'Le login doit contenir au moins 2 caractères',
- 'maxLength' => 'login too large'
- )
- ));
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
- array('div' => array('class' => 'error-message')),
- 'Le login doit contenir au moins 2 caractères',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $Contact->validationErrors['field'] = array('maxLength');
- $result = $this->Form->input('Contact.field', array(
- 'error' => array(
- 'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
- 'minLength' => 'Le login doit contenir au moins 2 caractères',
- 'maxLength' => 'login too large',
- )
- ));
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ContactField'),
- 'Field',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
- array('span' => array('class' => 'error-message', 'rel' => 'fake')),
- 'login too large',
- '/span',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that inputs with 0 can be created.
- *
- * @return void
- */
- public function testInputZero() {
- $this->Form->create('User');
- $result = $this->Form->input('0');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'User0'), '/label',
- 'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test input() with checkbox creation
- *
- * @return void
- */
- public function testInputCheckbox() {
- $result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('User.disabled', array(
- 'label' => 'Disabled',
- 'type' => 'checkbox',
- 'data-foo' => 'disabled'
- ));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
- array('input' => array(
- 'type' => 'checkbox',
- 'name' => 'data[User][disabled]',
- 'value' => '1',
- 'id' => 'UserDisabled',
- 'data-foo' => 'disabled'
- )),
- 'label' => array('for' => 'UserDisabled'),
- 'Disabled',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test form->input() with time types.
- *
- * @return void
- */
- public function testInputTime() {
- extract($this->dateRegex);
- $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
- $result = explode(':', $result);
- $this->assertRegExp('/option value="23"/', $result[0]);
- $this->assertNotRegExp('/option value="24"/', $result[0]);
- $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
- $result = explode(':', $result);
- $this->assertRegExp('/option value="23"/', $result[0]);
- $this->assertNotRegExp('/option value="24"/', $result[0]);
- $result = $this->Form->input('Model.field', array(
- 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
- $result = $this->Form->input('Model.field', array(
- 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
- $result = $this->Form->input('prueba', array(
- 'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
- 'maxYear' => date('Y') + 1, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
- $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
- $result = $this->Form->input('Random.start_time', array(
- 'type' => 'time',
- 'selected' => '18:15'
- ));
- $this->assertContains('<option value="06" selected="selected">6</option>', $result);
- $this->assertContains('<option value="15" selected="selected">15</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('published', array('type' => 'time'));
- $now = strtotime('now');
- $this->assertContains('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
- $now = strtotime('2013-03-09 00:42:21');
- $result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
- $this->assertContains('<option value="12" selected="selected">12</option>', $result);
- $this->assertContains('<option value="42" selected="selected">42</option>', $result);
- }
- /**
- * Test interval + selected near the hour roll over.
- *
- * @return void
- */
- public function testTimeSelectedWithInterval() {
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'interval' => 15,
- 'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
- ));
- $this->assertContains('<option value="04" selected="selected">4</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'interval' => 15,
- 'selected' => '2012-10-23 15:57:00'
- ));
- $this->assertContains('<option value="04" selected="selected">4</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'timeFormat' => 24,
- 'type' => 'time',
- 'interval' => 15,
- 'selected' => '15:57'
- ));
- $this->assertContains('<option value="16" selected="selected">16</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'timeFormat' => 24,
- 'type' => 'time',
- 'interval' => 15,
- 'selected' => '23:57'
- ));
- $this->assertContains('<option value="00" selected="selected">0</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $result = $this->Form->input('Model.created', array(
- 'timeFormat' => 24,
- 'type' => 'datetime',
- 'interval' => 15,
- 'selected' => '2012-09-30 23:56'
- ));
- $this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
- $this->assertContains('<option value="10" selected="selected">October</option>', $result);
- $this->assertContains('<option value="01" selected="selected">1</option>', $result);
- $this->assertContains('<option value="00" selected="selected">0</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- }
- /**
- * Test time with selected values around 12:xx:xx
- *
- * @return void
- */
- public function testTimeSelectedWithIntervalTwelve() {
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => 12,
- 'interval' => 15,
- 'selected' => '00:00:00'
- ));
- $this->assertContains('<option value="12" selected="selected">12</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $this->assertContains('<option value="am" selected="selected">am</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => 12,
- 'interval' => 15,
- 'selected' => '12:00:00'
- ));
- $this->assertContains('<option value="12" selected="selected">12</option>', $result);
- $this->assertContains('<option value="00" selected="selected">00</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => 12,
- 'interval' => 15,
- 'selected' => '12:15:00'
- ));
- $this->assertContains('<option value="12" selected="selected">12</option>', $result);
- $this->assertContains('<option value="15" selected="selected">15</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- }
- /**
- * Test interval & timeFormat = 12
- *
- * @return void
- */
- public function testInputTimeWithIntervalAnd12HourFormat() {
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => 12,
- 'interval' => 5,
- 'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
- ));
- $this->assertContains('<option value="04" selected="selected">4</option>', $result);
- $this->assertContains('<option value="30" selected="selected">30</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => '12',
- 'interval' => 5,
- 'selected' => '2013-04-19 16:30:00'
- ));
- $this->assertContains('<option value="04" selected="selected">4</option>', $result);
- $this->assertContains('<option value="30" selected="selected">30</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => '12',
- 'interval' => 10,
- 'selected' => '2013-05-19 00:33:00'
- ));
- $this->assertContains('<option value="12" selected="selected">12</option>', $result);
- $this->assertContains('<option value="30" selected="selected">30</option>', $result);
- $this->assertContains('<option value="am" selected="selected">am</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => '12',
- 'interval' => 10,
- 'selected' => '2013-05-19 13:33:00'
- ));
- $this->assertContains('<option value="01" selected="selected">1</option>', $result);
- $this->assertContains('<option value="30" selected="selected">30</option>', $result);
- $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
- $result = $this->Form->input('Model.start_time', array(
- 'type' => 'time',
- 'timeFormat' => '12',
- 'interval' => 10,
- 'selected' => '2013-05-19 01:33:00'
- ));
- $this->assertContains('<option value="01" selected="selected">1</option>', $result);
- $this->assertContains('<option value="30" selected="selected">30</option>', $result);
- $this->assertContains('<option value="am" selected="selected">am</option>', $result);
- }
- /**
- * test form->input() with datetime, date and time types
- *
- * @return void
- */
- public function testInputDatetime() {
- extract($this->dateRegex);
- $result = $this->Form->input('prueba', array(
- 'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
- 'maxYear' => date('Y') + 1, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
- $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
- //related to ticket #5013
- $result = $this->Form->input('Contact.date', array(
- 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
- ));
- $this->assertRegExp('/class="customClass"/', $result);
- $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
- $result = $this->Form->input('Contact.date', array(
- 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
- ));
- $this->assertRegExp('/id="customIdDay"/', $result);
- $this->assertRegExp('/id="customIdMonth"/', $result);
- $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
- $result = $this->Form->input('Model.field', array(
- 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
- ));
- $this->assertRegExp('/id="customIDDay"/', $result);
- $this->assertRegExp('/id="customIDHour"/', $result);
- $result = explode('</select><select', $result);
- $result = explode(':', $result[1]);
- $this->assertRegExp('/option value="23"/', $result[0]);
- $this->assertNotRegExp('/option value="24"/', $result[0]);
- $result = $this->Form->input('Model.field', array(
- 'type' => 'datetime', 'timeFormat' => 12
- ));
- $result = explode('</select><select', $result);
- $result = explode(':', $result[1]);
- $this->assertRegExp('/option value="12"/', $result[0]);
- $this->assertNotRegExp('/option value="13"/', $result[0]);
- $this->Form->request->data = array('Contact' => array('created' => null));
- $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ContactCreatedMonth'),
- 'Created',
- '/label',
- array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $monthsRegex,
- '/select', '-',
- array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $daysRegex,
- '/select', '-',
- array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $yearsRegex,
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Contact' => array('created' => null));
- $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
- $this->assertRegExp('/for\="ContactCreatedHour"/', $result);
- $this->Form->request->data = array('Contact' => array('created' => null));
- $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
- $this->assertRegExp('/for\="ContactCreatedMonth"/', $result);
- $result = $this->Form->input('Contact.created', array(
- 'type' => 'date',
- 'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
- 'timeFormat' => 'NONE'
- ));
- $this->assertRegExp('/for\="created-month"/', $result);
- }
- /**
- * Test generating checkboxes in a loop.
- *
- * @return void
- */
- public function testInputCheckboxesInLoop() {
- for ($i = 1; $i < 5; $i++) {
- $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
- 'label' => array('for' => "Contact{$i}Email"),
- 'Email',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- }
- /**
- * Test generating checkboxes with disabled elements.
- *
- * @return void
- */
- public function testInputCheckboxWithDisabledElements() {
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => "ContactMultiple")),
- 'Multiple',
- '/label',
- array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
- array('label' => array('for' => "ContactMultiple1")),
- 'One',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
- array('label' => array('for' => "ContactMultiple2")),
- 'Two',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
- array('label' => array('for' => "ContactMultiple3")),
- 'Three',
- '/label',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => true, 'options' => $options));
- $this->assertTags($result, $expected);
- $disabled = array('2', 3);
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => "ContactMultiple")),
- 'Multiple',
- '/label',
- array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
- array('label' => array('for' => "ContactMultiple1")),
- 'One',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
- array('label' => array('for' => "ContactMultiple2")),
- 'Two',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
- array('label' => array('for' => "ContactMultiple3")),
- 'Three',
- '/label',
- '/div',
- '/div'
- );
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
- $this->assertTags($result, $expected);
- // make sure 50 does only disable 50, and not 50f5c0cf
- $options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
- $disabled = array(50);
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => "ContactMultiple")),
- 'Multiple',
- '/label',
- array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
- array('label' => array('for' => "ContactMultiple50")),
- 'Fifty',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
- array('label' => array('for' => "ContactMultiple50f5c0cf")),
- 'Stringy',
- '/label',
- '/div',
- '/div'
- );
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
- $this->assertTags($result, $expected);
- }
- /**
- * test input name with leading integer, ensure attributes are generated correctly.
- *
- * @return void
- */
- public function testInputWithLeadingInteger() {
- $result = $this->Form->text('0.Node.title');
- $expected = array(
- 'input' => array('name' => 'data[0][Node][title]', 'id' => '0NodeTitle', 'type' => 'text')
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test form->input() with select type inputs.
- *
- * @return void
- */
- public function testInputSelectType() {
- $result = $this->Form->input('email', array(
- 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
- );
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'email'),
- 'Email',
- '/label',
- array('select' => array('name' => 'data[email]', 'id' => 'email')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'è')),
- 'Firést',
- '/option',
- array('option' => array('value' => 'é')),
- 'Secoènd',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('email', array(
- 'options' => array('First', 'Second'), 'empty' => true)
- );
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'email'),
- 'Email',
- '/label',
- array('select' => array('name' => 'data[email]', 'id' => 'email')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '0')),
- 'First',
- '/option',
- array('option' => array('value' => '1')),
- 'Second',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $this->Form->request->data = array('Model' => array('user_id' => 'value'));
- $result = $this->Form->input('Model.user_id', array('empty' => true));
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'ModelUserId'),
- 'User',
- '/label',
- 'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'value', 'selected' => 'selected')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $this->Form->request->data = array('Thing' => array('user_id' => null));
- $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'ThingUserId'),
- 'User',
- '/label',
- 'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
- array('option' => array('value' => '')),
- 'Some Empty',
- '/option',
- array('option' => array('value' => 'value')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $this->Form->request->data = array('Thing' => array('user_id' => 'value'));
- $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'ThingUserId'),
- 'User',
- '/label',
- 'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
- array('option' => array('value' => '')),
- 'Some Empty',
- '/option',
- array('option' => array('value' => 'value', 'selected' => 'selected')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $this->Form->request->data = array('User' => array('User' => array('value')));
- $result = $this->Form->input('User.User', array('empty' => true));
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'UserUser'),
- 'User',
- '/label',
- 'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => '', 'id' => 'UserUser_'),
- 'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'value', 'selected' => 'selected')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->data = array();
- $result = $this->Form->input('Publisher.id', array(
- 'label' => 'Publisher',
- 'type' => 'select',
- 'multiple' => 'checkbox',
- 'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
- ));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'PublisherId')),
- 'Publisher',
- '/label',
- 'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
- array('label' => array('for' => 'PublisherIdValue1')),
- 'Label 1',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
- array('label' => array('for' => 'PublisherIdValue2')),
- 'Label 2',
- '/label',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that input() and a non standard primary key makes a hidden input by default.
- *
- * @return void
- */
- public function testInputWithNonStandardPrimaryKeyMakesHidden() {
- $this->Form->create('User');
- $this->Form->fieldset = array(
- 'User' => array(
- 'fields' => array(
- 'model_id' => array('type' => 'integer')
- ),
- 'validates' => array(),
- 'key' => 'model_id'
- )
- );
- $result = $this->Form->input('model_id');
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that overriding the magic select type widget is possible
- *
- * @return void
- */
- public function testInputOverridingMagicSelectType() {
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $result = $this->Form->input('Model.user_id', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ModelUserId'), 'User', '/label',
- 'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
- '/div'
- );
- $this->assertTags($result, $expected);
- //Check that magic types still work for plural/singular vars
- $this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
- $result = $this->Form->input('Model.type');
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'ModelType'), 'Type', '/label',
- 'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
- array('option' => array('value' => 'value')), 'good', '/option',
- array('option' => array('value' => 'other')), 'bad', '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that inferred types do not override developer input
- *
- * @return void
- */
- public function testInputMagicTypeDoesNotOverride() {
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $result = $this->Form->input('Model.user', array('type' => 'checkbox'));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- array('input' => array(
- 'type' => 'hidden',
- 'name' => 'data[Model][user]',
- 'id' => 'ModelUser_',
- 'value' => 0,
- )),
- array('input' => array(
- 'name' => 'data[Model][user]',
- 'type' => 'checkbox',
- 'id' => 'ModelUser',
- 'value' => 1
- )),
- 'label' => array('for' => 'ModelUser'), 'User', '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that magic input() selects are created for type=number
- *
- * @return void
- */
- public function testInputMagicSelectForTypeNumber() {
- $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
- $this->Form->request->data = array('ValidateUser' => array('balance' => 1));
- $result = $this->Form->input('ValidateUser.balance');
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'ValidateUserBalance'),
- 'Balance',
- '/label',
- 'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'),
- array('option' => array('value' => '0')),
- 'nothing',
- '/option',
- array('option' => array('value' => '1', 'selected' => 'selected')),
- 'some',
- '/option',
- array('option' => array('value' => '100')),
- 'a lot',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that magic input() selects can easily be converted into radio types without error.
- *
- * @return void
- */
- public function testInputMagicSelectChangeToRadio() {
- $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $result = $this->Form->input('Model.user_id', array('type' => 'radio'));
- $this->assertRegExp('/input type="radio"/', $result);
- }
- /**
- * fields with the same name as the model should work.
- *
- * @return void
- */
- public function testInputWithMatchingFieldAndModelName() {
- $this->Form->create('User');
- $this->Form->fieldset = array(
- 'User' => array(
- 'fields' => array(
- 'User' => array('type' => 'text')
- ),
- 'validates' => array(),
- 'key' => 'id'
- )
- );
- $this->Form->request->data['User']['User'] = 'ABC, Inc.';
- $result = $this->Form->input('User', array('type' => 'text'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'UserUser'), 'User', '/label',
- 'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormInputs method
- *
- * test correct results from form::inputs().
- *
- * @return void
- */
- public function testFormInputs() {
- $this->Form->create('Contact');
- $result = $this->Form->inputs('The Legend');
- $expected = array(
- '<fieldset',
- '<legend',
- 'The Legend',
- '/legend',
- '*/fieldset',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
- $expected = array(
- 'fieldset' => array('class' => 'classy-stuff'),
- '<legend',
- 'Field of Dreams',
- '/legend',
- '*/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
- $this->assertTags($result, $expected);
- $result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $this->Form->request['prefix'] = 'admin';
- $this->Form->request['action'] = 'admin_edit';
- $result = $this->Form->inputs();
- $expected = array(
- '<fieldset',
- '<legend',
- 'Edit Contact',
- '/legend',
- '*/fieldset',
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(false);
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(null, null, array('fieldset' => false));
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
- $expected = array(
- 'fieldset' => array(),
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs('Hello');
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Hello',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(array('legend' => 'Hello'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Hello',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
- array('div' => array('class' => 'input text')),
- '*/div',
- array('div' => array('class' => 'input email')),
- '*/div',
- array('div' => array('class' => 'input tel')),
- '*/div',
- array('div' => array('class' => 'input password')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input date')),
- '*/div',
- array('div' => array('class' => 'input datetime')),
- '*/div',
- array('div' => array('class' => 'input number')),
- '*/div',
- array('div' => array('class' => 'input select')),
- '*/div',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
- $this->assertTags($result, $expected);
- $this->Form->end();
- $this->Form->create(false);
- $expected = array(
- 'fieldset' => array(),
- array('div' => array('class' => 'input text')),
- 'label' => array('for' => 'foo'),
- 'Foo',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[foo]', 'id' => 'foo'),
- '*/div',
- '/fieldset'
- );
- $result = $this->Form->inputs(
- array('foo' => array('type' => 'text')),
- array(),
- array('legend' => false)
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Tests inputs() works with plugin models
- *
- * @return void
- */
- public function testInputsPluginModel() {
- $this->loadFixtures('Post');
- App::build(array(
- 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
- ));
- CakePlugin::load('TestPlugin');
- $this->Form->request['models'] = array(
- 'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
- );
- $this->Form->create('TestPlugin.TestPluginPost');
- $result = $this->Form->inputs();
- $this->assertContains('data[TestPluginPost][id]', $result);
- $this->assertContains('data[TestPluginPost][author_id]', $result);
- $this->assertContains('data[TestPluginPost][title]', $result);
- $this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
- $this->assertFalse(ClassRegistry::isKeySet('TestPlugin'));
- $this->assertEquals('TestPluginPost', $this->Form->model());
- }
- /**
- * testSelectAsCheckbox method
- *
- * test multi-select widget with checkbox formatting.
- *
- * @return void
- */
- public function testSelectAsCheckbox() {
- $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
- array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
- array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
- array('label' => array('for' => 'ModelMultiField2')),
- 'third',
- '/label',
- '/div',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
- array('label' => array('for' => 'ModelMultiField12')),
- 'half',
- '/label',
- '/div',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testLabel method
- *
- * test label generation.
- *
- * @return void
- */
- public function testLabel() {
- $this->Form->text('Person.name');
- $result = $this->Form->label();
- $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
- $this->Form->text('Person.name');
- $result = $this->Form->label();
- $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
- $result = $this->Form->label('Person.first_name');
- $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));
- $result = $this->Form->label('Person.first_name', 'Your first name');
- $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));
- $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
- $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));
- $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
- $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
- $result = $this->Form->label('Person.first_name', '');
- $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));
- $result = $this->Form->label('Person.2.name', '');
- $this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));
- }
- /**
- * testTextbox method
- *
- * test textbox element generation
- *
- * @return void
- */
- public function testTextbox() {
- $result = $this->Form->text('Model.field');
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
- $result = $this->Form->text('Model.field', array('type' => 'password'));
- $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
- $result = $this->Form->text('Model.field', array('id' => 'theID'));
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'theID')));
- $this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
- $result = $this->Form->text('Model.text');
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText')));
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['text'] = array(true);
- $this->Form->request->data['Contact']['text'] = 'test';
- $result = $this->Form->text('Contact.text', array('id' => 'theID'));
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Contact][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
- $this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
- $result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
- $expected = array(
- 'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId')
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testDefaultValue method
- *
- * Test default value setting
- *
- * @return void
- */
- public function testDefaultValue() {
- $this->Form->request->data['Model']['field'] = 'test';
- $result = $this->Form->text('Model.field', array('default' => 'default value'));
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
- unset($this->Form->request->data['Model']['field']);
- $result = $this->Form->text('Model.field', array('default' => 'default value'));
- $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
- }
- /**
- * testCheckboxDefaultValue method
- *
- * Test default value setting on checkbox() method
- *
- * @return void
- */
- public function testCheckboxDefaultValue() {
- $this->Form->request->data['Model']['field'] = false;
- $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
- $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
- unset($this->Form->request->data['Model']['field']);
- $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
- $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
- $this->Form->request->data['Model']['field'] = true;
- $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
- $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
- unset($this->Form->request->data['Model']['field']);
- $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
- $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
- }
- /**
- * testError method
- *
- * Test field error generation
- *
- * @return void
- */
- public function testError() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['field'] = array(1);
- $result = $this->Form->error('Contact.field');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
- $result = $this->Form->error('Contact.field', null, array('wrap' => false));
- $this->assertEquals('Error in field Field', $result);
- $Contact->validationErrors['field'] = array("This field contains invalid input");
- $result = $this->Form->error('Contact.field', null, array('wrap' => false));
- $this->assertEquals('This field contains invalid input', $result);
- $Contact->validationErrors['field'] = array("This field contains invalid input");
- $result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
- $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
- $result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
- $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
- $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
- $this->assertEquals('<strong>Badness!</strong>', $result);
- $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
- $this->assertEquals('<strong>Badness!</strong>', $result);
- $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
- $this->assertEquals('<strong>Badness!</strong>', $result);
- $Contact->validationErrors['field'] = array("email");
- $result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
- $expected = array(
- 'div' => array('class' => 'field-error'),
- 'No good!',
- '/div'
- );
- $this->assertTags($result, $expected);
- $Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
- $result = $this->Form->error('Contact.field', array(
- 'notEmpty' => 'Cannot be empty',
- 'email' => 'No good!'
- ));
- $expected = array(
- 'div' => array('class' => 'error-message'),
- 'ul' => array(),
- '<li', 'Cannot be empty', '/li',
- '<li', 'No good!', '/li',
- '<li', 'Something else', '/li',
- '/ul',
- '/div'
- );
- $this->assertTags($result, $expected);
- // Testing error messages list options
- $Contact->validationErrors['field'] = array('notEmpty', 'email');
- $result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
- $expected = array(
- 'div' => array('class' => 'error-message'),
- 'ol' => array(),
- '<li', 'notEmpty', '/li',
- '<li', 'email', '/li',
- '/ol',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
- $expected = array(
- 'div' => array('class' => 'error-message'),
- 'ol' => array(),
- '<li', 'notEmpty', '/li',
- '<li', 'email', '/li',
- '/ol',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->error('Contact.field', null, array(
- 'listOptions' => array(
- 'class' => 'ul-class',
- 'itemOptions' => array(
- 'class' => 'li-class'
- )
- )
- ));
- $expected = array(
- 'div' => array('class' => 'error-message'),
- 'ul' => array('class' => 'ul-class'),
- array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
- array('li' => array('class' => 'li-class')), 'email', '/li',
- '/ul',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test error options when using form->input();
- *
- * @return void
- */
- public function testInputErrorEscape() {
- $this->Form->create('ValidateProfile');
- $ValidateProfile = ClassRegistry::getObject('ValidateProfile');
- $ValidateProfile->validationErrors['city'] = array('required<br>');
- $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
- $this->assertRegExp('/required<br>/', $result);
- $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
- $this->assertRegExp('/required<br>/', $result);
- }
- /**
- * testPassword method
- *
- * Test password element generation
- *
- * @return void
- */
- public function testPassword() {
- $Contact = ClassRegistry::getObject('Contact');
- $result = $this->Form->password('Contact.field');
- $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][field]', 'id' => 'ContactField')));
- $Contact->validationErrors['passwd'] = 1;
- $this->Form->request->data['Contact']['passwd'] = 'test';
- $result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
- $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
- }
- /**
- * testRadio method
- *
- * Test radio element set generation
- *
- * @return void
- */
- public function testRadio() {
- $result = $this->Form->radio('Model.field', array('option A'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
- 'label' => array('for' => 'ModelField0'),
- 'option A',
- '/label'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1/2' => 'half'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
- 'label' => array('for' => 'ModelField12'),
- 'half',
- '/label'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('option A', 'option B'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- 'br' => array(),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio(
- 'Employee.gender',
- array('male' => 'Male', 'female' => 'Female'),
- array('form' => 'my-form')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Gender',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_', 'form' => 'my-form'),
- array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale', 'form' => 'my-form')),
- array('label' => array('for' => 'EmployeeGenderMale')),
- 'Male',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale', 'form' => 'my-form')),
- array('label' => array('for' => 'EmployeeGenderFemale')),
- 'Female',
- '/label',
- '/fieldset',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Gender',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')),
- array('label' => array('for' => 'OfficerGenderMale')),
- 'Male',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')),
- array('label' => array('for' => 'OfficerGenderFemale')),
- 'Female',
- '/label',
- '/fieldset',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Contact.1.imrequired', array('option A'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][1][imrequired]', 'value' => '', 'id' => 'Contact1Imrequired_'),
- array('input' => array(
- 'type' => 'radio',
- 'name' => 'data[Contact][1][imrequired]',
- 'value' => '0',
- 'id' => 'Contact1Imrequired0',
- 'required' => 'required'
- )),
- 'label' => array('for' => 'Contact1Imrequired0'),
- 'option A',
- '/label'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.1.field', array('option A'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
- 'label' => array('for' => 'Model1Field0'),
- 'option A',
- '/label'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][custom]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '0', 'id' => 'ModelField0')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio(
- 'Model.field',
- array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][field]',
- 'id' => 'ModelField_', 'value' => '',
- ),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
- 'id' => 'ModelFieldAB', 'value' => 'a>b')),
- array('label' => array('for' => 'ModelFieldAB')),
- 'first',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
- 'id' => 'ModelFieldAB1', 'value' => 'a<b')),
- array('label' => array('for' => 'ModelFieldAB1')),
- 'second',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
- 'id' => 'ModelFieldAB2', 'value' => 'a"b')),
- array('label' => array('for' => 'ModelFieldAB2')),
- 'third',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testRadioDifferentModel
- * Refs #2911
- *
- * @return void
- */
- public function testRadioDifferentModel() {
- $this->Form->create('User');
- $result = $this->Form->radio(
- 'Model.field',
- array('v1' => 'option A', 'v2' => 'option B'),
- array('label' => true, 'legend' => false, 'value' => false)
- );
- $expected = array(
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => 'v1', 'id' => 'ModelFieldV1'
- )),
- array('label' => array('for' => 'ModelFieldV1')),
- 'option A',
- '/label',
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => 'v2', 'id' => 'ModelFieldV2'
- )),
- array('label' => array('for' => 'ModelFieldV2')),
- 'option B',
- '/label'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test radio inputs with between as string or array. Also ensure
- * that an array with less between elements works.
- *
- * @return void
- */
- public function testRadioBetween() {
- $result = $this->Form->radio(
- 'Model.field',
- array('option A', 'option B'),
- array('between' => 'I am between')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'I am between',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][field]',
- 'value' => '', 'id' => 'ModelField_'
- ),
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => '0', 'id' => 'ModelField0'
- )),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => '1', 'id' => 'ModelField1'
- )),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio(
- 'Model.field',
- array('option A', 'option B', 'option C'),
- array('separator' => '--separator--', 'between' => array('between A', 'between B', 'between C'))
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][field]',
- 'value' => '', 'id' => 'ModelField_'
- ),
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => '0', 'id' => 'ModelField0'
- )),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- 'between A',
- '--separator--',
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => '1', 'id' => 'ModelField1'
- )),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- 'between B',
- '--separator--',
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Model][field]',
- 'value' => '2', 'id' => 'ModelField2'
- )),
- array('label' => array('for' => 'ModelField2')),
- 'option C',
- '/label',
- 'between C',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.field', array(
- 'options' => array('1' => 'first', '2' => 'second'),
- 'type' => 'radio',
- 'before' => '--before--',
- 'after' => '--after--',
- 'separator' => '--separator--',
- 'between' => array('--between first--', '--between second--')
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- '--before--',
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'first',
- '/label',
- '--between first--',
- '--separator--',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
- array('label' => array('for' => 'ModelField2')),
- 'second',
- '/label',
- '--between second--',
- '/fieldset',
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.field', array(
- 'options' => array('1' => 'first', '2' => 'second'),
- 'type' => 'radio',
- 'before' => '--before--',
- 'after' => '--after--',
- 'separator' => '--separator--',
- 'between' => array('--between first--')
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- '--before--',
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'first',
- '/label',
- '--between first--',
- '--separator--',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
- array('label' => array('for' => 'ModelField2')),
- 'second',
- '/label',
- '/fieldset',
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that radios with a 0 value are selected under the correct conditions.
- * Also ensure that values that are booleanish are handled correctly.
- *
- * @return void
- */
- public function testRadioOptionWithBooleanishValues() {
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'Yes',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
- array('label' => array('for' => 'ModelField0')),
- 'No',
- '/label',
- '/fieldset'
- );
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 0));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => false));
- $this->assertTags($result, $expected);
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'Yes',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
- array('label' => array('for' => 'ModelField0')),
- 'No',
- '/label',
- '/fieldset'
- );
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => ''));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
- $this->assertTags($result, $expected);
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'Yes',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
- array('label' => array('for' => 'ModelField0')),
- 'No',
- '/label',
- '/fieldset'
- );
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 1));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => true));
- $this->assertTags($result, $expected);
- }
- /**
- * test disabled radio options
- *
- * @return void
- */
- public function testRadioDisabled() {
- $result = $this->Form->radio(
- 'Model.field',
- array('option A', 'option B'),
- array('disabled' => array(0), 'value' => '0')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio(
- 'Model.field',
- array('option A', 'option B'),
- array('disabled' => true, 'value' => '0')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio(
- 'Model.field',
- array('option A', 'option B'),
- array('disabled' => 'disabled', 'value' => '0')
- );
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
- array('label' => array('for' => 'ModelField0')),
- 'option A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
- array('label' => array('for' => 'ModelField1')),
- 'option B',
- '/label',
- '/fieldset'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.field', array(
- 'options' => array(1 => 'first', 2 => 'second', '2x' => '2x', '3' => 'third', '3x' => '3x'),
- 'type' => 'radio',
- 'disabled' => array(2, '3x'),
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
- array('label' => array('for' => 'ModelField1')),
- 'first',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '2', 'id' => 'ModelField2')),
- array('label' => array('for' => 'ModelField2')),
- 'second',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2x', 'id' => 'ModelField2x')),
- array('label' => array('for' => 'ModelField2x')),
- '2x',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '3', 'id' => 'ModelField3')),
- array('label' => array('for' => 'ModelField3')),
- 'third',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '3x', 'id' => 'ModelField3x')),
- array('label' => array('for' => 'ModelField3x')),
- '3x',
- '/label',
- '/fieldset',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.field', array(
- 'type' => 'radio',
- 'options' => array(
- 1 => 'A',
- 2 => 'B',
- 3 => 'C'
- ),
- 'disabled' => array(1)
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField1', 'disabled' => 'disabled', 'value' => '1')),
- array('label' => array('for' => 'ModelField1')),
- 'A',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField2', 'value' => '2')),
- array('label' => array('for' => 'ModelField2')),
- 'B',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField3', 'value' => '3')),
- array('label' => array('for' => 'ModelField3')),
- 'C',
- '/label',
- '/fieldset',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test disabling the hidden input for radio buttons
- *
- * @return void
- */
- public function testRadioHiddenInputDisabling() {
- $result = $this->Form->input('Model.1.field', array(
- 'type' => 'radio',
- 'options' => array('option A'),
- 'hiddenField' => false
- )
- );
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
- 'label' => array('for' => 'Model1Field0'),
- 'option A',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
- $expected = array(
- 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
- 'label' => array('for' => 'Model1Field0'),
- 'option A',
- '/label'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test adding an empty option for radio buttons
- *
- * @return void
- */
- public function testRadioAddEmptyOption() {
- $result = $this->Form->input('Model.1.field', array(
- 'type' => 'radio',
- 'options' => array('option A'),
- 'empty' => true,
- 'hiddenField' => false
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
- array('label' => array('for' => 'Model1Field')),
- __('empty'),
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
- array('label' => array('for' => 'Model1Field0')),
- 'option A',
- '/label',
- '/fieldset',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.1.field', array(
- 'type' => 'radio',
- 'options' => array('option A'),
- 'empty' => 'CustomEmptyLabel',
- 'hiddenField' => false
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'fieldset' => array(),
- 'legend' => array(),
- 'Field',
- '/legend',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
- array('label' => array('for' => 'Model1Field')),
- 'CustomEmptyLabel',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
- array('label' => array('for' => 'Model1Field0')),
- 'option A',
- '/label',
- '/fieldset',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.1.field', array(
- 'type' => 'radio',
- 'options' => array('option A'),
- 'empty' => false,
- 'hiddenField' => false
- ));
- $this->assertTextNotContains('"Model1Field"', $result);
- }
- /**
- * Test that radio() accepts an array for label
- *
- * @return void
- */
- public function testRadioLabelArray() {
- $result = $this->Form->input('Model.field', array(
- 'type' => 'radio',
- 'legend' => false,
- 'label' => array(
- 'class' => 'checkbox float-left',
- ),
- 'options' => array('1' => 'Option A', '2' => 'Option B.')
- ));
- $this->assertTextContains(
- '<label for="ModelField1" class="checkbox float-left">Option A</label>',
- $result
- );
- }
- /**
- * Test that label id's match the input element id's when radio is called after create().
- *
- * @return void
- */
- public function testRadioWithCreate() {
- $this->Form->create('Model');
- $result = $this->Form->radio('recipient',
- array('1' => '1', '2' => '2', '3' => '3'),
- array('legend' => false, 'value' => '1')
- );
- $this->assertTextNotContains(
- '<label for="ModelModelRecipient1">1</label>',
- $result
- );
- $this->assertTextContains(
- '<label for="ModelRecipient1">1</label>',
- $result
- );
- }
- /**
- * testDomIdSuffix method
- *
- * @return void
- */
- public function testDomIdSuffix() {
- $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs');
- $this->assertEquals('1StringWith1DollarSigns', $result);
- $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>');
- $this->assertEquals('AbcXFooYBar', $result);
- $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs', 'html5');
- $this->assertEquals('1StringWith1$-dollarSigns', $result);
- $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>', 'html5');
- $this->assertEquals('AbcX=FooY=Bar', $result);
- }
- /**
- * testDomIdSuffixCollisionResolvement()
- *
- * @return void
- */
- public function testDomIdSuffixCollisionResolvement() {
- $result = $this->Form->domIdSuffix('a>b');
- $this->assertEquals('AB', $result);
- $result = $this->Form->domIdSuffix('a<b');
- $this->assertEquals('AB1', $result);
- $result = $this->Form->domIdSuffix('a\'b');
- $this->assertEquals('AB2', $result);
- $result = $this->Form->domIdSuffix('1 string with 1$-dollar');
- $this->assertEquals('1StringWith1Dollar', $result);
- $result = $this->Form->domIdSuffix('1 string with 1$-dollar');
- $this->assertEquals('1StringWith1Dollar1', $result);
- $result = $this->Form->domIdSuffix('1 string with 1$-dollar');
- $this->assertEquals('1StringWith1Dollar2', $result);
- }
- /**
- * testSelect method
- *
- * Test select element generation.
- *
- * @return void
- */
- public function testSelect() {
- $result = $this->Form->select('Model.field', array());
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '')),
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('field' => 'value'));
- $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'value', 'selected' => 'selected')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array();
- $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'value')),
- 'good',
- '/option',
- array('option' => array('value' => 'other')),
- 'bad',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
- array('empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => 'first')),
- 'first "html" <chars>',
- '/option',
- array('option' => array('value' => 'second')),
- 'value',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.field',
- array('first' => 'first "html" <chars>', 'second' => 'value'),
- array('escape' => false, 'empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => 'first')),
- 'first "html" <chars>',
- '/option',
- array('option' => array('value' => 'second')),
- 'value',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $options = array(
- array('value' => 'first', 'name' => 'First'),
- array('value' => 'first', 'name' => 'Another First'),
- );
- $result = $this->Form->select(
- 'Model.field',
- $options,
- array('escape' => false, 'empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => 'first')),
- 'First',
- '/option',
- array('option' => array('value' => 'first')),
- 'Another First',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('contact_id' => 228));
- $result = $this->Form->select(
- 'Model.contact_id',
- array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
- array('escape' => false, 'empty' => 'pick something')
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'),
- array('option' => array('value' => '')), 'pick something', '/option',
- array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
- array('option' => array('value' => '228-1')), '228-1 value', '/option',
- array('option' => array('value' => '228-2')), '228-2 value', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = 0;
- $result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '')), '/option',
- array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
- array('option' => array('value' => '1')), 'Yes', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = 50;
- $result = $this->Form->select('Model.field', array('50f5c0cf' => 'Stringy', '50' => 'fifty'));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '')), '/option',
- array('option' => array('value' => '50f5c0cf')), 'Stringy', '/option',
- array('option' => array('value' => '50', 'selected' => 'selected')), 'fifty', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select('Contact.required_one', array('option A'));
- $expected = array(
- 'select' => array(
- 'name' => 'data[Contact][required_one]',
- 'id' => 'ContactRequiredOne',
- 'required' => 'required'
- ),
- array('option' => array('value' => '')), '/option',
- array('option' => array('value' => '0')), 'option A', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select('Contact.required_one', array('option A'), array('disabled' => true));
- $expected = array(
- 'select' => array(
- 'name' => 'data[Contact][required_one]',
- 'id' => 'ContactRequiredOne',
- 'disabled' => 'disabled'
- ),
- array('option' => array('value' => '')), '/option',
- array('option' => array('value' => '0')), 'option A', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that select() with optiongroups listens to the escape param.
- *
- * @return void
- */
- public function testSelectOptionGroupEscaping() {
- $options = array(
- '>< Key' => array(
- 1 => 'One',
- 2 => 'Two'
- )
- );
- $result = $this->Form->select('Model.field', $options, array('empty' => false));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- 'optgroup' => array('label' => '>< Key'),
- array('option' => array('value' => '1')), 'One', '/option',
- array('option' => array('value' => '2')), 'Two', '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- $options = array(
- '>< Key' => array(
- 1 => 'One',
- 2 => 'Two'
- )
- );
- $result = $this->Form->select('Model.field', $options, array('empty' => false, 'escape' => false));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- 'optgroup' => array('label' => '>< Key'),
- array('option' => array('value' => '1')), 'One', '/option',
- array('option' => array('value' => '2')), 'Two', '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Tests that FormHelper::select() allows null to be passed in the $attributes parameter
- *
- * @return void
- */
- public function testSelectWithNullAttributes() {
- $result = $this->Form->select('Model.field', array('first', 'second'), array('empty' => false));
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => '0')),
- 'first',
- '/option',
- array('option' => array('value' => '1')),
- 'second',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testNestedSelect method
- *
- * test select element generation with optgroups
- *
- * @return void
- */
- public function testNestedSelect() {
- $result = $this->Form->select(
- 'Model.field',
- array(1 => 'One', 2 => 'Two', 'Three' => array(
- 3 => 'Three', 4 => 'Four', 5 => 'Five'
- )), array('empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]',
- 'id' => 'ModelField'),
- array('option' => array('value' => 1)),
- 'One',
- '/option',
- array('option' => array('value' => 2)),
- 'Two',
- '/option',
- array('optgroup' => array('label' => 'Three')),
- array('option' => array('value' => 4)),
- 'Four',
- '/option',
- array('option' => array('value' => 5)),
- 'Five',
- '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.field',
- array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')),
- array('showParents' => true, 'empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => 1)),
- 'One',
- '/option',
- array('option' => array('value' => 2)),
- 'Two',
- '/option',
- array('optgroup' => array('label' => 'Three')),
- array('option' => array('value' => 3)),
- 'Three',
- '/option',
- array('option' => array('value' => 4)),
- 'Four',
- '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testSelectMultiple method
- *
- * test generation of multiple select elements
- *
- * @return void
- */
- public function testSelectMultiple() {
- $options = array('first', 'second', 'third');
- $result = $this->Form->select(
- 'Model.multi_field', $options, array('multiple' => true)
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
- ),
- 'select' => array(
- 'name' => 'data[Model][multi_field][]',
- 'id' => 'ModelMultiField', 'multiple' => 'multiple'
- ),
- array('option' => array('value' => '0')),
- 'first',
- '/option',
- array('option' => array('value' => '1')),
- 'second',
- '/option',
- array('option' => array('value' => '2')),
- 'third',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field', $options, array('form' => 'my-form', 'multiple' => 'multiple')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_',
- 'form' => 'my-form',
- ),
- 'select' => array(
- 'name' => 'data[Model][multi_field][]',
- 'id' => 'ModelMultiField',
- 'multiple' => 'multiple',
- 'form' => 'my-form',
- ),
- array('option' => array('value' => '0')),
- 'first',
- '/option',
- array('option' => array('value' => '1')),
- 'second',
- '/option',
- array('option' => array('value' => '2')),
- 'third',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field', $options, array('multiple' => true, 'value' => array(0, 1))
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
- ),
- 'select' => array(
- 'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField',
- 'multiple' => 'multiple'
- ),
- array('option' => array('value' => '0', 'selected' => 'selected')),
- 'first',
- '/option',
- array('option' => array('value' => '1', 'selected' => 'selected')),
- 'second',
- '/option',
- array('option' => array('value' => '2')),
- 'third',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field', $options, array('multiple' => false, 'value' => array(0, 1))
- );
- $expected = array(
- 'select' => array(
- 'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField'
- ),
- array('option' => array('value' => '0', 'selected' => 'selected')),
- 'first',
- '/option',
- array('option' => array('value' => '1', 'selected' => 'selected')),
- 'second',
- '/option',
- array('option' => array('value' => '2')),
- 'third',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $selected = array('2', '3x');
- $result = $this->Form->select(
- 'Model.multi_field', $options, array('multiple' => true, 'value' => $selected)
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
- ),
- 'select' => array(
- 'name' => 'data[Model][multi_field][]', 'multiple' => 'multiple', 'id' => 'ModelMultiField'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2', 'selected' => 'selected')),
- 'Two',
- '/option',
- array('option' => array('value' => '3')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x', 'selected' => 'selected')),
- 'Stringy',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select('Contact.required_one', array(
- '1' => 'option A',
- '2' => 'option B'
- ), array('multiple' => true));
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][required_one]', 'value' => '', 'id' => 'ContactRequiredOne_'
- ),
- 'select' => array(
- 'name' => 'data[Contact][required_one][]',
- 'id' => 'ContactRequiredOne',
- 'required' => 'required',
- 'multiple' => 'multiple'
- ),
- array('option' => array('value' => '1')), 'option A', '/option',
- array('option' => array('value' => '2')), 'option B', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field',
- array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
- array('multiple' => true)
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '',
- 'id' => 'ModelMultiField_'
- ),
- array('select' => array('name' => 'data[Model][multi_field][]',
- 'multiple' => 'multiple', 'id' => 'ModelMultiField'
- )),
- array('option' => array('value' => 'a>b')),
- 'first',
- '/option',
- array('option' => array('value' => 'a<b')),
- 'second',
- '/option',
- array('option' => array(
- 'value' => 'a"b'
- )),
- 'third',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test generating multiple select with disabled elements.
- *
- * @return void
- */
- public function testSelectMultipleWithDisabledElements() {
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = array(2, 3);
- $result = $this->Form->select('Contact.multiple', $options, array('multiple' => 'multiple', 'disabled' => $disabled));
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
- ),
- 'select' => array(
- 'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2', 'disabled' => 'disabled')),
- 'Two',
- '/option',
- array('option' => array('value' => '3', 'disabled' => 'disabled')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x')),
- 'Stringy',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = array('2', '3x');
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ContactMultiple')),
- 'Multiple',
- '/label',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
- ),
- 'select' => array(
- 'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2', 'disabled' => 'disabled')),
- 'Two',
- '/option',
- array('option' => array('value' => '3')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x', 'disabled' => 'disabled')),
- 'Stringy',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = true;
- $result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ContactMultiple')),
- 'Multiple',
- '/label',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
- ),
- 'select' => array(
- 'name' => 'data[Contact][multiple][]', 'disabled' => 'disabled', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2')),
- 'Two',
- '/option',
- array('option' => array('value' => '3')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x')),
- 'Stringy',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test generating select with disabled elements.
- *
- * @return void
- */
- public function testSelectWithDisabledElements() {
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = array(2, 3);
- $result = $this->Form->select('Model.field', $options, array('disabled' => $disabled));
- $expected = array(
- 'select' => array(
- 'name' => 'data[Model][field]', 'id' => 'ModelField'
- ),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2', 'disabled' => 'disabled')),
- 'Two',
- '/option',
- array('option' => array('value' => '3', 'disabled' => 'disabled')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x')),
- 'Stringy',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = array('2', '3x');
- $result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ModelField')),
- 'Field',
- '/label',
- 'select' => array(
- 'name' => 'data[Model][field]', 'id' => 'ModelField'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2', 'disabled' => 'disabled')),
- 'Two',
- '/option',
- array('option' => array('value' => '3')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x', 'disabled' => 'disabled')),
- 'Stringy',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
- $disabled = true;
- $result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ModelField')),
- 'Field',
- '/label',
- 'select' => array(
- 'name' => 'data[Model][field]', 'id' => 'ModelField', 'disabled' => 'disabled'
- ),
- array('option' => array('value' => '1')),
- 'One',
- '/option',
- array('option' => array('value' => '2')),
- 'Two',
- '/option',
- array('option' => array('value' => '3')),
- 'Three',
- '/option',
- array('option' => array('value' => '3x')),
- 'Stringy',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test generation of habtm select boxes.
- *
- * @return void
- */
- public function testHabtmSelectBox() {
- $this->View->viewVars['contactTags'] = array(
- 1 => 'blue',
- 2 => 'red',
- 3 => 'green'
- );
- $this->Form->request->data = array(
- 'Contact' => array(),
- 'ContactTag' => array(
- array(
- 'id' => '1',
- 'name' => 'blue'
- ),
- array(
- 'id' => 3,
- 'name' => 'green'
- )
- )
- );
- $this->Form->create('Contact');
- $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
- ),
- 'select' => array(
- 'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
- 'multiple' => 'multiple'
- ),
- array('option' => array('value' => '1', 'selected' => 'selected')),
- 'blue',
- '/option',
- array('option' => array('value' => '2')),
- 'red',
- '/option',
- array('option' => array('value' => '3', 'selected' => 'selected')),
- 'green',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- // make sure only 50 is selected, and not 50f5c0cf
- $this->View->viewVars['contactTags'] = array(
- '1' => 'blue',
- '50f5c0cf' => 'red',
- '50' => 'green'
- );
- $this->Form->request->data = array(
- 'Contact' => array(),
- 'ContactTag' => array(
- array(
- 'id' => 1,
- 'name' => 'blue'
- ),
- array(
- 'id' => 50,
- 'name' => 'green'
- )
- )
- );
- $this->Form->create('Contact');
- $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
- ),
- 'select' => array(
- 'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
- 'multiple' => 'multiple'
- ),
- array('option' => array('value' => '1', 'selected' => 'selected')),
- 'blue',
- '/option',
- array('option' => array('value' => '50f5c0cf')),
- 'red',
- '/option',
- array('option' => array('value' => '50', 'selected' => 'selected')),
- 'green',
- '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test generation of multi select elements in checkbox format
- *
- * @return void
- */
- public function testSelectMultipleCheckboxes() {
- $result = $this->Form->select(
- 'Model.multi_field',
- array('first', 'second', 'third'),
- array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '0', 'id' => 'ModelMultiField0'
- )),
- array('label' => array('for' => 'ModelMultiField0')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '1', 'id' => 'ModelMultiField1'
- )),
- array('label' => array('for' => 'ModelMultiField1')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '2', 'id' => 'ModelMultiField2'
- )),
- array('label' => array('for' => 'ModelMultiField2')),
- 'third',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field',
- array('a' => 'first', 'b' => 'second', 'c' => 'third'),
- array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a', 'id' => 'ModelMultiFieldA'
- )),
- array('label' => array('for' => 'ModelMultiFieldA')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'b', 'id' => 'ModelMultiFieldB'
- )),
- array('label' => array('for' => 'ModelMultiFieldB')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'c', 'id' => 'ModelMultiFieldC'
- )),
- array('label' => array('for' => 'ModelMultiFieldC')),
- 'third',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '1', 'id' => 'ModelMultiField1'
- )),
- array('label' => array('for' => 'ModelMultiField1')),
- 'first',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('tags' => array(1)));
- $result = $this->Form->select(
- 'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][tags][]',
- 'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
- )),
- array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][tags][]',
- 'value' => 'Array', 'id' => 'ModelTagsArray'
- )),
- array('label' => array('for' => 'ModelTagsArray')),
- 'Array',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field',
- array('a+' => 'first', 'a++' => 'second', 'a+++' => 'third'),
- array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a+', 'id' => 'ModelMultiFieldA2'
- )),
- array('label' => array('for' => 'ModelMultiFieldA2')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a++', 'id' => 'ModelMultiFieldA1'
- )),
- array('label' => array('for' => 'ModelMultiFieldA1')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a+++', 'id' => 'ModelMultiFieldA'
- )),
- array('label' => array('for' => 'ModelMultiFieldA')),
- 'third',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->select(
- 'Model.multi_field',
- array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
- array('multiple' => 'checkbox')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a>b', 'id' => 'ModelMultiFieldAB2'
- )),
- array('label' => array('for' => 'ModelMultiFieldAB2')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a<b', 'id' => 'ModelMultiFieldAB1'
- )),
- array('label' => array('for' => 'ModelMultiFieldAB1')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => 'a"b', 'id' => 'ModelMultiFieldAB'
- )),
- array('label' => array('for' => 'ModelMultiFieldAB')),
- 'third',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test multiple checkboxes with div styles.
- *
- * @return void
- */
- public function testSelectMultipleCheckboxDiv() {
- $result = $this->Form->select(
- 'Model.tags',
- array('first', 'second'),
- array('multiple' => 'checkbox', 'class' => 'my-class')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
- ),
- array('div' => array('class' => 'my-class')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][tags][]',
- 'value' => '0', 'id' => 'ModelTags0'
- )),
- array('label' => array('for' => 'ModelTags0')), 'first', '/label',
- '/div',
- array('div' => array('class' => 'my-class')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][tags][]',
- 'value' => '1', 'id' => 'ModelTags1'
- )),
- array('label' => array('for' => 'ModelTags1')), 'second', '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.tags', array(
- 'options' => array('first', 'second'),
- 'multiple' => 'checkbox',
- 'class' => 'my-class',
- 'div' => false,
- 'label' => false
- ));
- $this->assertTags($result, $expected);
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['tags'] = 'Select atleast one option';
- $result = $this->Form->input('Contact.tags', array(
- 'options' => array('one'),
- 'multiple' => 'checkbox',
- 'label' => false,
- 'div' => false
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
- array('div' => array('class' => 'checkbox form-error')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
- array('label' => array('for' => 'ContactTags0')),
- 'one',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.tags', array(
- 'options' => array('one'),
- 'multiple' => 'checkbox',
- 'class' => 'mycheckbox',
- 'label' => false,
- 'div' => false
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
- array('div' => array('class' => 'mycheckbox form-error')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
- array('label' => array('for' => 'ContactTags0')),
- 'one',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Checks the security hash array generated for multiple-input checkbox elements
- *
- * @return void
- */
- public function testSelectMultipleCheckboxSecurity() {
- $this->Form->request['_Token'] = array('key' => 'testKey');
- $this->assertEquals(array(), $this->Form->fields);
- $result = $this->Form->select(
- 'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
- array('multiple' => 'checkbox')
- );
- $this->assertEquals(array('Model.multi_field'), $this->Form->fields);
- $result = $this->Form->secure($this->Form->fields);
- $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
- $this->assertRegExp('/"' . $key . '"/', $result);
- }
- /**
- * Multiple select elements should always be secured as they always participate
- * in the POST data.
- *
- * @return void
- */
- public function testSelectMultipleSecureWithNoOptions() {
- $this->Form->request['_Token'] = array('key' => 'testkey');
- $this->assertEquals(array(), $this->Form->fields);
- $this->Form->select(
- 'Model.select',
- array(),
- array('multiple' => true)
- );
- $this->assertEquals(array('Model.select'), $this->Form->fields);
- }
- /**
- * When a select box has no options it should not be added to the fields list
- * as it always fail post validation.
- *
- * @return void
- */
- public function testSelectNoSecureWithNoOptions() {
- $this->Form->request['_Token'] = array('key' => 'testkey');
- $this->assertEquals(array(), $this->Form->fields);
- $this->Form->select(
- 'Model.select',
- array()
- );
- $this->assertEquals(array(), $this->Form->fields);
- $this->Form->select(
- 'Model.select',
- array(),
- array('empty' => true)
- );
- $this->assertEquals(array('Model.select'), $this->Form->fields);
- }
- /**
- * testInputMultipleCheckboxes method
- *
- * test input() resulting in multi select elements being generated.
- *
- * @return void
- */
- public function testInputMultipleCheckboxes() {
- $result = $this->Form->input('Model.multi_field', array(
- 'options' => array('first', 'second', 'third'),
- 'multiple' => 'checkbox'
- ));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ModelMultiField')),
- 'Multi Field',
- '/label',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
- array('label' => array('for' => 'ModelMultiField0')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
- array('label' => array('for' => 'ModelMultiField1')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
- array('label' => array('for' => 'ModelMultiField2')),
- 'third',
- '/label',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array(
- 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
- 'multiple' => 'checkbox'
- ));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ModelMultiField')),
- 'Multi Field',
- '/label',
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
- array('label' => array('for' => 'ModelMultiFieldA')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
- array('label' => array('for' => 'ModelMultiFieldB')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
- array('label' => array('for' => 'ModelMultiFieldC')),
- 'third',
- '/label',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array(
- 'options' => array('1' => 'first'),
- 'multiple' => 'checkbox',
- 'label' => false,
- 'div' => false
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
- array('label' => array('for' => 'ModelMultiField1')),
- 'first',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array(
- 'options' => array('2' => 'second'),
- 'multiple' => 'checkbox',
- 'label' => false,
- 'div' => false
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
- array('label' => array('for' => 'ModelMultiField2')),
- 'second',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testSelectHiddenFieldOmission method
- *
- * test that select() with 'hiddenField' => false omits the hidden field
- *
- * @return void
- */
- public function testSelectHiddenFieldOmission() {
- $result = $this->Form->select('Model.multi_field',
- array('first', 'second'),
- array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
- );
- $expected = array(
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
- array('label' => array('for' => 'ModelMultiField0')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
- array('label' => array('for' => 'ModelMultiField1')),
- 'second',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array(
- 'options' => array('first', 'second'),
- 'multiple' => 'checkbox',
- 'hiddenField' => false
- ));
- $expected = array(
- array('div' => array('class' => 'input select')),
- array('label' => array('for' => 'ModelMultiField')),
- 'Multi Field',
- '/label',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
- array('label' => array('for' => 'ModelMultiField0')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
- array('label' => array('for' => 'ModelMultiField1')),
- 'second',
- '/label',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that select() with multiple = checkbox works with overriding name attribute.
- *
- * @return void
- */
- public function testSelectCheckboxMultipleOverrideName() {
- $result = $this->Form->input('category', array(
- 'type' => 'select',
- 'multiple' => 'checkbox',
- 'name' => 'data[fish]',
- 'options' => array('1', '2'),
- 'div' => false,
- 'label' => false,
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'),
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')),
- array('label' => array('for' => 'Category0')), '1', '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')),
- array('label' => array('for' => 'Category1')), '2', '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that 'id' overrides all the checkbox id's as well.
- *
- * @return void
- */
- public function testSelectCheckboxMultipleId() {
- $result = $this->Form->select(
- 'Model.multi_field',
- array('first', 'second', 'third'),
- array('multiple' => 'checkbox', 'id' => 'CustomId')
- );
- $expected = array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'CustomId'
- ),
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '0', 'id' => 'CustomId0'
- )),
- array('label' => array('for' => 'CustomId0')),
- 'first',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '1', 'id' => 'CustomId1'
- )),
- array('label' => array('for' => 'CustomId1')),
- 'second',
- '/label',
- '/div',
- array('div' => array('class' => 'checkbox')),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
- 'value' => '2', 'id' => 'CustomId2'
- )),
- array('label' => array('for' => 'CustomId2')),
- 'third',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testCheckbox method
- *
- * Test generation of checkboxes
- *
- * @return void
- */
- public function testCheckbox() {
- $result = $this->Form->checkbox('Model.field');
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Model.field', array(
- 'id' => 'theID',
- 'value' => 'myvalue',
- 'form' => 'my-form',
- ));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_', 'form' => 'my-form'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID', 'form' => 'my-form'))
- );
- $this->assertTags($result, $expected);
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['field'] = 1;
- $this->Form->request->data['Contact']['field'] = 'myvalue';
- $result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
- array('input' => array('type', 'name', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
- array('input' => array('type', 'name', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['field'] = '';
- $result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
- );
- $this->assertTags($result, $expected);
- $Contact->validationErrors = array();
- $result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = 1;
- $result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked'))
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = 0;
- $result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Model.CustomField.1.value');
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][CustomField][1][value]', 'value' => '0', 'id' => 'ModelCustomField1Value_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][CustomField][1][value]', 'value' => '1', 'id' => 'ModelCustomField1Value'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('CustomField.1.value');
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[CustomField][1][value]', 'value' => '0', 'id' => 'CustomField1Value_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value'))
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test checkbox() with a custom name attribute
- *
- * @return void
- */
- public function testCheckboxCustomNameAttribute() {
- $result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'),
- array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1', 'id' => 'TestTest'))
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test the checked option for checkboxes.
- *
- * @return void
- */
- public function testCheckboxCheckedOption() {
- $result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Model.field', array('checked' => 1));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Model.field', array('checked' => true));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Model.field', array('checked' => false));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = 1;
- $result = $this->Form->checkbox('Model.field', array('checked' => false));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that disabled attribute works on both the checkbox and hidden input.
- *
- * @return void
- */
- public function testCheckboxDisabling() {
- $result = $this->Form->checkbox('Account.show_name', array('disabled' => 'disabled'));
- $expected = array(
- array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->checkbox('Account.show_name', array('disabled' => false));
- $expected = array(
- array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName'))
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that the hidden input for checkboxes can be omitted or set to a
- * specific value.
- *
- * @return void
- */
- public function testCheckboxHiddenField() {
- $result = $this->Form->input('UserForm.something', array(
- 'type' => 'checkbox',
- 'hiddenField' => false
- ));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[UserForm][something]',
- 'value' => '1', 'id' => 'UserFormSomething'
- )),
- 'label' => array('for' => 'UserFormSomething'),
- 'Something',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('UserForm.something', array(
- 'type' => 'checkbox',
- 'value' => 'Y',
- 'hiddenField' => 'N',
- ));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[UserForm][something]',
- 'value' => 'N', 'id' => 'UserFormSomething_'
- )),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[UserForm][something]',
- 'value' => 'Y', 'id' => 'UserFormSomething'
- )),
- 'label' => array('for' => 'UserFormSomething'),
- 'Something',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that a checkbox can have 0 for the value and 1 for the hidden input.
- *
- * @return void
- */
- public function testCheckboxZeroValue() {
- $result = $this->Form->input('User.get_spam', array(
- 'type' => 'checkbox',
- 'value' => '0',
- 'hiddenField' => '1',
- ));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[User][get_spam]',
- 'value' => '1', 'id' => 'UserGetSpam_'
- )),
- array('input' => array(
- 'type' => 'checkbox', 'name' => 'data[User][get_spam]',
- 'value' => '0', 'id' => 'UserGetSpam'
- )),
- 'label' => array('for' => 'UserGetSpam'),
- 'Get Spam',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testDateTime method
- *
- * Test generation of date/time select elements
- *
- * @return void
- */
- public function testDateTime() {
- extract($this->dateRegex);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
- $now = strtotime('now');
- $expected = array(
- array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
- $hoursRegex,
- array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
- date('g', $now),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
- $minutesRegex,
- array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
- date('i', $now),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
- $meridianRegex,
- array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
- date('a', $now),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
- $expected = array(
- array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
- $daysRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
- $monthsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
- $yearsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
- $hoursRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
- $minutesRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
- $this->assertTags($result, $expected);
- $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
- $this->assertTags($result, $expected);
- $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
- $expected = array(
- array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
- $daysRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
- $monthsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
- $yearsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
- $hoursRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
- $minutesRegex,
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '05')),
- '05',
- '/option',
- array('option' => array('value' => '10')),
- '10',
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
- $this->Form->request->data['Contact']['data'] = null;
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
- $expected = array(
- array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
- $daysRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
- $monthsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
- $yearsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
- $hoursRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
- $minutesRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
- $this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
- $now = strtotime($this->Form->data['Model']['field']);
- $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- $hoursRegex,
- array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
- date('g', $now),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- $minutesRegex,
- array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
- date('i', $now),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Model][field][meridian]', 'id' => 'ModelFieldMeridian')),
- $meridianRegex,
- array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
- date('a', $now),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $selected = strtotime('2008-10-26 12:33:00');
- $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
- $this->assertRegExp('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
- $this->Form->create('Contact');
- $result = $this->Form->input('published');
- $now = strtotime('now');
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ContactPublishedMonth'),
- 'Published',
- '/label',
- array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '/option',
- '*/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('published2', array('type' => 'date'));
- $now = strtotime('now');
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ContactPublished2Month'),
- 'Published2',
- '/label',
- array('select' => array('name' => 'data[Contact][published2][month]', 'id' => 'ContactPublished2Month')),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published2][day]', 'id' => 'ContactPublished2Day')),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published2][year]', 'id' => 'ContactPublished2Year')),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '/option',
- '*/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->create('Contact');
- $result = $this->Form->input('published', array('monthNames' => false));
- $now = strtotime('now');
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ContactPublishedMonth'),
- 'Published',
- '/label',
- array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
- 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('m', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '/option',
- '*/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('published', array(
- 'timeFormat' => 24,
- 'interval' => 5,
- 'selected' => strtotime('2009-09-03 13:37:00'),
- 'type' => 'datetime'
- ));
- $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
- }
- /**
- * Test dateTime with rounding
- *
- * @return void
- */
- public function testDateTimeRounding() {
- $this->Form->request->data['Contact'] = array(
- 'date' => array(
- 'day' => '13',
- 'month' => '12',
- 'year' => '2010',
- 'hour' => '04',
- 'min' => '19',
- 'meridian' => 'AM'
- )
- );
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
- $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
- $this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
- $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
- }
- /**
- * Test that empty values don't trigger errors.
- *
- * @return void
- */
- public function testDateTimeNoErrorsOnEmptyData() {
- $this->Form->request->data['Contact'] = array(
- 'date' => array(
- 'day' => '',
- 'month' => '',
- 'year' => '',
- 'hour' => '',
- 'min' => '',
- 'meridian' => ''
- )
- );
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
- $this->assertNotEmpty($result);
- }
- /**
- * test that datetime() and default values work.
- *
- * @return void
- */
- public function testDatetimeWithDefault() {
- $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
- $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
- $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
- 'default' => '2009-06-01 11:15:30'
- ));
- $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
- $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
- }
- /**
- * test that bogus non-date time data doesn't cause errors.
- *
- * @return void
- */
- public function testDateTimeWithBogusData() {
- $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
- $this->assertNotRegExp('/selected="selected">\d/', $result);
- }
- /**
- * testDateTime all zeros
- *
- * @return void
- */
- public function testDateTimeAllZeros() {
- $result = $this->Form->dateTime('Contact.date',
- 'DMY',
- false,
- array(
- 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
- 'value' => '0000-00-00'
- )
- );
- $this->assertRegExp('/<option value="">-<\/option>/', $result);
- $this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
- }
- /**
- * testDateTimeEmptyAsArray
- *
- * @return void
- */
- public function testDateTimeEmptyAsArray() {
- $result = $this->Form->dateTime('Contact.date',
- 'DMY',
- '12',
- array(
- 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
- 'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
- )
- )
- );
- $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
- $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
- $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
- $this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
- $this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
- $this->assertNotRegExp('/<option value=""><\/option>/', $result);
- $result = $this->Form->dateTime('Contact.date',
- 'DMY',
- '12',
- array(
- 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
- )
- );
- $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
- $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
- $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
- $this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
- $this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
- $this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
- }
- /**
- * testFormDateTimeMulti method
- *
- * test multiple datetime element generation
- *
- * @return void
- */
- public function testFormDateTimeMulti() {
- extract($this->dateRegex);
- $result = $this->Form->dateTime('Contact.1.updated');
- $expected = array(
- array('select' => array('name' => 'data[Contact][1][updated][day]', 'id' => 'Contact1UpdatedDay')),
- $daysRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
- $monthsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][1][updated][year]', 'id' => 'Contact1UpdatedYear')),
- $yearsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
- $hoursRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][1][updated][min]', 'id' => 'Contact1UpdatedMin')),
- $minutesRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->dateTime('Contact.2.updated');
- $expected = array(
- array('select' => array('name' => 'data[Contact][2][updated][day]', 'id' => 'Contact2UpdatedDay')),
- $daysRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
- $monthsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- '-',
- array('select' => array('name' => 'data[Contact][2][updated][year]', 'id' => 'Contact2UpdatedYear')),
- $yearsRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- array('select' => array('name' => 'data[Contact][2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
- $hoursRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ':',
- array('select' => array('name' => 'data[Contact][2][updated][min]', 'id' => 'Contact2UpdatedMin')),
- $minutesRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select',
- ' ',
- array('select' => array('name' => 'data[Contact][2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * When changing the date format, the label should always focus the first select box when
- * clicked.
- *
- * @return void
- */
- public function testDateTimeLabelIdMatchesFirstInput() {
- $result = $this->Form->input('Model.date', array('type' => 'date'));
- $this->assertContains('label for="ModelDateMonth"', $result);
- $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
- $this->assertContains('label for="ModelDateDay"', $result);
- $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
- $this->assertContains('label for="ModelDateYear"', $result);
- }
- /**
- * testMonth method
- *
- * @return void
- */
- public function testMonth() {
- $result = $this->Form->month('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- date('F', strtotime('2008-01-01 00:00:00')),
- '/option',
- array('option' => array('value' => '02')),
- date('F', strtotime('2008-02-01 00:00:00')),
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->month('Model.field', array('empty' => true));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- date('F', strtotime('2008-01-01 00:00:00')),
- '/option',
- array('option' => array('value' => '02')),
- date('F', strtotime('2008-02-01 00:00:00')),
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->month('Model.field', array('monthNames' => false));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '01',
- '/option',
- array('option' => array('value' => '02')),
- '02',
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- $monthNames = array(
- '01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
- '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
- $result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- 'Jan',
- '/option',
- array('option' => array('value' => '02')),
- 'Feb',
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Project']['release'] = '2050-02-10';
- $result = $this->Form->month('Project.release');
- $expected = array(
- array('select' => array('name' => 'data[Project][release][month]', 'id' => 'ProjectReleaseMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- 'January',
- '/option',
- array('option' => array('value' => '02', 'selected' => 'selected')),
- 'February',
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '12a';
- $result = $this->Form->month('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- date('F', strtotime('2008-01-01 00:00:00')),
- '/option',
- array('option' => array('value' => '02')),
- date('F', strtotime('2008-02-01 00:00:00')),
- '/option',
- '*/select',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testDay method
- *
- * @return void
- */
- public function testDay() {
- extract($this->dateRegex);
- $result = $this->Form->day('Model.field', array('value' => false));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
- $result = $this->Form->day('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- array('option' => array('value' => '10', 'selected' => 'selected')),
- '10',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '';
- $result = $this->Form->day('Model.field', array('value' => '10'));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- array('option' => array('value' => '10', 'selected' => 'selected')),
- '10',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
- $result = $this->Form->day('Model.field', array('value' => true));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- array('option' => array('value' => '10', 'selected' => 'selected')),
- '10',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Project']['release'] = '2050-10-10';
- $result = $this->Form->day('Project.release');
- $expected = array(
- array('select' => array('name' => 'data[Project][release][day]', 'id' => 'ProjectReleaseDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- array('option' => array('value' => '10', 'selected' => 'selected')),
- '10',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '12e';
- $result = $this->Form->day('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $daysRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testMinute method
- *
- * @return void
- */
- public function testMinute() {
- extract($this->dateRegex);
- $result = $this->Form->minute('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '01')),
- '01',
- '/option',
- array('option' => array('value' => '02')),
- '02',
- '/option',
- $minutesRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
- $result = $this->Form->minute('Model.field');
- $expected = array(
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '01')),
- '01',
- '/option',
- array('option' => array('value' => '02')),
- '02',
- '/option',
- $minutesRegex,
- array('option' => array('value' => '12', 'selected' => 'selected')),
- '12',
- '/option',
- $minutesRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '';
- $result = $this->Form->minute('Model.field', array('interval' => 5));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '05')),
- '05',
- '/option',
- array('option' => array('value' => '10')),
- '10',
- '/option',
- $minutesRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
- $result = $this->Form->minute('Model.field', array('interval' => 5));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '05')),
- '05',
- '/option',
- array('option' => array('value' => '10', 'selected' => 'selected')),
- '10',
- '/option',
- $minutesRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->minute('Model.field', array('value' => '#invalid#'));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '00',
- '/option',
- array('option' => array('value' => '01')),
- '01',
- '/option',
- array('option' => array('value' => '02')),
- '02',
- '/option',
- $minutesRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testHour method
- *
- * @return void
- */
- public function testHour() {
- extract($this->dateRegex);
- $result = $this->Form->hour('Model.field', false);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $hoursRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
- $result = $this->Form->hour('Model.field', false);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $hoursRegex,
- array('option' => array('value' => '12', 'selected' => 'selected')),
- '12',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '';
- $result = $this->Form->hour('Model.field', true, array('value' => '23'));
- $this->assertContains('<option value="23" selected="selected">23</option>', $result);
- $result = $this->Form->hour('Model.field', false, array('value' => '23'));
- $this->assertContains('<option value="11" selected="selected">11</option>', $result);
- $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
- $result = $this->Form->hour('Model.field', true);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00', 'selected' => 'selected')),
- '0',
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $hoursRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- unset($this->Form->request->data['Model']['field']);
- $result = $this->Form->hour('Model.field', true, array('value' => 'now'));
- $thisHour = date('H');
- $optValue = date('G');
- $this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
- $this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
- $result = $this->Form->hour('Model.field', true);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '00')),
- '0',
- '/option',
- array('option' => array('value' => '01', 'selected' => 'selected')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $hoursRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['field'] = '18a';
- $result = $this->Form->hour('Model.field', false);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '01')),
- '1',
- '/option',
- array('option' => array('value' => '02')),
- '2',
- '/option',
- $hoursRegex,
- '/select',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testYear method
- *
- * @return void
- */
- public function testYear() {
- $result = $this->Form->year('Model.field', 2006, 2007);
- $expected = array(
- array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
- $expected = array(
- array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->request->data['Contact']['published'] = '';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '2006-10-10';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006', 'selected' => 'selected')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '2006-10-10';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006', 'selected' => 'selected')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2007', 'selected' => 'selected')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '2006-10-10';
- $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2007', 'selected' => 'selected')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '';
- $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2008')),
- '2008',
- '/option',
- array('option' => array('value' => '2007', 'selected' => 'selected')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['published'] = '2006-10-10';
- $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2008')),
- '2008',
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006', 'selected' => 'selected')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array();
- $this->Form->create('Contact');
- $result = $this->Form->year('published', 2006, 2008, array('empty' => false));
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '2008')),
- '2008',
- '/option',
- array('option' => array('value' => '2007')),
- '2007',
- '/option',
- array('option' => array('value' => '2006')),
- '2006',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->year('published', array(), array(), array('empty' => false));
- $this->assertContains('data[Contact][published][year]', $result);
- $this->Form->request->data['Contact']['published'] = '2014ee';
- $result = $this->Form->year('Contact.published', 2010, 2011);
- $expected = array(
- array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '2011')),
- '2011',
- '/option',
- array('option' => array('value' => '2010')),
- '2010',
- '/option',
- '/select',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testYearAutoExpandRange method
- *
- * @return void
- */
- public function testYearAutoExpandRange() {
- $this->Form->request->data['User']['birthday'] = '1930-10-10';
- $result = $this->Form->year('User.birthday');
- preg_match_all('/<option value="([\d]+)"/', $result, $matches);
- $result = $matches[1];
- $expected = range(date('Y') + 20, 1930);
- $this->assertEquals($expected, $result);
- $this->Form->request->data['Project']['release'] = '2050-10-10';
- $result = $this->Form->year('Project.release');
- preg_match_all('/<option value="([\d]+)"/', $result, $matches);
- $result = $matches[1];
- $expected = range(2050, date('Y') - 20);
- $this->assertEquals($expected, $result);
- $this->Form->request->data['Project']['release'] = '1881-10-10';
- $result = $this->Form->year('Project.release', 1890, 1900);
- preg_match_all('/<option value="([\d]+)"/', $result, $matches);
- $result = $matches[1];
- $expected = range(1900, 1881);
- $this->assertEquals($expected, $result);
- }
- /**
- * testInputDate method
- *
- * Test various inputs with type date and different dateFormat values.
- * Failing to provide a dateFormat key should not error.
- * It should simply not pre-select any value then.
- *
- * @return void
- */
- public function testInputDate() {
- $this->Form->request->data = array(
- 'User' => array(
- 'month_year' => array('month' => date('m')),
- 'just_year' => array('month' => date('m')),
- 'just_month' => array('year' => date('Y')),
- 'just_day' => array('month' => date('m')),
- )
- );
- $this->Form->create('User');
- $result = $this->Form->input('month_year',
- array(
- 'label' => false,
- 'div' => false,
- 'type' => 'date',
- 'dateFormat' => 'MY',
- 'minYear' => 2006,
- 'maxYear' => 2008
- )
- );
- $this->assertContains('value="' . date('m') . '" selected="selected"', $result);
- $this->assertNotContains('value="2008" selected="selected"', $result);
- $result = $this->Form->input('just_year',
- array(
- 'type' => 'date',
- 'label' => false,
- 'dateFormat' => 'Y',
- 'minYear' => date('Y'),
- 'maxYear' => date('Y', strtotime('+20 years'))
- )
- );
- $this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
- $result = $this->Form->input('just_month',
- array(
- 'type' => 'date',
- 'label' => false,
- 'dateFormat' => 'M',
- 'empty' => false,
- )
- );
- $this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
- $result = $this->Form->input('just_day',
- array(
- 'type' => 'date',
- 'label' => false,
- 'dateFormat' => 'D',
- 'empty' => false,
- )
- );
- $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
- }
- /**
- * testInputDateMaxYear method
- *
- * Let's say we want to only allow users born from 2006 to 2008 to register
- * This being the first singup page, we still don't have any data
- *
- * @return void
- */
- public function testInputDateMaxYear() {
- $this->Form->request->data = array();
- $this->Form->create('User');
- $result = $this->Form->input('birthday',
- array(
- 'label' => false,
- 'div' => false,
- 'type' => 'date',
- 'dateFormat' => 'DMY',
- 'minYear' => 2006,
- 'maxYear' => 2008
- )
- );
- $this->assertContains('value="2008" selected="selected"', $result);
- }
- /**
- * testTextArea method
- *
- * @return void
- */
- public function testTextArea() {
- $this->Form->request->data = array('Model' => array('field' => 'some test data'));
- $result = $this->Form->textarea('Model.field');
- $expected = array(
- 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- 'some test data',
- '/textarea',
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->textarea('Model.tmp');
- $expected = array(
- 'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'),
- '/textarea',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
- $result = $this->Form->textarea('Model.field');
- $expected = array(
- 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
- '/textarea',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
- $result = $this->Form->textarea('Model.field', array('escape' => false));
- $expected = array(
- 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- 'some <strong>test</strong> data with <a href="#">HTML</a> chars',
- '/textarea',
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['0']['OtherModel']['field'] = null;
- $result = $this->Form->textarea('Model.0.OtherModel.field');
- $expected = array(
- 'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
- '/textarea'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testTextAreaWithStupidCharacters method
- *
- * test text area with non-ascii characters
- *
- * @return void
- */
- public function testTextAreaWithStupidCharacters() {
- $this->loadFixtures('Post');
- $result = $this->Form->input('Post.content', array(
- 'label' => 'Current Text', 'value' => "GREAT®", 'rows' => '15', 'cols' => '75'
- ));
- $expected = array(
- 'div' => array('class' => 'input textarea'),
- 'label' => array('for' => 'PostContent'),
- 'Current Text',
- '/label',
- 'textarea' => array('name' => 'data[Post][content]', 'id' => 'PostContent', 'rows' => '15', 'cols' => '75'),
- 'GREAT®',
- '/textarea',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testHiddenField method
- *
- * @return void
- */
- public function testHiddenField() {
- $Contact = ClassRegistry::getObject('Contact');
- $Contact->validationErrors['field'] = 1;
- $this->Form->request->data['Contact']['field'] = 'test';
- $result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
- $this->assertTags($result, array(
- 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'id' => 'theID', 'value' => 'test'))
- );
- }
- /**
- * testFileUploadField method
- *
- * @return void
- */
- public function testFileUploadField() {
- $result = $this->Form->file('Model.upload');
- $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
- $this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
- $result = $this->Form->input('Model.upload', array('type' => 'file'));
- $expected = array(
- 'div' => array('class' => 'input file'),
- 'label' => array('for' => 'ModelUpload'),
- 'Upload',
- '/label',
- 'input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Model']['upload'] = 'no data should be set in value';
- $result = $this->Form->file('Model.upload');
- $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
- }
- /**
- * test File upload input on a model not used in create();
- *
- * @return void
- */
- public function testFileUploadOnOtherModel() {
- $this->Form->create('ValidateUser', array('type' => 'file'));
- $result = $this->Form->file('ValidateProfile.city');
- $expected = array(
- 'input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity')
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testButton method
- *
- * @return void
- */
- public function testButton() {
- $result = $this->Form->button('Hi');
- $this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
- $result = $this->Form->button('Clear Form >', array('type' => 'reset'));
- $this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
- $result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
- $this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
- $result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
- $this->assertTags($result, array('button' => array('type' => 'reset'), '<Clear Form>', '/button'));
- $result = $this->Form->button('No type', array('type' => false));
- $this->assertTags($result, array('button' => array(), 'No type', '/button'));
- $result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false));
- $this->assertNotRegExp('/\&039/', $result);
- }
- /**
- * Test that button() makes unlocked fields by default.
- *
- * @return void
- */
- public function testButtonUnlockedByDefault() {
- $this->Form->request->params['_Token']['key'] = 'secured';
- $this->Form->button('Save', array('name' => 'save'));
- $this->Form->button('Clear');
- $result = $this->Form->unlockField();
- $this->assertEquals(array('save'), $result);
- }
- /**
- * testPostButton method
- *
- * @return void
- */
- public function testPostButton() {
- $result = $this->Form->postButton('Hi', '/controller/action');
- $this->assertTags($result, array(
- 'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div',
- 'button' => array('type' => 'submit'),
- 'Hi',
- '/button',
- '/form'
- ));
- $result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
- $this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false);
- }
- /**
- * Test using postButton with N dimensional data.
- *
- * @return void
- */
- public function testPostButtonNestedData() {
- $data = array(
- 'one' => array(
- 'two' => array(
- 3, 4, 5
- )
- )
- );
- $result = $this->Form->postButton('Send', '/', array('data' => $data));
- $this->assertContains('<input type="hidden" name="data[one][two][0]" value="3"', $result);
- $this->assertContains('<input type="hidden" name="data[one][two][1]" value="4"', $result);
- $this->assertContains('<input type="hidden" name="data[one][two][2]" value="5"', $result);
- }
- /**
- * Test that postButton adds _Token fields.
- *
- * @return void
- */
- public function testSecurePostButton() {
- $this->Form->request->params['_Token'] = array('key' => 'testkey');
- $result = $this->Form->postButton('Delete', '/posts/delete/1');
- $expected = array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
- ),
- array('div' => array('style' => 'display:none;')),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
- '/div',
- 'button' => array('type' => 'submit'),
- 'Delete',
- '/button',
- array('div' => array('style' => 'display:none;')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
- '/div',
- '/form',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testPostLink method
- *
- * @return void
- */
- public function testPostLink() {
- $result = $this->Form->postLink('Delete', '/posts/delete/1');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("'Confirm' this \\\\"deletion\\\\"\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
- $this->assertContains('<input type="hidden" name="data[id]" value="1"/>', $result);
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->Form->postLink(
- '',
- array('controller' => 'items', 'action' => 'delete', 10),
- array('class' => 'btn btn-danger', 'escape' => false),
- 'Confirm thing'
- );
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/items/delete/10',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- 'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\"\;Confirm thing\"\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
- '/a'
- ));
- }
- /**
- * Test that security hashes for postLink include the url.
- *
- * @return void
- */
- public function testPostLinkSecurityHash() {
- $hash = Security::hash(
- '/posts/delete/1' .
- serialize(array()) .
- '' .
- Configure::read('Security.salt')
- );
- $hash .= '%3A';
- $this->Form->request->params['_Token']['key'] = 'test';
- $result = $this->Form->postLink('Delete', '/posts/delete/1');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name', 'id', 'style' => 'display:none;'
- ),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'test', 'id')),
- 'div' => array('style' => 'display:none;'),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => $hash, 'id')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id')),
- '/div',
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- }
- /**
- * Test using postLink with N dimensional data.
- *
- * @return void
- */
- public function testPostLinkNestedData() {
- $data = array(
- 'one' => array(
- 'two' => array(
- 3, 4, 5
- )
- )
- );
- $result = $this->Form->postLink('Send', '/', array('data' => $data));
- $this->assertContains('<input type="hidden" name="data[one][two][0]" value="3"', $result);
- $this->assertContains('<input type="hidden" name="data[one][two][1]" value="4"', $result);
- $this->assertContains('<input type="hidden" name="data[one][two][2]" value="5"', $result);
- }
- /**
- * test creating postLinks after a GET form.
- *
- * @return void
- */
- public function testPostLinkAfterGetForm() {
- $this->Form->request->params['_Token']['key'] = 'testkey';
- $this->Form->create('User', array('type' => 'get'));
- $this->Form->end();
- $result = $this->Form->postLink('Delete', '/posts/delete/1');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
- 'div' => array('style' => 'display:none;'),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
- '/div',
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- }
- /**
- * Test that postLink adds _Token fields.
- *
- * @return void
- */
- public function testSecurePostLink() {
- $this->Form->request->params['_Token'] = array('key' => 'testkey');
- $result = $this->Form->postLink('Delete', '/posts/delete/1');
- $expected = array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
- 'div' => array('style' => 'display:none;'),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
- array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
- '/div',
- '/form',
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that postLink adds form tags to view block
- *
- * @return void
- */
- public function testPostLinkFormBuffer() {
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
- $this->assertTags($result, array(
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->View->fetch('postLink');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete/2',
- array('inline' => false, 'method' => 'DELETE')
- );
- $this->assertTags($result, array(
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->View->fetch('postLink');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form',
- array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/2',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- ),
- array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
- '/form'
- ));
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'foobar'));
- $this->assertTags($result, array(
- 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
- 'Delete',
- '/a'
- ));
- $result = $this->View->fetch('foobar');
- $this->assertTags($result, array(
- 'form' => array(
- 'method' => 'post', 'action' => '/posts/delete/1',
- 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
- ),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/form'
- ));
- }
- /**
- * testSubmitButton method
- *
- * @return void
- */
- public function testSubmitButton() {
- $result = $this->Form->submit('');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => ''),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test Submit');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
- $expected = array(
- 'span' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
- '/span'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
- $expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
- $expected = array(
- 'div' => array('class' => 'submit', 'id' => 'SaveButton'),
- 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Next >');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Next >'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Next >', array('escape' => false));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Next >'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Reset!', array('type' => 'reset'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'reset', 'value' => 'Reset!'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $before = '--before--';
- $after = '--after--';
- $result = $this->Form->submit('Test', array('before' => $before));
- $expected = array(
- 'div' => array('class' => 'submit'),
- '--before--',
- 'input' => array('type' => 'submit', 'value' => 'Test'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test', array('after' => $after));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Test'),
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
- $expected = array(
- 'div' => array('class' => 'submit'),
- '--before--',
- 'input' => array('type' => 'submit', 'value' => 'Test'),
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test image submit types.
- *
- * @return void
- */
- public function testSubmitImage() {
- $result = $this->Form->submit('http://example.com/cake.power.gif');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('/relative/cake.power.gif');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('cake.power.gif');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Not.an.image');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $after = '--after--';
- $before = '--before--';
- $result = $this->Form->submit('cake.power.gif', array('after' => $after));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('cake.power.gif', array('before' => $before));
- $expected = array(
- 'div' => array('class' => 'submit'),
- '--before--',
- 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
- $expected = array(
- 'div' => array('class' => 'submit'),
- '--before--',
- 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
- $expected = array(
- 'div' => array('class' => 'submit'),
- '--before--',
- 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
- '--after--',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Submit buttons should be unlocked by default as there could be multiples, and only one will
- * be submitted at a time.
- *
- * @return void
- */
- public function testSubmitUnlockedByDefault() {
- $this->Form->request->params['_Token']['key'] = 'secured';
- $this->Form->submit('Go go');
- $this->Form->submit('Save', array('name' => 'save'));
- $result = $this->Form->unlockField();
- $this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
- }
- /**
- * Test submit image with timestamps.
- *
- * @return void
- */
- public function testSubmitImageTimestamp() {
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Form->submit('cake.power.gif');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test the create() method
- *
- * @return void
- */
- public function testCreate() {
- $result = $this->Form->create('Contact');
- $encoding = strtolower(Configure::read('App.encoding'));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('type' => 'GET'));
- $expected = array('form' => array(
- 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('type' => 'get'));
- $expected = array('form' => array(
- 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('type' => 'put'));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('type' => 'file'));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['id'] = 1;
- $this->Form->request->here = '/contacts/edit/1';
- $this->Form->request['action'] = 'edit';
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['Contact']['id'] = 1;
- $this->Form->request->here = '/contacts/edit/1';
- $this->Form->request['action'] = 'edit';
- $result = $this->Form->create('Contact', array('type' => 'file'));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
- 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
- $result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
- 'action' => '/contact_non_standard_pks/edit/1', 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array('id' => 'TestId'));
- $expected = array(
- 'form' => array(
- 'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request['action'] = 'add';
- $result = $this->Form->create('User', array('url' => array('action' => 'login')));
- $expected = array(
- 'form' => array(
- 'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('User', array('action' => 'login'));
- $expected = array(
- 'form' => array(
- 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('User', array('url' => '/users/login'));
- $expected = array(
- 'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request['controller'] = 'pages';
- $result = $this->Form->create('User', array('action' => 'signup'));
- $expected = array(
- 'form' => array(
- 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array();
- $this->Form->request['controller'] = 'contacts';
- $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
- $result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param',
- 'accept-charset' => 'utf-8'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test the onsubmit option for create()
- *
- * @return void
- */
- public function testCreateOnSubmit() {
- $this->Form->request->data = array();
- $this->Form->request['controller'] = 'contacts';
- $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
- $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
- 'accept-charset' => 'utf-8'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array();
- $this->Form->request['controller'] = 'contacts';
- $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
- $result = $this->Form->create(array(
- 'url' => array('action' => 'index', 'param'),
- 'default' => false,
- 'onsubmit' => 'someFunction();'
- ));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post',
- 'onsubmit' => 'someFunction();event.returnValue = false; return false;',
- 'action' => '/contacts/index/param',
- 'accept-charset' => 'utf-8'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test create() with automatic url generation
- *
- * @return void
- */
- public function testCreateAutoUrl() {
- Router::setRequestInfo(array(array(), array('base' => '/base_url')));
- $this->Form->request->here = '/base_url/contacts/add/Contact:1';
- $this->Form->request->base = '/base_url';
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/base_url/contacts/add/Contact:1',
- 'accept-charset' => 'utf-8'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->request['action'] = 'delete';
- $this->Form->request->here = '/base_url/contacts/delete/10/User:42';
- $this->Form->request->base = '/base_url';
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/base_url/contacts/delete/10/User:42',
- 'accept-charset' => 'utf-8'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test create() with a custom route
- *
- * @return void
- */
- public function testCreateCustomRoute() {
- Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('User', array('action' => 'login'));
- $expected = array(
- 'form' => array(
- 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that inputDefaults are stored and used.
- *
- * @return void
- */
- public function testCreateWithInputDefaults() {
- $this->Form->create('User', array(
- 'inputDefaults' => array(
- 'div' => false,
- 'label' => false,
- 'error' => array('attributes' => array('wrap' => 'small', 'class' => 'error')),
- 'format' => array('before', 'label', 'between', 'input', 'after', 'error')
- )
- ));
- $result = $this->Form->input('username');
- $expected = array(
- 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'UserUsername'), 'username', '/label',
- 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('username', array('label' => 'Username', 'format' => array('input', 'label')));
- $expected = array(
- 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
- 'label' => array('for' => 'UserUsername'), 'Username', '/label',
- );
- $this->assertTags($result, $expected);
- $this->Form->create('User', array(
- 'inputDefaults' => array(
- 'div' => false,
- 'label' => array('class' => 'nice', 'for' => 'changed'),
- )
- ));
- $result = $this->Form->input('username', array('div' => true));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'changed', 'class' => 'nice'), 'Username', '/label',
- 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test automatic accept-charset overriding
- *
- * @return void
- */
- public function testCreateWithAcceptCharset() {
- $result = $this->Form->create('UserForm', array(
- 'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
- )
- );
- $expected = array(
- 'form' => array(
- 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
- 'accept-charset' => 'iso-8859-1'
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test base form URL when url param is passed with multiple parameters (&)
- *
- * @return void
- */
- public function testCreateQuerystringrequest() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact', array(
- 'type' => 'post',
- 'escape' => false,
- 'url' => array(
- 'controller' => 'controller',
- 'action' => 'action',
- '?' => array('param1' => 'value1', 'param2' => 'value2')
- )
- ));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm',
- 'method' => 'post',
- 'action' => '/controller/action?param1=value1&param2=value2',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->create('Contact', array(
- 'type' => 'post',
- 'url' => array(
- 'controller' => 'controller',
- 'action' => 'action',
- '?' => array('param1' => 'value1', 'param2' => 'value2')
- )
- ));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm',
- 'method' => 'post',
- 'action' => '/controller/action?param1=value1&param2=value2',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that create() doesn't cause errors by multiple id's being in the primary key
- * as could happen with multiple select or checkboxes.
- *
- * @return void
- */
- public function testCreateWithMultipleIdInData() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $this->Form->request->data['Contact']['id'] = array(1, 2);
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm',
- 'method' => 'post',
- 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that create() doesn't add in extra passed params.
- *
- * @return void
- */
- public function testCreatePassedArgs() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $this->Form->request->data['Contact']['id'] = 1;
- $result = $this->Form->create('Contact', array(
- 'type' => 'post',
- 'escape' => false,
- 'url' => array(
- 'action' => 'edit',
- 'myparam'
- )
- ));
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm',
- 'method' => 'post',
- 'action' => '/contacts/edit/myparam',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that create() works without raising errors with a Mock Model
- *
- * @return void
- */
- public function testCreateNoErrorsWithMockModel() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $ContactMock = $this->getMockBuilder('Contact')
- ->disableOriginalConstructor()
- ->getMock();
- ClassRegistry::removeObject('Contact');
- ClassRegistry::addObject('Contact', $ContactMock);
- $result = $this->Form->create('Contact', array('type' => 'GET'));
- $expected = array('form' => array(
- 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ));
- $this->assertTags($result, $expected);
- }
- /**
- * test creating a get form, and get form inputs.
- *
- * @return void
- */
- public function testGetFormCreate() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact', array('type' => 'get'));
- $this->assertTags($result, array('form' => array(
- 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- )));
- $result = $this->Form->text('Contact.name');
- $this->assertTags($result, array('input' => array(
- 'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
- )));
- $result = $this->Form->password('password');
- $this->assertTags($result, array('input' => array(
- 'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
- )));
- $this->assertNotRegExp('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
- $result = $this->Form->text('user_form');
- $this->assertTags($result, array('input' => array(
- 'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
- )));
- }
- /**
- * test get form, and inputs when the model param is false
- *
- * @return void
- */
- public function testGetFormWithFalseModel() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $this->Form->request['controller'] = 'contact_test';
- $result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
- $expected = array('form' => array(
- 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
- 'accept-charset' => $encoding
- ));
- $this->assertTags($result, $expected);
- $result = $this->Form->text('reason');
- $expected = array(
- 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that datetime() works with GET style forms.
- *
- * @return void
- */
- public function testDateTimeWithGetForms() {
- extract($this->dateRegex);
- $this->Form->create('Contact', array('type' => 'get'));
- $result = $this->Form->datetime('created');
- $this->assertRegExp('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
- $this->assertRegExp('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
- $this->assertRegExp('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
- $this->assertRegExp('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
- $this->assertRegExp('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
- $this->assertRegExp('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
- }
- /**
- * testEditFormWithData method
- *
- * test auto populating form elements from submitted data.
- *
- * @return void
- */
- public function testEditFormWithData() {
- $this->Form->request->data = array('Person' => array(
- 'id' => 1,
- 'first_name' => 'Nate',
- 'last_name' => 'Abele',
- 'email' => 'nate@example.com'
- ));
- $this->Form->request->addParams(array(
- 'models' => array('Person'),
- 'controller' => 'people',
- 'action' => 'add'
- ));
- $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
- $this->Form->create();
- $result = $this->Form->select('People.People', $options, array('multiple' => true));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[People][People]', 'value' => '', 'id' => 'PeoplePeople_'),
- 'select' => array(
- 'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
- ),
- array('option' => array('value' => 1)), 'Nate', '/option',
- array('option' => array('value' => 2)), 'Garrett', '/option',
- array('option' => array('value' => 3)), 'Larry', '/option',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that required fields are created for various types of validation.
- *
- * @return void
- */
- public function testFormInputRequiredDetection() {
- $this->Form->create('Contact');
- $result = $this->Form->input('Contact.non_existing');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactNonExisting'),
- 'Non Existing',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][non_existing]',
- 'id' => 'ContactNonExisting'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequired');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequired'),
- 'Imrequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequired]',
- 'id' => 'ContactImrequired',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imalsorequired');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImalsorequired'),
- 'Imalsorequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
- 'id' => 'ContactImalsorequired',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequiredtoo');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequiredtoo'),
- 'Imrequiredtoo',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
- 'id' => 'ContactImrequiredtoo',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.required_one');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactRequiredOne'),
- 'Required One',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][required_one]',
- 'id' => 'ContactRequiredOne',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.string_required');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactStringRequired'),
- 'String Required',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][string_required]',
- 'id' => 'ContactStringRequired',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imnotrequired');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImnotrequired'),
- 'Imnotrequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
- 'id' => 'ContactImnotrequired'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imalsonotrequired');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImalsonotrequired'),
- 'Imalsonotrequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
- 'id' => 'ContactImalsonotrequired'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imalsonotrequired2');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImalsonotrequired2'),
- 'Imalsonotrequired2',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imalsonotrequired2]',
- 'id' => 'ContactImalsonotrequired2'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imnotrequiredeither');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImnotrequiredeither'),
- 'Imnotrequiredeither',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
- 'id' => 'ContactImnotrequiredeither'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.iamrequiredalways');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactIamrequiredalways'),
- 'Iamrequiredalways',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][iamrequiredalways]',
- 'id' => 'ContactIamrequiredalways',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
- $expected = array(
- 'div' => array('class' => 'input checkbox required'),
- array('input' => array(
- 'type' => 'hidden',
- 'name' => 'data[Contact][boolean_field]',
- 'id' => 'ContactBooleanField_',
- 'value' => '0'
- )),
- array('input' => array(
- 'type' => 'checkbox',
- 'name' => 'data[Contact][boolean_field]',
- 'value' => '1',
- 'id' => 'ContactBooleanField'
- )),
- 'label' => array('for' => 'ContactBooleanField'),
- 'Boolean Field',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
- $expected = array(
- 'div' => array('class' => 'input checkbox required'),
- array('input' => array(
- 'type' => 'hidden',
- 'name' => 'data[Contact][boolean_field]',
- 'id' => 'ContactBooleanField_',
- 'value' => '0'
- )),
- array('input' => array(
- 'type' => 'checkbox',
- 'name' => 'data[Contact][boolean_field]',
- 'value' => '1',
- 'id' => 'ContactBooleanField',
- 'required' => 'required'
- )),
- 'label' => array('for' => 'ContactBooleanField'),
- 'Boolean Field',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
- $expected = array(
- 'div' => array('class' => 'input file required'),
- 'label' => array('for' => 'ContactIamrequiredalways'),
- 'Iamrequiredalways',
- '/label',
- 'input' => array(
- 'type' => 'file',
- 'name' => 'data[Contact][iamrequiredalways]',
- 'id' => 'ContactIamrequiredalways',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test that required fields are created when only using ModelValidator::add().
- *
- * @return void
- */
- public function testFormInputRequiredDetectionModelValidator() {
- ClassRegistry::getObject('ContactTag')->validator()->add('iwillberequired', 'required', array('rule' => 'notEmpty'));
- $this->Form->create('ContactTag');
- $result = $this->Form->input('ContactTag.iwillberequired');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactTagIwillberequired'),
- 'Iwillberequired',
- '/label',
- 'input' => array(
- 'name' => 'data[ContactTag][iwillberequired]',
- 'type' => 'text',
- 'id' => 'ContactTagIwillberequired',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormMagicInput method
- *
- * @return void
- */
- public function testFormMagicInput() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('name');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactName'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'ContactName', 'maxlength' => '255'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('non_existing_field_in_contact_model');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
- 'Non Existing Field In Contact Model',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][non_existing_field_in_contact_model]',
- 'id' => 'ContactNonExistingFieldInContactModel'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Address.street');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'AddressStreet'),
- 'Street',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Address][street]',
- 'id' => 'AddressStreet'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Address.non_existing_field_in_model');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'AddressNonExistingFieldInModel'),
- 'Non Existing Field In Model',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Address][non_existing_field_in_model]',
- 'id' => 'AddressNonExistingFieldInModel'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('name', array('div' => false));
- $expected = array(
- 'label' => array('for' => 'ContactName'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'ContactName', 'maxlength' => '255'
- )
- );
- $this->assertTags($result, $expected);
- extract($this->dateRegex);
- $now = strtotime('now');
- $result = $this->Form->input('Contact.published', array('div' => false));
- $expected = array(
- 'label' => array('for' => 'ContactPublishedMonth'),
- 'Published',
- '/label',
- array('select' => array(
- 'name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth'
- )),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array(
- 'name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay'
- )),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array(
- 'name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear'
- )),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '*/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.updated', array('div' => false));
- $expected = array(
- 'label' => array('for' => 'ContactUpdatedMonth'),
- 'Updated',
- '/label',
- array('select' => array(
- 'name' => 'data[Contact][updated][month]', 'id' => 'ContactUpdatedMonth'
- )),
- $monthsRegex,
- array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
- date('F', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array(
- 'name' => 'data[Contact][updated][day]', 'id' => 'ContactUpdatedDay'
- )),
- $daysRegex,
- array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
- date('j', $now),
- '/option',
- '*/select',
- '-',
- array('select' => array(
- 'name' => 'data[Contact][updated][year]', 'id' => 'ContactUpdatedYear'
- )),
- $yearsRegex,
- array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
- date('Y', $now),
- '*/select'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('UserForm.stuff');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'UserFormStuff'),
- 'Stuff',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[UserForm][stuff]',
- 'id' => 'UserFormStuff', 'maxlength' => 10
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testForMagicInputNonExistingNorValidated method
- *
- * @return void
- */
- public function testForMagicInputNonExistingNorValidated() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
- $expected = array(
- 'label' => array('for' => 'ContactNonExistingNorValidated'),
- 'Non Existing Nor Validated',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
- 'id' => 'ContactNonExistingNorValidated'
- )
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.non_existing_nor_validated', array(
- 'div' => false, 'value' => 'my value'
- ));
- $expected = array(
- 'label' => array('for' => 'ContactNonExistingNorValidated'),
- 'Non Existing Nor Validated',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
- 'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
- )
- );
- $this->assertTags($result, $expected);
- $this->Form->request->data = array(
- 'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
- ));
- $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
- $expected = array(
- 'label' => array('for' => 'ContactNonExistingNorValidated'),
- 'Non Existing Nor Validated',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
- 'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
- )
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormMagicInputLabel method
- *
- * @return void
- */
- public function testFormMagicInputLabel() {
- $encoding = strtolower(Configure::read('App.encoding'));
- $result = $this->Form->create('Contact');
- $expected = array(
- 'form' => array(
- 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
- 'accept-charset' => $encoding
- ),
- 'div' => array('style' => 'display:none;'),
- 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
- $this->assertTags($result, array('input' => array(
- 'name' => 'data[Contact][name]', 'type' => 'text',
- 'id' => 'ContactName', 'maxlength' => '255')
- ));
- $result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
- $expected = array(
- 'label' => array('for' => 'ContactName'),
- 'My label',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'ContactName', 'maxlength' => '255'
- )
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.name', array(
- 'div' => false, 'label' => array('class' => 'mandatory')
- ));
- $expected = array(
- 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'ContactName', 'maxlength' => '255'
- )
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.name', array(
- 'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
- ));
- $expected = array(
- 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
- 'My label',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'ContactName', 'maxlength' => '255'
- )
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.name', array(
- 'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
- ));
- $expected = array(
- 'label' => array('for' => 'my_id'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][name]',
- 'id' => 'my_id', 'maxlength' => '255'
- )
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('1.id');
- $this->assertTags($result, array('input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][1][id]',
- 'id' => 'Contact1Id'
- )));
- $result = $this->Form->input("1.name");
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'Contact1Name'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][1][name]',
- 'id' => 'Contact1Name', 'maxlength' => '255'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.1.id');
- $this->assertTags($result, array(
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][1][id]',
- 'id' => 'Contact1Id'
- )
- ));
- $result = $this->Form->input("Model.1.name");
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'Model1Name'),
- 'Name',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Model][1][name]',
- 'id' => 'Model1Name'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testFormEnd method
- *
- * @return void
- */
- public function testFormEnd() {
- $this->assertEquals('</form>', $this->Form->end());
- $result = $this->Form->end('', array('form' => 'form-name'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => ''),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end('');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => ''),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array('label' => ''));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => ''),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end('save');
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'save'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array('label' => 'save'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'save'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array('name' => 'Whatever'));
- $expected = array(
- 'div' => array('class' => 'submit'),
- 'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
- $expected = array(
- 'div' => array('class' => 'good'),
- 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->end(array(
- 'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
- ));
- $expected = array(
- 'div' => array('class' => 'good'),
- 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
- '/div',
- '/form'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testMultipleFormWithIdFields method
- *
- * @return void
- */
- public function testMultipleFormWithIdFields() {
- $this->Form->create('UserForm');
- $result = $this->Form->input('id');
- $this->assertTags($result, array('input' => array(
- 'type' => 'hidden', 'name' => 'data[UserForm][id]', 'id' => 'UserFormId'
- )));
- $result = $this->Form->input('ValidateItem.id');
- $this->assertTags($result, array('input' => array(
- 'type' => 'hidden', 'name' => 'data[ValidateItem][id]',
- 'id' => 'ValidateItemId'
- )));
- $result = $this->Form->input('ValidateUser.id');
- $this->assertTags($result, array('input' => array(
- 'type' => 'hidden', 'name' => 'data[ValidateUser][id]',
- 'id' => 'ValidateUserId'
- )));
- }
- /**
- * testDbLessModel method
- *
- * @return void
- */
- public function testDbLessModel() {
- $this->Form->create('TestMail');
- $result = $this->Form->input('name');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'TestMailName'),
- 'Name',
- '/label',
- 'input' => array(
- 'name' => 'data[TestMail][name]', 'type' => 'text',
- 'id' => 'TestMailName'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- ClassRegistry::init('TestMail');
- $this->Form->create('TestMail');
- $result = $this->Form->input('name');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'TestMailName'),
- 'Name',
- '/label',
- 'input' => array(
- 'name' => 'data[TestMail][name]', 'type' => 'text',
- 'id' => 'TestMailName'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testBrokenness method
- *
- * @return void
- */
- public function testBrokenness() {
- /*
- * #4 This test has two parents and four children. By default (as of r7117) both
- * parents are show but the first parent is missing a child. This is the inconsistency
- * in the default behaviour - one parent has all children, the other does not - dependent
- * on the data values.
- */
- $result = $this->Form->select('Model.field', array(
- 'Fred' => array(
- 'freds_son_1' => 'Fred',
- 'freds_son_2' => 'Freddie'
- ),
- 'Bert' => array(
- 'berts_son_1' => 'Albert',
- 'berts_son_2' => 'Bertie')
- ),
- array('showParents' => true, 'empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('optgroup' => array('label' => 'Fred')),
- array('option' => array('value' => 'freds_son_1')),
- 'Fred',
- '/option',
- array('option' => array('value' => 'freds_son_2')),
- 'Freddie',
- '/option',
- '/optgroup',
- array('optgroup' => array('label' => 'Bert')),
- array('option' => array('value' => 'berts_son_1')),
- 'Albert',
- '/option',
- array('option' => array('value' => 'berts_son_2')),
- 'Bertie',
- '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- /*
- * #2 This is structurally identical to the test above (#1) - only the parent name has
- * changed, so we should expect the same select list data, just with a different name
- * for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
- * This is where data corruption can occur, because when a select value is missing from
- * a list a form will substitute the first value in the list - without the user knowing.
- * If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
- * affect the availability of 3 => 'Three' as a valid option.
- */
- $options = array(1 => 'One', 2 => 'Two', 'Three' => array(
- 3 => 'Three', 4 => 'Four', 5 => 'Five'
- ));
- $result = $this->Form->select(
- 'Model.field', $options, array('showParents' => true, 'empty' => false)
- );
- $expected = array(
- 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
- array('option' => array('value' => 1)),
- 'One',
- '/option',
- array('option' => array('value' => 2)),
- 'Two',
- '/option',
- array('optgroup' => array('label' => 'Three')),
- array('option' => array('value' => 3)),
- 'Three',
- '/option',
- array('option' => array('value' => 4)),
- 'Four',
- '/option',
- array('option' => array('value' => 5)),
- 'Five',
- '/option',
- '/optgroup',
- '/select'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test the generation of fields for a multi record form.
- *
- * @return void
- */
- public function testMultiRecordForm() {
- $this->Form->create('ValidateProfile');
- $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
- $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
- $expected = array(
- 'div' => array('class' => 'input textarea'),
- 'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
- 'Name',
- '/label',
- 'textarea' => array(
- 'id' => 'ValidateProfile1ValidateItem2Name',
- 'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
- 'cols' => 30,
- 'rows' => 6
- ),
- 'Value',
- '/textarea',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
- 'Created',
- '/label',
- array('select' => array(
- 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][month]',
- 'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
- )
- ),
- array('option' => array('value' => '')), '/option',
- $this->dateRegex['monthsRegex'],
- '/select', '-',
- array('select' => array(
- 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][day]',
- 'id' => 'ValidateProfile1ValidateItem2CreatedDay'
- )
- ),
- array('option' => array('value' => '')), '/option',
- $this->dateRegex['daysRegex'],
- '/select', '-',
- array('select' => array(
- 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][year]',
- 'id' => 'ValidateProfile1ValidateItem2CreatedYear'
- )
- ),
- array('option' => array('value' => '')), '/option',
- $this->dateRegex['yearsRegex'],
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
- $ValidateProfile = ClassRegistry::getObject('ValidateProfile');
- $ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
- $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
- $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
- $expected = array(
- 'div' => array('class' => 'input select error'),
- 'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
- 'Profile',
- '/label',
- 'select' => array(
- 'name' => 'data[ValidateProfile][1][ValidateItem][2][profile_id]',
- 'id' => 'ValidateProfile1ValidateItem2ProfileId',
- 'class' => 'form-error'
- ),
- '/select',
- array('div' => array('class' => 'error-message')),
- 'Error',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test the correct display of multi-record form validation errors.
- *
- * @return void
- */
- public function testMultiRecordFormValidationErrors() {
- $this->Form->create('ValidateProfile');
- $ValidateProfile = ClassRegistry::getObject('ValidateProfile');
- $ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
- $result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
- $ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
- $result = $this->Form->error('ValidateProfile.2.city');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
- $result = $this->Form->error('2.city');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
- }
- /**
- * test the correct display of multi-record form validation errors.
- *
- * @return void
- */
- public function testSaveManyRecordFormValidationErrors() {
- $this->Form->create('ValidateUser');
- $ValidateUser = ClassRegistry::getObject('ValidateUser');
- $ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
- $result = $this->Form->error('0.ValidateUser.ValidateItem.name');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
- $ValidateUser->validationErrors[0]['city'] = array('Error in field city');
- $result = $this->Form->error('ValidateUser.0.city');
- $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
- }
- /**
- * tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
- *
- * @return void
- */
- public function testInputTemplate() {
- $result = $this->Form->input('Contact.email', array(
- 'type' => 'text', 'format' => array('input')
- ));
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
- 'id' => 'ContactEmail'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array(
- 'type' => 'text', 'format' => array('input', 'label'),
- 'label' => '<em>Email (required)</em>'
- ));
- $expected = array(
- 'div' => array('class' => 'input text'),
- array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
- 'id' => 'ContactEmail'
- )),
- 'label' => array('for' => 'ContactEmail'),
- 'em' => array(),
- 'Email (required)',
- '/em',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.email', array(
- 'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
- 'between' => '<div>Something in the middle</div>',
- 'after' => '<span>Some text at the end</span>'
- ));
- $expected = array(
- 'div' => array('class' => 'input text'),
- array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
- 'id' => 'ContactEmail'
- )),
- array('div' => array()),
- 'Something in the middle',
- '/div',
- 'label' => array('for' => 'ContactEmail'),
- 'Email',
- '/label',
- 'span' => array(),
- 'Some text at the end',
- '/span',
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.method', array(
- 'type' => 'radio',
- 'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
- 'between' => 'I am between',
- ));
- $expected = array(
- 'div' => array('class' => 'input radio'),
- 'fieldset' => array(),
- 'legend' => array(),
- 'Method',
- '/legend',
- 'I am between',
- 'input' => array(
- 'type' => 'hidden', 'name' => 'data[Contact][method]',
- 'value' => '', 'id' => 'ContactMethod_'
- ),
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Contact][method]',
- 'value' => 'email', 'id' => 'ContactMethodEmail'
- )),
- array('label' => array('for' => 'ContactMethodEmail')),
- 'Email',
- '/label',
- array('input' => array(
- 'type' => 'radio', 'name' => 'data[Contact][method]',
- 'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
- )),
- array('label' => array('for' => 'ContactMethodPigeon')),
- 'Pigeon',
- '/label',
- '/fieldset',
- '/div',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * test that some html5 inputs + FormHelper::__call() work
- *
- * @return void
- */
- public function testHtml5Inputs() {
- $result = $this->Form->email('User.email');
- $expected = array(
- 'input' => array('type' => 'email', 'name' => 'data[User][email]', 'id' => 'UserEmail')
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->search('User.query');
- $expected = array(
- 'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery')
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->search('User.query', array('value' => 'test'));
- $expected = array(
- 'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
- $expected = array(
- 'input' => array('type' => 'text', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('User.website', array('type' => 'url', 'value' => 'http://domain.tld', 'div' => false, 'label' => false));
- $expected = array(
- 'input' => array('type' => 'url', 'name' => 'data[User][website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
- );
- $this->assertTags($result, $expected);
- }
- /**
- *
- * @expectedException CakeException
- * @return void
- */
- public function testHtml5InputException() {
- $this->Form->email();
- }
- /**
- * Tests that a model can be loaded from the model names passed in the request object
- *
- * @return void
- */
- public function testIntrospectModelFromRequest() {
- $this->loadFixtures('Post');
- App::build(array(
- 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
- ));
- CakePlugin::load('TestPlugin');
- $this->Form->request['models'] = array('TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost'));
- $this->assertFalse(ClassRegistry::isKeySet('TestPluginPost'));
- $this->Form->create('TestPluginPost');
- $this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
- $this->assertInstanceOf('TestPluginPost', ClassRegistry::getObject('TestPluginPost'));
- CakePlugin::unload();
- App::build();
- }
- /**
- * Tests that it is possible to set the validation errors directly in the helper for a field
- *
- * @return void
- */
- public function testCustomValidationErrors() {
- $this->Form->validationErrors['Thing']['field'] = 'Badness!';
- $result = $this->Form->error('Thing.field', null, array('wrap' => false));
- $this->assertEquals('Badness!', $result);
- }
- /**
- * Tests that the 'on' key validates as expected on create
- *
- * @return void
- */
- public function testRequiredOnCreate() {
- $this->Form->create('Contact');
- $result = $this->Form->input('Contact.imrequiredonupdate');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImrequiredonupdate'),
- 'Imrequiredonupdate',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
- 'id' => 'ContactImrequiredonupdate'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequiredoncreate');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequiredoncreate'),
- 'Imrequiredoncreate',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
- 'id' => 'ContactImrequiredoncreate',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequiredonboth');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequiredonboth'),
- 'Imrequiredonboth',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
- 'id' => 'ContactImrequiredonboth',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->inputDefaults(array('required' => false));
- $result = $this->Form->input('Contact.imrequired');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImrequired'),
- 'Imrequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequired]',
- 'id' => 'ContactImrequired'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequired', array('required' => false));
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequired', array('required' => true));
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequired'),
- 'Imrequired',
- '/label',
- 'input' => array(
- 'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
- 'id' => 'ContactImrequired'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequired', array('required' => null));
- $this->assertTags($result, $expected);
- }
- /**
- * Tests that the 'on' key validates as expected on update
- *
- * @return void
- */
- public function testRequiredOnUpdate() {
- $this->Form->request->data['Contact']['id'] = 1;
- $this->Form->create('Contact');
- $result = $this->Form->input('Contact.imrequiredonupdate');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequiredonupdate'),
- 'Imrequiredonupdate',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
- 'id' => 'ContactImrequiredonupdate',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequiredoncreate');
- $expected = array(
- 'div' => array('class' => 'input text'),
- 'label' => array('for' => 'ContactImrequiredoncreate'),
- 'Imrequiredoncreate',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
- 'id' => 'ContactImrequiredoncreate'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequiredonboth');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequiredonboth'),
- 'Imrequiredonboth',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
- 'id' => 'ContactImrequiredonboth',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.imrequired');
- $expected = array(
- 'div' => array('class' => 'input text required'),
- 'label' => array('for' => 'ContactImrequired'),
- 'Imrequired',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][imrequired]',
- 'id' => 'ContactImrequired',
- 'required' => 'required'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * Test inputDefaults setter and getter
- *
- * @return void
- */
- public function testInputDefaults() {
- $this->Form->create('Contact');
- $this->Form->inputDefaults(array(
- 'label' => false,
- 'div' => array(
- 'style' => 'color: #000;'
- )
- ));
- $result = $this->Form->input('Contact.field1');
- $expected = array(
- 'div' => array('class' => 'input text', 'style' => 'color: #000;'),
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field1]',
- 'id' => 'ContactField1'
- ),
- '/div'
- );
- $this->assertTags($result, $expected);
- $this->Form->inputDefaults(array(
- 'div' => false,
- 'label' => 'Label',
- ));
- $result = $this->Form->input('Contact.field1');
- $expected = array(
- 'label' => array('for' => 'ContactField1'),
- 'Label',
- '/label',
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field1]',
- 'id' => 'ContactField1'
- ),
- );
- $this->assertTags($result, $expected);
- $this->Form->inputDefaults(array(
- 'label' => false,
- ), true);
- $result = $this->Form->input('Contact.field1');
- $expected = array(
- 'input' => array(
- 'type' => 'text', 'name' => 'data[Contact][field1]',
- 'id' => 'ContactField1'
- ),
- );
- $this->assertTags($result, $expected);
- $result = $this->Form->inputDefaults();
- $expected = array(
- 'div' => false,
- 'label' => false,
- );
- $this->assertEquals($expected, $result);
- }
- }
|