| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920 |
- <?php
- /**
- * FormHelperTest file
- *
- * PHP 5
- *
- * 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 MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTestController extends Controller {
- /**
- * uses property
- *
- * @var mixed null
- */
- public $uses = null;
- }
- /**
- * Contact class
- *
- * @package cake
- * @package Cake.Test.Case.View.Helper
- */
- class Contact extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTagsContact extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ContactNonStandardPk extends Contact {
- /**
- * primaryKey property
- *
- * @var string 'pk'
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ContactTag extends Model {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class UserForm extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class OpenidUrl extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateUser extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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'),
- '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
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateProfile extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class ValidateItem extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- 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
- * @package Cake.Test.Case.View.Helper
- */
- class TestMail extends CakeTestModel {
- /**
- * useTable property
- *
- * @var bool false
- */
- public $useTable = false;
- }
- /**
- * FormHelperTest class
- *
- * @package cake
- * @subpackage 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('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');
- $this->Form->request['_Token'] = array('key' => $key);
- $result = $this->Form->secure($fields);
- $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+/'
- )),
- array('input' => array(
- 'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
- 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
- )),
- '/div'
- );
- $this->assertTags($result, $expected);
- $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
- $this->Form->Html->loadConfig('htmlhelper_tags', $path);
- $result = $this->Form->secure($fields);
- $expected = array(
- 'div' => array('class' => 'hidden'),
- 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);
- }
- /**
- * 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
- *
- * @access public
- * @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);
- }
- /**
- * 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 = 'c9118120e680a7201b543f562e5301006ccfcbe2%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 = '629b6536dcece48aa41a117045628ce602ccbbb2%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 = '2981c38990f3f6ba935e6561dc77277966fabd6d%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 = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%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 testFormSecuredFileInput() {
- $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 testFormSecuredMultipleSelect() {
- $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 testFormSecuredRadio() {
- $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 testFormSecuredAndDisabledNotAssoc() {
- $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 testFormSecuredAndDisabled() {
- $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);
- }
- /**
- * 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.
- *
- * @access public
- * @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.
- *
- * @access public
- * @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' => 'preg:/[^<]+/',
- 'id' => 'preg:/[^<]+/', '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'),
- '/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.
- *
- */
- 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 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 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'));
- $expected = array(
- 'fieldset' => array(),
- 'legend' => array(),
- 'Gender',
- '/legend',
- 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'),
- array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')),
- array('label' => array('for' => 'EmployeeGenderMale')),
- 'Male',
- '/label',
- array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')),
- 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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('multiple' => 'multiple')
- );
- $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('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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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'));
- $expected = array(
- 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
- array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID'))
- );
- $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('preg:/[^<]+/', '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('preg:/[^<]+/', '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);
- }
- /**
- * 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 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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);
- }
- /**
- * 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($result, $expected);
- $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($result, $expected);
- $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($result, $expected);
- }
- /**
- * 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 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', 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'
- ));
- }
- /**
- * 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);
- }
- /**
- * 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 (&)
- *
- */
- 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 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);
- }
- /**
- * 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('');
- $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->assertEqual($result, $expected);
- }
- }
|