FormHelperTest.php 274 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824
  1. <?php
  2. /**
  3. * FormHelperTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @since CakePHP(tm) v 1.2.0.4206
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\View\Helper;
  18. use Cake\Controller\Controller;
  19. use Cake\Core\App;
  20. use Cake\Core\Configure;
  21. use Cake\Core\Plugin;
  22. use Cake\Network\Request;
  23. use Cake\ORM\Entity;
  24. use Cake\ORM\Table;
  25. use Cake\ORM\TableRegistry;
  26. use Cake\Routing\Router;
  27. use Cake\TestSuite\TestCase;
  28. use Cake\Utility\Security;
  29. use Cake\View\Helper\FormHelper;
  30. use Cake\View\Helper\HtmlHelper;
  31. use Cake\View\View;
  32. /**
  33. * Test stub.
  34. */
  35. class Article extends Entity {
  36. }
  37. /**
  38. * ContactTestController class
  39. *
  40. */
  41. class ContactTestController extends Controller {
  42. /**
  43. * uses property
  44. *
  45. * @var mixed null
  46. */
  47. public $uses = null;
  48. }
  49. /**
  50. * Contact class
  51. *
  52. */
  53. class ContactsTable extends Table {
  54. /**
  55. * Default schema
  56. *
  57. * @var array
  58. */
  59. protected $_schema = array(
  60. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  61. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  62. 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  63. 'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  64. 'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  65. 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
  66. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  67. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
  68. 'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
  69. );
  70. /**
  71. * validate property
  72. *
  73. * @var array
  74. */
  75. public $validate = array(
  76. 'non_existing' => array(),
  77. 'idontexist' => array(),
  78. 'imrequired' => array('_allowEmpty' => false, array('rule' => array('between', 5, 30))),
  79. 'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
  80. 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
  81. 'imrequiredonboth' => array(
  82. 'required' => array('rule' => 'alphaNumeric'),
  83. ),
  84. 'string_required' => 'notEmpty',
  85. 'imalsorequired' => array('_allowEmpty' => false, array('rule' => 'alphaNumeric')),
  86. 'imrequiredtoo' => array('rule' => 'notEmpty'),
  87. 'required_one' => array('required' => array('rule' => array('notEmpty'))),
  88. 'imnotrequired' => array(
  89. '_allowEmpty' => true,
  90. array('rule' => 'alphaNumeric')
  91. ),
  92. 'imalsonotrequired' => array(
  93. '_allowEmpty' => true,
  94. 'alpha' => array('rule' => 'alphaNumeric'),
  95. 'between' => array('rule' => array('between', 5, 30)),
  96. ),
  97. 'imnotrequiredeither' => array(
  98. '_allowEmpty' => true,
  99. array('rule' => array('between', 5, 30))
  100. ),
  101. 'iamrequiredalways' => array(
  102. 'email' => array('rule' => 'email'),
  103. 'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
  104. 'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
  105. ),
  106. 'boolean_field' => array('rule' => 'boolean')
  107. );
  108. /**
  109. * schema method
  110. *
  111. * @return void
  112. */
  113. public function setSchema($schema) {
  114. $this->_schema = $schema;
  115. }
  116. /**
  117. * hasAndBelongsToMany property
  118. *
  119. * @var array
  120. */
  121. public $hasAndBelongsToMany = array(
  122. 'ContactTag' => array(
  123. 'className' => 'Cake\Test\TestCase\View\Helper\ContactTag',
  124. 'with' => 'Cake\Test\TestCase\View\Helper\ContactTagsContact'
  125. )
  126. );
  127. /**
  128. * hasAndBelongsToMany property
  129. *
  130. * @var array
  131. */
  132. public $belongsTo = array(
  133. 'User' => array('className' => 'UserForm'
  134. ));
  135. }
  136. /**
  137. * ContactTagsContact class
  138. *
  139. */
  140. class ContactTagsContactsTable extends Table {
  141. /**
  142. * Default schema
  143. *
  144. * @var array
  145. */
  146. protected $_schema = array(
  147. 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  148. 'contact_tag_id' => array(
  149. 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
  150. )
  151. );
  152. /**
  153. * schema method
  154. *
  155. * @return void
  156. */
  157. public function setSchema($schema) {
  158. $this->_schema = $schema;
  159. }
  160. }
  161. /**
  162. * ContactNonStandardPk class
  163. *
  164. */
  165. class ContactNonStandardPk extends ContactsTable {
  166. /**
  167. * primaryKey property
  168. *
  169. * @var string
  170. */
  171. public $primaryKey = 'pk';
  172. /**
  173. * schema method
  174. *
  175. * @return void
  176. */
  177. public function schema($field = false) {
  178. $this->_schema = parent::schema();
  179. $this->_schema['pk'] = $this->_schema['id'];
  180. unset($this->_schema['id']);
  181. return $this->_schema;
  182. }
  183. }
  184. /**
  185. * ContactTag class
  186. *
  187. */
  188. class ContactTagsTable extends Table {
  189. /**
  190. * schema definition
  191. *
  192. * @var array
  193. */
  194. protected $_schema = array(
  195. 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
  196. 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  197. 'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
  198. 'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
  199. );
  200. }
  201. /**
  202. * UserForm class
  203. *
  204. */
  205. class UserFormsTable extends Table {
  206. /**
  207. * hasMany property
  208. *
  209. * @var array
  210. */
  211. public $hasMany = array(
  212. 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
  213. ));
  214. /**
  215. * schema definition
  216. *
  217. * @var array
  218. */
  219. protected $_schema = array(
  220. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  221. 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
  222. 'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
  223. 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
  224. 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
  225. 'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
  226. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  227. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  228. );
  229. }
  230. /**
  231. * OpenidUrl class
  232. *
  233. */
  234. class OpenidUrlsTable extends Table {
  235. /**
  236. * belongsTo property
  237. *
  238. * @var array
  239. */
  240. public $belongsTo = array('UserForm' => array(
  241. 'className' => 'UserForm', 'foreignKey' => 'user_form_id'
  242. ));
  243. /**
  244. * validate property
  245. *
  246. * @var array
  247. */
  248. public $validate = array('openid_not_registered' => array());
  249. /**
  250. * schema method
  251. *
  252. * @var array
  253. */
  254. protected $_schema = array(
  255. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  256. 'user_form_id' => array(
  257. 'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
  258. ),
  259. 'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  260. );
  261. /**
  262. * beforeValidate method
  263. *
  264. * @return void
  265. */
  266. public function beforeValidate($options = array()) {
  267. $this->invalidate('openid_not_registered');
  268. return true;
  269. }
  270. }
  271. /**
  272. * ValidateUser class
  273. *
  274. */
  275. class ValidateUsersTable extends Table {
  276. /**
  277. * hasOne property
  278. *
  279. * @var array
  280. */
  281. public $hasOne = array('ValidateProfile' => array(
  282. 'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
  283. ));
  284. /**
  285. * schema method
  286. *
  287. * @var array
  288. */
  289. protected $_schema = array(
  290. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  291. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  292. 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  293. 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
  294. 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'),
  295. 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'),
  296. 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'),
  297. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  298. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  299. );
  300. /**
  301. * beforeValidate method
  302. *
  303. * @return void
  304. */
  305. public function beforeValidate($options = array()) {
  306. $this->invalidate('email');
  307. return false;
  308. }
  309. }
  310. /**
  311. * ValidateProfile class
  312. *
  313. */
  314. class ValidateProfilesTable extends Table {
  315. /**
  316. * useTable property
  317. *
  318. * @var boolean
  319. */
  320. public $useTable = false;
  321. /**
  322. * schema property
  323. *
  324. * @var array
  325. */
  326. protected $_schema = array(
  327. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  328. 'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  329. 'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  330. 'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  331. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  332. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  333. );
  334. /**
  335. * hasOne property
  336. *
  337. * @var array
  338. */
  339. public $hasOne = array('ValidateItem' => array(
  340. 'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
  341. ));
  342. /**
  343. * belongsTo property
  344. *
  345. * @var array
  346. */
  347. public $belongsTo = array('ValidateUser' => array(
  348. 'className' => 'ValidateUser', 'foreignKey' => 'user_id'
  349. ));
  350. /**
  351. * beforeValidate method
  352. *
  353. * @return void
  354. */
  355. public function beforeValidate($options = array()) {
  356. $this->invalidate('full_name');
  357. $this->invalidate('city');
  358. return false;
  359. }
  360. }
  361. /**
  362. * ValidateItem class
  363. *
  364. */
  365. class ValidateItemsTable extends Table {
  366. /**
  367. * schema property
  368. *
  369. * @var array
  370. */
  371. protected $_schema = array(
  372. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  373. 'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  374. 'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
  375. 'description' => array(
  376. 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
  377. ),
  378. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  379. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  380. );
  381. /**
  382. * belongsTo property
  383. *
  384. * @var array
  385. */
  386. public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
  387. /**
  388. * beforeValidate method
  389. *
  390. * @return void
  391. */
  392. public function beforeValidate($options = array()) {
  393. $this->invalidate('description');
  394. return false;
  395. }
  396. }
  397. /**
  398. * TestMail class
  399. *
  400. */
  401. class TestMailsTable extends Table {
  402. }
  403. /**
  404. * FormHelperTest class
  405. *
  406. * @property FormHelper $Form
  407. */
  408. class FormHelperTest extends TestCase {
  409. /**
  410. * Fixtures to be used
  411. *
  412. * @var array
  413. */
  414. public $fixtures = array('core.article');
  415. /**
  416. * Do not load the fixtures by default
  417. *
  418. * @var boolean
  419. */
  420. public $autoFixtures = false;
  421. /**
  422. * setUp method
  423. *
  424. * @return void
  425. */
  426. public function setUp() {
  427. parent::setUp();
  428. Configure::write('Config.language', 'eng');
  429. Configure::write('App.base', '');
  430. Configure::write('App.namespace', 'Cake\Test\TestCase\View\Helper');
  431. Configure::delete('Asset');
  432. $this->View = new View(null);
  433. $this->Form = new FormHelper($this->View);
  434. $this->Form->Html = new HtmlHelper($this->View);
  435. $this->Form->request = new Request('articles/add');
  436. $this->Form->request->here = '/articles/add';
  437. $this->Form->request['controller'] = 'articles';
  438. $this->Form->request['action'] = 'add';
  439. $this->Form->request->webroot = '';
  440. $this->Form->request->base = '';
  441. $this->dateRegex = array(
  442. 'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
  443. 'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
  444. 'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
  445. 'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
  446. 'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
  447. 'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
  448. );
  449. $this->article = [
  450. 'schema' => [
  451. 'id' => ['type' => 'integer'],
  452. 'author_id' => ['type' => 'integer', 'null' => true],
  453. 'title' => ['type' => 'string', 'null' => true],
  454. 'body' => 'text',
  455. 'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
  456. '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
  457. ],
  458. 'required' => [
  459. 'author_id' => true,
  460. 'title' => true,
  461. ]
  462. ];
  463. Configure::write('Security.salt', 'foo!');
  464. Router::connect('/:controller', array('action' => 'index'));
  465. Router::connect('/:controller/:action/*');
  466. }
  467. /**
  468. * tearDown method
  469. *
  470. * @return void
  471. */
  472. public function tearDown() {
  473. parent::tearDown();
  474. unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
  475. }
  476. /**
  477. * Test registering a new widget class and rendering it.
  478. *
  479. * @return void
  480. */
  481. public function testAddWidgetAndRenderWidget() {
  482. $data = [
  483. 'val' => 1
  484. ];
  485. $mock = $this->getMock('Cake\View\Widget\WidgetInterface');
  486. $this->assertNull($this->Form->addWidget('test', $mock));
  487. $mock->expects($this->once())
  488. ->method('render')
  489. ->with($data)
  490. ->will($this->returnValue('HTML'));
  491. $result = $this->Form->widget('test', $data);
  492. $this->assertEquals('HTML', $result);
  493. }
  494. /**
  495. * Test registering an invalid widget class.
  496. *
  497. * @expectedException \RuntimeException
  498. * @return void
  499. */
  500. public function testAddWidgetInvalid() {
  501. $mock = new \StdClass();
  502. $this->Form->addWidget('test', $mock);
  503. $this->Form->widget('test');
  504. }
  505. /**
  506. * Test adding a new context class.
  507. *
  508. * @return void
  509. */
  510. public function testAddContextProvider() {
  511. $context = 'My data';
  512. $this->Form->addContextProvider('test', function ($request, $data) use ($context) {
  513. $this->assertInstanceOf('Cake\Network\Request', $request);
  514. $this->assertEquals($context, $data['entity']);
  515. return $this->getMock('Cake\View\Form\ContextInterface');
  516. });
  517. $this->Form->create($context);
  518. }
  519. /**
  520. * Test adding an invalid context class.
  521. *
  522. * @expectedException RuntimeException
  523. * @expectedExceptionMessage Context objects must implement Cake\View\Form\ContextInterface
  524. * @return void
  525. */
  526. public function testAddContextProviderInvalid() {
  527. $context = 'My data';
  528. $this->Form->addContextProvider('test', function ($request, $data) use ($context) {
  529. return new \StdClass();
  530. });
  531. $this->Form->create($context);
  532. }
  533. /**
  534. * Provides context options for create().
  535. *
  536. * @return array
  537. */
  538. public function contextSelectionProvider() {
  539. $entity = new Article();
  540. $collection = $this->getMock('Cake\Collection\Collection', ['extract'], [[$entity]]);
  541. $data = [
  542. 'schema' => [
  543. 'title' => ['type' => 'string']
  544. ]
  545. ];
  546. return [
  547. 'entity' => [$entity, 'Cake\View\Form\EntityContext'],
  548. 'collection' => [$collection, 'Cake\View\Form\EntityContext'],
  549. 'array' => [$data, 'Cake\View\Form\ArrayContext'],
  550. 'none' => [null, 'Cake\View\Form\NullContext'],
  551. 'false' => [false, 'Cake\View\Form\NullContext'],
  552. ];
  553. }
  554. /**
  555. * Test default context selection in create()
  556. *
  557. * @dataProvider contextSelectionProvider
  558. * @return void
  559. */
  560. public function testCreateContextSelectionBuiltIn($data, $class) {
  561. $this->loadFixtures('Article');
  562. $this->Form->create($data);
  563. $this->assertInstanceOf($class, $this->Form->context());
  564. }
  565. /**
  566. * Data provider for type option.
  567. *
  568. * @return array
  569. */
  570. public static function requestTypeProvider() {
  571. return [
  572. // type, method, override
  573. ['post', 'post', 'POST'],
  574. ['put', 'post', 'PUT'],
  575. ['patch', 'post', 'PATCH'],
  576. ['delete', 'post', 'DELETE'],
  577. ];
  578. }
  579. /**
  580. * Test creating file forms.
  581. *
  582. * @return void
  583. */
  584. public function testCreateFile() {
  585. $encoding = strtolower(Configure::read('App.encoding'));
  586. $result = $this->Form->create(false, array('type' => 'file'));
  587. $expected = array(
  588. 'form' => array(
  589. 'method' => 'post', 'action' => '/articles/add',
  590. 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
  591. ),
  592. 'div' => array('style' => 'display:none;'),
  593. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  594. '/div'
  595. );
  596. $this->assertTags($result, $expected);
  597. }
  598. /**
  599. * Test creating GET forms.
  600. *
  601. * @return void
  602. */
  603. public function testCreateGet() {
  604. $encoding = strtolower(Configure::read('App.encoding'));
  605. $result = $this->Form->create(false, array('type' => 'get'));
  606. $expected = array('form' => array(
  607. 'method' => 'get', 'action' => '/articles/add',
  608. 'accept-charset' => $encoding
  609. ));
  610. $this->assertTags($result, $expected);
  611. }
  612. /**
  613. * test the create() method
  614. *
  615. * @dataProvider requestTypeProvider
  616. * @return void
  617. */
  618. public function testCreateTypeOptions($type, $method, $override) {
  619. $encoding = strtolower(Configure::read('App.encoding'));
  620. $result = $this->Form->create(false, array('type' => $type));
  621. $expected = array(
  622. 'form' => array(
  623. 'method' => $method, 'action' => '/articles/add',
  624. 'accept-charset' => $encoding
  625. ),
  626. 'div' => array('style' => 'display:none;'),
  627. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => $override),
  628. '/div'
  629. );
  630. $this->assertTags($result, $expected);
  631. }
  632. /**
  633. * Test opening a form for an update operation.
  634. *
  635. * @return void
  636. */
  637. public function testCreateUpdateForm() {
  638. $encoding = strtolower(Configure::read('App.encoding'));
  639. $this->Form->request->here = '/articles/edit/1';
  640. $this->Form->request['action'] = 'edit';
  641. $this->article['defaults']['id'] = 1;
  642. $result = $this->Form->create($this->article);
  643. $expected = array(
  644. 'form' => array(
  645. 'method' => 'post', 'action' => '/articles/edit/1',
  646. 'accept-charset' => $encoding
  647. ),
  648. 'div' => array('style' => 'display:none;'),
  649. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  650. '/div'
  651. );
  652. $this->assertTags($result, $expected);
  653. }
  654. /**
  655. * Test the onsubmit option for create()
  656. *
  657. * @return void
  658. */
  659. public function testCreateOnSubmit() {
  660. $this->Form->request->data = [];
  661. $this->Form->request['controller'] = 'articles';
  662. $result = $this->Form->create($this->article, ['url' => ['action' => 'index', 'param'], 'default' => false]);
  663. $expected = array(
  664. 'form' => array(
  665. 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/articles/index/param',
  666. 'accept-charset' => 'utf-8'
  667. ),
  668. 'div' => array('style' => 'display:none;'),
  669. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  670. '/div'
  671. );
  672. $this->assertTags($result, $expected);
  673. $this->Form->request->data = [];
  674. $this->Form->request['controller'] = 'articles';
  675. $result = $this->Form->create($this->article, array(
  676. 'url' => array('action' => 'index', 'param'),
  677. 'default' => false,
  678. 'onsubmit' => 'someFunction();'
  679. ));
  680. $expected = array(
  681. 'form' => array(
  682. 'method' => 'post',
  683. 'onsubmit' => 'someFunction();event.returnValue = false; return false;',
  684. 'action' => '/articles/index/param',
  685. 'accept-charset' => 'utf-8'
  686. ),
  687. 'div' => array('style' => 'display:none;'),
  688. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  689. '/div'
  690. );
  691. $this->assertTags($result, $expected);
  692. }
  693. /**
  694. * test create() with automatic url generation
  695. *
  696. * @return void
  697. */
  698. public function testCreateAutoUrl() {
  699. $encoding = strtolower(Configure::read('App.encoding'));
  700. $this->Form->request['action'] = 'delete';
  701. $this->Form->request->here = '/articles/delete/10';
  702. $this->Form->request->base = '';
  703. $result = $this->Form->create($this->article);
  704. $expected = array(
  705. 'form' => array(
  706. 'method' => 'post', 'action' => '/articles/delete/10',
  707. 'accept-charset' => $encoding
  708. ),
  709. 'div' => array('style' => 'display:none;'),
  710. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  711. '/div'
  712. );
  713. $this->assertTags($result, $expected);
  714. $this->article['defaults'] = ['id' => 1];
  715. $this->Form->request->here = '/articles/edit/1';
  716. $this->Form->request['action'] = 'delete';
  717. $result = $this->Form->create($this->article, ['action' => 'edit']);
  718. $expected = array(
  719. 'form' => array(
  720. 'method' => 'post',
  721. 'action' => '/articles/edit/1',
  722. 'accept-charset' => $encoding
  723. ),
  724. 'div' => array('style' => 'display:none;'),
  725. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  726. '/div'
  727. );
  728. $this->assertTags($result, $expected);
  729. $this->Form->request['action'] = 'add';
  730. $result = $this->Form->create($this->article, ['url' => ['action' => 'publish']]);
  731. $expected = array(
  732. 'form' => array(
  733. 'method' => 'post',
  734. 'action' => '/articles/publish/1',
  735. 'accept-charset' => $encoding
  736. ),
  737. 'div' => array('style' => 'display:none;'),
  738. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  739. '/div'
  740. );
  741. $this->assertTags($result, $expected);
  742. $result = $this->Form->create($this->article, array('url' => '/articles/publish'));
  743. $expected = array(
  744. 'form' => array('method' => 'post', 'action' => '/articles/publish', 'accept-charset' => $encoding),
  745. 'div' => array('style' => 'display:none;'),
  746. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  747. '/div'
  748. );
  749. $this->assertTags($result, $expected);
  750. $this->Form->request['controller'] = 'pages';
  751. $result = $this->Form->create($this->article, array('action' => 'signup'));
  752. $expected = array(
  753. 'form' => array(
  754. 'method' => 'post', 'action' => '/pages/signup/1',
  755. 'accept-charset' => $encoding
  756. ),
  757. 'div' => array('style' => 'display:none;'),
  758. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
  759. '/div'
  760. );
  761. $this->assertTags($result, $expected);
  762. }
  763. /**
  764. * test create() with a custom route
  765. *
  766. * @return void
  767. */
  768. public function testCreateCustomRoute() {
  769. Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
  770. $encoding = strtolower(Configure::read('App.encoding'));
  771. $this->Form->request['controller'] = 'users';
  772. $result = $this->Form->create(false, array('action' => 'login'));
  773. $expected = array(
  774. 'form' => array(
  775. 'method' => 'post', 'action' => '/login',
  776. 'accept-charset' => $encoding
  777. ),
  778. 'div' => array('style' => 'display:none;'),
  779. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  780. '/div'
  781. );
  782. $this->assertTags($result, $expected);
  783. }
  784. /**
  785. * test that inputDefaults are stored and used.
  786. *
  787. * @return void
  788. */
  789. public function testCreateWithInputDefaults() {
  790. $this->markTestIncomplete('Need to revisit once models work again.');
  791. $this->Form->create('User', array(
  792. 'inputDefaults' => array(
  793. 'div' => false,
  794. 'label' => false,
  795. 'error' => array('attributes' => array('wrap' => 'small', 'class' => 'error')),
  796. 'format' => array('before', 'label', 'between', 'input', 'after', 'error')
  797. )
  798. ));
  799. $result = $this->Form->input('username');
  800. $expected = array(
  801. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername')
  802. );
  803. $this->assertTags($result, $expected);
  804. $result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
  805. $expected = array(
  806. 'div' => array('class' => 'input text'),
  807. 'label' => array('for' => 'UserUsername'), 'username', '/label',
  808. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  809. '/div'
  810. );
  811. $this->assertTags($result, $expected);
  812. $result = $this->Form->input('username', array('label' => 'Username', 'format' => array('input', 'label')));
  813. $expected = array(
  814. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  815. 'label' => array('for' => 'UserUsername'), 'Username', '/label',
  816. );
  817. $this->assertTags($result, $expected);
  818. $this->Form->create('User', array(
  819. 'inputDefaults' => array(
  820. 'div' => false,
  821. 'label' => array('class' => 'nice', 'for' => 'changed'),
  822. )
  823. ));
  824. $result = $this->Form->input('username', array('div' => true));
  825. $expected = array(
  826. 'div' => array('class' => 'input text'),
  827. 'label' => array('for' => 'changed', 'class' => 'nice'), 'Username', '/label',
  828. 'input' => array('type' => 'text', 'name' => 'User[username]', 'id' => 'UserUsername'),
  829. '/div'
  830. );
  831. $this->assertTags($result, $expected);
  832. }
  833. /**
  834. * test automatic accept-charset overriding
  835. *
  836. * @return void
  837. */
  838. public function testCreateWithAcceptCharset() {
  839. $this->markTestIncomplete('Need to revisit once models work again.');
  840. $result = $this->Form->create('UserForm', array(
  841. 'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
  842. )
  843. );
  844. $expected = array(
  845. 'form' => array(
  846. 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
  847. 'accept-charset' => 'iso-8859-1'
  848. ),
  849. 'div' => array('style' => 'display:none;'),
  850. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  851. '/div'
  852. );
  853. $this->assertTags($result, $expected);
  854. }
  855. /**
  856. * Test base form URL when url param is passed with multiple parameters (&)
  857. *
  858. */
  859. public function testCreateQuerystringrequest() {
  860. $this->markTestIncomplete('Need to revisit once models work again.');
  861. $encoding = strtolower(Configure::read('App.encoding'));
  862. $result = $this->Form->create('Contact', array(
  863. 'type' => 'post',
  864. 'escape' => false,
  865. 'url' => array(
  866. 'controller' => 'controller',
  867. 'action' => 'action',
  868. '?' => array('param1' => 'value1', 'param2' => 'value2')
  869. )
  870. ));
  871. $expected = array(
  872. 'form' => array(
  873. 'id' => 'ContactAddForm',
  874. 'method' => 'post',
  875. 'action' => '/controller/action?param1=value1&amp;param2=value2',
  876. 'accept-charset' => $encoding
  877. ),
  878. 'div' => array('style' => 'display:none;'),
  879. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  880. '/div'
  881. );
  882. $this->assertTags($result, $expected);
  883. $result = $this->Form->create('Contact', array(
  884. 'type' => 'post',
  885. 'url' => array(
  886. 'controller' => 'controller',
  887. 'action' => 'action',
  888. '?' => array('param1' => 'value1', 'param2' => 'value2')
  889. )
  890. ));
  891. $expected = array(
  892. 'form' => array(
  893. 'id' => 'ContactAddForm',
  894. 'method' => 'post',
  895. 'action' => '/controller/action?param1=value1&amp;param2=value2',
  896. 'accept-charset' => $encoding
  897. ),
  898. 'div' => array('style' => 'display:none;'),
  899. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  900. '/div'
  901. );
  902. $this->assertTags($result, $expected);
  903. }
  904. /**
  905. * test that create() doesn't cause errors by multiple id's being in the primary key
  906. * as could happen with multiple select or checkboxes.
  907. *
  908. * @return void
  909. */
  910. public function testCreateWithMultipleIdInData() {
  911. $this->markTestIncomplete('Need to revisit once models work again.');
  912. $encoding = strtolower(Configure::read('App.encoding'));
  913. $this->Form->request->data['Contact']['id'] = array(1, 2);
  914. $result = $this->Form->create('Contact');
  915. $expected = array(
  916. 'form' => array(
  917. 'id' => 'ContactAddForm',
  918. 'method' => 'post',
  919. 'action' => '/contacts/add',
  920. 'accept-charset' => $encoding
  921. ),
  922. 'div' => array('style' => 'display:none;'),
  923. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  924. '/div'
  925. );
  926. $this->assertTags($result, $expected);
  927. }
  928. /**
  929. * test that create() doesn't add in extra passed params.
  930. *
  931. * @return void
  932. */
  933. public function testCreatePassedArgs() {
  934. $this->markTestIncomplete('Need to revisit once models work again.');
  935. $encoding = strtolower(Configure::read('App.encoding'));
  936. $this->Form->request->data['Contact']['id'] = 1;
  937. $result = $this->Form->create('Contact', array(
  938. 'type' => 'post',
  939. 'escape' => false,
  940. 'url' => array(
  941. 'action' => 'edit',
  942. 'myparam'
  943. )
  944. ));
  945. $expected = array(
  946. 'form' => array(
  947. 'id' => 'ContactAddForm',
  948. 'method' => 'post',
  949. 'action' => '/contacts/edit/myparam',
  950. 'accept-charset' => $encoding
  951. ),
  952. 'div' => array('style' => 'display:none;'),
  953. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  954. '/div'
  955. );
  956. $this->assertTags($result, $expected);
  957. }
  958. /**
  959. * test creating a get form, and get form inputs.
  960. *
  961. * @return void
  962. */
  963. public function testGetFormCreate() {
  964. $this->markTestIncomplete('Need to revisit once models work again.');
  965. $encoding = strtolower(Configure::read('App.encoding'));
  966. $result = $this->Form->create('Contact', array('type' => 'get'));
  967. $this->assertTags($result, array('form' => array(
  968. 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
  969. 'accept-charset' => $encoding
  970. )));
  971. $result = $this->Form->text('Contact.name');
  972. $this->assertTags($result, array('input' => array(
  973. 'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
  974. )));
  975. $result = $this->Form->password('password');
  976. $this->assertTags($result, array('input' => array(
  977. 'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
  978. )));
  979. $this->assertNotRegExp('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
  980. $result = $this->Form->text('user_form');
  981. $this->assertTags($result, array('input' => array(
  982. 'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
  983. )));
  984. }
  985. /**
  986. * test get form, and inputs when the model param is false
  987. *
  988. * @return void
  989. */
  990. public function testGetFormWithFalseModel() {
  991. $this->markTestIncomplete('Need to revisit once models work again.');
  992. $encoding = strtolower(Configure::read('App.encoding'));
  993. $this->Form->request['controller'] = 'contact_test';
  994. $result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
  995. $expected = array('form' => array(
  996. 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
  997. 'accept-charset' => $encoding
  998. ));
  999. $this->assertTags($result, $expected);
  1000. $result = $this->Form->text('reason');
  1001. $expected = array(
  1002. 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
  1003. );
  1004. $this->assertTags($result, $expected);
  1005. }
  1006. /**
  1007. * testFormCreateWithSecurity method
  1008. *
  1009. * Test form->create() with security key.
  1010. *
  1011. * @return void
  1012. */
  1013. public function testCreateWithSecurity() {
  1014. $this->Form->request->params['_csrfToken'] = 'testKey';
  1015. $encoding = strtolower(Configure::read('App.encoding'));
  1016. $result = $this->Form->create($this->article, [
  1017. 'url' => '/articles/publish',
  1018. ]);
  1019. $expected = array(
  1020. 'form' => array('method' => 'post', 'action' => '/articles/publish', 'accept-charset' => $encoding),
  1021. 'div' => array('style' => 'display:none;'),
  1022. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  1023. array('input' => array(
  1024. 'type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testKey'
  1025. )),
  1026. '/div'
  1027. );
  1028. $this->assertTags($result, $expected);
  1029. $result = $this->Form->create($this->article, ['url' => '/articles/publish', 'id' => 'MyForm']);
  1030. $expected['form']['id'] = 'MyForm';
  1031. $this->assertTags($result, $expected);
  1032. }
  1033. /**
  1034. * testFormCreateGetNoSecurity method
  1035. *
  1036. * Test form->create() with no security key as its a get form
  1037. *
  1038. * @return void
  1039. */
  1040. public function testCreateEndGetNoSecurity() {
  1041. $this->Form->request->params['_csrfToken'] = 'testKey';
  1042. $encoding = strtolower(Configure::read('App.encoding'));
  1043. $article = new Article();
  1044. $result = $this->Form->create($article, [
  1045. 'type' => 'get',
  1046. 'url' => '/contacts/add'
  1047. ]);
  1048. $this->assertNotContains('testKey', $result);
  1049. $result = $this->Form->end('Save');
  1050. $this->assertNotContains('testKey', $result);
  1051. }
  1052. /**
  1053. * test that create() clears the fields property so it starts fresh
  1054. *
  1055. * @return void
  1056. */
  1057. public function testCreateClearingFields() {
  1058. $this->Form->fields = array('model_id');
  1059. $this->Form->create($this->article);
  1060. $this->assertEquals(array(), $this->Form->fields);
  1061. }
  1062. /**
  1063. * Tests form hash generation with model-less data
  1064. *
  1065. * @return void
  1066. */
  1067. public function testValidateHashNoModel() {
  1068. $this->markTestIncomplete('Need to revisit once models work again.');
  1069. $this->Form->request->params['_csrfToken'] = 'foo';
  1070. $result = $this->Form->secure(array('anything'));
  1071. $this->assertRegExp('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
  1072. }
  1073. /**
  1074. * Tests that models with identical field names get resolved properly
  1075. *
  1076. * @return void
  1077. */
  1078. public function testDuplicateFieldNameResolution() {
  1079. $this->markTestIncomplete('Need to revisit once models work again.');
  1080. $result = $this->Form->create('ValidateUser');
  1081. $this->assertEquals(array('ValidateUser'), $this->Form->entity());
  1082. $result = $this->Form->input('ValidateItem.name');
  1083. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1084. $result = $this->Form->input('ValidateUser.name');
  1085. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1086. $this->assertContains('name="ValidateUser[name]"', $result);
  1087. $this->assertContains('type="text"', $result);
  1088. $result = $this->Form->input('ValidateItem.name');
  1089. $this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
  1090. $this->assertContains('name="ValidateItem[name]"', $result);
  1091. $this->assertContains('<textarea', $result);
  1092. $result = $this->Form->input('name');
  1093. $this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
  1094. $this->assertContains('name="ValidateUser[name]"', $result);
  1095. $this->assertContains('type="text"', $result);
  1096. }
  1097. /**
  1098. * Tests that hidden fields generated for checkboxes don't get locked
  1099. *
  1100. * @return void
  1101. */
  1102. public function testNoCheckboxLocking() {
  1103. $this->Form->request->params['_Token'] = 'foo';
  1104. $this->assertSame([], $this->Form->fields);
  1105. $this->Form->checkbox('check', array('value' => '1'));
  1106. $this->assertSame($this->Form->fields, array('check'));
  1107. }
  1108. /**
  1109. * testFormSecurityFields method
  1110. *
  1111. * Test generation of secure form hash generation.
  1112. *
  1113. * @return void
  1114. */
  1115. public function testFormSecurityFields() {
  1116. $this->markTestIncomplete('Need to revisit once models work again.');
  1117. $key = 'testKey';
  1118. $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
  1119. $this->Form->request->params['_csrfToken'] = $key;
  1120. $result = $this->Form->secure($fields);
  1121. $hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
  1122. $hash .= ':' . 'Model.valid';
  1123. $hash = urlencode($hash);
  1124. $expected = array(
  1125. 'div' => array('style' => 'display:none;'),
  1126. array('input' => array(
  1127. 'type' => 'hidden', 'name' => '_Token[fields]',
  1128. 'value' => $hash
  1129. )),
  1130. array('input' => array(
  1131. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1132. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1133. )),
  1134. '/div'
  1135. );
  1136. $this->assertTags($result, $expected);
  1137. $path = CAKE . 'Test/TestApp/Config/';
  1138. $this->Form->Html->loadConfig('htmlhelper_tags', $path);
  1139. $result = $this->Form->secure($fields);
  1140. $expected = array(
  1141. 'div' => array('class' => 'hidden'),
  1142. array('input' => array(
  1143. 'type' => 'hidden', 'name' => '_Token[fields]',
  1144. 'value' => $hash
  1145. )),
  1146. array('input' => array(
  1147. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1148. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1149. )),
  1150. '/div'
  1151. );
  1152. $this->assertTags($result, $expected);
  1153. }
  1154. /**
  1155. * Tests correct generation of number fields for double and float fields
  1156. *
  1157. * @return void
  1158. */
  1159. public function testTextFieldGenerationForFloats() {
  1160. $this->markTestIncomplete('Need to revisit once models work again.');
  1161. $this->article['schema'] = [
  1162. 'foo' => [
  1163. 'type' => 'float',
  1164. 'null' => false,
  1165. 'default' => null,
  1166. 'length' => 10
  1167. ]
  1168. ];
  1169. $this->Form->create('Contact');
  1170. $result = $this->Form->input('foo');
  1171. $expected = array(
  1172. 'div' => array('class' => 'input number'),
  1173. 'label' => array('for' => 'ContactFoo'),
  1174. 'Foo',
  1175. '/label',
  1176. array('input' => array(
  1177. 'type' => 'number',
  1178. 'name' => 'Contact[foo]',
  1179. 'id' => 'ContactFoo',
  1180. 'step' => 'any'
  1181. )),
  1182. '/div'
  1183. );
  1184. $this->assertTags($result, $expected);
  1185. $result = $this->Form->input('foo', array('step' => 0.5));
  1186. $expected = array(
  1187. 'div' => array('class' => 'input number'),
  1188. 'label' => array('for' => 'ContactFoo'),
  1189. 'Foo',
  1190. '/label',
  1191. array('input' => array(
  1192. 'type' => 'number',
  1193. 'name' => 'Contact[foo]',
  1194. 'id' => 'ContactFoo',
  1195. 'step' => '0.5'
  1196. )),
  1197. '/div'
  1198. );
  1199. $this->assertTags($result, $expected);
  1200. }
  1201. /**
  1202. * Tests correct generation of number fields for integer fields
  1203. *
  1204. * @return void
  1205. */
  1206. public function testTextFieldTypeNumberGenerationForIntegers() {
  1207. $this->markTestIncomplete('Need to revisit once models work again.');
  1208. $model->setSchema(array('foo' => array(
  1209. 'type' => 'integer',
  1210. 'null' => false,
  1211. 'default' => null,
  1212. 'length' => null
  1213. )));
  1214. $this->Form->create('Contact');
  1215. $result = $this->Form->input('foo');
  1216. $expected = array(
  1217. 'div' => array('class' => 'input number'),
  1218. 'label' => array('for' => 'ContactFoo'),
  1219. 'Foo',
  1220. '/label',
  1221. array('input' => array(
  1222. 'type' => 'number', 'name' => 'Contact[foo]',
  1223. 'id' => 'ContactFoo'
  1224. )),
  1225. '/div'
  1226. );
  1227. $this->assertTags($result, $expected);
  1228. }
  1229. /**
  1230. * Tests correct generation of file upload fields for binary fields
  1231. *
  1232. * @return void
  1233. */
  1234. public function testFileUploadFieldTypeGenerationForBinaries() {
  1235. $this->markTestIncomplete('Need to revisit once models work again.');
  1236. $model->setSchema(array('foo' => array(
  1237. 'type' => 'binary',
  1238. 'null' => false,
  1239. 'default' => null,
  1240. 'length' => 1024
  1241. )));
  1242. $this->Form->create('Contact');
  1243. $result = $this->Form->input('foo');
  1244. $expected = array(
  1245. 'div' => array('class' => 'input file'),
  1246. 'label' => array('for' => 'ContactFoo'),
  1247. 'Foo',
  1248. '/label',
  1249. array('input' => array(
  1250. 'type' => 'file', 'name' => 'data[Contact][foo]',
  1251. 'id' => 'ContactFoo'
  1252. )),
  1253. '/div'
  1254. );
  1255. $this->assertTags($result, $expected);
  1256. }
  1257. /**
  1258. * testFormSecurityMultipleFields method
  1259. *
  1260. * Test secure() with multiple row form. Ensure hash is correct.
  1261. *
  1262. * @return void
  1263. */
  1264. public function testFormSecurityMultipleFields() {
  1265. $this->markTestIncomplete('Need to revisit once models work again.');
  1266. $key = 'testKey';
  1267. $fields = array(
  1268. 'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
  1269. 'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
  1270. 'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
  1271. );
  1272. $this->Form->request->params['_csrfToken'] = $key;
  1273. $result = $this->Form->secure($fields);
  1274. $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
  1275. $hash .= '%7CModel.1.hidden%7CModel.1.valid';
  1276. $expected = array(
  1277. 'div' => array('style' => 'display:none;'),
  1278. array('input' => array(
  1279. 'type' => 'hidden', 'name' => '_Token[fields]',
  1280. 'value' => $hash
  1281. )),
  1282. array('input' => array(
  1283. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1284. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1285. )),
  1286. '/div'
  1287. );
  1288. $this->assertTags($result, $expected);
  1289. }
  1290. /**
  1291. * testFormSecurityMultipleSubmitButtons
  1292. *
  1293. * test form submit generation and ensure that _Token is only created on end()
  1294. *
  1295. * @return void
  1296. */
  1297. public function testFormSecurityMultipleSubmitButtons() {
  1298. $this->markTestIncomplete('Need to revisit once models work again.');
  1299. $key = 'testKey';
  1300. $this->Form->request->params['_csrfToken'] = $key;
  1301. $this->Form->create('Addresses');
  1302. $this->Form->input('Address.title');
  1303. $this->Form->input('Address.first_name');
  1304. $result = $this->Form->submit('Save', array('name' => 'save'));
  1305. $expected = array(
  1306. 'div' => array('class' => 'submit'),
  1307. 'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
  1308. '/div',
  1309. );
  1310. $this->assertTags($result, $expected);
  1311. $result = $this->Form->submit('Cancel', array('name' => 'cancel'));
  1312. $expected = array(
  1313. 'div' => array('class' => 'submit'),
  1314. 'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
  1315. '/div',
  1316. );
  1317. $this->assertTags($result, $expected);
  1318. $result = $this->Form->end(null);
  1319. $expected = array(
  1320. 'div' => array('style' => 'display:none;'),
  1321. array('input' => array(
  1322. 'type' => 'hidden', 'name' => '_Token[fields]',
  1323. 'value' => 'preg:/.+/'
  1324. )),
  1325. array('input' => array(
  1326. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1327. 'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
  1328. )),
  1329. '/div'
  1330. );
  1331. $this->assertTags($result, $expected);
  1332. }
  1333. /**
  1334. * Test that buttons created with foo[bar] name attributes are unlocked correctly.
  1335. *
  1336. * @return void
  1337. */
  1338. public function testSecurityButtonNestedNamed() {
  1339. $this->markTestIncomplete('Need to revisit once models work again.');
  1340. $key = 'testKey';
  1341. $this->Form->request->params['_csrfToken'] = $key;
  1342. $this->Form->create('Addresses');
  1343. $this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1344. $result = $this->Form->unlockField();
  1345. $this->assertEquals(array('Address.button'), $result);
  1346. }
  1347. /**
  1348. * Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
  1349. *
  1350. * @return void
  1351. */
  1352. public function testSecuritySubmitNestedNamed() {
  1353. $this->markTestIncomplete('Need to revisit once models work again.');
  1354. $key = 'testKey';
  1355. $this->Form->request->params['_csrfToken'] = $key;
  1356. $this->Form->create('Addresses');
  1357. $this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
  1358. $result = $this->Form->unlockField();
  1359. $this->assertEquals(array('Address.button'), $result);
  1360. }
  1361. /**
  1362. * Test that the correct fields are unlocked for image submits with no names.
  1363. *
  1364. * @return void
  1365. */
  1366. public function testSecuritySubmitImageNoName() {
  1367. $this->markTestIncomplete('Need to revisit once models work again.');
  1368. $key = 'testKey';
  1369. $this->Form->request->params['_csrfToken'] = $key;
  1370. $this->Form->create('User');
  1371. $result = $this->Form->submit('save.png');
  1372. $expected = array(
  1373. 'div' => array('class' => 'submit'),
  1374. 'input' => array('type' => 'image', 'src' => 'img/save.png'),
  1375. '/div'
  1376. );
  1377. $this->assertTags($result, $expected);
  1378. $this->assertEquals(array('x', 'y'), $this->Form->unlockField());
  1379. }
  1380. /**
  1381. * Test that the correct fields are unlocked for image submits with names.
  1382. *
  1383. * @return void
  1384. */
  1385. public function testSecuritySubmitImageName() {
  1386. $this->markTestIncomplete('Need to revisit once models work again.');
  1387. $key = 'testKey';
  1388. $this->Form->request->params['_csrfToken'] = $key;
  1389. $this->Form->create('User');
  1390. $result = $this->Form->submit('save.png', array('name' => 'test'));
  1391. $expected = array(
  1392. 'div' => array('class' => 'submit'),
  1393. 'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
  1394. '/div'
  1395. );
  1396. $this->assertTags($result, $expected);
  1397. $this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
  1398. }
  1399. /**
  1400. * testFormSecurityMultipleInputFields method
  1401. *
  1402. * Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
  1403. *
  1404. * @return void
  1405. */
  1406. public function testFormSecurityMultipleInputFields() {
  1407. $this->markTestIncomplete('Need to revisit once models work again.');
  1408. $key = 'testKey';
  1409. $this->Form->request->params['_csrfToken'] = $key;
  1410. $this->Form->create('Addresses');
  1411. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1412. $this->Form->input('Addresses.0.title');
  1413. $this->Form->input('Addresses.0.first_name');
  1414. $this->Form->input('Addresses.0.last_name');
  1415. $this->Form->input('Addresses.0.address');
  1416. $this->Form->input('Addresses.0.city');
  1417. $this->Form->input('Addresses.0.phone');
  1418. $this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
  1419. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1420. $this->Form->input('Addresses.1.title');
  1421. $this->Form->input('Addresses.1.first_name');
  1422. $this->Form->input('Addresses.1.last_name');
  1423. $this->Form->input('Addresses.1.address');
  1424. $this->Form->input('Addresses.1.city');
  1425. $this->Form->input('Addresses.1.phone');
  1426. $this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
  1427. $result = $this->Form->secure($this->Form->fields);
  1428. $hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
  1429. $expected = array(
  1430. 'div' => array('style' => 'display:none;'),
  1431. array('input' => array(
  1432. 'type' => 'hidden', 'name' => '_Token[fields]',
  1433. 'value' => $hash
  1434. )),
  1435. array('input' => array(
  1436. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1437. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1438. )),
  1439. '/div'
  1440. );
  1441. $this->assertTags($result, $expected);
  1442. }
  1443. /**
  1444. * Test form security with Model.field.0 style inputs
  1445. *
  1446. * @return void
  1447. */
  1448. public function testFormSecurityArrayFields() {
  1449. $this->markTestIncomplete('Need to revisit once models work again.');
  1450. $key = 'testKey';
  1451. $this->Form->request->params['_csrfToken'] = $key;
  1452. $this->Form->create('Address');
  1453. $this->Form->input('Address.primary.1');
  1454. $this->assertEquals('Address.primary', $this->Form->fields[0]);
  1455. $this->Form->input('Address.secondary.1.0');
  1456. $this->assertEquals('Address.secondary', $this->Form->fields[1]);
  1457. }
  1458. /**
  1459. * testFormSecurityMultipleInputDisabledFields method
  1460. *
  1461. * test secure form generation with multiple records and disabled fields.
  1462. *
  1463. * @return void
  1464. */
  1465. public function testFormSecurityMultipleInputDisabledFields() {
  1466. $this->markTestIncomplete('Need to revisit once models work again.');
  1467. $key = 'testKey';
  1468. $this->Form->request->params['_csrfToken'] = $key;
  1469. $this->Form->request->params['_Token'] = array(
  1470. 'unlockedFields' => array('first_name', 'address')
  1471. );
  1472. $this->Form->create();
  1473. $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
  1474. $this->Form->input('Addresses.0.title');
  1475. $this->Form->input('Addresses.0.first_name');
  1476. $this->Form->input('Addresses.0.last_name');
  1477. $this->Form->input('Addresses.0.address');
  1478. $this->Form->input('Addresses.0.city');
  1479. $this->Form->input('Addresses.0.phone');
  1480. $this->Form->hidden('Addresses.1.id', array('value' => '654321'));
  1481. $this->Form->input('Addresses.1.title');
  1482. $this->Form->input('Addresses.1.first_name');
  1483. $this->Form->input('Addresses.1.last_name');
  1484. $this->Form->input('Addresses.1.address');
  1485. $this->Form->input('Addresses.1.city');
  1486. $this->Form->input('Addresses.1.phone');
  1487. $result = $this->Form->secure($this->Form->fields);
  1488. $hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';
  1489. $expected = array(
  1490. 'div' => array('style' => 'display:none;'),
  1491. array('input' => array(
  1492. 'type' => 'hidden', 'name' => '_Token[fields]',
  1493. 'value' => $hash
  1494. )),
  1495. array('input' => array(
  1496. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1497. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1498. )),
  1499. '/div'
  1500. );
  1501. $this->assertTags($result, $expected);
  1502. }
  1503. /**
  1504. * testFormSecurityInputDisabledFields method
  1505. *
  1506. * Test single record form with disabled fields.
  1507. *
  1508. * @return void
  1509. */
  1510. public function testFormSecurityInputUnlockedFields() {
  1511. $this->markTestIncomplete('Need to revisit once models work again.');
  1512. $key = 'testKey';
  1513. $this->Form->request->params['_csrfToken'] = $key;
  1514. $this->Form->request['_Token'] = array(
  1515. 'unlockedFields' => array('first_name', 'address')
  1516. );
  1517. $this->Form->create();
  1518. $this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
  1519. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1520. $this->Form->input('Addresses.title');
  1521. $this->Form->input('Addresses.first_name');
  1522. $this->Form->input('Addresses.last_name');
  1523. $this->Form->input('Addresses.address');
  1524. $this->Form->input('Addresses.city');
  1525. $this->Form->input('Addresses.phone');
  1526. $result = $this->Form->fields;
  1527. $expected = array(
  1528. 'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
  1529. 'Addresses.city', 'Addresses.phone'
  1530. );
  1531. $this->assertEquals($expected, $result);
  1532. $result = $this->Form->secure($expected);
  1533. $hash = '2981c38990f3f6ba935e6561dc77277966fabd6d%3AAddresses.id';
  1534. $expected = array(
  1535. 'div' => array('style' => 'display:none;'),
  1536. array('input' => array(
  1537. 'type' => 'hidden', 'name' => '_Token[fields]',
  1538. 'value' => $hash
  1539. )),
  1540. array('input' => array(
  1541. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1542. 'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
  1543. )),
  1544. '/div'
  1545. );
  1546. $this->assertTags($result, $expected);
  1547. }
  1548. /**
  1549. * test securing inputs with custom name attributes.
  1550. *
  1551. * @return void
  1552. */
  1553. public function testFormSecureWithCustomNameAttribute() {
  1554. $this->markTestIncomplete('Need to revisit once models work again.');
  1555. $this->Form->request->params['_csrfToken'] = 'testKey';
  1556. $this->Form->text('UserForm.published', array('name' => 'User[custom]'));
  1557. $this->assertEquals('User.custom', $this->Form->fields[0]);
  1558. $this->Form->text('UserForm.published', array('name' => 'User[custom][another][value]'));
  1559. $this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
  1560. }
  1561. /**
  1562. * testFormSecuredInput method
  1563. *
  1564. * Test generation of entire secure form, assertions made on input() output.
  1565. *
  1566. * @return void
  1567. */
  1568. public function testFormSecuredInput() {
  1569. $this->markTestIncomplete('Need to revisit once models work again.');
  1570. $this->Form->request->params['_csrfToken'] = 'testKey';
  1571. $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
  1572. $encoding = strtolower(Configure::read('App.encoding'));
  1573. $expected = array(
  1574. 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
  1575. 'div' => array('style' => 'display:none;'),
  1576. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  1577. array('input' => array(
  1578. 'type' => 'hidden', 'name' => '_csrfToken',
  1579. 'value' => 'testKey', 'id' => 'preg:/Token\d+/'
  1580. )),
  1581. '/div'
  1582. );
  1583. $this->assertTags($result, $expected);
  1584. $result = $this->Form->input('ValidateUser.ratio');
  1585. $expected = array(
  1586. 'div' => array('class'),
  1587. 'label' => array('for'),
  1588. 'Ratio',
  1589. '/label',
  1590. 'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'),
  1591. '/div',
  1592. );
  1593. $this->assertTags($result, $expected);
  1594. $result = $this->Form->input('ValidateUser.population');
  1595. $expected = array(
  1596. 'div' => array('class'),
  1597. 'label' => array('for'),
  1598. 'Population',
  1599. '/label',
  1600. 'input' => array('name', 'type' => 'number', 'step' => '1', 'id'),
  1601. '/div',
  1602. );
  1603. $this->assertTags($result, $expected);
  1604. $result = $this->Form->input('UserForm.published', array('type' => 'text'));
  1605. $expected = array(
  1606. 'div' => array('class' => 'input text'),
  1607. 'label' => array('for' => 'UserFormPublished'),
  1608. 'Published',
  1609. '/label',
  1610. array('input' => array(
  1611. 'type' => 'text', 'name' => 'UserForm[published]',
  1612. 'id' => 'UserFormPublished'
  1613. )),
  1614. '/div'
  1615. );
  1616. $this->assertTags($result, $expected);
  1617. $result = $this->Form->input('UserForm.other', array('type' => 'text'));
  1618. $expected = array(
  1619. 'div' => array('class' => 'input text'),
  1620. 'label' => array('for' => 'UserFormOther'),
  1621. 'Other',
  1622. '/label',
  1623. array('input' => array(
  1624. 'type' => 'text', 'name' => 'UserForm[other]',
  1625. 'id' => 'UserFormOther'
  1626. )),
  1627. '/div'
  1628. );
  1629. $this->assertTags($result, $expected);
  1630. $result = $this->Form->hidden('UserForm.stuff');
  1631. $expected = array(
  1632. 'input' => array(
  1633. 'type' => 'hidden', 'name' => 'UserForm[stuff]',
  1634. 'id' => 'UserFormStuff'
  1635. ));
  1636. $this->assertTags($result, $expected);
  1637. $result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
  1638. $expected = array('input' => array(
  1639. 'type' => 'hidden', 'name' => 'UserForm[hidden]',
  1640. 'value' => '0', 'id' => 'UserFormHidden'
  1641. ));
  1642. $this->assertTags($result, $expected);
  1643. $result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
  1644. $expected = array(
  1645. 'div' => array('class' => 'input checkbox'),
  1646. array('input' => array(
  1647. 'type' => 'hidden', 'name' => 'UserForm[something]',
  1648. 'value' => '0', 'id' => 'UserFormSomething_'
  1649. )),
  1650. array('input' => array(
  1651. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  1652. 'value' => '1', 'id' => 'UserFormSomething'
  1653. )),
  1654. 'label' => array('for' => 'UserFormSomething'),
  1655. 'Something',
  1656. '/label',
  1657. '/div'
  1658. );
  1659. $this->assertTags($result, $expected);
  1660. $result = $this->Form->fields;
  1661. $expected = array(
  1662. 'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
  1663. 'UserForm.hidden' => '0', 'UserForm.something'
  1664. );
  1665. $this->assertEquals($expected, $result);
  1666. $hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
  1667. $result = $this->Form->secure($this->Form->fields);
  1668. $expected = array(
  1669. 'div' => array('style' => 'display:none;'),
  1670. array('input' => array(
  1671. 'type' => 'hidden', 'name' => '_Token[fields]',
  1672. 'value' => $hash
  1673. )),
  1674. array('input' => array(
  1675. 'type' => 'hidden', 'name' => '_Token[unlocked]',
  1676. 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  1677. )),
  1678. '/div'
  1679. );
  1680. $this->assertTags($result, $expected);
  1681. }
  1682. /**
  1683. * Test secured inputs with custom names.
  1684. *
  1685. * @return void
  1686. */
  1687. public function testSecuredInputCustomName() {
  1688. $this->markTestIncomplete('Need to revisit once models work again.');
  1689. $this->Form->request->params['_csrfToken'] = 'testKey';
  1690. $this->assertEquals(array(), $this->Form->fields);
  1691. $this->Form->input('text_input', array(
  1692. 'name' => 'data[Option][General.default_role]',
  1693. ));
  1694. $expected = array('Option.General.default_role');
  1695. $this->assertEquals($expected, $this->Form->fields);
  1696. $this->Form->input('select_box', array(
  1697. 'name' => 'data[Option][General.select_role]',
  1698. 'type' => 'select',
  1699. 'options' => array(1, 2),
  1700. ));
  1701. $expected = array('Option.General.default_role', 'Option.General.select_role');
  1702. $this->assertEquals($expected, $this->Form->fields);
  1703. }
  1704. /**
  1705. * Tests that the correct keys are added to the field hash index
  1706. *
  1707. * @return void
  1708. */
  1709. public function testFormSecuredFileInput() {
  1710. $this->markTestIncomplete('Need to revisit once models work again.');
  1711. $this->Form->request->params['_csrfToken'] = 'testKey';
  1712. $this->assertEquals(array(), $this->Form->fields);
  1713. $this->Form->file('Attachment.file');
  1714. $expected = array(
  1715. 'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
  1716. 'Attachment.file.error', 'Attachment.file.size'
  1717. );
  1718. $this->assertEquals($expected, $this->Form->fields);
  1719. }
  1720. /**
  1721. * test that multiple selects keys are added to field hash
  1722. *
  1723. * @return void
  1724. */
  1725. public function testFormSecuredMultipleSelect() {
  1726. $this->markTestIncomplete('Need to revisit once models work again.');
  1727. $this->Form->request->params['_csrfToken'] = 'testKey';
  1728. $this->assertEquals(array(), $this->Form->fields);
  1729. $options = array('1' => 'one', '2' => 'two');
  1730. $this->Form->select('Model.select', $options);
  1731. $expected = array('Model.select');
  1732. $this->assertEquals($expected, $this->Form->fields);
  1733. $this->Form->fields = array();
  1734. $this->Form->select('Model.select', $options, array('multiple' => true));
  1735. $this->assertEquals($expected, $this->Form->fields);
  1736. }
  1737. /**
  1738. * testFormSecuredRadio method
  1739. *
  1740. * @return void
  1741. */
  1742. public function testFormSecuredRadio() {
  1743. $this->markTestIncomplete('Need to revisit once models work again.');
  1744. $this->Form->request->params['_csrfToken'] = 'testKey';
  1745. $this->assertEquals(array(), $this->Form->fields);
  1746. $options = array('1' => 'option1', '2' => 'option2');
  1747. $this->Form->radio('Test.test', $options);
  1748. $expected = array('Test.test');
  1749. $this->assertEquals($expected, $this->Form->fields);
  1750. }
  1751. /**
  1752. * Test that when disabled is in a list based attribute array it works.
  1753. *
  1754. * @return void
  1755. */
  1756. public function testFormSecuredAndDisabledNotAssoc() {
  1757. $this->markTestIncomplete('Need to revisit once models work again.');
  1758. $this->Form->request->params['_csrfToken'] = 'testKey';
  1759. $this->Form->select('Model.select', array(1, 2), array('disabled'));
  1760. $this->Form->checkbox('Model.checkbox', array('disabled'));
  1761. $this->Form->text('Model.text', array('disabled'));
  1762. $this->Form->textarea('Model.textarea', array('disabled'));
  1763. $this->Form->password('Model.password', array('disabled'));
  1764. $this->Form->radio('Model.radio', array(1, 2), array('disabled'));
  1765. $expected = array(
  1766. 'Model.radio' => ''
  1767. );
  1768. $this->assertEquals($expected, $this->Form->fields);
  1769. }
  1770. /**
  1771. * test that forms with disabled inputs + secured forms leave off the inputs from the form
  1772. * hashing.
  1773. *
  1774. * @return void
  1775. */
  1776. public function testFormSecuredAndDisabled() {
  1777. $this->markTestIncomplete('Need to revisit once models work again.');
  1778. $this->Form->request->params['_csrfToken'] = 'testKey';
  1779. $this->Form->checkbox('Model.checkbox', array('disabled' => true));
  1780. $this->Form->text('Model.text', array('disabled' => true));
  1781. $this->Form->password('Model.text', array('disabled' => true));
  1782. $this->Form->textarea('Model.textarea', array('disabled' => true));
  1783. $this->Form->select('Model.select', array(1, 2), array('disabled' => true));
  1784. $this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
  1785. $this->Form->year('Model.year', null, null, array('disabled' => true));
  1786. $this->Form->month('Model.month', array('disabled' => true));
  1787. $this->Form->day('Model.day', array('disabled' => true));
  1788. $this->Form->hour('Model.hour', false, array('disabled' => true));
  1789. $this->Form->minute('Model.minute', array('disabled' => true));
  1790. $this->Form->meridian('Model.meridian', array('disabled' => true));
  1791. $expected = array(
  1792. 'Model.radio' => ''
  1793. );
  1794. $this->assertEquals($expected, $this->Form->fields);
  1795. }
  1796. /**
  1797. * testDisableSecurityUsingForm method
  1798. *
  1799. * @return void
  1800. */
  1801. public function testDisableSecurityUsingForm() {
  1802. $this->markTestIncomplete('Need to revisit once models work again.');
  1803. $this->Form->request->params['_csrfToken'] = 'testKey';
  1804. $this->Form->request['_Token'] = array(
  1805. 'disabledFields' => array()
  1806. );
  1807. $this->Form->create();
  1808. $this->Form->hidden('Addresses.id', array('value' => '123456'));
  1809. $this->Form->input('Addresses.title');
  1810. $this->Form->input('Addresses.first_name', array('secure' => false));
  1811. $this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
  1812. $this->Form->input('Addresses.zip', array(
  1813. 'type' => 'select', 'options' => array(1, 2), 'secure' => false
  1814. ));
  1815. $result = $this->Form->fields;
  1816. $expected = array(
  1817. 'Addresses.id' => '123456', 'Addresses.title',
  1818. );
  1819. $this->assertEquals($expected, $result);
  1820. }
  1821. /**
  1822. * test disableField
  1823. *
  1824. * @return void
  1825. */
  1826. public function testUnlockFieldAddsToList() {
  1827. $this->markTestIncomplete('Need to revisit once models work again.');
  1828. $this->Form->request->params['_csrfToken'] = 'testKey';
  1829. $this->Form->request['_Token'] = array(
  1830. 'unlockedFields' => array()
  1831. );
  1832. $this->Form->create('Contact');
  1833. $this->Form->unlockField('Contact.name');
  1834. $this->Form->text('Contact.name');
  1835. $this->assertEquals(array('Contact.name'), $this->Form->unlockField());
  1836. $this->assertEquals(array(), $this->Form->fields);
  1837. }
  1838. /**
  1839. * test unlockField removing from fields array.
  1840. *
  1841. * @return void
  1842. */
  1843. public function testUnlockFieldRemovingFromFields() {
  1844. $this->markTestIncomplete('Need to revisit once models work again.');
  1845. $this->Form->request->params['_csrfToken'] = 'testKey';
  1846. $this->Form->request['_Token'] = array(
  1847. 'unlockedFields' => array()
  1848. );
  1849. $this->Form->create('Contact');
  1850. $this->Form->hidden('Contact.id', array('value' => 1));
  1851. $this->Form->text('Contact.name');
  1852. $this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
  1853. $this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
  1854. $this->Form->unlockField('Contact.name');
  1855. $this->Form->unlockField('Contact.id');
  1856. $this->assertEquals(array(), $this->Form->fields);
  1857. }
  1858. /**
  1859. * testTagIsInvalid method
  1860. *
  1861. * @return void
  1862. */
  1863. public function testTagIsInvalid() {
  1864. $this->markTestIncomplete('Need to revisit once models work again.');
  1865. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1866. $this->Form->setEntity('Contact.0.email');
  1867. $result = $this->Form->tagIsInvalid();
  1868. $this->assertEquals($expected, $result);
  1869. $this->Form->setEntity('Contact.1.email');
  1870. $result = $this->Form->tagIsInvalid();
  1871. $this->assertFalse($result);
  1872. $this->Form->setEntity('Contact.0.name');
  1873. $result = $this->Form->tagIsInvalid();
  1874. $this->assertFalse($result);
  1875. }
  1876. /**
  1877. * Test tagIsInvalid with validation errors from a saveMany
  1878. *
  1879. * @return void
  1880. */
  1881. public function testTagIsInvalidSaveMany() {
  1882. $this->markTestIncomplete('Need to revisit once models work again.');
  1883. $Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
  1884. $this->Form->create('Contact');
  1885. $this->Form->setEntity('0.email');
  1886. $result = $this->Form->tagIsInvalid();
  1887. $this->assertEquals($expected, $result);
  1888. $this->Form->setEntity('0.Contact.email');
  1889. $result = $this->Form->tagIsInvalid();
  1890. $this->assertEquals($expected, $result);
  1891. }
  1892. /**
  1893. * Test validation errors.
  1894. *
  1895. * @return void
  1896. */
  1897. public function testPasswordValidation() {
  1898. $this->markTestIncomplete('Need to revisit once models work again.');
  1899. $Contact->validationErrors['password'] = array('Please provide a password');
  1900. $result = $this->Form->input('Contact.password');
  1901. $expected = array(
  1902. 'div' => array('class' => 'input password error'),
  1903. 'label' => array('for' => 'ContactPassword'),
  1904. 'Password',
  1905. '/label',
  1906. 'input' => array(
  1907. 'type' => 'password', 'name' => 'Contact[password]',
  1908. 'id' => 'ContactPassword', 'class' => 'form-error'
  1909. ),
  1910. array('div' => array('class' => 'error-message')),
  1911. 'Please provide a password',
  1912. '/div',
  1913. '/div'
  1914. );
  1915. $this->assertTags($result, $expected);
  1916. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1917. $expected = array(
  1918. 'div' => array('class' => 'input password error'),
  1919. 'label' => array('for' => 'ContactPassword'),
  1920. 'Password',
  1921. '/label',
  1922. 'input' => array(
  1923. 'type' => 'password', 'name' => 'Contact[password]',
  1924. 'id' => 'ContactPassword', 'class' => 'form-error'
  1925. ),
  1926. '/div'
  1927. );
  1928. $this->assertTags($result, $expected);
  1929. }
  1930. /**
  1931. * Test validation errors, when validation message is an empty string.
  1932. *
  1933. * @return void
  1934. */
  1935. public function testEmptyErrorValidation() {
  1936. $this->markTestIncomplete('Need to revisit once models work again.');
  1937. $this->Form->validationErrors['Contact']['password'] = '';
  1938. $result = $this->Form->input('Contact.password');
  1939. $expected = array(
  1940. 'div' => array('class' => 'input password error'),
  1941. 'label' => array('for' => 'ContactPassword'),
  1942. 'Password',
  1943. '/label',
  1944. 'input' => array(
  1945. 'type' => 'password', 'name' => 'Contact[password]',
  1946. 'id' => 'ContactPassword', 'class' => 'form-error'
  1947. ),
  1948. array('div' => array('class' => 'error-message')),
  1949. array(),
  1950. '/div',
  1951. '/div'
  1952. );
  1953. $this->assertTags($result, $expected);
  1954. $result = $this->Form->input('Contact.password', array('errorMessage' => false));
  1955. $expected = array(
  1956. 'div' => array('class' => 'input password error'),
  1957. 'label' => array('for' => 'ContactPassword'),
  1958. 'Password',
  1959. '/label',
  1960. 'input' => array(
  1961. 'type' => 'password', 'name' => 'Contact[password]',
  1962. 'id' => 'ContactPassword', 'class' => 'form-error'
  1963. ),
  1964. '/div'
  1965. );
  1966. $this->assertTags($result, $expected);
  1967. }
  1968. /**
  1969. * Test validation errors, when calling input() overriding validation message by an empty string.
  1970. *
  1971. * @return void
  1972. */
  1973. public function testEmptyInputErrorValidation() {
  1974. $this->markTestIncomplete('Need to revisit once models work again.');
  1975. $this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
  1976. $result = $this->Form->input('Contact.password', array('error' => ''));
  1977. $expected = array(
  1978. 'div' => array('class' => 'input password error'),
  1979. 'label' => array('for' => 'ContactPassword'),
  1980. 'Password',
  1981. '/label',
  1982. 'input' => array(
  1983. 'type' => 'password', 'name' => 'Contact[password]',
  1984. 'id' => 'ContactPassword', 'class' => 'form-error'
  1985. ),
  1986. array('div' => array('class' => 'error-message')),
  1987. array(),
  1988. '/div',
  1989. '/div'
  1990. );
  1991. $this->assertTags($result, $expected);
  1992. $result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
  1993. $expected = array(
  1994. 'div' => array('class' => 'input password error'),
  1995. 'label' => array('for' => 'ContactPassword'),
  1996. 'Password',
  1997. '/label',
  1998. 'input' => array(
  1999. 'type' => 'password', 'name' => 'Contact[password]',
  2000. 'id' => 'ContactPassword', 'class' => 'form-error'
  2001. ),
  2002. '/div'
  2003. );
  2004. $this->assertTags($result, $expected);
  2005. }
  2006. /**
  2007. * testFormValidationAssociated method
  2008. *
  2009. * test display of form errors in conjunction with model::validates.
  2010. *
  2011. * @return void
  2012. */
  2013. public function testFormValidationAssociated() {
  2014. $this->markTestIncomplete('Need to revisit once models work again.');
  2015. $data = array(
  2016. 'UserForm' => array('name' => 'user'),
  2017. 'OpenidUrl' => array('url' => 'http://www.cakephp.org')
  2018. );
  2019. $result = $this->UserForm->OpenidUrl->create($data);
  2020. $this->assertFalse(empty($result));
  2021. $this->assertFalse($this->UserForm->OpenidUrl->validates());
  2022. $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
  2023. $encoding = strtolower(Configure::read('App.encoding'));
  2024. $expected = array(
  2025. 'form' => array(
  2026. 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
  2027. 'accept-charset' => $encoding
  2028. ),
  2029. 'div' => array('style' => 'display:none;'),
  2030. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2031. '/div'
  2032. );
  2033. $this->assertTags($result, $expected);
  2034. $result = $this->Form->error(
  2035. 'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
  2036. );
  2037. $this->assertEquals('Error, not registered', $result);
  2038. unset($this->UserForm->OpenidUrl, $this->UserForm);
  2039. }
  2040. /**
  2041. * testFormValidationAssociatedFirstLevel method
  2042. *
  2043. * test form error display with associated model.
  2044. *
  2045. * @return void
  2046. */
  2047. public function testFormValidationAssociatedFirstLevel() {
  2048. $this->markTestIncomplete('Need to revisit once models work again.');
  2049. $data = array(
  2050. 'ValidateUser' => array('name' => 'mariano'),
  2051. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
  2052. );
  2053. $result = $this->ValidateUser->create($data);
  2054. $this->assertFalse(empty($result));
  2055. $this->assertFalse($this->ValidateUser->validates());
  2056. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2057. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2058. $encoding = strtolower(Configure::read('App.encoding'));
  2059. $expected = array(
  2060. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2061. 'div' => array('style' => 'display:none;'),
  2062. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2063. '/div'
  2064. );
  2065. $this->assertTags($result, $expected);
  2066. $result = $this->Form->error(
  2067. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2068. );
  2069. $this->assertEquals('Invalid email', $result);
  2070. $result = $this->Form->error(
  2071. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2072. );
  2073. $this->assertEquals('Invalid name', $result);
  2074. $result = $this->Form->error(
  2075. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2076. );
  2077. $this->assertEquals('Invalid city', $result);
  2078. unset($this->ValidateUser->ValidateProfile);
  2079. unset($this->ValidateUser);
  2080. }
  2081. /**
  2082. * testFormValidationAssociatedSecondLevel method
  2083. *
  2084. * test form error display with associated model.
  2085. *
  2086. * @return void
  2087. */
  2088. public function testFormValidationAssociatedSecondLevel() {
  2089. $this->markTestIncomplete('Need to revisit once models work again.');
  2090. $data = array(
  2091. 'ValidateUser' => array('name' => 'mariano'),
  2092. 'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
  2093. 'ValidateItem' => array('name' => 'Item')
  2094. );
  2095. $result = $this->ValidateUser->create($data);
  2096. $this->assertFalse(empty($result));
  2097. $this->assertFalse($this->ValidateUser->validates());
  2098. $this->assertFalse($this->ValidateUser->ValidateProfile->validates());
  2099. $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
  2100. $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
  2101. $encoding = strtolower(Configure::read('App.encoding'));
  2102. $expected = array(
  2103. 'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
  2104. 'div' => array('style' => 'display:none;'),
  2105. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  2106. '/div'
  2107. );
  2108. $this->assertTags($result, $expected);
  2109. $result = $this->Form->error(
  2110. 'ValidateUser.email', 'Invalid email', array('wrap' => false)
  2111. );
  2112. $this->assertEquals('Invalid email', $result);
  2113. $result = $this->Form->error(
  2114. 'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
  2115. );
  2116. $this->assertEquals('Invalid name', $result);
  2117. $result = $this->Form->error(
  2118. 'ValidateProfile.city', 'Invalid city', array('wrap' => false)
  2119. );
  2120. $result = $this->Form->error(
  2121. 'ValidateItem.description', 'Invalid description', array('wrap' => false)
  2122. );
  2123. $this->assertEquals('Invalid description', $result);
  2124. unset($this->ValidateUser->ValidateProfile->ValidateItem);
  2125. unset($this->ValidateUser->ValidateProfile);
  2126. unset($this->ValidateUser);
  2127. }
  2128. /**
  2129. * testFormValidationMultiRecord method
  2130. *
  2131. * test form error display with multiple records.
  2132. *
  2133. * @return void
  2134. */
  2135. public function testFormValidationMultiRecord() {
  2136. $this->markTestIncomplete('Need to revisit once models work again.');
  2137. $Contact->validationErrors[2] = array(
  2138. 'name' => array('The provided value is invalid')
  2139. );
  2140. $result = $this->Form->input('Contact.2.name');
  2141. $expected = array(
  2142. 'div' => array('class' => 'input text error'),
  2143. 'label' => array('for' => 'Contact2Name'),
  2144. 'Name',
  2145. '/label',
  2146. 'input' => array(
  2147. 'type' => 'text', 'name' => 'Contact[2][name]', 'id' => 'Contact2Name',
  2148. 'class' => 'form-error', 'maxlength' => 255
  2149. ),
  2150. array('div' => array('class' => 'error-message')),
  2151. 'The provided value is invalid',
  2152. '/div',
  2153. '/div'
  2154. );
  2155. $this->assertTags($result, $expected);
  2156. }
  2157. /**
  2158. * testMultipleInputValidation method
  2159. *
  2160. * test multiple record form validation error display.
  2161. *
  2162. * @return void
  2163. */
  2164. public function testMultipleInputValidation() {
  2165. $this->markTestIncomplete('Need to revisit once models work again.');
  2166. $Address->validationErrors[0] = array(
  2167. 'title' => array('This field cannot be empty'),
  2168. 'first_name' => array('This field cannot be empty')
  2169. );
  2170. $Address->validationErrors[1] = array(
  2171. 'last_name' => array('You must have a last name')
  2172. );
  2173. $this->Form->create();
  2174. $result = $this->Form->input('Address.0.title');
  2175. $expected = array(
  2176. 'div' => array('class'),
  2177. 'label' => array('for'),
  2178. 'preg:/[^<]+/',
  2179. '/label',
  2180. 'input' => array(
  2181. 'type' => 'text', 'name', 'id', 'class' => 'form-error'
  2182. ),
  2183. array('div' => array('class' => 'error-message')),
  2184. 'This field cannot be empty',
  2185. '/div',
  2186. '/div'
  2187. );
  2188. $this->assertTags($result, $expected);
  2189. $result = $this->Form->input('Address.0.first_name');
  2190. $expected = array(
  2191. 'div' => array('class'),
  2192. 'label' => array('for'),
  2193. 'preg:/[^<]+/',
  2194. '/label',
  2195. 'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
  2196. array('div' => array('class' => 'error-message')),
  2197. 'This field cannot be empty',
  2198. '/div',
  2199. '/div'
  2200. );
  2201. $this->assertTags($result, $expected);
  2202. $result = $this->Form->input('Address.0.last_name');
  2203. $expected = array(
  2204. 'div' => array('class'),
  2205. 'label' => array('for'),
  2206. 'preg:/[^<]+/',
  2207. '/label',
  2208. 'input' => array('type' => 'text', 'name', 'id'),
  2209. '/div'
  2210. );
  2211. $this->assertTags($result, $expected);
  2212. $result = $this->Form->input('Address.1.last_name');
  2213. $expected = array(
  2214. 'div' => array('class'),
  2215. 'label' => array('for'),
  2216. 'preg:/[^<]+/',
  2217. '/label',
  2218. 'input' => array(
  2219. 'type' => 'text', 'name' => 'preg:/[^<]+/',
  2220. 'id' => 'preg:/[^<]+/', 'class' => 'form-error'
  2221. ),
  2222. array('div' => array('class' => 'error-message')),
  2223. 'You must have a last name',
  2224. '/div',
  2225. '/div'
  2226. );
  2227. $this->assertTags($result, $expected);
  2228. }
  2229. /**
  2230. * testInput method
  2231. *
  2232. * Test various incarnations of input().
  2233. *
  2234. * @return void
  2235. */
  2236. public function testInput() {
  2237. $this->markTestIncomplete('Need to revisit once models work again.');
  2238. $result = $this->Form->input('ValidateUser.balance');
  2239. $expected = array(
  2240. 'div' => array('class'),
  2241. 'label' => array('for'),
  2242. 'Balance',
  2243. '/label',
  2244. 'input' => array('name', 'type' => 'number', 'id'),
  2245. '/div',
  2246. );
  2247. $this->assertTags($result, $expected);
  2248. $result = $this->Form->input('ValidateUser.cost_decimal');
  2249. $expected = array(
  2250. 'div' => array('class'),
  2251. 'label' => array('for'),
  2252. 'Cost Decimal',
  2253. '/label',
  2254. 'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
  2255. '/div',
  2256. );
  2257. $this->assertTags($result, $expected);
  2258. $result = $this->Form->input('Contact.email', array('id' => 'custom'));
  2259. $expected = array(
  2260. 'div' => array('class' => 'input email'),
  2261. 'label' => array('for' => 'custom'),
  2262. 'Email',
  2263. '/label',
  2264. array('input' => array(
  2265. 'type' => 'email', 'name' => 'Contact[email]',
  2266. 'id' => 'custom', 'maxlength' => 255
  2267. )),
  2268. '/div'
  2269. );
  2270. $this->assertTags($result, $expected);
  2271. $result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
  2272. $expected = array(
  2273. '<div',
  2274. 'label' => array('for' => 'ContactEmail'),
  2275. 'Email',
  2276. '/label',
  2277. array('input' => array(
  2278. 'type' => 'email', 'name' => 'Contact[email]',
  2279. 'id' => 'ContactEmail', 'maxlength' => 255
  2280. )),
  2281. '/div'
  2282. );
  2283. $this->assertTags($result, $expected);
  2284. $result = $this->Form->hidden('Contact.idontexist');
  2285. $expected = array('input' => array(
  2286. 'type' => 'hidden', 'name' => 'Contact[idontexist]',
  2287. 'id' => 'ContactIdontexist'
  2288. ));
  2289. $this->assertTags($result, $expected);
  2290. $result = $this->Form->input('Contact.email', array('type' => 'text'));
  2291. $expected = array(
  2292. 'div' => array('class' => 'input text'),
  2293. 'label' => array('for' => 'ContactEmail'),
  2294. 'Email',
  2295. '/label',
  2296. array('input' => array(
  2297. 'type' => 'text', 'name' => 'Contact[email]',
  2298. 'id' => 'ContactEmail'
  2299. )),
  2300. '/div'
  2301. );
  2302. $this->assertTags($result, $expected);
  2303. $result = $this->Form->input('Contact.5.email', array('type' => 'text'));
  2304. $expected = array(
  2305. 'div' => array('class' => 'input text'),
  2306. 'label' => array('for' => 'Contact5Email'),
  2307. 'Email',
  2308. '/label',
  2309. array('input' => array(
  2310. 'type' => 'text', 'name' => 'Contact[5][email]',
  2311. 'id' => 'Contact5Email'
  2312. )),
  2313. '/div'
  2314. );
  2315. $this->assertTags($result, $expected);
  2316. $result = $this->Form->input('Contact.password');
  2317. $expected = array(
  2318. 'div' => array('class' => 'input password'),
  2319. 'label' => array('for' => 'ContactPassword'),
  2320. 'Password',
  2321. '/label',
  2322. array('input' => array(
  2323. 'type' => 'password', 'name' => 'Contact[password]',
  2324. 'id' => 'ContactPassword'
  2325. )),
  2326. '/div'
  2327. );
  2328. $this->assertTags($result, $expected);
  2329. $result = $this->Form->input('Contact.email', array(
  2330. 'type' => 'file', 'class' => 'textbox'
  2331. ));
  2332. $expected = array(
  2333. 'div' => array('class' => 'input file'),
  2334. 'label' => array('for' => 'ContactEmail'),
  2335. 'Email',
  2336. '/label',
  2337. array('input' => array(
  2338. 'type' => 'file', 'name' => 'Contact[email]', 'class' => 'textbox',
  2339. 'id' => 'ContactEmail'
  2340. )),
  2341. '/div'
  2342. );
  2343. $this->assertTags($result, $expected);
  2344. $this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
  2345. $result = $this->Form->input('Contact.phone');
  2346. $expected = array(
  2347. 'div' => array('class' => 'input tel'),
  2348. 'label' => array('for' => 'ContactPhone'),
  2349. 'Phone',
  2350. '/label',
  2351. array('input' => array(
  2352. 'type' => 'tel', 'name' => 'Contact[phone]',
  2353. 'value' => 'Hello &amp; World &gt; weird chars',
  2354. 'id' => 'ContactPhone', 'maxlength' => 255
  2355. )),
  2356. '/div'
  2357. );
  2358. $this->assertTags($result, $expected);
  2359. $this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
  2360. $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
  2361. $expected = array(
  2362. 'div' => array('class' => 'input text'),
  2363. 'label' => array('for' => 'myId'),
  2364. 'Field',
  2365. '/label',
  2366. 'input' => array(
  2367. 'type' => 'text', 'name' => 'Model[0][OtherModel][field]',
  2368. 'value' => 'My value', 'id' => 'myId'
  2369. ),
  2370. '/div'
  2371. );
  2372. $this->assertTags($result, $expected);
  2373. unset($this->Form->request->data);
  2374. $Contact->validationErrors['field'] = array('Badness!');
  2375. $result = $this->Form->input('Contact.field');
  2376. $expected = array(
  2377. 'div' => array('class' => 'input text error'),
  2378. 'label' => array('for' => 'ContactField'),
  2379. 'Field',
  2380. '/label',
  2381. 'input' => array(
  2382. 'type' => 'text', 'name' => 'Contact[field]',
  2383. 'id' => 'ContactField', 'class' => 'form-error'
  2384. ),
  2385. array('div' => array('class' => 'error-message')),
  2386. 'Badness!',
  2387. '/div',
  2388. '/div'
  2389. );
  2390. $this->assertTags($result, $expected);
  2391. $result = $this->Form->input('Contact.field', array(
  2392. 'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
  2393. ));
  2394. $expected = array(
  2395. 'label' => array('for' => 'ContactField'),
  2396. 'Field',
  2397. '/label',
  2398. 'input' => array(
  2399. 'type' => 'text', 'name' => 'Contact[field]',
  2400. 'id' => 'ContactField', 'class' => 'form-error'
  2401. ),
  2402. array('span' => array('class' => 'error-message')),
  2403. 'Badness!',
  2404. '/span'
  2405. );
  2406. $this->assertTags($result, $expected);
  2407. $result = $this->Form->input('Contact.field', array(
  2408. 'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
  2409. ));
  2410. $expected = array(
  2411. 'div' => array('class' => 'input text error'),
  2412. 'label' => array('for' => 'ContactField'),
  2413. 'Field',
  2414. '/label',
  2415. 'input' => array(
  2416. 'type' => 'text', 'name' => 'Contact[field]',
  2417. 'id' => 'ContactField', 'class' => 'form-error'
  2418. ),
  2419. array('div' => array('class' => 'error')),
  2420. 'Badness!',
  2421. '/div'
  2422. );
  2423. $this->assertTags($result, $expected);
  2424. $result = $this->Form->input('Contact.field', array(
  2425. 'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
  2426. ));
  2427. $expected = array(
  2428. 'span' => array('class' => 'input text error'),
  2429. 'label' => array('for' => 'ContactField'),
  2430. 'Field',
  2431. '/label',
  2432. 'input' => array(
  2433. 'type' => 'text', 'name' => 'Contact[field]',
  2434. 'id' => 'ContactField', 'class' => 'form-error'
  2435. ),
  2436. 'Badness!',
  2437. '/span'
  2438. );
  2439. $this->assertTags($result, $expected);
  2440. $result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
  2441. $expected = array(
  2442. 'div' => array('class' => 'input text error'),
  2443. 'label' => array('for' => 'ContactField'),
  2444. 'Field',
  2445. '/label',
  2446. 'input' => array(
  2447. 'type' => 'text', 'name' => 'Contact[field]',
  2448. 'id' => 'ContactField', 'class' => 'form-error'
  2449. ),
  2450. 'A message to you, Rudy',
  2451. array('div' => array('class' => 'error-message')),
  2452. 'Badness!',
  2453. '/div',
  2454. '/div'
  2455. );
  2456. $this->assertTags($result, $expected);
  2457. $this->Form->setEntity(null);
  2458. $this->Form->setEntity('Contact.field');
  2459. $result = $this->Form->input('Contact.field', array(
  2460. 'after' => 'A message to you, Rudy', 'error' => false
  2461. ));
  2462. $expected = array(
  2463. 'div' => array('class' => 'input text'),
  2464. 'label' => array('for' => 'ContactField'),
  2465. 'Field',
  2466. '/label',
  2467. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2468. 'A message to you, Rudy',
  2469. '/div'
  2470. );
  2471. $this->assertTags($result, $expected);
  2472. $result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
  2473. $expected = array(
  2474. 'div' => array('class' => 'input text'),
  2475. 'label' => array('for' => 'ObjectField'),
  2476. 'Field',
  2477. '/label',
  2478. 'input' => array('type' => 'text', 'name' => 'Object[field]', 'id' => 'ObjectField'),
  2479. 'A message to you, Rudy',
  2480. '/div'
  2481. );
  2482. $this->assertTags($result, $expected);
  2483. $Contact->validationErrors['field'] = array('minLength');
  2484. $result = $this->Form->input('Contact.field', array(
  2485. 'error' => array(
  2486. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2487. 'maxLength' => 'login too large'
  2488. )
  2489. ));
  2490. $expected = array(
  2491. 'div' => array('class' => 'input text error'),
  2492. 'label' => array('for' => 'ContactField'),
  2493. 'Field',
  2494. '/label',
  2495. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2496. array('div' => array('class' => 'error-message')),
  2497. 'Le login doit contenir au moins 2 caractères',
  2498. '/div',
  2499. '/div'
  2500. );
  2501. $this->assertTags($result, $expected);
  2502. $Contact->validationErrors['field'] = array('maxLength');
  2503. $result = $this->Form->input('Contact.field', array(
  2504. 'error' => array(
  2505. 'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
  2506. 'minLength' => 'Le login doit contenir au moins 2 caractères',
  2507. 'maxLength' => 'login too large',
  2508. )
  2509. ));
  2510. $expected = array(
  2511. 'div' => array('class' => 'input text error'),
  2512. 'label' => array('for' => 'ContactField'),
  2513. 'Field',
  2514. '/label',
  2515. 'input' => array('type' => 'text', 'name' => 'Contact[field]', 'id' => 'ContactField', 'class' => 'form-error'),
  2516. array('span' => array('class' => 'error-message', 'rel' => 'fake')),
  2517. 'login too large',
  2518. '/span',
  2519. '/div'
  2520. );
  2521. $this->assertTags($result, $expected);
  2522. }
  2523. /**
  2524. * Test that inputs with 0 can be created.
  2525. *
  2526. * @return void
  2527. */
  2528. public function testInputZero() {
  2529. $this->markTestIncomplete('Need to revisit once models work again.');
  2530. $this->Form->create('User');
  2531. $result = $this->Form->input('0');
  2532. $expected = array(
  2533. 'div' => array('class' => 'input text'),
  2534. 'label' => array('for' => 'User0'), '/label',
  2535. 'input' => array('type' => 'text', 'name' => 'User[0]', 'id' => 'User0'),
  2536. '/div'
  2537. );
  2538. $this->assertTags($result, $expected);
  2539. }
  2540. /**
  2541. * test input() with checkbox creation
  2542. *
  2543. * @return void
  2544. */
  2545. public function testInputCheckbox() {
  2546. $this->markTestIncomplete('Need to revisit once models work again.');
  2547. $result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
  2548. $expected = array(
  2549. 'div' => array('class' => 'input checkbox'),
  2550. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2551. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2552. '/div'
  2553. );
  2554. $this->assertTags($result, $expected);
  2555. $result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
  2556. $expected = array(
  2557. 'div' => array('class' => 'input checkbox'),
  2558. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2559. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2560. '/div'
  2561. );
  2562. $this->assertTags($result, $expected);
  2563. $result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
  2564. $expected = array(
  2565. 'div' => array('class' => 'input checkbox'),
  2566. 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
  2567. array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
  2568. '/div'
  2569. );
  2570. $this->assertTags($result, $expected);
  2571. $result = $this->Form->input('User.disabled', array(
  2572. 'label' => 'Disabled',
  2573. 'type' => 'checkbox',
  2574. 'data-foo' => 'disabled'
  2575. ));
  2576. $expected = array(
  2577. 'div' => array('class' => 'input checkbox'),
  2578. 'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
  2579. array('input' => array(
  2580. 'type' => 'checkbox',
  2581. 'name' => 'data[User][disabled]',
  2582. 'value' => '1',
  2583. 'id' => 'UserDisabled',
  2584. 'data-foo' => 'disabled'
  2585. )),
  2586. 'label' => array('for' => 'UserDisabled'),
  2587. 'Disabled',
  2588. '/label',
  2589. '/div'
  2590. );
  2591. $this->assertTags($result, $expected);
  2592. }
  2593. /**
  2594. * test form->input() with time types.
  2595. *
  2596. */
  2597. public function testInputTime() {
  2598. $this->markTestIncomplete('Need to revisit once models work again.');
  2599. extract($this->dateRegex);
  2600. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2601. $result = explode(':', $result);
  2602. $this->assertRegExp('/option value="23"/', $result[0]);
  2603. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2604. $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
  2605. $result = explode(':', $result);
  2606. $this->assertRegExp('/option value="23"/', $result[0]);
  2607. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2608. $result = $this->Form->input('Model.field', array(
  2609. 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
  2610. ));
  2611. $result = explode(':', $result);
  2612. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2613. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2614. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2615. $result = $this->Form->input('Model.field', array(
  2616. 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
  2617. ));
  2618. $result = explode(':', $result);
  2619. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2620. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2621. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2622. $result = $this->Form->input('prueba', array(
  2623. 'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2624. 'maxYear' => date('Y') + 1, 'interval' => 15
  2625. ));
  2626. $result = explode(':', $result);
  2627. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2628. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2629. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2630. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2631. $result = $this->Form->input('Random.start_time', array(
  2632. 'type' => 'time',
  2633. 'selected' => '18:15'
  2634. ));
  2635. $this->assertContains('<option value="06" selected="selected">6</option>', $result);
  2636. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2637. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2638. $result = $this->Form->input('published', array('type' => 'time'));
  2639. $now = strtotime('now');
  2640. $this->assertContains('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
  2641. $now = strtotime('2013-03-09 00:42:21');
  2642. $result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
  2643. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2644. $this->assertContains('<option value="42" selected="selected">42</option>', $result);
  2645. }
  2646. /**
  2647. * Test interval + selected near the hour roll over.
  2648. *
  2649. * @return void
  2650. */
  2651. public function testTimeSelectedWithInterval() {
  2652. $this->markTestIncomplete('Need to revisit once models work again.');
  2653. $result = $this->Form->input('Model.start_time', array(
  2654. 'type' => 'time',
  2655. 'interval' => 15,
  2656. 'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
  2657. ));
  2658. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2659. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2660. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2661. $result = $this->Form->input('Model.start_time', array(
  2662. 'type' => 'time',
  2663. 'interval' => 15,
  2664. 'selected' => '2012-10-23 15:57:00'
  2665. ));
  2666. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2667. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2668. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2669. $result = $this->Form->input('Model.start_time', array(
  2670. 'timeFormat' => 24,
  2671. 'type' => 'time',
  2672. 'interval' => 15,
  2673. 'selected' => '15:57'
  2674. ));
  2675. $this->assertContains('<option value="16" selected="selected">16</option>', $result);
  2676. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2677. $result = $this->Form->input('Model.start_time', array(
  2678. 'timeFormat' => 24,
  2679. 'type' => 'time',
  2680. 'interval' => 15,
  2681. 'selected' => '23:57'
  2682. ));
  2683. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2684. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2685. $result = $this->Form->input('Model.created', array(
  2686. 'timeFormat' => 24,
  2687. 'type' => 'datetime',
  2688. 'interval' => 15,
  2689. 'selected' => '2012-09-30 23:56'
  2690. ));
  2691. $this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
  2692. $this->assertContains('<option value="10" selected="selected">October</option>', $result);
  2693. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2694. $this->assertContains('<option value="00" selected="selected">0</option>', $result);
  2695. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2696. }
  2697. /**
  2698. * Test time with selected values around 12:xx:xx
  2699. *
  2700. * @return void
  2701. */
  2702. public function testTimeSelectedWithIntervalTwelve() {
  2703. $this->markTestIncomplete('Need to revisit once models work again.');
  2704. $result = $this->Form->input('Model.start_time', array(
  2705. 'type' => 'time',
  2706. 'timeFormat' => 12,
  2707. 'interval' => 15,
  2708. 'selected' => '00:00:00'
  2709. ));
  2710. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2711. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2712. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2713. $result = $this->Form->input('Model.start_time', array(
  2714. 'type' => 'time',
  2715. 'timeFormat' => 12,
  2716. 'interval' => 15,
  2717. 'selected' => '12:00:00'
  2718. ));
  2719. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2720. $this->assertContains('<option value="00" selected="selected">00</option>', $result);
  2721. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2722. $result = $this->Form->input('Model.start_time', array(
  2723. 'type' => 'time',
  2724. 'timeFormat' => 12,
  2725. 'interval' => 15,
  2726. 'selected' => '12:15:00'
  2727. ));
  2728. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2729. $this->assertContains('<option value="15" selected="selected">15</option>', $result);
  2730. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2731. }
  2732. /**
  2733. * Test interval & timeFormat = 12
  2734. *
  2735. * @return void
  2736. */
  2737. public function testInputTimeWithIntervalAnd12HourFormat() {
  2738. $this->markTestIncomplete('Need to revisit once models work again.');
  2739. $result = $this->Form->input('Model.start_time', array(
  2740. 'type' => 'time',
  2741. 'timeFormat' => 12,
  2742. 'interval' => 5,
  2743. 'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
  2744. ));
  2745. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2746. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2747. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2748. $result = $this->Form->input('Model.start_time', array(
  2749. 'type' => 'time',
  2750. 'timeFormat' => '12',
  2751. 'interval' => 5,
  2752. 'selected' => '2013-04-19 16:30:00'
  2753. ));
  2754. $this->assertContains('<option value="04" selected="selected">4</option>', $result);
  2755. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2756. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2757. $result = $this->Form->input('Model.start_time', array(
  2758. 'type' => 'time',
  2759. 'timeFormat' => '12',
  2760. 'interval' => 10,
  2761. 'selected' => '2013-05-19 00:33:00'
  2762. ));
  2763. $this->assertContains('<option value="12" selected="selected">12</option>', $result);
  2764. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2765. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2766. $result = $this->Form->input('Model.start_time', array(
  2767. 'type' => 'time',
  2768. 'timeFormat' => '12',
  2769. 'interval' => 10,
  2770. 'selected' => '2013-05-19 13:33:00'
  2771. ));
  2772. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2773. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2774. $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
  2775. $result = $this->Form->input('Model.start_time', array(
  2776. 'type' => 'time',
  2777. 'timeFormat' => '12',
  2778. 'interval' => 10,
  2779. 'selected' => '2013-05-19 01:33:00'
  2780. ));
  2781. $this->assertContains('<option value="01" selected="selected">1</option>', $result);
  2782. $this->assertContains('<option value="30" selected="selected">30</option>', $result);
  2783. $this->assertContains('<option value="am" selected="selected">am</option>', $result);
  2784. }
  2785. /**
  2786. * test form->input() with datetime, date and time types
  2787. *
  2788. * @return void
  2789. */
  2790. public function testInputDatetime() {
  2791. $this->markTestIncomplete('Need to revisit once models work again.');
  2792. extract($this->dateRegex);
  2793. $result = $this->Form->input('prueba', array(
  2794. 'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
  2795. 'maxYear' => date('Y') + 1, 'interval' => 15
  2796. ));
  2797. $result = explode(':', $result);
  2798. $this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
  2799. $this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
  2800. $this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
  2801. $this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
  2802. //related to ticket #5013
  2803. $result = $this->Form->input('Contact.date', array(
  2804. 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
  2805. ));
  2806. $this->assertRegExp('/class="customClass"/', $result);
  2807. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2808. $result = $this->Form->input('Contact.date', array(
  2809. 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
  2810. ));
  2811. $this->assertRegExp('/id="customIdDay"/', $result);
  2812. $this->assertRegExp('/id="customIdMonth"/', $result);
  2813. $this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
  2814. $result = $this->Form->input('Model.field', array(
  2815. 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
  2816. ));
  2817. $this->assertRegExp('/id="customIDDay"/', $result);
  2818. $this->assertRegExp('/id="customIDHour"/', $result);
  2819. $result = explode('</select><select', $result);
  2820. $result = explode(':', $result[1]);
  2821. $this->assertRegExp('/option value="23"/', $result[0]);
  2822. $this->assertNotRegExp('/option value="24"/', $result[0]);
  2823. $result = $this->Form->input('Model.field', array(
  2824. 'type' => 'datetime', 'timeFormat' => 12
  2825. ));
  2826. $result = explode('</select><select', $result);
  2827. $result = explode(':', $result[1]);
  2828. $this->assertRegExp('/option value="12"/', $result[0]);
  2829. $this->assertNotRegExp('/option value="13"/', $result[0]);
  2830. $this->Form->request->data = array('Contact' => array('created' => null));
  2831. $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
  2832. $expected = array(
  2833. 'div' => array('class' => 'input date'),
  2834. 'label' => array('for' => 'ContactCreatedMonth'),
  2835. 'Created',
  2836. '/label',
  2837. array('select' => array('name' => 'Contact[created][month]', 'id' => 'ContactCreatedMonth')),
  2838. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2839. $monthsRegex,
  2840. '/select', '-',
  2841. array('select' => array('name' => 'Contact[created][day]', 'id' => 'ContactCreatedDay')),
  2842. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2843. $daysRegex,
  2844. '/select', '-',
  2845. array('select' => array('name' => 'Contact[created][year]', 'id' => 'ContactCreatedYear')),
  2846. array('option' => array('value' => '')), 'Date Unknown', '/option',
  2847. $yearsRegex,
  2848. '/select',
  2849. '/div'
  2850. );
  2851. $this->assertTags($result, $expected);
  2852. $this->Form->request->data = array('Contact' => array('created' => null));
  2853. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
  2854. $this->assertRegExp('/for\="ContactCreatedHour"/', $result);
  2855. $this->Form->request->data = array('Contact' => array('created' => null));
  2856. $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
  2857. $this->assertRegExp('/for\="ContactCreatedMonth"/', $result);
  2858. $result = $this->Form->input('Contact.created', array(
  2859. 'type' => 'date',
  2860. 'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
  2861. 'timeFormat' => 'NONE'
  2862. ));
  2863. $this->assertRegExp('/for\="created-month"/', $result);
  2864. }
  2865. /**
  2866. * Test generating checkboxes with disabled elements.
  2867. *
  2868. * @return void
  2869. */
  2870. public function testInputCheckboxWithDisabledElements() {
  2871. $this->markTestIncomplete('Need to revisit once models work again.');
  2872. $options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
  2873. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
  2874. $expected = array(
  2875. array('div' => array('class' => 'input select')),
  2876. array('label' => array('for' => "ContactMultiple")),
  2877. 'Multiple',
  2878. '/label',
  2879. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2880. array('div' => array('class' => 'checkbox')),
  2881. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
  2882. array('label' => array('for' => "ContactMultiple1")),
  2883. 'One',
  2884. '/label',
  2885. '/div',
  2886. array('div' => array('class' => 'checkbox')),
  2887. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2888. array('label' => array('for' => "ContactMultiple2")),
  2889. 'Two',
  2890. '/label',
  2891. '/div',
  2892. array('div' => array('class' => 'checkbox')),
  2893. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2894. array('label' => array('for' => "ContactMultiple3")),
  2895. 'Three',
  2896. '/label',
  2897. '/div',
  2898. '/div'
  2899. );
  2900. $this->assertTags($result, $expected);
  2901. $result = $this->Form->radio('Model.field', array('1/2' => 'half'));
  2902. $expected = array(
  2903. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '', 'id' => 'ModelField_'),
  2904. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1/2', 'id' => 'ModelField12')),
  2905. 'label' => array('for' => 'ModelField12'),
  2906. 'half',
  2907. '/label'
  2908. );
  2909. $this->assertTags($result, $expected);
  2910. $disabled = array('2', 3);
  2911. $expected = array(
  2912. array('div' => array('class' => 'input select')),
  2913. array('label' => array('for' => "ContactMultiple")),
  2914. 'Multiple',
  2915. '/label',
  2916. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2917. array('div' => array('class' => 'checkbox')),
  2918. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
  2919. array('label' => array('for' => "ContactMultiple1")),
  2920. 'One',
  2921. '/label',
  2922. '/div',
  2923. array('div' => array('class' => 'checkbox')),
  2924. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
  2925. array('label' => array('for' => "ContactMultiple2")),
  2926. 'Two',
  2927. '/label',
  2928. '/div',
  2929. array('div' => array('class' => 'checkbox')),
  2930. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
  2931. array('label' => array('for' => "ContactMultiple3")),
  2932. 'Three',
  2933. '/label',
  2934. '/div',
  2935. '/div'
  2936. );
  2937. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2938. $this->assertTags($result, $expected);
  2939. // make sure 50 does only disable 50, and not 50f5c0cf
  2940. $options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
  2941. $disabled = array(50);
  2942. $expected = array(
  2943. array('div' => array('class' => 'input select')),
  2944. array('label' => array('for' => "ContactMultiple")),
  2945. 'Multiple',
  2946. '/label',
  2947. array('input' => array('type' => 'hidden', 'name' => "Contact[multiple]", 'value' => '', 'id' => "ContactMultiple")),
  2948. array('div' => array('class' => 'checkbox')),
  2949. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
  2950. array('label' => array('for' => "ContactMultiple50")),
  2951. 'Fifty',
  2952. '/label',
  2953. '/div',
  2954. array('div' => array('class' => 'checkbox')),
  2955. array('input' => array('type' => 'checkbox', 'name' => "Contact[multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
  2956. array('label' => array('for' => "ContactMultiple50f5c0cf")),
  2957. 'Stringy',
  2958. '/label',
  2959. '/div',
  2960. '/div'
  2961. );
  2962. $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
  2963. $this->assertTags($result, $expected);
  2964. }
  2965. /**
  2966. * test input name with leading integer, ensure attributes are generated correctly.
  2967. *
  2968. * @return void
  2969. */
  2970. public function testInputWithLeadingInteger() {
  2971. $result = $this->Form->text('0.Node.title');
  2972. $expected = array(
  2973. 'input' => array('name' => '0[Node][title]', 'type' => 'text')
  2974. );
  2975. $this->assertTags($result, $expected);
  2976. }
  2977. /**
  2978. * test form->input() with select type inputs.
  2979. *
  2980. * @return void
  2981. */
  2982. public function testInputSelectType() {
  2983. $this->markTestIncomplete('Need to revisit once models work again.');
  2984. $result = $this->Form->input('email', array(
  2985. 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
  2986. );
  2987. $expected = array(
  2988. 'div' => array('class' => 'input select'),
  2989. 'label' => array('for' => 'email'),
  2990. 'Email',
  2991. '/label',
  2992. array('select' => array('name' => 'email', 'id' => 'email')),
  2993. array('option' => array('value' => '')),
  2994. '/option',
  2995. array('option' => array('value' => 'è')),
  2996. 'Firést',
  2997. '/option',
  2998. array('option' => array('value' => 'é')),
  2999. 'Secoènd',
  3000. '/option',
  3001. '/select',
  3002. '/div'
  3003. );
  3004. $this->assertTags($result, $expected);
  3005. $result = $this->Form->input('email', array(
  3006. 'options' => array('First', 'Second'), 'empty' => true)
  3007. );
  3008. $expected = array(
  3009. 'div' => array('class' => 'input select'),
  3010. 'label' => array('for' => 'email'),
  3011. 'Email',
  3012. '/label',
  3013. array('select' => array('name' => 'email', 'id' => 'email')),
  3014. array('option' => array('value' => '')),
  3015. '/option',
  3016. array('option' => array('value' => '0')),
  3017. 'First',
  3018. '/option',
  3019. array('option' => array('value' => '1')),
  3020. 'Second',
  3021. '/option',
  3022. '/select',
  3023. '/div'
  3024. );
  3025. $this->assertTags($result, $expected);
  3026. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3027. $this->Form->request->data = array('Model' => array('user_id' => 'value'));
  3028. $result = $this->Form->input('Model.user_id', array('empty' => true));
  3029. $expected = array(
  3030. 'div' => array('class' => 'input select'),
  3031. 'label' => array('for' => 'ModelUserId'),
  3032. 'User',
  3033. '/label',
  3034. 'select' => array('name' => 'Model[user_id]', 'id' => 'ModelUserId'),
  3035. array('option' => array('value' => '')),
  3036. '/option',
  3037. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3038. 'good',
  3039. '/option',
  3040. array('option' => array('value' => 'other')),
  3041. 'bad',
  3042. '/option',
  3043. '/select',
  3044. '/div'
  3045. );
  3046. $this->assertTags($result, $expected);
  3047. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3048. $this->Form->request->data = array('Thing' => array('user_id' => null));
  3049. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3050. $expected = array(
  3051. 'div' => array('class' => 'input select'),
  3052. 'label' => array('for' => 'ThingUserId'),
  3053. 'User',
  3054. '/label',
  3055. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3056. array('option' => array('value' => '')),
  3057. 'Some Empty',
  3058. '/option',
  3059. array('option' => array('value' => 'value')),
  3060. 'good',
  3061. '/option',
  3062. array('option' => array('value' => 'other')),
  3063. 'bad',
  3064. '/option',
  3065. '/select',
  3066. '/div'
  3067. );
  3068. $this->assertTags($result, $expected);
  3069. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3070. $this->Form->request->data = array('Thing' => array('user_id' => 'value'));
  3071. $result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
  3072. $expected = array(
  3073. 'div' => array('class' => 'input select'),
  3074. 'label' => array('for' => 'ThingUserId'),
  3075. 'User',
  3076. '/label',
  3077. 'select' => array('name' => 'Thing[user_id]', 'id' => 'ThingUserId'),
  3078. array('option' => array('value' => '')),
  3079. 'Some Empty',
  3080. '/option',
  3081. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3082. 'good',
  3083. '/option',
  3084. array('option' => array('value' => 'other')),
  3085. 'bad',
  3086. '/option',
  3087. '/select',
  3088. '/div'
  3089. );
  3090. $this->assertTags($result, $expected);
  3091. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3092. $this->Form->request->data = array('User' => array('User' => array('value')));
  3093. $result = $this->Form->input('User.User', array('empty' => true));
  3094. $expected = array(
  3095. 'div' => array('class' => 'input select'),
  3096. 'label' => array('for' => 'UserUser'),
  3097. 'User',
  3098. '/label',
  3099. 'input' => array('type' => 'hidden', 'name' => 'User[User]', 'value' => '', 'id' => 'UserUser_'),
  3100. 'select' => array('name' => 'User[User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
  3101. array('option' => array('value' => '')),
  3102. '/option',
  3103. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3104. 'good',
  3105. '/option',
  3106. array('option' => array('value' => 'other')),
  3107. 'bad',
  3108. '/option',
  3109. '/select',
  3110. '/div'
  3111. );
  3112. $this->assertTags($result, $expected);
  3113. $this->Form->data = array();
  3114. $result = $this->Form->input('Publisher.id', array(
  3115. 'label' => 'Publisher',
  3116. 'type' => 'select',
  3117. 'multiple' => 'checkbox',
  3118. 'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
  3119. ));
  3120. $expected = array(
  3121. array('div' => array('class' => 'input select')),
  3122. array('label' => array('for' => 'PublisherId')),
  3123. 'Publisher',
  3124. '/label',
  3125. 'input' => array('type' => 'hidden', 'name' => 'Publisher[id]', 'value' => '', 'id' => 'PublisherId'),
  3126. array('div' => array('class' => 'checkbox')),
  3127. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
  3128. array('label' => array('for' => 'PublisherIdValue1')),
  3129. 'Label 1',
  3130. '/label',
  3131. '/div',
  3132. array('div' => array('class' => 'checkbox')),
  3133. array('input' => array('type' => 'checkbox', 'name' => 'Publisher[id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
  3134. array('label' => array('for' => 'PublisherIdValue2')),
  3135. 'Label 2',
  3136. '/label',
  3137. '/div',
  3138. '/div'
  3139. );
  3140. $this->assertTags($result, $expected);
  3141. }
  3142. /**
  3143. * test that input() and a non standard primary key makes a hidden input by default.
  3144. *
  3145. * @return void
  3146. */
  3147. public function testInputWithNonStandardPrimaryKeyMakesHidden() {
  3148. $this->markTestIncomplete('Need to revisit once models work again.');
  3149. $this->Form->create('User');
  3150. $this->Form->fieldset = array(
  3151. 'User' => array(
  3152. 'fields' => array(
  3153. 'model_id' => array('type' => 'integer')
  3154. ),
  3155. 'validates' => array(),
  3156. 'key' => 'model_id'
  3157. )
  3158. );
  3159. $result = $this->Form->input('model_id');
  3160. $expected = array(
  3161. 'input' => array('type' => 'hidden', 'name' => 'User[model_id]', 'id' => 'UserModelId'),
  3162. );
  3163. $this->assertTags($result, $expected);
  3164. }
  3165. /**
  3166. * test that overriding the magic select type widget is possible
  3167. *
  3168. * @return void
  3169. */
  3170. public function testInputOverridingMagicSelectType() {
  3171. $this->markTestIncomplete('Need to revisit once models work again.');
  3172. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3173. $result = $this->Form->input('Model.user_id', array('type' => 'text'));
  3174. $expected = array(
  3175. 'div' => array('class' => 'input text'),
  3176. 'label' => array('for' => 'ModelUserId'), 'User', '/label',
  3177. 'input' => array('name' => 'Model[user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
  3178. '/div'
  3179. );
  3180. $this->assertTags($result, $expected);
  3181. //Check that magic types still work for plural/singular vars
  3182. $this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
  3183. $result = $this->Form->input('Model.type');
  3184. $expected = array(
  3185. 'div' => array('class' => 'input select'),
  3186. 'label' => array('for' => 'ModelType'), 'Type', '/label',
  3187. 'select' => array('name' => 'Model[type]', 'id' => 'ModelType'),
  3188. array('option' => array('value' => 'value')), 'good', '/option',
  3189. array('option' => array('value' => 'other')), 'bad', '/option',
  3190. '/select',
  3191. '/div'
  3192. );
  3193. $this->assertTags($result, $expected);
  3194. }
  3195. /**
  3196. * Test that inferred types do not override developer input
  3197. *
  3198. * @return void
  3199. */
  3200. public function testInputMagicTypeDoesNotOverride() {
  3201. $this->markTestIncomplete('Need to revisit once models work again.');
  3202. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3203. $result = $this->Form->input('Model.user', array('type' => 'checkbox'));
  3204. $expected = array(
  3205. 'div' => array('class' => 'input checkbox'),
  3206. array('input' => array(
  3207. 'type' => 'hidden',
  3208. 'name' => 'data[Model][user]',
  3209. 'id' => 'ModelUser_',
  3210. 'value' => 0,
  3211. )),
  3212. array('input' => array(
  3213. 'name' => 'data[Model][user]',
  3214. 'type' => 'checkbox',
  3215. 'id' => 'ModelUser',
  3216. 'value' => 1
  3217. )),
  3218. 'label' => array('for' => 'ModelUser'), 'User', '/label',
  3219. '/div'
  3220. );
  3221. $this->assertTags($result, $expected);
  3222. }
  3223. /**
  3224. * Test that magic input() selects are created for type=number
  3225. *
  3226. * @return void
  3227. */
  3228. public function testInputMagicSelectForTypeNumber() {
  3229. $this->markTestIncomplete('Need to revisit once models work again.');
  3230. $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
  3231. $this->Form->request->data = array('ValidateUser' => array('balance' => 1));
  3232. $result = $this->Form->input('ValidateUser.balance');
  3233. $expected = array(
  3234. 'div' => array('class' => 'input select'),
  3235. 'label' => array('for' => 'ValidateUserBalance'),
  3236. 'Balance',
  3237. '/label',
  3238. 'select' => array('name' => 'ValidateUser[balance]', 'id' => 'ValidateUserBalance'),
  3239. array('option' => array('value' => '0')),
  3240. 'nothing',
  3241. '/option',
  3242. array('option' => array('value' => '1', 'selected' => 'selected')),
  3243. 'some',
  3244. '/option',
  3245. array('option' => array('value' => '100')),
  3246. 'a lot',
  3247. '/option',
  3248. '/select',
  3249. '/div'
  3250. );
  3251. $this->assertTags($result, $expected);
  3252. }
  3253. /**
  3254. * Test that magic input() selects can easily be converted into radio types without error.
  3255. *
  3256. * @return void
  3257. */
  3258. public function testInputMagicSelectChangeToRadio() {
  3259. $this->markTestIncomplete('Need to revisit once models work again.');
  3260. $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
  3261. $result = $this->Form->input('Model.user_id', array('type' => 'radio'));
  3262. $this->assertRegExp('/input type="radio"/', $result);
  3263. }
  3264. /**
  3265. * fields with the same name as the model should work.
  3266. *
  3267. * @return void
  3268. */
  3269. public function testInputWithMatchingFieldAndModelName() {
  3270. $this->markTestIncomplete('Need to revisit once models work again.');
  3271. $this->Form->create('User');
  3272. $this->Form->fieldset = array(
  3273. 'User' => array(
  3274. 'fields' => array(
  3275. 'User' => array('type' => 'text')
  3276. ),
  3277. 'validates' => array(),
  3278. 'key' => 'id'
  3279. )
  3280. );
  3281. $this->Form->request->data['User']['User'] = 'ABC, Inc.';
  3282. $result = $this->Form->input('User', array('type' => 'text'));
  3283. $expected = array(
  3284. 'div' => array('class' => 'input text'),
  3285. 'label' => array('for' => 'UserUser'), 'User', '/label',
  3286. 'input' => array('name' => 'User[User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
  3287. '/div'
  3288. );
  3289. $this->assertTags($result, $expected);
  3290. }
  3291. /**
  3292. * testFormInputs method
  3293. *
  3294. * test correct results from form::inputs().
  3295. *
  3296. * @return void
  3297. */
  3298. public function testFormInputs() {
  3299. $this->markTestIncomplete('Need to revisit once models work again.');
  3300. $this->Form->create('Cake\Test\TestCase\View\Helper\Contact');
  3301. $result = $this->Form->inputs('The Legend');
  3302. $expected = array(
  3303. '<fieldset',
  3304. '<legend',
  3305. 'The Legend',
  3306. '/legend',
  3307. '*/fieldset',
  3308. );
  3309. $this->assertTags($result, $expected);
  3310. $result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3311. $expected = array(
  3312. 'fieldset' => array('class' => 'classy-stuff'),
  3313. '<legend',
  3314. 'Field of Dreams',
  3315. '/legend',
  3316. '*/fieldset'
  3317. );
  3318. $this->assertTags($result, $expected);
  3319. $result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
  3320. $this->assertTags($result, $expected);
  3321. $result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
  3322. $this->assertTags($result, $expected);
  3323. $this->Form->create('Contact');
  3324. $this->Form->request['prefix'] = 'admin';
  3325. $this->Form->request['action'] = 'admin_edit';
  3326. $result = $this->Form->inputs();
  3327. $expected = array(
  3328. '<fieldset',
  3329. '<legend',
  3330. 'Edit Contact',
  3331. '/legend',
  3332. '*/fieldset',
  3333. );
  3334. $this->assertTags($result, $expected);
  3335. $this->Form->create('Contact');
  3336. $result = $this->Form->inputs(false);
  3337. $expected = array(
  3338. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3339. array('div' => array('class' => 'input text')),
  3340. '*/div',
  3341. array('div' => array('class' => 'input email')),
  3342. '*/div',
  3343. array('div' => array('class' => 'input tel')),
  3344. '*/div',
  3345. array('div' => array('class' => 'input password')),
  3346. '*/div',
  3347. array('div' => array('class' => 'input date')),
  3348. '*/div',
  3349. array('div' => array('class' => 'input date')),
  3350. '*/div',
  3351. array('div' => array('class' => 'input datetime')),
  3352. '*/div',
  3353. array('div' => array('class' => 'input number')),
  3354. '*/div',
  3355. array('div' => array('class' => 'input select')),
  3356. '*/div',
  3357. );
  3358. $this->assertTags($result, $expected);
  3359. $this->Form->create('Contact');
  3360. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
  3361. $expected = array(
  3362. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3363. array('div' => array('class' => 'input text')),
  3364. '*/div',
  3365. array('div' => array('class' => 'input email')),
  3366. '*/div',
  3367. array('div' => array('class' => 'input tel')),
  3368. '*/div',
  3369. array('div' => array('class' => 'input password')),
  3370. '*/div',
  3371. array('div' => array('class' => 'input date')),
  3372. '*/div',
  3373. array('div' => array('class' => 'input date')),
  3374. '*/div',
  3375. array('div' => array('class' => 'input datetime')),
  3376. '*/div',
  3377. array('div' => array('class' => 'input number')),
  3378. '*/div',
  3379. array('div' => array('class' => 'input select')),
  3380. '*/div',
  3381. );
  3382. $this->assertTags($result, $expected);
  3383. $this->Form->create('Contact');
  3384. $result = $this->Form->inputs(null, null, array('fieldset' => false));
  3385. $this->assertTags($result, $expected);
  3386. $this->Form->create('Contact');
  3387. $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
  3388. $expected = array(
  3389. 'fieldset' => array(),
  3390. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3391. array('div' => array('class' => 'input text')),
  3392. '*/div',
  3393. array('div' => array('class' => 'input email')),
  3394. '*/div',
  3395. array('div' => array('class' => 'input tel')),
  3396. '*/div',
  3397. array('div' => array('class' => 'input password')),
  3398. '*/div',
  3399. array('div' => array('class' => 'input date')),
  3400. '*/div',
  3401. array('div' => array('class' => 'input date')),
  3402. '*/div',
  3403. array('div' => array('class' => 'input datetime')),
  3404. '*/div',
  3405. array('div' => array('class' => 'input number')),
  3406. '*/div',
  3407. array('div' => array('class' => 'input select')),
  3408. '*/div',
  3409. '/fieldset'
  3410. );
  3411. $this->assertTags($result, $expected);
  3412. $this->Form->create('Contact');
  3413. $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
  3414. $expected = array(
  3415. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3416. array('div' => array('class' => 'input text')),
  3417. '*/div',
  3418. array('div' => array('class' => 'input email')),
  3419. '*/div',
  3420. array('div' => array('class' => 'input tel')),
  3421. '*/div',
  3422. array('div' => array('class' => 'input password')),
  3423. '*/div',
  3424. array('div' => array('class' => 'input date')),
  3425. '*/div',
  3426. array('div' => array('class' => 'input date')),
  3427. '*/div',
  3428. array('div' => array('class' => 'input datetime')),
  3429. '*/div',
  3430. array('div' => array('class' => 'input number')),
  3431. '*/div',
  3432. array('div' => array('class' => 'input select')),
  3433. '*/div',
  3434. );
  3435. $this->assertTags($result, $expected);
  3436. $this->Form->create('Contact');
  3437. $result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
  3438. $this->assertTags($result, $expected);
  3439. $this->Form->create('Contact');
  3440. $result = $this->Form->inputs('Hello');
  3441. $expected = array(
  3442. 'fieldset' => array(),
  3443. 'legend' => array(),
  3444. 'Hello',
  3445. '/legend',
  3446. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3447. array('div' => array('class' => 'input text')),
  3448. '*/div',
  3449. array('div' => array('class' => 'input email')),
  3450. '*/div',
  3451. array('div' => array('class' => 'input tel')),
  3452. '*/div',
  3453. array('div' => array('class' => 'input password')),
  3454. '*/div',
  3455. array('div' => array('class' => 'input date')),
  3456. '*/div',
  3457. array('div' => array('class' => 'input date')),
  3458. '*/div',
  3459. array('div' => array('class' => 'input datetime')),
  3460. '*/div',
  3461. array('div' => array('class' => 'input number')),
  3462. '*/div',
  3463. array('div' => array('class' => 'input select')),
  3464. '*/div',
  3465. '/fieldset'
  3466. );
  3467. $this->assertTags($result, $expected);
  3468. $this->Form->create('Contact');
  3469. $result = $this->Form->inputs(array('legend' => 'Hello'));
  3470. $expected = array(
  3471. 'fieldset' => array(),
  3472. 'legend' => array(),
  3473. 'Hello',
  3474. '/legend',
  3475. 'input' => array('type' => 'hidden', 'name' => 'Contact[id]', 'id' => 'ContactId'),
  3476. array('div' => array('class' => 'input text')),
  3477. '*/div',
  3478. array('div' => array('class' => 'input email')),
  3479. '*/div',
  3480. array('div' => array('class' => 'input tel')),
  3481. '*/div',
  3482. array('div' => array('class' => 'input password')),
  3483. '*/div',
  3484. array('div' => array('class' => 'input date')),
  3485. '*/div',
  3486. array('div' => array('class' => 'input date')),
  3487. '*/div',
  3488. array('div' => array('class' => 'input datetime')),
  3489. '*/div',
  3490. array('div' => array('class' => 'input number')),
  3491. '*/div',
  3492. array('div' => array('class' => 'input select')),
  3493. '*/div',
  3494. '/fieldset'
  3495. );
  3496. $this->assertTags($result, $expected);
  3497. $this->Form->create('Contact');
  3498. $result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
  3499. $this->assertTags($result, $expected);
  3500. $this->Form->end();
  3501. $this->Form->create(false);
  3502. $expected = array(
  3503. 'fieldset' => array(),
  3504. array('div' => array('class' => 'input text')),
  3505. 'label' => array('for' => 'foo'),
  3506. 'Foo',
  3507. '/label',
  3508. 'input' => array('type' => 'text', 'name' => 'foo', 'id' => 'foo'),
  3509. '*/div',
  3510. '/fieldset'
  3511. );
  3512. $result = $this->Form->inputs(
  3513. array('foo' => array('type' => 'text')),
  3514. array(),
  3515. array('legend' => false)
  3516. );
  3517. $this->assertTags($result, $expected);
  3518. }
  3519. /**
  3520. * Tests inputs() works with plugin models
  3521. *
  3522. * @return void
  3523. */
  3524. public function testInputsPluginModel() {
  3525. $this->markTestIncomplete('Need to revisit once models work again.');
  3526. $this->loadFixtures('Post');
  3527. Plugin::load('TestPlugin');
  3528. $this->Form->request['models'] = array(
  3529. 'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
  3530. );
  3531. $this->Form->create('TestPlugin.TestPluginPost');
  3532. $result = $this->Form->inputs();
  3533. $this->assertContains('TestPluginPost[id]', $result);
  3534. $this->assertContains('TestPluginPost[author_id]', $result);
  3535. $this->assertContains('TestPluginPost[title]', $result);
  3536. $this->assertEquals('TestPluginPost', $this->Form->model());
  3537. }
  3538. /**
  3539. * testSelectAsCheckbox method
  3540. *
  3541. * test multi-select widget with checkbox formatting.
  3542. *
  3543. * @return void
  3544. */
  3545. public function testSelectAsCheckbox() {
  3546. $this->markTestIncomplete('Need to revisit once models work again.');
  3547. $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
  3548. $expected = array(
  3549. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3550. array('div' => array('class' => 'checkbox')),
  3551. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
  3552. array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
  3553. 'first',
  3554. '/label',
  3555. '/div',
  3556. array('div' => array('class' => 'checkbox')),
  3557. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
  3558. array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
  3559. 'second',
  3560. '/label',
  3561. '/div',
  3562. array('div' => array('class' => 'checkbox')),
  3563. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  3564. array('label' => array('for' => 'ModelMultiField2')),
  3565. 'third',
  3566. '/label',
  3567. '/div',
  3568. );
  3569. $this->assertTags($result, $expected);
  3570. $result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
  3571. $expected = array(
  3572. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  3573. array('div' => array('class' => 'checkbox')),
  3574. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField1/22')),
  3575. array('label' => array('for' => 'ModelMultiField1/22')),
  3576. 'half',
  3577. '/label',
  3578. '/div',
  3579. );
  3580. $this->assertTags($result, $expected);
  3581. }
  3582. /**
  3583. * testLabel method
  3584. *
  3585. * test label generation.
  3586. *
  3587. * @return void
  3588. */
  3589. public function testLabel() {
  3590. $result = $this->Form->label('Person.name');
  3591. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3592. $result = $this->Form->label('Person.name');
  3593. $this->assertTags($result, array('label' => array('for' => 'person-name'), 'Name', '/label'));
  3594. $result = $this->Form->label('Person.first_name');
  3595. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'First Name', '/label'));
  3596. $result = $this->Form->label('Person.first_name', 'Your first name');
  3597. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), 'Your first name', '/label'));
  3598. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
  3599. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class'), 'Your first name', '/label'));
  3600. $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
  3601. $this->assertTags($result, array('label' => array('for' => 'person-first-name', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
  3602. $result = $this->Form->label('Person.first_name', '');
  3603. $this->assertTags($result, array('label' => array('for' => 'person-first-name'), '/label'));
  3604. $result = $this->Form->label('Person.2.name', '');
  3605. $this->assertTags($result, array('label' => array('for' => 'person-2-name'), '/label'));
  3606. }
  3607. /**
  3608. * testTextbox method
  3609. *
  3610. * test textbox element generation
  3611. *
  3612. * @return void
  3613. */
  3614. public function testTextbox() {
  3615. $result = $this->Form->text('Model.field');
  3616. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]')));
  3617. $result = $this->Form->text('Model.field', array('type' => 'password'));
  3618. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Model[field]')));
  3619. $result = $this->Form->text('Model.field', array('id' => 'theID'));
  3620. $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'Model[field]', 'id' => 'theID')));
  3621. }
  3622. /**
  3623. * Test that text() hooks up with request data and error fields.
  3624. *
  3625. * @return void
  3626. */
  3627. public function testTextBoxDataAndError() {
  3628. $this->article['errors'] = [
  3629. 'Contact' => ['text' => 'wrong']
  3630. ];
  3631. $this->Form->create($this->article);
  3632. $this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
  3633. $result = $this->Form->text('Model.text');
  3634. $expected = [
  3635. 'input' => [
  3636. 'type' => 'text',
  3637. 'name' => 'Model[text]',
  3638. 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values',
  3639. ]
  3640. ];
  3641. $this->assertTags($result, $expected);
  3642. $this->Form->request->data['Contact']['text'] = 'test';
  3643. $result = $this->Form->text('Contact.text', ['id' => 'theID']);
  3644. $expected = [
  3645. 'input' => [
  3646. 'type' => 'text',
  3647. 'name' => 'Contact[text]',
  3648. 'value' => 'test',
  3649. 'id' => 'theID',
  3650. 'class' => 'form-error'
  3651. ]
  3652. ];
  3653. $this->assertTags($result, $expected);
  3654. }
  3655. /**
  3656. * testDefaultValue method
  3657. *
  3658. * Test default value setting
  3659. *
  3660. * @return void
  3661. */
  3662. public function testTextDefaultValue() {
  3663. $this->Form->request->data['Model']['field'] = 'test';
  3664. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3665. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'test']];
  3666. $this->assertTags($result, $expected);
  3667. unset($this->Form->request->data['Model']['field']);
  3668. $result = $this->Form->text('Model.field', array('default' => 'default value'));
  3669. $expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'default value']];
  3670. $this->assertTags($result, $expected);
  3671. }
  3672. /**
  3673. * testCheckboxDefaultValue method
  3674. *
  3675. * Test default value setting on checkbox() method
  3676. *
  3677. * @return void
  3678. */
  3679. public function testCheckboxDefaultValue() {
  3680. $this->markTestIncomplete('Need to revisit once models work again.');
  3681. $this->Form->request->data['Model']['field'] = false;
  3682. $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
  3683. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField')));
  3684. unset($this->Form->request->data['Model']['field']);
  3685. $result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
  3686. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
  3687. $this->Form->request->data['Model']['field'] = true;
  3688. $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
  3689. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
  3690. unset($this->Form->request->data['Model']['field']);
  3691. $result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
  3692. $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1', 'id' => 'ModelField')));
  3693. }
  3694. /**
  3695. * testError method
  3696. *
  3697. * Test field error generation
  3698. *
  3699. * @return void
  3700. */
  3701. public function testError() {
  3702. $this->markTestIncomplete('Need to revisit once models work again.');
  3703. $Contact->validationErrors['field'] = array(1);
  3704. $result = $this->Form->error('Contact.field');
  3705. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
  3706. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3707. $this->assertEquals('Error in field Field', $result);
  3708. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3709. $result = $this->Form->error('Contact.field', null, array('wrap' => false));
  3710. $this->assertEquals('This field contains invalid input', $result);
  3711. $Contact->validationErrors['field'] = array("This field contains invalid input");
  3712. $result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
  3713. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
  3714. $result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
  3715. $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
  3716. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
  3717. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3718. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
  3719. $this->assertEquals('&lt;strong&gt;Badness!&lt;/strong&gt;', $result);
  3720. $result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
  3721. $this->assertEquals('<strong>Badness!</strong>', $result);
  3722. $Contact->validationErrors['field'] = array("email");
  3723. $result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
  3724. $expected = array(
  3725. 'div' => array('class' => 'field-error'),
  3726. 'No good!',
  3727. '/div'
  3728. );
  3729. $this->assertTags($result, $expected);
  3730. $Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
  3731. $result = $this->Form->error('Contact.field', array(
  3732. 'notEmpty' => 'Cannot be empty',
  3733. 'email' => 'No good!'
  3734. ));
  3735. $expected = array(
  3736. 'div' => array('class' => 'error-message'),
  3737. 'ul' => array(),
  3738. '<li', 'Cannot be empty', '/li',
  3739. '<li', 'No good!', '/li',
  3740. '<li', 'Something else', '/li',
  3741. '/ul',
  3742. '/div'
  3743. );
  3744. $this->assertTags($result, $expected);
  3745. // Testing error messages list options
  3746. $Contact->validationErrors['field'] = array('notEmpty', 'email');
  3747. $result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
  3748. $expected = array(
  3749. 'div' => array('class' => 'error-message'),
  3750. 'ol' => array(),
  3751. '<li', 'notEmpty', '/li',
  3752. '<li', 'email', '/li',
  3753. '/ol',
  3754. '/div'
  3755. );
  3756. $this->assertTags($result, $expected);
  3757. $result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
  3758. $expected = array(
  3759. 'div' => array('class' => 'error-message'),
  3760. 'ol' => array(),
  3761. '<li', 'notEmpty', '/li',
  3762. '<li', 'email', '/li',
  3763. '/ol',
  3764. '/div'
  3765. );
  3766. $this->assertTags($result, $expected);
  3767. $result = $this->Form->error('Contact.field', null, array(
  3768. 'listOptions' => array(
  3769. 'class' => 'ul-class',
  3770. 'itemOptions' => array(
  3771. 'class' => 'li-class'
  3772. )
  3773. )
  3774. ));
  3775. $expected = array(
  3776. 'div' => array('class' => 'error-message'),
  3777. 'ul' => array('class' => 'ul-class'),
  3778. array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
  3779. array('li' => array('class' => 'li-class')), 'email', '/li',
  3780. '/ul',
  3781. '/div'
  3782. );
  3783. $this->assertTags($result, $expected);
  3784. }
  3785. /**
  3786. * test error options when using form->input();
  3787. *
  3788. * @return void
  3789. */
  3790. public function testInputErrorEscape() {
  3791. $this->markTestIncomplete('Need to revisit once models work again.');
  3792. $this->Form->create('ValidateProfile');
  3793. $ValidateProfile->validationErrors['city'] = array('required<br>');
  3794. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
  3795. $this->assertRegExp('/required&lt;br&gt;/', $result);
  3796. $result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
  3797. $this->assertRegExp('/required<br>/', $result);
  3798. }
  3799. /**
  3800. * testPassword method
  3801. *
  3802. * Test password element generation
  3803. *
  3804. * @return void
  3805. */
  3806. public function testPassword() {
  3807. $this->article['errors'] = [
  3808. 'Contact' => [
  3809. 'passwd' => 1
  3810. ]
  3811. ];
  3812. $this->Form->create($this->article);
  3813. $result = $this->Form->password('Contact.field');
  3814. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[field]')));
  3815. $this->Form->request->data['Contact']['passwd'] = 'test';
  3816. $result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
  3817. $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'Contact[passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
  3818. }
  3819. /**
  3820. * testRadio method
  3821. *
  3822. * Test radio element set generation
  3823. *
  3824. * @return void
  3825. */
  3826. public function testRadio() {
  3827. $result = $this->Form->radio('Model.field', array('option A'));
  3828. $expected = array(
  3829. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3830. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3831. 'label' => array('for' => 'model-field-0'),
  3832. 'option A',
  3833. '/label'
  3834. );
  3835. $this->assertTags($result, $expected);
  3836. $result = $this->Form->radio('Model.field', array('option A', 'option B'));
  3837. $expected = array(
  3838. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => ''),
  3839. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '0', 'id' => 'model-field-0')),
  3840. array('label' => array('for' => 'model-field-0')),
  3841. 'option A',
  3842. '/label',
  3843. array('input' => array('type' => 'radio', 'name' => 'Model[field]', 'value' => '1', 'id' => 'model-field-1')),
  3844. array('label' => array('for' => 'model-field-1')),
  3845. 'option B',
  3846. '/label',
  3847. );
  3848. $this->assertTags($result, $expected);
  3849. $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
  3850. $expected = array(
  3851. 'input' => array('type' => 'hidden', 'name' => 'Employee[gender]', 'value' => ''),
  3852. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'male', 'id' => 'employee-gender-male')),
  3853. array('label' => array('for' => 'employee-gender-male')),
  3854. 'Male',
  3855. '/label',
  3856. array('input' => array('type' => 'radio', 'name' => 'Employee[gender]', 'value' => 'female', 'id' => 'employee-gender-female')),
  3857. array('label' => array('for' => 'employee-gender-female')),
  3858. 'Female',
  3859. '/label',
  3860. );
  3861. $this->assertTags($result, $expected);
  3862. $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'Model[custom]'));
  3863. $expected = array(
  3864. array('input' => array('type' => 'hidden', 'name' => 'Model[custom]', 'value' => '')),
  3865. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '0', 'id' => 'model-custom-0')),
  3866. array('label' => array('for' => 'model-custom-0')),
  3867. 'option A',
  3868. '/label',
  3869. array('input' => array('type' => 'radio', 'name' => 'Model[custom]', 'value' => '1', 'id' => 'model-custom-1')),
  3870. array('label' => array('for' => 'model-custom-1')),
  3871. 'option B',
  3872. '/label',
  3873. );
  3874. $this->assertTags($result, $expected);
  3875. }
  3876. /**
  3877. * test disabling the hidden input for radio buttons
  3878. *
  3879. * @return void
  3880. */
  3881. public function testRadioHiddenInputDisabling() {
  3882. $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
  3883. $expected = array(
  3884. 'input' => array('type' => 'radio', 'name' => 'Model[1][field]', 'value' => '0', 'id' => 'model-1-field-0'),
  3885. 'label' => array('for' => 'model-1-field-0'),
  3886. 'option A',
  3887. '/label'
  3888. );
  3889. $this->assertTags($result, $expected);
  3890. }
  3891. /**
  3892. * testDomIdSuffix method
  3893. *
  3894. * @return void
  3895. */
  3896. public function testDomIdSuffix() {
  3897. $this->markTestIncomplete('Need to revisit once models work again.');
  3898. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs');
  3899. $this->assertEquals('1StringWith1$-dollarSigns', $result);
  3900. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>');
  3901. $this->assertEquals('AbcX=FooY=Bar', $result);
  3902. $result = $this->Form->domIdSuffix('1 string with 1$-dollar signs', 'xhtml');
  3903. $this->assertEquals('1StringWith1-dollarSigns', $result);
  3904. $result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>', 'xhtml');
  3905. $this->assertEquals('AbcXFooYBar', $result);
  3906. }
  3907. /**
  3908. * testDomIdSuffixCollisionResolvement()
  3909. *
  3910. * @return void
  3911. */
  3912. public function testDomIdSuffixCollisionResolvement() {
  3913. $this->markTestIncomplete('Need to revisit once models work again.');
  3914. $result = $this->Form->domIdSuffix('a>b');
  3915. $this->assertEquals('AB', $result);
  3916. $result = $this->Form->domIdSuffix('a<b');
  3917. $this->assertEquals('AB1', $result);
  3918. $result = $this->Form->domIdSuffix('a\'b');
  3919. $this->assertEquals('AB2', $result);
  3920. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3921. $this->assertEquals('1StringWith1-dollar', $result);
  3922. $result = $this->Form->domIdSuffix('1 string with 1€-dollar', 'xhtml');
  3923. $this->assertEquals('1StringWith1-dollar1', $result);
  3924. $result = $this->Form->domIdSuffix('1 string with 1$-dollar', 'xhtml');
  3925. $this->assertEquals('1StringWith1-dollar2', $result);
  3926. }
  3927. /**
  3928. * testSelect method
  3929. *
  3930. * Test select element generation.
  3931. *
  3932. * @return void
  3933. */
  3934. public function testSelect() {
  3935. $result = $this->Form->select('Model.field', array());
  3936. $expected = array(
  3937. 'select' => array('name' => 'Model[field]'),
  3938. array('option' => array('value' => '')),
  3939. '/option',
  3940. '/select'
  3941. );
  3942. $this->assertTags($result, $expected);
  3943. $this->Form->request->data = array('Model' => array('field' => 'value'));
  3944. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3945. $expected = array(
  3946. 'select' => array('name' => 'Model[field]'),
  3947. array('option' => array('value' => '')),
  3948. '/option',
  3949. array('option' => array('value' => 'value', 'selected' => 'selected')),
  3950. 'good',
  3951. '/option',
  3952. array('option' => array('value' => 'other')),
  3953. 'bad',
  3954. '/option',
  3955. '/select'
  3956. );
  3957. $this->assertTags($result, $expected);
  3958. $this->Form->request->data = array();
  3959. $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
  3960. $expected = array(
  3961. 'select' => array('name' => 'Model[field]'),
  3962. array('option' => array('value' => '')),
  3963. '/option',
  3964. array('option' => array('value' => 'value')),
  3965. 'good',
  3966. '/option',
  3967. array('option' => array('value' => 'other')),
  3968. 'bad',
  3969. '/option',
  3970. '/select'
  3971. );
  3972. $this->assertTags($result, $expected);
  3973. $result = $this->Form->select(
  3974. 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
  3975. array('empty' => false)
  3976. );
  3977. $expected = array(
  3978. 'select' => array('name' => 'Model[field]'),
  3979. array('option' => array('value' => 'first')),
  3980. 'first &quot;html&quot; &lt;chars&gt;',
  3981. '/option',
  3982. array('option' => array('value' => 'second')),
  3983. 'value',
  3984. '/option',
  3985. '/select'
  3986. );
  3987. $this->assertTags($result, $expected);
  3988. $result = $this->Form->select(
  3989. 'Model.field',
  3990. array('first' => 'first "html" <chars>', 'second' => 'value'),
  3991. array('escape' => false, 'empty' => false)
  3992. );
  3993. $expected = array(
  3994. 'select' => array('name' => 'Model[field]'),
  3995. array('option' => array('value' => 'first')),
  3996. 'first "html" <chars>',
  3997. '/option',
  3998. array('option' => array('value' => 'second')),
  3999. 'value',
  4000. '/option',
  4001. '/select'
  4002. );
  4003. $this->assertTags($result, $expected);
  4004. $options = array(
  4005. array('value' => 'first', 'text' => 'First'),
  4006. array('value' => 'first', 'text' => 'Another First'),
  4007. );
  4008. $result = $this->Form->select(
  4009. 'Model.field',
  4010. $options,
  4011. array('escape' => false, 'empty' => false)
  4012. );
  4013. $expected = array(
  4014. 'select' => array('name' => 'Model[field]'),
  4015. array('option' => array('value' => 'first')),
  4016. 'First',
  4017. '/option',
  4018. array('option' => array('value' => 'first')),
  4019. 'Another First',
  4020. '/option',
  4021. '/select'
  4022. );
  4023. $this->assertTags($result, $expected);
  4024. $this->Form->request->data = array('Model' => array('contact_id' => 228));
  4025. $result = $this->Form->select(
  4026. 'Model.contact_id',
  4027. array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
  4028. array('escape' => false, 'empty' => 'pick something')
  4029. );
  4030. $expected = array(
  4031. 'select' => array('name' => 'Model[contact_id]'),
  4032. array('option' => array('value' => '')), 'pick something', '/option',
  4033. array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
  4034. array('option' => array('value' => '228-1')), '228-1 value', '/option',
  4035. array('option' => array('value' => '228-2')), '228-2 value', '/option',
  4036. '/select'
  4037. );
  4038. $this->assertTags($result, $expected);
  4039. $this->Form->request->data['Model']['field'] = 0;
  4040. $result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
  4041. $expected = array(
  4042. 'select' => array('name' => 'Model[field]'),
  4043. array('option' => array('value' => '')), '/option',
  4044. array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
  4045. array('option' => array('value' => '1')), 'Yes', '/option',
  4046. '/select'
  4047. );
  4048. $this->assertTags($result, $expected);
  4049. }
  4050. /**
  4051. * test select() with required and disabled attributes.
  4052. *
  4053. * @return void
  4054. */
  4055. public function testSelectRequired() {
  4056. $this->article['required'] = [
  4057. 'user_id' => true
  4058. ];
  4059. $this->Form->create($this->article);
  4060. $result = $this->Form->select('user_id', array('option A'));
  4061. $expected = array(
  4062. 'select' => array(
  4063. 'name' => 'user_id',
  4064. 'required' => 'required'
  4065. ),
  4066. array('option' => array('value' => '')), '/option',
  4067. array('option' => array('value' => '0')), 'option A', '/option',
  4068. '/select'
  4069. );
  4070. $this->assertTags($result, $expected);
  4071. $result = $this->Form->select('user_id', array('option A'), array('disabled' => true));
  4072. $expected = array(
  4073. 'select' => array(
  4074. 'name' => 'user_id',
  4075. 'disabled' => 'disabled'
  4076. ),
  4077. array('option' => array('value' => '')), '/option',
  4078. array('option' => array('value' => '0')), 'option A', '/option',
  4079. '/select'
  4080. );
  4081. $this->assertTags($result, $expected);
  4082. }
  4083. /**
  4084. * testNestedSelect method
  4085. *
  4086. * test select element generation with optgroups
  4087. *
  4088. * @return void
  4089. */
  4090. public function testNestedSelect() {
  4091. $this->markTestIncomplete('Need to revisit once models work again.');
  4092. $result = $this->Form->select(
  4093. 'Model.field',
  4094. array(1 => 'One', 2 => 'Two', 'Three' => array(
  4095. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  4096. )), array('empty' => false)
  4097. );
  4098. $expected = array(
  4099. 'select' => array('name' => 'Model[field]',
  4100. 'id' => 'ModelField'),
  4101. array('option' => array('value' => 1)),
  4102. 'One',
  4103. '/option',
  4104. array('option' => array('value' => 2)),
  4105. 'Two',
  4106. '/option',
  4107. array('optgroup' => array('label' => 'Three')),
  4108. array('option' => array('value' => 4)),
  4109. 'Four',
  4110. '/option',
  4111. array('option' => array('value' => 5)),
  4112. 'Five',
  4113. '/option',
  4114. '/optgroup',
  4115. '/select'
  4116. );
  4117. $this->assertTags($result, $expected);
  4118. $result = $this->Form->select(
  4119. 'Model.field',
  4120. array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')),
  4121. array('showParents' => true, 'empty' => false)
  4122. );
  4123. $expected = array(
  4124. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  4125. array('option' => array('value' => 1)),
  4126. 'One',
  4127. '/option',
  4128. array('option' => array('value' => 2)),
  4129. 'Two',
  4130. '/option',
  4131. array('optgroup' => array('label' => 'Three')),
  4132. array('option' => array('value' => 3)),
  4133. 'Three',
  4134. '/option',
  4135. array('option' => array('value' => 4)),
  4136. 'Four',
  4137. '/option',
  4138. '/optgroup',
  4139. '/select'
  4140. );
  4141. $this->assertTags($result, $expected);
  4142. }
  4143. /**
  4144. * testSelectMultiple method
  4145. *
  4146. * test generation of multiple select elements
  4147. *
  4148. * @return void
  4149. */
  4150. public function testSelectMultiple() {
  4151. $options = array('first', 'second', 'third');
  4152. $result = $this->Form->select(
  4153. 'Model.multi_field',
  4154. $options,
  4155. array('multiple' => true)
  4156. );
  4157. $expected = array(
  4158. 'input' => array(
  4159. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => ''
  4160. ),
  4161. 'select' => array(
  4162. 'name' => 'Model[multi_field][]',
  4163. 'multiple' => 'multiple'
  4164. ),
  4165. array('option' => array('value' => '0')),
  4166. 'first',
  4167. '/option',
  4168. array('option' => array('value' => '1')),
  4169. 'second',
  4170. '/option',
  4171. array('option' => array('value' => '2')),
  4172. 'third',
  4173. '/option',
  4174. '/select'
  4175. );
  4176. $this->assertTags($result, $expected);
  4177. $result = $this->Form->select(
  4178. 'Model.multi_field',
  4179. $options,
  4180. array('multiple' => 'multiple')
  4181. );
  4182. $this->assertTags($result, $expected);
  4183. }
  4184. /**
  4185. * Test that a checkbox can have 0 for the value and 1 for the hidden input.
  4186. *
  4187. * @return void
  4188. */
  4189. public function testCheckboxZeroValue() {
  4190. $this->markTestIncomplete('Need to revisit once models work again.');
  4191. $result = $this->Form->input('User.get_spam', array(
  4192. 'type' => 'checkbox',
  4193. 'value' => '0',
  4194. 'hiddenField' => '1',
  4195. ));
  4196. $expected = array(
  4197. 'div' => array('class' => 'input checkbox'),
  4198. array('input' => array(
  4199. 'type' => 'hidden', 'name' => 'data[User][get_spam]',
  4200. 'value' => '1', 'id' => 'UserGetSpam_'
  4201. )),
  4202. array('input' => array(
  4203. 'type' => 'checkbox', 'name' => 'data[User][get_spam]',
  4204. 'value' => '0', 'id' => 'UserGetSpam'
  4205. )),
  4206. 'label' => array('for' => 'UserGetSpam'),
  4207. 'Get Spam',
  4208. '/label',
  4209. '/div'
  4210. );
  4211. $this->assertTags($result, $expected);
  4212. }
  4213. /**
  4214. * test generation of habtm select boxes.
  4215. *
  4216. * @return void
  4217. */
  4218. public function testHabtmSelectBox() {
  4219. $this->markTestIncomplete('Need to revisit once models work again.');
  4220. $this->View->viewVars['contactTags'] = array(
  4221. 1 => 'blue',
  4222. 2 => 'red',
  4223. 3 => 'green'
  4224. );
  4225. $this->Form->request->data = array(
  4226. 'Contact' => array(),
  4227. 'ContactTag' => array(
  4228. array(
  4229. 'id' => '1',
  4230. 'name' => 'blue'
  4231. ),
  4232. array(
  4233. 'id' => 3,
  4234. 'name' => 'green'
  4235. )
  4236. )
  4237. );
  4238. $this->Form->create('Contact');
  4239. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4240. $expected = array(
  4241. 'input' => array(
  4242. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4243. ),
  4244. 'select' => array(
  4245. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4246. 'multiple' => 'multiple'
  4247. ),
  4248. array('option' => array('value' => '1', 'selected' => 'selected')),
  4249. 'blue',
  4250. '/option',
  4251. array('option' => array('value' => '2')),
  4252. 'red',
  4253. '/option',
  4254. array('option' => array('value' => '3', 'selected' => 'selected')),
  4255. 'green',
  4256. '/option',
  4257. '/select'
  4258. );
  4259. $this->assertTags($result, $expected);
  4260. // make sure only 50 is selected, and not 50f5c0cf
  4261. $this->View->viewVars['contactTags'] = array(
  4262. '1' => 'blue',
  4263. '50f5c0cf' => 'red',
  4264. '50' => 'green'
  4265. );
  4266. $this->Form->request->data = array(
  4267. 'Contact' => array(),
  4268. 'ContactTag' => array(
  4269. array(
  4270. 'id' => 1,
  4271. 'name' => 'blue'
  4272. ),
  4273. array(
  4274. 'id' => 50,
  4275. 'name' => 'green'
  4276. )
  4277. )
  4278. );
  4279. $this->Form->create('Contact');
  4280. $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  4281. $expected = array(
  4282. 'input' => array(
  4283. 'type' => 'hidden', 'name' => 'ContactTag[ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
  4284. ),
  4285. 'select' => array(
  4286. 'name' => 'ContactTag[ContactTag][]', 'id' => 'ContactTagContactTag',
  4287. 'multiple' => 'multiple'
  4288. ),
  4289. array('option' => array('value' => '1', 'selected' => 'selected')),
  4290. 'blue',
  4291. '/option',
  4292. array('option' => array('value' => '50f5c0cf')),
  4293. 'red',
  4294. '/option',
  4295. array('option' => array('value' => '50', 'selected' => 'selected')),
  4296. 'green',
  4297. '/option',
  4298. '/select'
  4299. );
  4300. $this->assertTags($result, $expected);
  4301. }
  4302. /**
  4303. * test generation of multi select elements in checkbox format
  4304. *
  4305. * @return void
  4306. */
  4307. public function testSelectMultipleCheckboxes() {
  4308. $this->markTestIncomplete('Need to revisit once models work again.');
  4309. $result = $this->Form->select(
  4310. 'Model.multi_field',
  4311. array('first', 'second', 'third'),
  4312. array('multiple' => 'checkbox')
  4313. );
  4314. $expected = array(
  4315. 'input' => array(
  4316. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4317. ),
  4318. array('div' => array('class' => 'checkbox')),
  4319. array('input' => array(
  4320. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4321. 'value' => '0', 'id' => 'ModelMultiField0'
  4322. )),
  4323. array('label' => array('for' => 'ModelMultiField0')),
  4324. 'first',
  4325. '/label',
  4326. '/div',
  4327. array('div' => array('class' => 'checkbox')),
  4328. array('input' => array(
  4329. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4330. 'value' => '1', 'id' => 'ModelMultiField1'
  4331. )),
  4332. array('label' => array('for' => 'ModelMultiField1')),
  4333. 'second',
  4334. '/label',
  4335. '/div',
  4336. array('div' => array('class' => 'checkbox')),
  4337. array('input' => array(
  4338. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4339. 'value' => '2', 'id' => 'ModelMultiField2'
  4340. )),
  4341. array('label' => array('for' => 'ModelMultiField2')),
  4342. 'third',
  4343. '/label',
  4344. '/div'
  4345. );
  4346. $this->assertTags($result, $expected);
  4347. $result = $this->Form->select(
  4348. 'Model.multi_field',
  4349. array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4350. array('multiple' => 'checkbox')
  4351. );
  4352. $expected = array(
  4353. 'input' => array(
  4354. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4355. ),
  4356. array('div' => array('class' => 'checkbox')),
  4357. array('input' => array(
  4358. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4359. 'value' => 'a', 'id' => 'ModelMultiFieldA'
  4360. )),
  4361. array('label' => array('for' => 'ModelMultiFieldA')),
  4362. 'first',
  4363. '/label',
  4364. '/div',
  4365. array('div' => array('class' => 'checkbox')),
  4366. array('input' => array(
  4367. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4368. 'value' => 'b', 'id' => 'ModelMultiFieldB'
  4369. )),
  4370. array('label' => array('for' => 'ModelMultiFieldB')),
  4371. 'second',
  4372. '/label',
  4373. '/div',
  4374. array('div' => array('class' => 'checkbox')),
  4375. array('input' => array(
  4376. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4377. 'value' => 'c', 'id' => 'ModelMultiFieldC'
  4378. )),
  4379. array('label' => array('for' => 'ModelMultiFieldC')),
  4380. 'third',
  4381. '/label',
  4382. '/div'
  4383. );
  4384. $this->assertTags($result, $expected);
  4385. $result = $this->Form->select(
  4386. 'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
  4387. );
  4388. $expected = array(
  4389. 'input' => array(
  4390. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4391. ),
  4392. array('div' => array('class' => 'checkbox')),
  4393. array('input' => array(
  4394. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4395. 'value' => '1', 'id' => 'ModelMultiField1'
  4396. )),
  4397. array('label' => array('for' => 'ModelMultiField1')),
  4398. 'first',
  4399. '/label',
  4400. '/div'
  4401. );
  4402. $this->assertTags($result, $expected);
  4403. $this->Form->request->data = array('Model' => array('tags' => array(1)));
  4404. $result = $this->Form->select(
  4405. 'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
  4406. );
  4407. $expected = array(
  4408. 'input' => array(
  4409. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4410. ),
  4411. array('div' => array('class' => 'checkbox')),
  4412. array('input' => array(
  4413. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4414. 'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
  4415. )),
  4416. array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
  4417. 'first',
  4418. '/label',
  4419. '/div',
  4420. array('div' => array('class' => 'checkbox')),
  4421. array('input' => array(
  4422. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4423. 'value' => 'Array', 'id' => 'ModelTagsArray'
  4424. )),
  4425. array('label' => array('for' => 'ModelTagsArray')),
  4426. 'Array',
  4427. '/label',
  4428. '/div'
  4429. );
  4430. $this->assertTags($result, $expected);
  4431. $result = $this->Form->select(
  4432. 'Model.multi_field',
  4433. array('a+' => 'first', 'a++' => 'second', 'a+++' => 'third'),
  4434. array('multiple' => 'checkbox')
  4435. );
  4436. $expected = array(
  4437. 'input' => array(
  4438. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4439. ),
  4440. array('div' => array('class' => 'checkbox')),
  4441. array('input' => array(
  4442. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4443. 'value' => 'a+', 'id' => 'ModelMultiFieldA+'
  4444. )),
  4445. array('label' => array('for' => 'ModelMultiFieldA+')),
  4446. 'first',
  4447. '/label',
  4448. '/div',
  4449. array('div' => array('class' => 'checkbox')),
  4450. array('input' => array(
  4451. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4452. 'value' => 'a++', 'id' => 'ModelMultiFieldA++'
  4453. )),
  4454. array('label' => array('for' => 'ModelMultiFieldA++')),
  4455. 'second',
  4456. '/label',
  4457. '/div',
  4458. array('div' => array('class' => 'checkbox')),
  4459. array('input' => array(
  4460. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4461. 'value' => 'a+++', 'id' => 'ModelMultiFieldA+++'
  4462. )),
  4463. array('label' => array('for' => 'ModelMultiFieldA+++')),
  4464. 'third',
  4465. '/label',
  4466. '/div'
  4467. );
  4468. $this->assertTags($result, $expected);
  4469. $result = $this->Form->select(
  4470. 'Model.multi_field',
  4471. array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
  4472. array('multiple' => 'checkbox')
  4473. );
  4474. $expected = array(
  4475. 'input' => array(
  4476. 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
  4477. ),
  4478. array('div' => array('class' => 'checkbox')),
  4479. array('input' => array(
  4480. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4481. 'value' => 'a&gt;b', 'id' => 'ModelMultiFieldAB2'
  4482. )),
  4483. array('label' => array('for' => 'ModelMultiFieldAB2')),
  4484. 'first',
  4485. '/label',
  4486. '/div',
  4487. array('div' => array('class' => 'checkbox')),
  4488. array('input' => array(
  4489. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4490. 'value' => 'a&lt;b', 'id' => 'ModelMultiFieldAB1'
  4491. )),
  4492. array('label' => array('for' => 'ModelMultiFieldAB1')),
  4493. 'second',
  4494. '/label',
  4495. '/div',
  4496. array('div' => array('class' => 'checkbox')),
  4497. array('input' => array(
  4498. 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
  4499. 'value' => 'a&quot;b', 'id' => 'ModelMultiFieldAB'
  4500. )),
  4501. array('label' => array('for' => 'ModelMultiFieldAB')),
  4502. 'third',
  4503. '/label',
  4504. '/div'
  4505. );
  4506. $this->assertTags($result, $expected);
  4507. }
  4508. /**
  4509. * test multiple checkboxes with div styles.
  4510. *
  4511. * @return void
  4512. */
  4513. public function testSelectMultipleCheckboxDiv() {
  4514. $this->markTestIncomplete('Need to revisit once models work again.');
  4515. $result = $this->Form->select(
  4516. 'Model.tags',
  4517. array('first', 'second'),
  4518. array('multiple' => 'checkbox', 'class' => 'my-class')
  4519. );
  4520. $expected = array(
  4521. 'input' => array(
  4522. 'type' => 'hidden', 'name' => 'Model[tags]', 'value' => '', 'id' => 'ModelTags'
  4523. ),
  4524. array('div' => array('class' => 'my-class')),
  4525. array('input' => array(
  4526. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4527. 'value' => '0', 'id' => 'ModelTags0'
  4528. )),
  4529. array('label' => array('for' => 'ModelTags0')), 'first', '/label',
  4530. '/div',
  4531. array('div' => array('class' => 'my-class')),
  4532. array('input' => array(
  4533. 'type' => 'checkbox', 'name' => 'Model[tags][]',
  4534. 'value' => '1', 'id' => 'ModelTags1'
  4535. )),
  4536. array('label' => array('for' => 'ModelTags1')), 'second', '/label',
  4537. '/div'
  4538. );
  4539. $this->assertTags($result, $expected);
  4540. $result = $this->Form->input('Model.tags', array(
  4541. 'options' => array('first', 'second'),
  4542. 'multiple' => 'checkbox',
  4543. 'class' => 'my-class',
  4544. 'div' => false,
  4545. 'label' => false
  4546. ));
  4547. $this->assertTags($result, $expected);
  4548. $Contact->validationErrors['tags'] = 'Select atleast one option';
  4549. $result = $this->Form->input('Contact.tags', array(
  4550. 'options' => array('one'),
  4551. 'multiple' => 'checkbox',
  4552. 'label' => false,
  4553. 'div' => false
  4554. ));
  4555. $expected = array(
  4556. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4557. array('div' => array('class' => 'checkbox form-error')),
  4558. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4559. array('label' => array('for' => 'ContactTags0')),
  4560. 'one',
  4561. '/label',
  4562. '/div'
  4563. );
  4564. $this->assertTags($result, $expected);
  4565. $result = $this->Form->input('Contact.tags', array(
  4566. 'options' => array('one'),
  4567. 'multiple' => 'checkbox',
  4568. 'class' => 'mycheckbox',
  4569. 'label' => false,
  4570. 'div' => false
  4571. ));
  4572. $expected = array(
  4573. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'Contact[tags]', 'value' => '', 'id' => 'ContactTags'),
  4574. array('div' => array('class' => 'mycheckbox form-error')),
  4575. array('input' => array('type' => 'checkbox', 'name' => 'Contact[tags][]', 'value' => '0', 'id' => 'ContactTags0')),
  4576. array('label' => array('for' => 'ContactTags0')),
  4577. 'one',
  4578. '/label',
  4579. '/div'
  4580. );
  4581. $this->assertTags($result, $expected);
  4582. }
  4583. /**
  4584. * Checks the security hash array generated for multiple-input checkbox elements
  4585. *
  4586. * @return void
  4587. */
  4588. public function testSelectMultipleCheckboxSecurity() {
  4589. $this->markTestIncomplete('Need to revisit once models work again.');
  4590. $this->Form->request->params['_csrfToken'] = 'testKey';
  4591. $this->assertEquals(array(), $this->Form->fields);
  4592. $result = $this->Form->select(
  4593. 'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
  4594. array('multiple' => 'checkbox')
  4595. );
  4596. $this->assertEquals(array('Model.multi_field'), $this->Form->fields);
  4597. $result = $this->Form->secure($this->Form->fields);
  4598. $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
  4599. $this->assertRegExp('/"' . $key . '"/', $result);
  4600. }
  4601. /**
  4602. * Multiple select elements should always be secured as they always participate
  4603. * in the POST data.
  4604. *
  4605. * @return void
  4606. */
  4607. public function testSelectMultipleSecureWithNoOptions() {
  4608. $this->Form->request->params['_Token'] = 'testkey';
  4609. $this->assertEquals(array(), $this->Form->fields);
  4610. $this->Form->select(
  4611. 'Model.select',
  4612. array(),
  4613. array('multiple' => true)
  4614. );
  4615. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4616. }
  4617. /**
  4618. * When a select box has no options it should not be added to the fields list
  4619. * as it always fail post validation.
  4620. *
  4621. * @return void
  4622. */
  4623. public function testSelectNoSecureWithNoOptions() {
  4624. $this->markTestIncomplete('Need to revisit once models work again.');
  4625. $this->Form->request->params['_csrfToken'] = 'testkey';
  4626. $this->assertEquals(array(), $this->Form->fields);
  4627. $this->Form->select(
  4628. 'Model.select',
  4629. array()
  4630. );
  4631. $this->assertEquals(array(), $this->Form->fields);
  4632. $this->Form->select(
  4633. 'Model.select',
  4634. array(),
  4635. array('empty' => true)
  4636. );
  4637. $this->assertEquals(array('Model.select'), $this->Form->fields);
  4638. }
  4639. /**
  4640. * testInputMultipleCheckboxes method
  4641. *
  4642. * test input() resulting in multi select elements being generated.
  4643. *
  4644. * @return void
  4645. */
  4646. public function testInputMultipleCheckboxes() {
  4647. $this->markTestIncomplete('Need to revisit once models work again.');
  4648. $result = $this->Form->input('Model.multi_field', array(
  4649. 'options' => array('first', 'second', 'third'),
  4650. 'multiple' => 'checkbox'
  4651. ));
  4652. $expected = array(
  4653. array('div' => array('class' => 'input select')),
  4654. array('label' => array('for' => 'ModelMultiField')),
  4655. 'Multi Field',
  4656. '/label',
  4657. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4658. array('div' => array('class' => 'checkbox')),
  4659. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4660. array('label' => array('for' => 'ModelMultiField0')),
  4661. 'first',
  4662. '/label',
  4663. '/div',
  4664. array('div' => array('class' => 'checkbox')),
  4665. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4666. array('label' => array('for' => 'ModelMultiField1')),
  4667. 'second',
  4668. '/label',
  4669. '/div',
  4670. array('div' => array('class' => 'checkbox')),
  4671. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4672. array('label' => array('for' => 'ModelMultiField2')),
  4673. 'third',
  4674. '/label',
  4675. '/div',
  4676. '/div'
  4677. );
  4678. $this->assertTags($result, $expected);
  4679. $result = $this->Form->input('Model.multi_field', array(
  4680. 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
  4681. 'multiple' => 'checkbox'
  4682. ));
  4683. $expected = array(
  4684. array('div' => array('class' => 'input select')),
  4685. array('label' => array('for' => 'ModelMultiField')),
  4686. 'Multi Field',
  4687. '/label',
  4688. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4689. array('div' => array('class' => 'checkbox')),
  4690. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
  4691. array('label' => array('for' => 'ModelMultiFieldA')),
  4692. 'first',
  4693. '/label',
  4694. '/div',
  4695. array('div' => array('class' => 'checkbox')),
  4696. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
  4697. array('label' => array('for' => 'ModelMultiFieldB')),
  4698. 'second',
  4699. '/label',
  4700. '/div',
  4701. array('div' => array('class' => 'checkbox')),
  4702. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
  4703. array('label' => array('for' => 'ModelMultiFieldC')),
  4704. 'third',
  4705. '/label',
  4706. '/div',
  4707. '/div'
  4708. );
  4709. $this->assertTags($result, $expected);
  4710. $result = $this->Form->input('Model.multi_field', array(
  4711. 'options' => array('1' => 'first'),
  4712. 'multiple' => 'checkbox',
  4713. 'label' => false,
  4714. 'div' => false
  4715. ));
  4716. $expected = array(
  4717. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4718. array('div' => array('class' => 'checkbox')),
  4719. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4720. array('label' => array('for' => 'ModelMultiField1')),
  4721. 'first',
  4722. '/label',
  4723. '/div'
  4724. );
  4725. $this->assertTags($result, $expected);
  4726. $result = $this->Form->input('Model.multi_field', array(
  4727. 'options' => array('2' => 'second'),
  4728. 'multiple' => 'checkbox',
  4729. 'label' => false,
  4730. 'div' => false
  4731. ));
  4732. $expected = array(
  4733. 'input' => array('type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
  4734. array('div' => array('class' => 'checkbox')),
  4735. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
  4736. array('label' => array('for' => 'ModelMultiField2')),
  4737. 'second',
  4738. '/label',
  4739. '/div'
  4740. );
  4741. $this->assertTags($result, $expected);
  4742. }
  4743. /**
  4744. * testSelectHiddenFieldOmission method
  4745. *
  4746. * test that select() with 'hiddenField' => false omits the hidden field
  4747. *
  4748. * @return void
  4749. */
  4750. public function testSelectHiddenFieldOmission() {
  4751. $this->markTestIncomplete('Need to revisit once models work again.');
  4752. $result = $this->Form->select('Model.multi_field',
  4753. array('first', 'second'),
  4754. array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
  4755. );
  4756. $expected = array(
  4757. array('div' => array('class' => 'checkbox')),
  4758. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4759. array('label' => array('for' => 'ModelMultiField0')),
  4760. 'first',
  4761. '/label',
  4762. '/div',
  4763. array('div' => array('class' => 'checkbox')),
  4764. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4765. array('label' => array('for' => 'ModelMultiField1')),
  4766. 'second',
  4767. '/label',
  4768. '/div'
  4769. );
  4770. $this->assertTags($result, $expected);
  4771. $result = $this->Form->input('Model.multi_field', array(
  4772. 'options' => array('first', 'second'),
  4773. 'multiple' => 'checkbox',
  4774. 'hiddenField' => false
  4775. ));
  4776. $expected = array(
  4777. array('div' => array('class' => 'input select')),
  4778. array('label' => array('for' => 'ModelMultiField')),
  4779. 'Multi Field',
  4780. '/label',
  4781. array('div' => array('class' => 'checkbox')),
  4782. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
  4783. array('label' => array('for' => 'ModelMultiField0')),
  4784. 'first',
  4785. '/label',
  4786. '/div',
  4787. array('div' => array('class' => 'checkbox')),
  4788. array('input' => array('type' => 'checkbox', 'name' => 'Model[multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
  4789. array('label' => array('for' => 'ModelMultiField1')),
  4790. 'second',
  4791. '/label',
  4792. '/div',
  4793. '/div'
  4794. );
  4795. $this->assertTags($result, $expected);
  4796. }
  4797. /**
  4798. * test that select() with multiple = checkbox works with overriding name attribute.
  4799. *
  4800. * @return void
  4801. */
  4802. public function testSelectCheckboxMultipleOverrideName() {
  4803. $this->markTestIncomplete('Need to revisit once models work again.');
  4804. $result = $this->Form->input('category', array(
  4805. 'type' => 'select',
  4806. 'multiple' => 'checkbox',
  4807. 'name' => 'fish',
  4808. 'options' => array('1', '2'),
  4809. 'div' => false,
  4810. 'label' => false,
  4811. ));
  4812. $expected = array(
  4813. 'input' => array('type' => 'hidden', 'name' => 'fish', 'value' => '', 'id' => 'category'),
  4814. array('div' => array('class' => 'checkbox')),
  4815. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '0', 'id' => 'Category0')),
  4816. array('label' => array('for' => 'Category0')), '1', '/label',
  4817. '/div',
  4818. array('div' => array('class' => 'checkbox')),
  4819. array('input' => array('type' => 'checkbox', 'name' => 'fish[]', 'value' => '1', 'id' => 'Category1')),
  4820. array('label' => array('for' => 'Category1')), '2', '/label',
  4821. '/div'
  4822. );
  4823. $this->assertTags($result, $expected);
  4824. }
  4825. /**
  4826. * Test that 'id' overrides all the checkbox id's as well.
  4827. *
  4828. * @return void
  4829. */
  4830. public function testSelectCheckboxMultipleId() {
  4831. $this->markTestIncomplete('Need to revisit once models work again.');
  4832. $result = $this->Form->select(
  4833. 'Model.multi_field',
  4834. array('first', 'second', 'third'),
  4835. array('multiple' => 'checkbox', 'id' => 'CustomId')
  4836. );
  4837. $expected = array(
  4838. 'input' => array(
  4839. 'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => '', 'id' => 'CustomId'
  4840. ),
  4841. array('div' => array('class' => 'checkbox')),
  4842. array('input' => array(
  4843. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4844. 'value' => '0', 'id' => 'CustomId0'
  4845. )),
  4846. array('label' => array('for' => 'CustomId0')),
  4847. 'first',
  4848. '/label',
  4849. '/div',
  4850. array('div' => array('class' => 'checkbox')),
  4851. array('input' => array(
  4852. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4853. 'value' => '1', 'id' => 'CustomId1'
  4854. )),
  4855. array('label' => array('for' => 'CustomId1')),
  4856. 'second',
  4857. '/label',
  4858. '/div',
  4859. array('div' => array('class' => 'checkbox')),
  4860. array('input' => array(
  4861. 'type' => 'checkbox', 'name' => 'Model[multi_field][]',
  4862. 'value' => '2', 'id' => 'CustomId2'
  4863. )),
  4864. array('label' => array('for' => 'CustomId2')),
  4865. 'third',
  4866. '/label',
  4867. '/div'
  4868. );
  4869. $this->assertTags($result, $expected);
  4870. }
  4871. /**
  4872. * testCheckbox method
  4873. *
  4874. * Test generation of checkboxes
  4875. *
  4876. * @return void
  4877. */
  4878. public function testCheckbox() {
  4879. $result = $this->Form->checkbox('Model.field');
  4880. $expected = array(
  4881. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4882. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1'))
  4883. );
  4884. $this->assertTags($result, $expected);
  4885. $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
  4886. $expected = array(
  4887. 'input' => array('type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'),
  4888. array('input' => array('type' => 'checkbox', 'name' => 'Model[field]', 'value' => 'myvalue', 'id' => 'theID'))
  4889. );
  4890. $this->assertTags($result, $expected);
  4891. }
  4892. /**
  4893. * Test checkbox being checked or having errors.
  4894. *
  4895. * @return void
  4896. */
  4897. public function testCheckboxCheckedAndError() {
  4898. $this->article['errors'] = [
  4899. 'published' => true
  4900. ];
  4901. $this->Form->request->data['published'] = 'myvalue';
  4902. $this->Form->create($this->article);
  4903. $result = $this->Form->checkbox('published', array('id' => 'theID', 'value' => 'myvalue'));
  4904. $expected = array(
  4905. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4906. array('input' => array(
  4907. 'type' => 'checkbox',
  4908. 'name' => 'published',
  4909. 'value' => 'myvalue',
  4910. 'id' => 'theID',
  4911. 'checked' => 'checked',
  4912. 'class' => 'form-error'
  4913. ))
  4914. );
  4915. $this->assertTags($result, $expected);
  4916. $this->Form->request->data['published'] = '';
  4917. $result = $this->Form->checkbox('published');
  4918. $expected = array(
  4919. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'published', 'value' => '0'),
  4920. array('input' => array('type' => 'checkbox', 'name' => 'published', 'value' => '1', 'class' => 'form-error'))
  4921. );
  4922. $this->assertTags($result, $expected);
  4923. }
  4924. /**
  4925. * test checkbox() with a custom name attribute
  4926. *
  4927. * @return void
  4928. */
  4929. public function testCheckboxCustomNameAttribute() {
  4930. $result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
  4931. $expected = array(
  4932. 'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0'),
  4933. array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1'))
  4934. );
  4935. $this->assertTags($result, $expected);
  4936. }
  4937. /**
  4938. * Test that the hidden input for checkboxes can be omitted or set to a
  4939. * specific value.
  4940. *
  4941. * @return void
  4942. */
  4943. public function testCheckboxHiddenField() {
  4944. $result = $this->Form->checkbox('UserForm.something', array(
  4945. 'hiddenField' => false
  4946. ));
  4947. $expected = array(
  4948. 'input' => array(
  4949. 'type' => 'checkbox',
  4950. 'name' => 'UserForm[something]',
  4951. 'value' => '1'
  4952. ),
  4953. );
  4954. $this->assertTags($result, $expected);
  4955. $result = $this->Form->checkbox('UserForm.something', array(
  4956. 'value' => 'Y',
  4957. 'hiddenField' => 'N',
  4958. ));
  4959. $expected = array(
  4960. array('input' => array(
  4961. 'type' => 'hidden', 'name' => 'UserForm[something]',
  4962. 'value' => 'N'
  4963. )),
  4964. array('input' => array(
  4965. 'type' => 'checkbox', 'name' => 'UserForm[something]',
  4966. 'value' => 'Y'
  4967. )),
  4968. );
  4969. $this->assertTags($result, $expected);
  4970. }
  4971. /**
  4972. * testDateTime method
  4973. *
  4974. * Test generation of date/time select elements
  4975. *
  4976. * @return void
  4977. */
  4978. public function testDateTime() {
  4979. $this->markTestIncomplete('Need to revisit once models work again.');
  4980. extract($this->dateRegex);
  4981. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  4982. $now = strtotime('now');
  4983. $expected = array(
  4984. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  4985. $daysRegex,
  4986. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  4987. date('j', $now),
  4988. '/option',
  4989. '*/select',
  4990. '-',
  4991. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  4992. $monthsRegex,
  4993. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  4994. date('F', $now),
  4995. '/option',
  4996. '*/select',
  4997. '-',
  4998. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  4999. $yearsRegex,
  5000. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5001. date('Y', $now),
  5002. '/option',
  5003. '*/select',
  5004. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5005. $hoursRegex,
  5006. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5007. date('g', $now),
  5008. '/option',
  5009. '*/select',
  5010. ':',
  5011. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5012. $minutesRegex,
  5013. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  5014. date('i', $now),
  5015. '/option',
  5016. '*/select',
  5017. ' ',
  5018. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5019. $meridianRegex,
  5020. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  5021. date('a', $now),
  5022. '/option',
  5023. '*/select'
  5024. );
  5025. $this->assertTags($result, $expected);
  5026. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  5027. $expected = array(
  5028. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5029. $daysRegex,
  5030. array('option' => array('value' => '')),
  5031. '/option',
  5032. '*/select',
  5033. '-',
  5034. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5035. $monthsRegex,
  5036. array('option' => array('value' => '')),
  5037. '/option',
  5038. '*/select',
  5039. '-',
  5040. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5041. $yearsRegex,
  5042. array('option' => array('value' => '')),
  5043. '/option',
  5044. '*/select',
  5045. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5046. $hoursRegex,
  5047. array('option' => array('value' => '')),
  5048. '/option',
  5049. '*/select',
  5050. ':',
  5051. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5052. $minutesRegex,
  5053. array('option' => array('value' => '')),
  5054. '/option',
  5055. '*/select',
  5056. ' ',
  5057. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5058. $meridianRegex,
  5059. array('option' => array('value' => '')),
  5060. '/option',
  5061. '*/select'
  5062. );
  5063. $this->assertTags($result, $expected);
  5064. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5065. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
  5066. $this->assertTags($result, $expected);
  5067. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5068. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
  5069. $this->assertTags($result, $expected);
  5070. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5071. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
  5072. $expected = array(
  5073. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5074. $daysRegex,
  5075. array('option' => array('value' => '')),
  5076. '/option',
  5077. '*/select',
  5078. '-',
  5079. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5080. $monthsRegex,
  5081. array('option' => array('value' => '')),
  5082. '/option',
  5083. '*/select',
  5084. '-',
  5085. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5086. $yearsRegex,
  5087. array('option' => array('value' => '')),
  5088. '/option',
  5089. '*/select',
  5090. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5091. $hoursRegex,
  5092. array('option' => array('value' => '')),
  5093. '/option',
  5094. '*/select',
  5095. ':',
  5096. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5097. $minutesRegex,
  5098. array('option' => array('value' => '')),
  5099. '/option',
  5100. array('option' => array('value' => '00')),
  5101. '00',
  5102. '/option',
  5103. array('option' => array('value' => '05')),
  5104. '05',
  5105. '/option',
  5106. array('option' => array('value' => '10')),
  5107. '10',
  5108. '/option',
  5109. '*/select',
  5110. ' ',
  5111. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5112. $meridianRegex,
  5113. array('option' => array('value' => '')),
  5114. '/option',
  5115. '*/select'
  5116. );
  5117. $this->assertTags($result, $expected);
  5118. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5119. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5120. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
  5121. $this->Form->request->data['Contact']['data'] = null;
  5122. $result = $this->Form->dateTime('Contact.date', 'DMY', '12');
  5123. $expected = array(
  5124. array('select' => array('name' => 'Contact[date][day]', 'id' => 'ContactDateDay')),
  5125. $daysRegex,
  5126. array('option' => array('value' => '')),
  5127. '/option',
  5128. '*/select',
  5129. '-',
  5130. array('select' => array('name' => 'Contact[date][month]', 'id' => 'ContactDateMonth')),
  5131. $monthsRegex,
  5132. array('option' => array('value' => '')),
  5133. '/option',
  5134. '*/select',
  5135. '-',
  5136. array('select' => array('name' => 'Contact[date][year]', 'id' => 'ContactDateYear')),
  5137. $yearsRegex,
  5138. array('option' => array('value' => '')),
  5139. '/option',
  5140. '*/select',
  5141. array('select' => array('name' => 'Contact[date][hour]', 'id' => 'ContactDateHour')),
  5142. $hoursRegex,
  5143. array('option' => array('value' => '')),
  5144. '/option',
  5145. '*/select',
  5146. ':',
  5147. array('select' => array('name' => 'Contact[date][min]', 'id' => 'ContactDateMin')),
  5148. $minutesRegex,
  5149. array('option' => array('value' => '')),
  5150. '/option',
  5151. '*/select',
  5152. ' ',
  5153. array('select' => array('name' => 'Contact[date][meridian]', 'id' => 'ContactDateMeridian')),
  5154. $meridianRegex,
  5155. array('option' => array('value' => '')),
  5156. '/option',
  5157. '*/select'
  5158. );
  5159. $this->assertTags($result, $expected);
  5160. $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
  5161. $this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
  5162. $now = strtotime($this->Form->data['Model']['field']);
  5163. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
  5164. $expected = array(
  5165. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5166. $daysRegex,
  5167. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5168. date('j', $now),
  5169. '/option',
  5170. '*/select',
  5171. '-',
  5172. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5173. $monthsRegex,
  5174. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5175. date('F', $now),
  5176. '/option',
  5177. '*/select',
  5178. '-',
  5179. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5180. $yearsRegex,
  5181. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5182. date('Y', $now),
  5183. '/option',
  5184. '*/select',
  5185. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5186. $hoursRegex,
  5187. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5188. date('g', $now),
  5189. '/option',
  5190. '*/select',
  5191. ':',
  5192. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5193. $minutesRegex,
  5194. array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
  5195. date('i', $now),
  5196. '/option',
  5197. '*/select',
  5198. ' ',
  5199. array('select' => array('name' => 'Model[field][meridian]', 'id' => 'ModelFieldMeridian')),
  5200. $meridianRegex,
  5201. array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
  5202. date('a', $now),
  5203. '/option',
  5204. '*/select'
  5205. );
  5206. $this->assertTags($result, $expected);
  5207. $selected = strtotime('2008-10-26 12:33:00');
  5208. $result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
  5209. $this->assertRegExp('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
  5210. $this->assertRegExp('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
  5211. $this->assertRegExp('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
  5212. $this->assertRegExp('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
  5213. $this->assertRegExp('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
  5214. $this->assertRegExp('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
  5215. $this->Form->create('Contact');
  5216. $result = $this->Form->input('published');
  5217. $now = strtotime('now');
  5218. $expected = array(
  5219. 'div' => array('class' => 'input date'),
  5220. 'label' => array('for' => 'ContactPublishedMonth'),
  5221. 'Published',
  5222. '/label',
  5223. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5224. $monthsRegex,
  5225. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5226. date('F', $now),
  5227. '/option',
  5228. '*/select',
  5229. '-',
  5230. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5231. $daysRegex,
  5232. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5233. date('j', $now),
  5234. '/option',
  5235. '*/select',
  5236. '-',
  5237. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5238. $yearsRegex,
  5239. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5240. date('Y', $now),
  5241. '/option',
  5242. '*/select',
  5243. '/div'
  5244. );
  5245. $this->assertTags($result, $expected);
  5246. $result = $this->Form->input('published2', array('type' => 'date'));
  5247. $now = strtotime('now');
  5248. $expected = array(
  5249. 'div' => array('class' => 'input date'),
  5250. 'label' => array('for' => 'ContactPublished2Month'),
  5251. 'Published2',
  5252. '/label',
  5253. array('select' => array('name' => 'Contact[published2][month]', 'id' => 'ContactPublished2Month')),
  5254. $monthsRegex,
  5255. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5256. date('F', $now),
  5257. '/option',
  5258. '*/select',
  5259. '-',
  5260. array('select' => array('name' => 'Contact[published2][day]', 'id' => 'ContactPublished2Day')),
  5261. $daysRegex,
  5262. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5263. date('j', $now),
  5264. '/option',
  5265. '*/select',
  5266. '-',
  5267. array('select' => array('name' => 'Contact[published2][year]', 'id' => 'ContactPublished2Year')),
  5268. $yearsRegex,
  5269. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5270. date('Y', $now),
  5271. '/option',
  5272. '*/select',
  5273. '/div'
  5274. );
  5275. $this->assertTags($result, $expected);
  5276. $this->Form->create('Contact');
  5277. $result = $this->Form->input('published', array('monthNames' => false));
  5278. $now = strtotime('now');
  5279. $expected = array(
  5280. 'div' => array('class' => 'input date'),
  5281. 'label' => array('for' => 'ContactPublishedMonth'),
  5282. 'Published',
  5283. '/label',
  5284. array('select' => array('name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth')),
  5285. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5286. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  5287. date('m', $now),
  5288. '/option',
  5289. '*/select',
  5290. '-',
  5291. array('select' => array('name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay')),
  5292. $daysRegex,
  5293. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  5294. date('j', $now),
  5295. '/option',
  5296. '*/select',
  5297. '-',
  5298. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5299. $yearsRegex,
  5300. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  5301. date('Y', $now),
  5302. '/option',
  5303. '*/select',
  5304. '/div'
  5305. );
  5306. $this->assertTags($result, $expected);
  5307. $result = $this->Form->input('published', array('type' => 'time'));
  5308. $now = strtotime('now');
  5309. $expected = array(
  5310. 'div' => array('class' => 'input time'),
  5311. 'label' => array('for' => 'ContactPublishedHour'),
  5312. 'Published',
  5313. '/label',
  5314. array('select' => array('name' => 'Contact[published][hour]', 'id' => 'ContactPublishedHour')),
  5315. 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
  5316. array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
  5317. date('g', $now),
  5318. '/option',
  5319. '*/select',
  5320. ':',
  5321. );
  5322. $this->assertTags($result, $expected);
  5323. $result = $this->Form->input('published', array(
  5324. 'timeFormat' => 24,
  5325. 'interval' => 5,
  5326. 'selected' => strtotime('2009-09-03 13:37:00'),
  5327. 'type' => 'datetime'
  5328. ));
  5329. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5330. $this->assertRegExp('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
  5331. $this->assertRegExp('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
  5332. $this->assertRegExp('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
  5333. $this->assertRegExp('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
  5334. }
  5335. /**
  5336. * Test dateTime with rounding
  5337. *
  5338. * @return void
  5339. */
  5340. public function testDateTimeRounding() {
  5341. $this->markTestIncomplete('Need to revisit once models work again.');
  5342. $this->Form->request->data['Contact'] = array(
  5343. 'date' => array(
  5344. 'day' => '13',
  5345. 'month' => '12',
  5346. 'year' => '2010',
  5347. 'hour' => '04',
  5348. 'min' => '19',
  5349. 'meridian' => 'AM'
  5350. )
  5351. );
  5352. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
  5353. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5354. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
  5355. $this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
  5356. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
  5357. $this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
  5358. }
  5359. /**
  5360. * Test that empty values don't trigger errors.
  5361. *
  5362. * @return void
  5363. */
  5364. public function testDateTimeNoErrorsOnEmptyData() {
  5365. $this->markTestIncomplete('Need to revisit once models work again.');
  5366. $this->Form->request->data['Contact'] = array(
  5367. 'date' => array(
  5368. 'day' => '',
  5369. 'month' => '',
  5370. 'year' => '',
  5371. 'hour' => '',
  5372. 'min' => '',
  5373. 'meridian' => ''
  5374. )
  5375. );
  5376. $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
  5377. $this->assertNotEmpty($result);
  5378. }
  5379. /**
  5380. * test that datetime() and default values work.
  5381. *
  5382. * @return void
  5383. */
  5384. public function testDatetimeWithDefault() {
  5385. $this->markTestIncomplete('Need to revisit once models work again.');
  5386. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
  5387. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5388. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5389. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5390. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
  5391. 'default' => '2009-06-01 11:15:30'
  5392. ));
  5393. $this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
  5394. $this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
  5395. $this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
  5396. }
  5397. /**
  5398. * test that bogus non-date time data doesn't cause errors.
  5399. *
  5400. * @return void
  5401. */
  5402. public function testDateTimeWithBogusData() {
  5403. $this->markTestIncomplete('Need to revisit once models work again.');
  5404. $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
  5405. $this->assertNotRegExp('/selected="selected">\d/', $result);
  5406. }
  5407. /**
  5408. * testDateTime all zeros
  5409. *
  5410. * @return void
  5411. */
  5412. public function testDateTimeAllZeros() {
  5413. $this->markTestIncomplete('Need to revisit once models work again.');
  5414. $result = $this->Form->dateTime('Contact.date',
  5415. 'DMY',
  5416. false,
  5417. array(
  5418. 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
  5419. 'value' => '0000-00-00'
  5420. )
  5421. );
  5422. $this->assertRegExp('/<option value="">-<\/option>/', $result);
  5423. $this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
  5424. }
  5425. /**
  5426. * testDateTimeEmptyAsArray
  5427. *
  5428. * @return void
  5429. */
  5430. public function testDateTimeEmptyAsArray() {
  5431. $this->markTestIncomplete('Need to revisit once models work again.');
  5432. $result = $this->Form->dateTime('Contact.date',
  5433. 'DMY',
  5434. '12',
  5435. array(
  5436. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
  5437. 'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
  5438. )
  5439. )
  5440. );
  5441. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5442. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5443. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5444. $this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
  5445. $this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
  5446. $this->assertNotRegExp('/<option value=""><\/option>/', $result);
  5447. $result = $this->Form->dateTime('Contact.date',
  5448. 'DMY',
  5449. '12',
  5450. array(
  5451. 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
  5452. )
  5453. );
  5454. $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
  5455. $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
  5456. $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
  5457. $this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
  5458. $this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
  5459. $this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
  5460. }
  5461. /**
  5462. * testFormDateTimeMulti method
  5463. *
  5464. * test multiple datetime element generation
  5465. *
  5466. * @return void
  5467. */
  5468. public function testFormDateTimeMulti() {
  5469. $this->markTestIncomplete('Need to revisit once models work again.');
  5470. extract($this->dateRegex);
  5471. $result = $this->Form->dateTime('Contact.1.updated');
  5472. $expected = array(
  5473. array('select' => array('name' => 'Contact[1][updated][day]', 'id' => 'Contact1UpdatedDay')),
  5474. $daysRegex,
  5475. array('option' => array('value' => '')),
  5476. '/option',
  5477. '*/select',
  5478. '-',
  5479. array('select' => array('name' => 'Contact[1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
  5480. $monthsRegex,
  5481. array('option' => array('value' => '')),
  5482. '/option',
  5483. '*/select',
  5484. '-',
  5485. array('select' => array('name' => 'Contact[1][updated][year]', 'id' => 'Contact1UpdatedYear')),
  5486. $yearsRegex,
  5487. array('option' => array('value' => '')),
  5488. '/option',
  5489. '*/select',
  5490. array('select' => array('name' => 'Contact[1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
  5491. $hoursRegex,
  5492. array('option' => array('value' => '')),
  5493. '/option',
  5494. '*/select',
  5495. ':',
  5496. array('select' => array('name' => 'Contact[1][updated][min]', 'id' => 'Contact1UpdatedMin')),
  5497. $minutesRegex,
  5498. array('option' => array('value' => '')),
  5499. '/option',
  5500. '*/select',
  5501. ' ',
  5502. array('select' => array('name' => 'Contact[1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
  5503. $meridianRegex,
  5504. array('option' => array('value' => '')),
  5505. '/option',
  5506. '*/select'
  5507. );
  5508. $this->assertTags($result, $expected);
  5509. $result = $this->Form->dateTime('Contact.2.updated');
  5510. $expected = array(
  5511. array('select' => array('name' => 'Contact[2][updated][day]', 'id' => 'Contact2UpdatedDay')),
  5512. $daysRegex,
  5513. array('option' => array('value' => '')),
  5514. '/option',
  5515. '*/select',
  5516. '-',
  5517. array('select' => array('name' => 'Contact[2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
  5518. $monthsRegex,
  5519. array('option' => array('value' => '')),
  5520. '/option',
  5521. '*/select',
  5522. '-',
  5523. array('select' => array('name' => 'Contact[2][updated][year]', 'id' => 'Contact2UpdatedYear')),
  5524. $yearsRegex,
  5525. array('option' => array('value' => '')),
  5526. '/option',
  5527. '*/select',
  5528. array('select' => array('name' => 'Contact[2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
  5529. $hoursRegex,
  5530. array('option' => array('value' => '')),
  5531. '/option',
  5532. '*/select',
  5533. ':',
  5534. array('select' => array('name' => 'Contact[2][updated][min]', 'id' => 'Contact2UpdatedMin')),
  5535. $minutesRegex,
  5536. array('option' => array('value' => '')),
  5537. '/option',
  5538. '*/select',
  5539. ' ',
  5540. array('select' => array('name' => 'Contact[2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
  5541. $meridianRegex,
  5542. array('option' => array('value' => '')),
  5543. '/option',
  5544. '*/select'
  5545. );
  5546. $this->assertTags($result, $expected);
  5547. }
  5548. /**
  5549. * When changing the date format, the label should always focus the first select box when
  5550. * clicked.
  5551. *
  5552. * @return void
  5553. */
  5554. public function testDateTimeLabelIdMatchesFirstInput() {
  5555. $this->markTestIncomplete('Need to revisit once models work again.');
  5556. $result = $this->Form->input('Model.date', array('type' => 'date'));
  5557. $this->assertContains('label for="ModelDateMonth"', $result);
  5558. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
  5559. $this->assertContains('label for="ModelDateDay"', $result);
  5560. $result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
  5561. $this->assertContains('label for="ModelDateYear"', $result);
  5562. }
  5563. /**
  5564. * testMonth method
  5565. *
  5566. * @return void
  5567. */
  5568. public function testMonth() {
  5569. $this->markTestIncomplete('Need to revisit once models work again.');
  5570. $result = $this->Form->month('Model.field');
  5571. $expected = array(
  5572. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5573. array('option' => array('value' => '')),
  5574. '/option',
  5575. array('option' => array('value' => '01')),
  5576. date('F', strtotime('2008-01-01 00:00:00')),
  5577. '/option',
  5578. array('option' => array('value' => '02')),
  5579. date('F', strtotime('2008-02-01 00:00:00')),
  5580. '/option',
  5581. '*/select',
  5582. );
  5583. $this->assertTags($result, $expected);
  5584. $result = $this->Form->month('Model.field', array('empty' => true));
  5585. $expected = array(
  5586. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5587. array('option' => array('value' => '')),
  5588. '/option',
  5589. array('option' => array('value' => '01')),
  5590. date('F', strtotime('2008-01-01 00:00:00')),
  5591. '/option',
  5592. array('option' => array('value' => '02')),
  5593. date('F', strtotime('2008-02-01 00:00:00')),
  5594. '/option',
  5595. '*/select',
  5596. );
  5597. $this->assertTags($result, $expected);
  5598. $result = $this->Form->month('Model.field', array('monthNames' => false));
  5599. $expected = array(
  5600. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5601. array('option' => array('value' => '')),
  5602. '/option',
  5603. array('option' => array('value' => '01')),
  5604. '01',
  5605. '/option',
  5606. array('option' => array('value' => '02')),
  5607. '02',
  5608. '/option',
  5609. '*/select',
  5610. );
  5611. $this->assertTags($result, $expected);
  5612. $monthNames = array(
  5613. '01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
  5614. '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
  5615. $result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
  5616. $expected = array(
  5617. array('select' => array('name' => 'Model[field][month]', 'id' => 'ModelFieldMonth')),
  5618. array('option' => array('value' => '')),
  5619. '/option',
  5620. array('option' => array('value' => '01')),
  5621. 'Jan',
  5622. '/option',
  5623. array('option' => array('value' => '02')),
  5624. 'Feb',
  5625. '/option',
  5626. '*/select',
  5627. );
  5628. $this->assertTags($result, $expected);
  5629. $this->Form->request->data['Project']['release'] = '2050-02-10';
  5630. $result = $this->Form->month('Project.release');
  5631. $expected = array(
  5632. array('select' => array('name' => 'Project[release][month]', 'id' => 'ProjectReleaseMonth')),
  5633. array('option' => array('value' => '')),
  5634. '/option',
  5635. array('option' => array('value' => '01')),
  5636. 'January',
  5637. '/option',
  5638. array('option' => array('value' => '02', 'selected' => 'selected')),
  5639. 'February',
  5640. '/option',
  5641. '*/select',
  5642. );
  5643. $this->assertTags($result, $expected);
  5644. }
  5645. /**
  5646. * testDay method
  5647. *
  5648. * @return void
  5649. */
  5650. public function testDay() {
  5651. $this->markTestIncomplete('Need to revisit once models work again.');
  5652. extract($this->dateRegex);
  5653. $result = $this->Form->day('Model.field', array('value' => false));
  5654. $expected = array(
  5655. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5656. array('option' => array('value' => '')),
  5657. '/option',
  5658. array('option' => array('value' => '01')),
  5659. '1',
  5660. '/option',
  5661. array('option' => array('value' => '02')),
  5662. '2',
  5663. '/option',
  5664. $daysRegex,
  5665. '/select',
  5666. );
  5667. $this->assertTags($result, $expected);
  5668. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5669. $result = $this->Form->day('Model.field');
  5670. $expected = array(
  5671. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5672. array('option' => array('value' => '')),
  5673. '/option',
  5674. array('option' => array('value' => '01')),
  5675. '1',
  5676. '/option',
  5677. array('option' => array('value' => '02')),
  5678. '2',
  5679. '/option',
  5680. $daysRegex,
  5681. array('option' => array('value' => '10', 'selected' => 'selected')),
  5682. '10',
  5683. '/option',
  5684. $daysRegex,
  5685. '/select',
  5686. );
  5687. $this->assertTags($result, $expected);
  5688. $this->Form->request->data['Model']['field'] = '';
  5689. $result = $this->Form->day('Model.field', array('value' => '10'));
  5690. $expected = array(
  5691. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5692. array('option' => array('value' => '')),
  5693. '/option',
  5694. array('option' => array('value' => '01')),
  5695. '1',
  5696. '/option',
  5697. array('option' => array('value' => '02')),
  5698. '2',
  5699. '/option',
  5700. $daysRegex,
  5701. array('option' => array('value' => '10', 'selected' => 'selected')),
  5702. '10',
  5703. '/option',
  5704. $daysRegex,
  5705. '/select',
  5706. );
  5707. $this->assertTags($result, $expected);
  5708. $this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
  5709. $result = $this->Form->day('Model.field', array('value' => true));
  5710. $expected = array(
  5711. array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
  5712. array('option' => array('value' => '')),
  5713. '/option',
  5714. array('option' => array('value' => '01')),
  5715. '1',
  5716. '/option',
  5717. array('option' => array('value' => '02')),
  5718. '2',
  5719. '/option',
  5720. $daysRegex,
  5721. array('option' => array('value' => '10', 'selected' => 'selected')),
  5722. '10',
  5723. '/option',
  5724. $daysRegex,
  5725. '/select',
  5726. );
  5727. $this->assertTags($result, $expected);
  5728. $this->Form->request->data['Project']['release'] = '2050-10-10';
  5729. $result = $this->Form->day('Project.release');
  5730. $expected = array(
  5731. array('select' => array('name' => 'Project[release][day]', 'id' => 'ProjectReleaseDay')),
  5732. array('option' => array('value' => '')),
  5733. '/option',
  5734. array('option' => array('value' => '01')),
  5735. '1',
  5736. '/option',
  5737. array('option' => array('value' => '02')),
  5738. '2',
  5739. '/option',
  5740. $daysRegex,
  5741. array('option' => array('value' => '10', 'selected' => 'selected')),
  5742. '10',
  5743. '/option',
  5744. $daysRegex,
  5745. '/select',
  5746. );
  5747. $this->assertTags($result, $expected);
  5748. }
  5749. /**
  5750. * testMinute method
  5751. *
  5752. * @return void
  5753. */
  5754. public function testMinute() {
  5755. $this->markTestIncomplete('Need to revisit once models work again.');
  5756. extract($this->dateRegex);
  5757. $result = $this->Form->minute('Model.field');
  5758. $expected = array(
  5759. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5760. array('option' => array('value' => '')),
  5761. '/option',
  5762. array('option' => array('value' => '00')),
  5763. '00',
  5764. '/option',
  5765. array('option' => array('value' => '01')),
  5766. '01',
  5767. '/option',
  5768. array('option' => array('value' => '02')),
  5769. '02',
  5770. '/option',
  5771. $minutesRegex,
  5772. '/select',
  5773. );
  5774. $this->assertTags($result, $expected);
  5775. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5776. $result = $this->Form->minute('Model.field');
  5777. $expected = array(
  5778. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5779. array('option' => array('value' => '')),
  5780. '/option',
  5781. array('option' => array('value' => '00')),
  5782. '00',
  5783. '/option',
  5784. array('option' => array('value' => '01')),
  5785. '01',
  5786. '/option',
  5787. array('option' => array('value' => '02')),
  5788. '02',
  5789. '/option',
  5790. $minutesRegex,
  5791. array('option' => array('value' => '12', 'selected' => 'selected')),
  5792. '12',
  5793. '/option',
  5794. $minutesRegex,
  5795. '/select',
  5796. );
  5797. $this->assertTags($result, $expected);
  5798. $this->Form->request->data['Model']['field'] = '';
  5799. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5800. $expected = array(
  5801. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5802. array('option' => array('value' => '')),
  5803. '/option',
  5804. array('option' => array('value' => '00')),
  5805. '00',
  5806. '/option',
  5807. array('option' => array('value' => '05')),
  5808. '05',
  5809. '/option',
  5810. array('option' => array('value' => '10')),
  5811. '10',
  5812. '/option',
  5813. $minutesRegex,
  5814. '/select',
  5815. );
  5816. $this->assertTags($result, $expected);
  5817. $this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
  5818. $result = $this->Form->minute('Model.field', array('interval' => 5));
  5819. $expected = array(
  5820. array('select' => array('name' => 'Model[field][min]', 'id' => 'ModelFieldMin')),
  5821. array('option' => array('value' => '')),
  5822. '/option',
  5823. array('option' => array('value' => '00')),
  5824. '00',
  5825. '/option',
  5826. array('option' => array('value' => '05')),
  5827. '05',
  5828. '/option',
  5829. array('option' => array('value' => '10', 'selected' => 'selected')),
  5830. '10',
  5831. '/option',
  5832. $minutesRegex,
  5833. '/select',
  5834. );
  5835. $this->assertTags($result, $expected);
  5836. }
  5837. /**
  5838. * testHour method
  5839. *
  5840. * @return void
  5841. */
  5842. public function testHour() {
  5843. $this->markTestIncomplete('Need to revisit once models work again.');
  5844. extract($this->dateRegex);
  5845. $result = $this->Form->hour('Model.field', false);
  5846. $expected = array(
  5847. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5848. array('option' => array('value' => '')),
  5849. '/option',
  5850. array('option' => array('value' => '01')),
  5851. '1',
  5852. '/option',
  5853. array('option' => array('value' => '02')),
  5854. '2',
  5855. '/option',
  5856. $hoursRegex,
  5857. '/select',
  5858. );
  5859. $this->assertTags($result, $expected);
  5860. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5861. $result = $this->Form->hour('Model.field', false);
  5862. $expected = array(
  5863. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5864. array('option' => array('value' => '')),
  5865. '/option',
  5866. array('option' => array('value' => '01')),
  5867. '1',
  5868. '/option',
  5869. array('option' => array('value' => '02')),
  5870. '2',
  5871. '/option',
  5872. $hoursRegex,
  5873. array('option' => array('value' => '12', 'selected' => 'selected')),
  5874. '12',
  5875. '/option',
  5876. '/select',
  5877. );
  5878. $this->assertTags($result, $expected);
  5879. $this->Form->request->data['Model']['field'] = '';
  5880. $result = $this->Form->hour('Model.field', true, array('value' => '23'));
  5881. $this->assertContains('<option value="23" selected="selected">23</option>', $result);
  5882. $result = $this->Form->hour('Model.field', false, array('value' => '23'));
  5883. $this->assertContains('<option value="11" selected="selected">11</option>', $result);
  5884. $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
  5885. $result = $this->Form->hour('Model.field', true);
  5886. $expected = array(
  5887. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5888. array('option' => array('value' => '')),
  5889. '/option',
  5890. array('option' => array('value' => '00', 'selected' => 'selected')),
  5891. '0',
  5892. '/option',
  5893. array('option' => array('value' => '01')),
  5894. '1',
  5895. '/option',
  5896. array('option' => array('value' => '02')),
  5897. '2',
  5898. '/option',
  5899. $hoursRegex,
  5900. '/select',
  5901. );
  5902. $this->assertTags($result, $expected);
  5903. unset($this->Form->request->data['Model']['field']);
  5904. $result = $this->Form->hour('Model.field', true, array('value' => 'now'));
  5905. $thisHour = date('H');
  5906. $optValue = date('G');
  5907. $this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
  5908. $this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
  5909. $result = $this->Form->hour('Model.field', true);
  5910. $expected = array(
  5911. array('select' => array('name' => 'Model[field][hour]', 'id' => 'ModelFieldHour')),
  5912. array('option' => array('value' => '')),
  5913. '/option',
  5914. array('option' => array('value' => '00')),
  5915. '0',
  5916. '/option',
  5917. array('option' => array('value' => '01', 'selected' => 'selected')),
  5918. '1',
  5919. '/option',
  5920. array('option' => array('value' => '02')),
  5921. '2',
  5922. '/option',
  5923. $hoursRegex,
  5924. '/select',
  5925. );
  5926. $this->assertTags($result, $expected);
  5927. }
  5928. /**
  5929. * testYear method
  5930. *
  5931. * @return void
  5932. */
  5933. public function testYear() {
  5934. $this->markTestIncomplete('Need to revisit once models work again.');
  5935. $result = $this->Form->year('Model.field', 2006, 2007);
  5936. $expected = array(
  5937. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5938. array('option' => array('value' => '')),
  5939. '/option',
  5940. array('option' => array('value' => '2007')),
  5941. '2007',
  5942. '/option',
  5943. array('option' => array('value' => '2006')),
  5944. '2006',
  5945. '/option',
  5946. '/select',
  5947. );
  5948. $this->assertTags($result, $expected);
  5949. $result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
  5950. $expected = array(
  5951. array('select' => array('name' => 'Model[field][year]', 'id' => 'ModelFieldYear')),
  5952. array('option' => array('value' => '')),
  5953. '/option',
  5954. array('option' => array('value' => '2006')),
  5955. '2006',
  5956. '/option',
  5957. array('option' => array('value' => '2007')),
  5958. '2007',
  5959. '/option',
  5960. '/select',
  5961. );
  5962. $this->assertTags($result, $expected);
  5963. $this->request->data['Contact']['published'] = '';
  5964. $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
  5965. $expected = array(
  5966. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
  5967. array('option' => array('value' => '')),
  5968. '/option',
  5969. array('option' => array('value' => '2007')),
  5970. '2007',
  5971. '/option',
  5972. array('option' => array('value' => '2006')),
  5973. '2006',
  5974. '/option',
  5975. '/select',
  5976. );
  5977. $this->assertTags($result, $expected);
  5978. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  5979. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
  5980. $expected = array(
  5981. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5982. array('option' => array('value' => '2007')),
  5983. '2007',
  5984. '/option',
  5985. array('option' => array('value' => '2006', 'selected' => 'selected')),
  5986. '2006',
  5987. '/option',
  5988. '/select',
  5989. );
  5990. $this->assertTags($result, $expected);
  5991. $this->Form->request->data['Contact']['published'] = '';
  5992. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
  5993. $expected = array(
  5994. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  5995. array('option' => array('value' => '')),
  5996. '/option',
  5997. array('option' => array('value' => '2007')),
  5998. '2007',
  5999. '/option',
  6000. array('option' => array('value' => '2006')),
  6001. '2006',
  6002. '/option',
  6003. '/select',
  6004. );
  6005. $this->assertTags($result, $expected);
  6006. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6007. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
  6008. $expected = array(
  6009. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6010. array('option' => array('value' => '2007')),
  6011. '2007',
  6012. '/option',
  6013. array('option' => array('value' => '2006', 'selected' => 'selected')),
  6014. '2006',
  6015. '/option',
  6016. '/select',
  6017. );
  6018. $this->assertTags($result, $expected);
  6019. $this->Form->request->data['Contact']['published'] = '';
  6020. $result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
  6021. $expected = array(
  6022. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6023. array('option' => array('value' => '')),
  6024. '/option',
  6025. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6026. '2007',
  6027. '/option',
  6028. array('option' => array('value' => '2006')),
  6029. '2006',
  6030. '/option',
  6031. '/select',
  6032. );
  6033. $this->assertTags($result, $expected);
  6034. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6035. $result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
  6036. $expected = array(
  6037. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6038. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6039. '2007',
  6040. '/option',
  6041. array('option' => array('value' => '2006')),
  6042. '2006',
  6043. '/option',
  6044. '/select',
  6045. );
  6046. $this->assertTags($result, $expected);
  6047. $this->Form->request->data['Contact']['published'] = '';
  6048. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
  6049. $expected = array(
  6050. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6051. array('option' => array('value' => '2008')),
  6052. '2008',
  6053. '/option',
  6054. array('option' => array('value' => '2007', 'selected' => 'selected')),
  6055. '2007',
  6056. '/option',
  6057. array('option' => array('value' => '2006')),
  6058. '2006',
  6059. '/option',
  6060. '/select',
  6061. );
  6062. $this->assertTags($result, $expected);
  6063. $this->Form->request->data['Contact']['published'] = '2006-10-10';
  6064. $result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
  6065. $expected = array(
  6066. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6067. array('option' => array('value' => '2008')),
  6068. '2008',
  6069. '/option',
  6070. array('option' => array('value' => '2007')),
  6071. '2007',
  6072. '/option',
  6073. array('option' => array('value' => '2006', 'selected' => 'selected')),
  6074. '2006',
  6075. '/option',
  6076. '/select',
  6077. );
  6078. $this->assertTags($result, $expected);
  6079. $this->Form->request->data = array();
  6080. $this->Form->create('Contact');
  6081. $result = $this->Form->year('published', 2006, 2008, array('empty' => false));
  6082. $expected = array(
  6083. array('select' => array('name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear')),
  6084. array('option' => array('value' => '2008')),
  6085. '2008',
  6086. '/option',
  6087. array('option' => array('value' => '2007')),
  6088. '2007',
  6089. '/option',
  6090. array('option' => array('value' => '2006')),
  6091. '2006',
  6092. '/option',
  6093. '/select',
  6094. );
  6095. $this->assertTags($result, $expected);
  6096. $result = $this->Form->year('published', array(), array(), array('empty' => false));
  6097. $this->assertContains('Contact[published][year]', $result);
  6098. }
  6099. /**
  6100. * testYearAutoExpandRange method
  6101. *
  6102. * @return void
  6103. */
  6104. public function testYearAutoExpandRange() {
  6105. $this->markTestIncomplete('Need to revisit once models work again.');
  6106. $this->Form->request->data['User']['birthday'] = '1930-10-10';
  6107. $result = $this->Form->year('User.birthday');
  6108. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6109. $result = $matches[1];
  6110. $expected = range(date('Y') + 20, 1930);
  6111. $this->assertEquals($expected, $result);
  6112. $this->Form->request->data['Project']['release'] = '2050-10-10';
  6113. $result = $this->Form->year('Project.release');
  6114. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6115. $result = $matches[1];
  6116. $expected = range(2050, date('Y') - 20);
  6117. $this->assertEquals($expected, $result);
  6118. $this->Form->request->data['Project']['release'] = '1881-10-10';
  6119. $result = $this->Form->year('Project.release', 1890, 1900);
  6120. preg_match_all('/<option value="([\d]+)"/', $result, $matches);
  6121. $result = $matches[1];
  6122. $expected = range(1900, 1881);
  6123. $this->assertEquals($expected, $result);
  6124. }
  6125. /**
  6126. * testInputDate method
  6127. *
  6128. * Test various inputs with type date and different dateFormat values.
  6129. * Failing to provide a dateFormat key should not error.
  6130. * It should simply not pre-select any value then.
  6131. *
  6132. * @return void
  6133. */
  6134. public function testInputDate() {
  6135. $this->markTestIncomplete('Need to revisit once models work again.');
  6136. $this->Form->request->data = array(
  6137. 'User' => array(
  6138. 'month_year' => array('month' => date('m')),
  6139. 'just_year' => array('month' => date('m')),
  6140. 'just_month' => array('year' => date('Y')),
  6141. 'just_day' => array('month' => date('m')),
  6142. )
  6143. );
  6144. $this->Form->create('User');
  6145. $result = $this->Form->input('month_year',
  6146. array(
  6147. 'label' => false,
  6148. 'div' => false,
  6149. 'type' => 'date',
  6150. 'dateFormat' => 'MY',
  6151. 'minYear' => 2006,
  6152. 'maxYear' => 2008
  6153. )
  6154. );
  6155. $this->assertContains('value="' . date('m') . '" selected="selected"', $result);
  6156. $this->assertNotContains('value="2008" selected="selected"', $result);
  6157. $result = $this->Form->input('just_year',
  6158. array(
  6159. 'type' => 'date',
  6160. 'label' => false,
  6161. 'dateFormat' => 'Y',
  6162. 'minYear' => date('Y'),
  6163. 'maxYear' => date('Y', strtotime('+20 years'))
  6164. )
  6165. );
  6166. $this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
  6167. $result = $this->Form->input('just_month',
  6168. array(
  6169. 'type' => 'date',
  6170. 'label' => false,
  6171. 'dateFormat' => 'M',
  6172. 'empty' => false,
  6173. )
  6174. );
  6175. $this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
  6176. $result = $this->Form->input('just_day',
  6177. array(
  6178. 'type' => 'date',
  6179. 'label' => false,
  6180. 'dateFormat' => 'D',
  6181. 'empty' => false,
  6182. )
  6183. );
  6184. $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
  6185. }
  6186. /**
  6187. * testInputDateMaxYear method
  6188. *
  6189. * Let's say we want to only allow users born from 2006 to 2008 to register
  6190. * This being the first singup page, we still don't have any data
  6191. *
  6192. * @return void
  6193. */
  6194. public function testInputDateMaxYear() {
  6195. $this->markTestIncomplete('Need to revisit once models work again.');
  6196. $this->Form->request->data = array();
  6197. $this->Form->create('User');
  6198. $result = $this->Form->input('birthday',
  6199. array(
  6200. 'label' => false,
  6201. 'div' => false,
  6202. 'type' => 'date',
  6203. 'dateFormat' => 'DMY',
  6204. 'minYear' => 2006,
  6205. 'maxYear' => 2008
  6206. )
  6207. );
  6208. $this->assertContains('value="2008" selected="selected"', $result);
  6209. }
  6210. /**
  6211. * testTextArea method
  6212. *
  6213. * @return void
  6214. */
  6215. public function testTextArea() {
  6216. $this->Form->request->data = array('field' => 'some test data');
  6217. $result = $this->Form->textarea('field');
  6218. $expected = array(
  6219. 'textarea' => array('name' => 'field'),
  6220. 'some test data',
  6221. '/textarea',
  6222. );
  6223. $this->assertTags($result, $expected);
  6224. $result = $this->Form->textarea('user.bio');
  6225. $expected = array(
  6226. 'textarea' => array('name' => 'user[bio]'),
  6227. '/textarea',
  6228. );
  6229. $this->assertTags($result, $expected);
  6230. $this->Form->request->data = array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars');
  6231. $result = $this->Form->textarea('field');
  6232. $expected = array(
  6233. 'textarea' => array('name' => 'field'),
  6234. htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
  6235. '/textarea',
  6236. );
  6237. $this->assertTags($result, $expected);
  6238. $this->Form->request->data = [
  6239. 'Model' => ['field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars']
  6240. ];
  6241. $result = $this->Form->textarea('Model.field', ['escape' => false]);
  6242. $expected = array(
  6243. 'textarea' => array('name' => 'Model[field]'),
  6244. 'some <strong>test</strong> data with <a href="#">HTML</a> chars',
  6245. '/textarea',
  6246. );
  6247. $this->assertTags($result, $expected);
  6248. $result = $this->Form->textarea('0.OtherModel.field');
  6249. $expected = array(
  6250. 'textarea' => array('name' => '0[OtherModel][field]'),
  6251. '/textarea'
  6252. );
  6253. $this->assertTags($result, $expected);
  6254. }
  6255. /**
  6256. * testTextAreaWithStupidCharacters method
  6257. *
  6258. * test text area with non-ascii characters
  6259. *
  6260. * @return void
  6261. */
  6262. public function testTextAreaWithStupidCharacters() {
  6263. $result = $this->Form->textarea('Post.content', [
  6264. 'value' => "GREAT®",
  6265. 'rows' => '15',
  6266. 'cols' => '75'
  6267. ]);
  6268. $expected = [
  6269. 'textarea' => ['name' => 'Post[content]', 'rows' => '15', 'cols' => '75'],
  6270. 'GREAT®',
  6271. '/textarea',
  6272. ];
  6273. $this->assertTags($result, $expected);
  6274. }
  6275. /**
  6276. * testHiddenField method
  6277. *
  6278. * @return void
  6279. */
  6280. public function testHiddenField() {
  6281. $this->article['errors'] = [
  6282. 'field' => true
  6283. ];
  6284. $this->Form->request->data['field'] = 'test';
  6285. $this->Form->create($this->article);
  6286. $result = $this->Form->hidden('field', array('id' => 'theID'));
  6287. $this->assertTags($result, array(
  6288. 'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'id' => 'theID', 'value' => 'test'))
  6289. );
  6290. $result = $this->Form->hidden('field', ['value' => 'my value']);
  6291. $expected = [
  6292. 'input' => ['type' => 'hidden', 'class' => 'form-error', 'name' => 'field', 'value' => 'my value']
  6293. ];
  6294. $this->assertTags($result, $expected);
  6295. }
  6296. /**
  6297. * testFileUploadField method
  6298. *
  6299. * @return void
  6300. */
  6301. public function testFileUploadField() {
  6302. $this->markTestIncomplete('Need to revisit once models work again.');
  6303. $result = $this->Form->file('Model.upload');
  6304. $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload')));
  6305. $this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
  6306. $result = $this->Form->input('Model.upload', array('type' => 'file'));
  6307. $expected = array(
  6308. 'div' => array('class' => 'input file'),
  6309. 'label' => array('for' => 'ModelUpload'),
  6310. 'Upload',
  6311. '/label',
  6312. 'input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload'),
  6313. '/div'
  6314. );
  6315. $this->assertTags($result, $expected);
  6316. $this->Form->request->data['Model']['upload'] = 'no data should be set in value';
  6317. $result = $this->Form->file('Model.upload');
  6318. $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload')));
  6319. }
  6320. /**
  6321. * test File upload input on a model not used in create();
  6322. *
  6323. * @return void
  6324. */
  6325. public function testFileUploadOnOtherModel() {
  6326. $this->markTestIncomplete('Need to revisit once models work again.');
  6327. $this->Form->create('ValidateUser', array('type' => 'file'));
  6328. $result = $this->Form->file('ValidateProfile.city');
  6329. $expected = array(
  6330. 'input' => array('type' => 'file', 'name' => 'ValidateProfile[city]', 'id' => 'ValidateProfileCity')
  6331. );
  6332. $this->assertTags($result, $expected);
  6333. }
  6334. /**
  6335. * testButton method
  6336. *
  6337. * @return void
  6338. */
  6339. public function testButton() {
  6340. $result = $this->Form->button('Hi');
  6341. $this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
  6342. $result = $this->Form->button('Clear Form >', array('type' => 'reset'));
  6343. $this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
  6344. $result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
  6345. $this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
  6346. $result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
  6347. $this->assertTags($result, array('button' => array('type' => 'reset'), '&lt;Clear Form&gt;', '/button'));
  6348. $result = $this->Form->button('No type', array('type' => false));
  6349. $this->assertTags($result, array('button' => array(), 'No type', '/button'));
  6350. $result = $this->Form->button('Upload Text', array(
  6351. 'onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'",
  6352. 'escape' => false
  6353. ));
  6354. $this->assertNotRegExp('/\&039/', $result);
  6355. }
  6356. /**
  6357. * Test that button() makes unlocked fields by default.
  6358. *
  6359. * @return void
  6360. */
  6361. public function testButtonUnlockedByDefault() {
  6362. $this->Form->request->params['_csrfToken'] = 'secured';
  6363. $this->Form->button('Save', array('name' => 'save'));
  6364. $this->Form->button('Clear');
  6365. $result = $this->Form->unlockField();
  6366. $this->assertEquals(array('save'), $result);
  6367. }
  6368. /**
  6369. * testPostButton method
  6370. *
  6371. * @return void
  6372. */
  6373. public function testPostButton() {
  6374. $result = $this->Form->postButton('Hi', '/controller/action');
  6375. $this->assertTags($result, array(
  6376. 'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
  6377. 'div' => array('style' => 'display:none;'),
  6378. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6379. '/div',
  6380. 'button' => array('type' => 'submit'),
  6381. 'Hi',
  6382. '/button',
  6383. '/form'
  6384. ));
  6385. $result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
  6386. $this->assertTrue(strpos($result, '<input type="hidden" name="extra" value="value"') !== false);
  6387. }
  6388. /**
  6389. * Test that postButton adds _Token fields.
  6390. *
  6391. * @return void
  6392. */
  6393. public function testSecurePostButton() {
  6394. $this->Form->request->params['_csrfToken'] = 'testkey';
  6395. $this->Form->request->params['_Token'] = ['unlockedFields' => []];
  6396. $result = $this->Form->postButton('Delete', '/posts/delete/1');
  6397. $expected = array(
  6398. 'form' => array(
  6399. 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
  6400. ),
  6401. array('div' => array('style' => 'display:none;')),
  6402. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6403. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6404. '/div',
  6405. 'button' => array('type' => 'submit'),
  6406. 'Delete',
  6407. '/button',
  6408. array('div' => array('style' => 'display:none;')),
  6409. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6410. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6411. '/div',
  6412. '/form',
  6413. );
  6414. $this->assertTags($result, $expected);
  6415. }
  6416. /**
  6417. * testPostLink method
  6418. *
  6419. * @return void
  6420. */
  6421. public function testPostLink() {
  6422. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6423. $this->assertTags($result, array(
  6424. 'form' => array(
  6425. 'method' => 'post', 'action' => '/posts/delete/1',
  6426. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6427. ),
  6428. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6429. '/form',
  6430. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6431. 'Delete',
  6432. '/a'
  6433. ));
  6434. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
  6435. $this->assertTags($result, array(
  6436. 'form' => array(
  6437. 'method' => 'post', 'action' => '/posts/delete/1',
  6438. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6439. ),
  6440. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
  6441. '/form',
  6442. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6443. 'Delete',
  6444. '/a'
  6445. ));
  6446. $result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
  6447. $this->assertTags($result, array(
  6448. 'form' => array(
  6449. 'method' => 'post', 'action' => '/posts/delete/1',
  6450. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6451. ),
  6452. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6453. '/form',
  6454. 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\(&quot;Confirm\?&quot;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6455. 'Delete',
  6456. '/a'
  6457. ));
  6458. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
  6459. $this->assertTags($result, array(
  6460. 'form' => array(
  6461. 'method' => 'post', 'action' => '/posts/delete/1',
  6462. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6463. ),
  6464. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6465. '/form',
  6466. 'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\(&quot;&#039;Confirm&#039; this \\\\&quot;deletion\\\\&quot;\?&quot;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6467. 'Delete',
  6468. '/a'
  6469. ));
  6470. $result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
  6471. $this->assertContains('<input type="hidden" name="id" value="1"', $result);
  6472. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
  6473. $this->assertTags($result, array(
  6474. 'form' => array(
  6475. 'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
  6476. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6477. ),
  6478. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6479. '/form',
  6480. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6481. 'Delete',
  6482. '/a'
  6483. ));
  6484. $result = $this->Form->postLink(
  6485. '',
  6486. array('controller' => 'items', 'action' => 'delete', 10),
  6487. array('class' => 'btn btn-danger', 'escape' => false),
  6488. 'Confirm thing'
  6489. );
  6490. $this->assertTags($result, array(
  6491. 'form' => array(
  6492. 'method' => 'post', 'action' => '/items/delete/10',
  6493. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6494. ),
  6495. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6496. '/form',
  6497. 'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\&quot\;Confirm thing\&quot\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
  6498. '/a'
  6499. ));
  6500. }
  6501. /**
  6502. * test creating postLinks after a GET form.
  6503. *
  6504. * @return void
  6505. */
  6506. public function testPostLinkAfterGetForm() {
  6507. $this->Form->request->params['_csrfToken'] = 'testkey';
  6508. $this->Form->request->params['_Token'] = 'val';
  6509. $this->Form->create($this->article, array('type' => 'get'));
  6510. $this->Form->end();
  6511. $result = $this->Form->postLink('Delete', '/posts/delete/1');
  6512. $this->assertTags($result, array(
  6513. 'form' => array(
  6514. 'method' => 'post', 'action' => '/posts/delete/1',
  6515. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6516. ),
  6517. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
  6518. array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
  6519. 'div' => array('style' => 'display:none;'),
  6520. array('input' => array('type' => 'hidden', 'name' => '_Token[fields]', 'value' => 'preg:/[\w\d%]+/')),
  6521. array('input' => array('type' => 'hidden', 'name' => '_Token[unlocked]', 'value' => '')),
  6522. '/div',
  6523. '/form',
  6524. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6525. 'Delete',
  6526. '/a'
  6527. ));
  6528. }
  6529. /**
  6530. * Test that postLink adds form tags to view block
  6531. *
  6532. * @return void
  6533. */
  6534. public function testPostLinkFormBuffer() {
  6535. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
  6536. $this->assertTags($result, array(
  6537. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6538. 'Delete',
  6539. '/a'
  6540. ));
  6541. $result = $this->View->fetch('postLink');
  6542. $this->assertTags($result, array(
  6543. 'form' => array(
  6544. 'method' => 'post', 'action' => '/posts/delete/1',
  6545. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6546. ),
  6547. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6548. '/form'
  6549. ));
  6550. $result = $this->Form->postLink('Delete', '/posts/delete/2',
  6551. array('inline' => false, 'method' => 'DELETE')
  6552. );
  6553. $this->assertTags($result, array(
  6554. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6555. 'Delete',
  6556. '/a'
  6557. ));
  6558. $result = $this->View->fetch('postLink');
  6559. $this->assertTags($result, array(
  6560. 'form' => array(
  6561. 'method' => 'post', 'action' => '/posts/delete/1',
  6562. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6563. ),
  6564. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6565. '/form',
  6566. array(
  6567. 'form' => array(
  6568. 'method' => 'post', 'action' => '/posts/delete/2',
  6569. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6570. ),
  6571. ),
  6572. array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
  6573. '/form'
  6574. ));
  6575. $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'foobar'));
  6576. $this->assertTags($result, array(
  6577. 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
  6578. 'Delete',
  6579. '/a'
  6580. ));
  6581. $result = $this->View->fetch('foobar');
  6582. $this->assertTags($result, array(
  6583. 'form' => array(
  6584. 'method' => 'post', 'action' => '/posts/delete/1',
  6585. 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
  6586. ),
  6587. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  6588. '/form'
  6589. ));
  6590. }
  6591. /**
  6592. * testSubmitButton method
  6593. *
  6594. * @return void
  6595. */
  6596. public function testSubmitButton() {
  6597. $this->markTestIncomplete('Need to revisit once models work again.');
  6598. $result = $this->Form->submit('');
  6599. $expected = array(
  6600. 'div' => array('class' => 'submit'),
  6601. 'input' => array('type' => 'submit', 'value' => ''),
  6602. '/div'
  6603. );
  6604. $this->assertTags($result, $expected);
  6605. $result = $this->Form->submit('Test Submit');
  6606. $expected = array(
  6607. 'div' => array('class' => 'submit'),
  6608. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6609. '/div'
  6610. );
  6611. $this->assertTags($result, $expected);
  6612. $result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
  6613. $expected = array(
  6614. 'span' => array('class' => 'submit'),
  6615. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6616. '/span'
  6617. );
  6618. $this->assertTags($result, $expected);
  6619. $result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
  6620. $expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
  6621. $this->assertTags($result, $expected);
  6622. $result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
  6623. $expected = array(
  6624. 'div' => array('class' => 'submit', 'id' => 'SaveButton'),
  6625. 'input' => array('type' => 'submit', 'value' => 'Test Submit'),
  6626. '/div'
  6627. );
  6628. $this->assertTags($result, $expected);
  6629. $result = $this->Form->submit('Next >');
  6630. $expected = array(
  6631. 'div' => array('class' => 'submit'),
  6632. 'input' => array('type' => 'submit', 'value' => 'Next &gt;'),
  6633. '/div'
  6634. );
  6635. $this->assertTags($result, $expected);
  6636. $result = $this->Form->submit('Next >', array('escape' => false));
  6637. $expected = array(
  6638. 'div' => array('class' => 'submit'),
  6639. 'input' => array('type' => 'submit', 'value' => 'Next >'),
  6640. '/div'
  6641. );
  6642. $this->assertTags($result, $expected);
  6643. $result = $this->Form->submit('Reset!', array('type' => 'reset'));
  6644. $expected = array(
  6645. 'div' => array('class' => 'submit'),
  6646. 'input' => array('type' => 'reset', 'value' => 'Reset!'),
  6647. '/div'
  6648. );
  6649. $this->assertTags($result, $expected);
  6650. $before = '--before--';
  6651. $after = '--after--';
  6652. $result = $this->Form->submit('Test', array('before' => $before));
  6653. $expected = array(
  6654. 'div' => array('class' => 'submit'),
  6655. '--before--',
  6656. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6657. '/div'
  6658. );
  6659. $this->assertTags($result, $expected);
  6660. $result = $this->Form->submit('Test', array('after' => $after));
  6661. $expected = array(
  6662. 'div' => array('class' => 'submit'),
  6663. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6664. '--after--',
  6665. '/div'
  6666. );
  6667. $this->assertTags($result, $expected);
  6668. $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
  6669. $expected = array(
  6670. 'div' => array('class' => 'submit'),
  6671. '--before--',
  6672. 'input' => array('type' => 'submit', 'value' => 'Test'),
  6673. '--after--',
  6674. '/div'
  6675. );
  6676. $this->assertTags($result, $expected);
  6677. }
  6678. /**
  6679. * test image submit types.
  6680. *
  6681. * @return void
  6682. */
  6683. public function testSubmitImage() {
  6684. $this->markTestIncomplete('Need to revisit once models work again.');
  6685. $result = $this->Form->submit('http://example.com/cake.power.gif');
  6686. $expected = array(
  6687. 'div' => array('class' => 'submit'),
  6688. 'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
  6689. '/div'
  6690. );
  6691. $this->assertTags($result, $expected);
  6692. $result = $this->Form->submit('/relative/cake.power.gif');
  6693. $expected = array(
  6694. 'div' => array('class' => 'submit'),
  6695. 'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
  6696. '/div'
  6697. );
  6698. $this->assertTags($result, $expected);
  6699. $result = $this->Form->submit('cake.power.gif');
  6700. $expected = array(
  6701. 'div' => array('class' => 'submit'),
  6702. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6703. '/div'
  6704. );
  6705. $this->assertTags($result, $expected);
  6706. $result = $this->Form->submit('Not.an.image');
  6707. $expected = array(
  6708. 'div' => array('class' => 'submit'),
  6709. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6710. '/div'
  6711. );
  6712. $this->assertTags($result, $expected);
  6713. $after = '--after--';
  6714. $before = '--before--';
  6715. $result = $this->Form->submit('cake.power.gif', array('after' => $after));
  6716. $expected = array(
  6717. 'div' => array('class' => 'submit'),
  6718. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6719. '--after--',
  6720. '/div'
  6721. );
  6722. $this->assertTags($result, $expected);
  6723. $result = $this->Form->submit('cake.power.gif', array('before' => $before));
  6724. $expected = array(
  6725. 'div' => array('class' => 'submit'),
  6726. '--before--',
  6727. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6728. '/div'
  6729. );
  6730. $this->assertTags($result, $expected);
  6731. $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
  6732. $expected = array(
  6733. 'div' => array('class' => 'submit'),
  6734. '--before--',
  6735. 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
  6736. '--after--',
  6737. '/div'
  6738. );
  6739. $this->assertTags($result, $expected);
  6740. $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
  6741. $expected = array(
  6742. 'div' => array('class' => 'submit'),
  6743. '--before--',
  6744. 'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
  6745. '--after--',
  6746. '/div'
  6747. );
  6748. $this->assertTags($result, $expected);
  6749. }
  6750. /**
  6751. * Submit buttons should be unlocked by default as there could be multiples, and only one will
  6752. * be submitted at a time.
  6753. *
  6754. * @return void
  6755. */
  6756. public function testSubmitUnlockedByDefault() {
  6757. $this->markTestIncomplete('Need to revisit once models work again.');
  6758. $this->Form->request->params['_csrfToken'] = 'secured';
  6759. $this->Form->submit('Go go');
  6760. $this->Form->submit('Save', array('name' => 'save'));
  6761. $result = $this->Form->unlockField();
  6762. $this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
  6763. }
  6764. /**
  6765. * Test submit image with timestamps.
  6766. *
  6767. * @return void
  6768. */
  6769. public function testSubmitImageTimestamp() {
  6770. $this->markTestIncomplete('Need to revisit once models work again.');
  6771. Configure::write('Asset.timestamp', 'force');
  6772. $result = $this->Form->submit('cake.power.gif');
  6773. $expected = array(
  6774. 'div' => array('class' => 'submit'),
  6775. 'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
  6776. '/div'
  6777. );
  6778. $this->assertTags($result, $expected);
  6779. }
  6780. /**
  6781. * test that datetime() works with GET style forms.
  6782. *
  6783. * @return void
  6784. */
  6785. public function testDateTimeWithGetForms() {
  6786. $this->markTestIncomplete('Need to revisit once models work again.');
  6787. extract($this->dateRegex);
  6788. $this->Form->create('Contact', array('type' => 'get'));
  6789. $result = $this->Form->datetime('created');
  6790. $this->assertRegExp('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
  6791. $this->assertRegExp('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
  6792. $this->assertRegExp('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
  6793. $this->assertRegExp('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
  6794. $this->assertRegExp('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
  6795. $this->assertRegExp('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
  6796. }
  6797. /**
  6798. * testEditFormWithData method
  6799. *
  6800. * test auto populating form elements from submitted data.
  6801. *
  6802. * @return void
  6803. */
  6804. public function testEditFormWithData() {
  6805. $this->markTestIncomplete('Need to revisit once models work again.');
  6806. $this->Form->request->data = array('Person' => array(
  6807. 'id' => 1,
  6808. 'first_name' => 'Nate',
  6809. 'last_name' => 'Abele',
  6810. 'email' => 'nate@example.com'
  6811. ));
  6812. $this->Form->request->addParams(array(
  6813. 'models' => array('Person'),
  6814. 'controller' => 'people',
  6815. 'action' => 'add'
  6816. ));
  6817. $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
  6818. $this->Form->create();
  6819. $result = $this->Form->select('People.People', $options, array('multiple' => true));
  6820. $expected = array(
  6821. 'input' => array('type' => 'hidden', 'name' => 'People[People]', 'value' => '', 'id' => 'PeoplePeople_'),
  6822. 'select' => array(
  6823. 'name' => 'People[People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
  6824. ),
  6825. array('option' => array('value' => 1)), 'Nate', '/option',
  6826. array('option' => array('value' => 2)), 'Garrett', '/option',
  6827. array('option' => array('value' => 3)), 'Larry', '/option',
  6828. '/select'
  6829. );
  6830. $this->assertTags($result, $expected);
  6831. }
  6832. /**
  6833. * Test that required fields are created for various types of validation.
  6834. *
  6835. * @return void
  6836. */
  6837. public function testFormInputRequiredDetection() {
  6838. $this->markTestIncomplete('Need to revisit once models work again.');
  6839. $this->Form->create('Contact');
  6840. $result = $this->Form->input('Contact.non_existing');
  6841. $expected = array(
  6842. 'div' => array('class' => 'input text'),
  6843. 'label' => array('for' => 'ContactNonExisting'),
  6844. 'Non Existing',
  6845. '/label',
  6846. 'input' => array(
  6847. 'type' => 'text', 'name' => 'Contact[non_existing]',
  6848. 'id' => 'ContactNonExisting'
  6849. ),
  6850. '/div'
  6851. );
  6852. $this->assertTags($result, $expected);
  6853. $result = $this->Form->input('Contact.imrequired');
  6854. $expected = array(
  6855. 'div' => array('class' => 'input text required'),
  6856. 'label' => array('for' => 'ContactImrequired'),
  6857. 'Imrequired',
  6858. '/label',
  6859. 'input' => array(
  6860. 'type' => 'text', 'name' => 'Contact[imrequired]',
  6861. 'id' => 'ContactImrequired',
  6862. 'required' => 'required'
  6863. ),
  6864. '/div'
  6865. );
  6866. $this->assertTags($result, $expected);
  6867. $result = $this->Form->input('Contact.imalsorequired');
  6868. $expected = array(
  6869. 'div' => array('class' => 'input text required'),
  6870. 'label' => array('for' => 'ContactImalsorequired'),
  6871. 'Imalsorequired',
  6872. '/label',
  6873. 'input' => array(
  6874. 'type' => 'text', 'name' => 'Contact[imalsorequired]',
  6875. 'id' => 'ContactImalsorequired',
  6876. 'required' => 'required'
  6877. ),
  6878. '/div'
  6879. );
  6880. $this->assertTags($result, $expected);
  6881. $result = $this->Form->input('Contact.imrequiredtoo');
  6882. $expected = array(
  6883. 'div' => array('class' => 'input text required'),
  6884. 'label' => array('for' => 'ContactImrequiredtoo'),
  6885. 'Imrequiredtoo',
  6886. '/label',
  6887. 'input' => array(
  6888. 'type' => 'text', 'name' => 'Contact[imrequiredtoo]',
  6889. 'id' => 'ContactImrequiredtoo',
  6890. 'required' => 'required'
  6891. ),
  6892. '/div'
  6893. );
  6894. $this->assertTags($result, $expected);
  6895. $result = $this->Form->input('Contact.required_one');
  6896. $expected = array(
  6897. 'div' => array('class' => 'input text required'),
  6898. 'label' => array('for' => 'ContactRequiredOne'),
  6899. 'Required One',
  6900. '/label',
  6901. 'input' => array(
  6902. 'type' => 'text', 'name' => 'Contact[required_one]',
  6903. 'id' => 'ContactRequiredOne',
  6904. 'required' => 'required'
  6905. ),
  6906. '/div'
  6907. );
  6908. $this->assertTags($result, $expected);
  6909. $result = $this->Form->input('Contact.string_required');
  6910. $expected = array(
  6911. 'div' => array('class' => 'input text required'),
  6912. 'label' => array('for' => 'ContactStringRequired'),
  6913. 'String Required',
  6914. '/label',
  6915. 'input' => array(
  6916. 'type' => 'text', 'name' => 'Contact[string_required]',
  6917. 'id' => 'ContactStringRequired',
  6918. 'required' => 'required'
  6919. ),
  6920. '/div'
  6921. );
  6922. $this->assertTags($result, $expected);
  6923. $result = $this->Form->input('Contact.imnotrequired');
  6924. $expected = array(
  6925. 'div' => array('class' => 'input text'),
  6926. 'label' => array('for' => 'ContactImnotrequired'),
  6927. 'Imnotrequired',
  6928. '/label',
  6929. 'input' => array(
  6930. 'type' => 'text', 'name' => 'Contact[imnotrequired]',
  6931. 'id' => 'ContactImnotrequired'
  6932. ),
  6933. '/div'
  6934. );
  6935. $this->assertTags($result, $expected);
  6936. $result = $this->Form->input('Contact.imalsonotrequired');
  6937. $expected = array(
  6938. 'div' => array('class' => 'input text'),
  6939. 'label' => array('for' => 'ContactImalsonotrequired'),
  6940. 'Imalsonotrequired',
  6941. '/label',
  6942. 'input' => array(
  6943. 'type' => 'text', 'name' => 'Contact[imalsonotrequired]',
  6944. 'id' => 'ContactImalsonotrequired'
  6945. ),
  6946. '/div'
  6947. );
  6948. $this->assertTags($result, $expected);
  6949. $result = $this->Form->input('Contact.imalsonotrequired2');
  6950. $expected = array(
  6951. 'div' => array('class' => 'input text'),
  6952. 'label' => array('for' => 'ContactImalsonotrequired2'),
  6953. 'Imalsonotrequired2',
  6954. '/label',
  6955. 'input' => array(
  6956. 'type' => 'text', 'name' => 'Contact[imalsonotrequired2]',
  6957. 'id' => 'ContactImalsonotrequired2'
  6958. ),
  6959. '/div'
  6960. );
  6961. $this->assertTags($result, $expected);
  6962. $result = $this->Form->input('Contact.imnotrequiredeither');
  6963. $expected = array(
  6964. 'div' => array('class' => 'input text'),
  6965. 'label' => array('for' => 'ContactImnotrequiredeither'),
  6966. 'Imnotrequiredeither',
  6967. '/label',
  6968. 'input' => array(
  6969. 'type' => 'text', 'name' => 'Contact[imnotrequiredeither]',
  6970. 'id' => 'ContactImnotrequiredeither'
  6971. ),
  6972. '/div'
  6973. );
  6974. $this->assertTags($result, $expected);
  6975. $result = $this->Form->input('Contact.iamrequiredalways');
  6976. $expected = array(
  6977. 'div' => array('class' => 'input text required'),
  6978. 'label' => array('for' => 'ContactIamrequiredalways'),
  6979. 'Iamrequiredalways',
  6980. '/label',
  6981. 'input' => array(
  6982. 'type' => 'text', 'name' => 'Contact[iamrequiredalways]',
  6983. 'id' => 'ContactIamrequiredalways',
  6984. 'required' => 'required'
  6985. ),
  6986. '/div'
  6987. );
  6988. $this->assertTags($result, $expected);
  6989. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
  6990. $expected = array(
  6991. 'div' => array('class' => 'input checkbox required'),
  6992. array('input' => array(
  6993. 'type' => 'hidden',
  6994. 'name' => 'Contact[boolean_field]',
  6995. 'id' => 'ContactBooleanField_',
  6996. 'value' => '0'
  6997. )),
  6998. array('input' => array(
  6999. 'type' => 'checkbox',
  7000. 'name' => 'Contact[boolean_field]',
  7001. 'value' => '1',
  7002. 'id' => 'ContactBooleanField'
  7003. )),
  7004. 'label' => array('for' => 'ContactBooleanField'),
  7005. 'Boolean Field',
  7006. '/label',
  7007. '/div'
  7008. );
  7009. $this->assertTags($result, $expected);
  7010. $result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
  7011. $expected = array(
  7012. 'div' => array('class' => 'input checkbox required'),
  7013. array('input' => array(
  7014. 'type' => 'hidden',
  7015. 'name' => 'Contact[boolean_field]',
  7016. 'id' => 'ContactBooleanField_',
  7017. 'value' => '0'
  7018. )),
  7019. array('input' => array(
  7020. 'type' => 'checkbox',
  7021. 'name' => 'Contact[boolean_field]',
  7022. 'value' => '1',
  7023. 'id' => 'ContactBooleanField',
  7024. 'required' => 'required'
  7025. )),
  7026. 'label' => array('for' => 'ContactBooleanField'),
  7027. 'Boolean Field',
  7028. '/label',
  7029. '/div'
  7030. );
  7031. $this->assertTags($result, $expected);
  7032. $result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
  7033. $expected = array(
  7034. 'div' => array('class' => 'input file required'),
  7035. 'label' => array('for' => 'ContactIamrequiredalways'),
  7036. 'Iamrequiredalways',
  7037. '/label',
  7038. 'input' => array(
  7039. 'type' => 'file',
  7040. 'name' => 'data[Contact][iamrequiredalways]',
  7041. 'id' => 'ContactIamrequiredalways',
  7042. 'required' => 'required'
  7043. ),
  7044. '/div'
  7045. );
  7046. $this->assertTags($result, $expected);
  7047. }
  7048. /**
  7049. * Test that required fields are created when only using ModelValidator::add().
  7050. *
  7051. * @return void
  7052. */
  7053. public function testFormInputRequiredDetectionModelValidator() {
  7054. $this->markTestIncomplete('Need to revisit once models work again.');
  7055. $this->Form->create('ContactTag');
  7056. $result = $this->Form->input('ContactTag.iwillberequired');
  7057. $expected = array(
  7058. 'div' => array('class' => 'input text required'),
  7059. 'label' => array('for' => 'ContactTagIwillberequired'),
  7060. 'Iwillberequired',
  7061. '/label',
  7062. 'input' => array(
  7063. 'name' => 'data[ContactTag][iwillberequired]',
  7064. 'type' => 'text',
  7065. 'id' => 'ContactTagIwillberequired',
  7066. 'required' => 'required'
  7067. ),
  7068. '/div'
  7069. );
  7070. $this->assertTags($result, $expected);
  7071. }
  7072. /**
  7073. * testFormMagicInput method
  7074. *
  7075. * @return void
  7076. */
  7077. public function testFormMagicInput() {
  7078. $this->markTestIncomplete('Need to revisit once models work again.');
  7079. $encoding = strtolower(Configure::read('App.encoding'));
  7080. $result = $this->Form->create('Contact');
  7081. $expected = array(
  7082. 'form' => array(
  7083. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7084. 'accept-charset' => $encoding
  7085. ),
  7086. 'div' => array('style' => 'display:none;'),
  7087. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7088. '/div'
  7089. );
  7090. $this->assertTags($result, $expected);
  7091. $result = $this->Form->input('name');
  7092. $expected = array(
  7093. 'div' => array('class' => 'input text'),
  7094. 'label' => array('for' => 'ContactName'),
  7095. 'Name',
  7096. '/label',
  7097. 'input' => array(
  7098. 'type' => 'text', 'name' => 'Contact[name]',
  7099. 'id' => 'ContactName', 'maxlength' => '255'
  7100. ),
  7101. '/div'
  7102. );
  7103. $this->assertTags($result, $expected);
  7104. $result = $this->Form->input('non_existing_field_in_contact_model');
  7105. $expected = array(
  7106. 'div' => array('class' => 'input text'),
  7107. 'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
  7108. 'Non Existing Field In Contact Model',
  7109. '/label',
  7110. 'input' => array(
  7111. 'type' => 'text', 'name' => 'Contact[non_existing_field_in_contact_model]',
  7112. 'id' => 'ContactNonExistingFieldInContactModel'
  7113. ),
  7114. '/div'
  7115. );
  7116. $this->assertTags($result, $expected);
  7117. $result = $this->Form->input('Address.street');
  7118. $expected = array(
  7119. 'div' => array('class' => 'input text'),
  7120. 'label' => array('for' => 'AddressStreet'),
  7121. 'Street',
  7122. '/label',
  7123. 'input' => array(
  7124. 'type' => 'text', 'name' => 'Address[street]',
  7125. 'id' => 'AddressStreet'
  7126. ),
  7127. '/div'
  7128. );
  7129. $this->assertTags($result, $expected);
  7130. $result = $this->Form->input('Address.non_existing_field_in_model');
  7131. $expected = array(
  7132. 'div' => array('class' => 'input text'),
  7133. 'label' => array('for' => 'AddressNonExistingFieldInModel'),
  7134. 'Non Existing Field In Model',
  7135. '/label',
  7136. 'input' => array(
  7137. 'type' => 'text', 'name' => 'Address[non_existing_field_in_model]',
  7138. 'id' => 'AddressNonExistingFieldInModel'
  7139. ),
  7140. '/div'
  7141. );
  7142. $this->assertTags($result, $expected);
  7143. $result = $this->Form->input('name', array('div' => false));
  7144. $expected = array(
  7145. 'label' => array('for' => 'ContactName'),
  7146. 'Name',
  7147. '/label',
  7148. 'input' => array(
  7149. 'type' => 'text', 'name' => 'Contact[name]',
  7150. 'id' => 'ContactName', 'maxlength' => '255'
  7151. )
  7152. );
  7153. $this->assertTags($result, $expected);
  7154. extract($this->dateRegex);
  7155. $now = strtotime('now');
  7156. $result = $this->Form->input('Contact.published', array('div' => false));
  7157. $expected = array(
  7158. 'label' => array('for' => 'ContactPublishedMonth'),
  7159. 'Published',
  7160. '/label',
  7161. array('select' => array(
  7162. 'name' => 'Contact[published][month]', 'id' => 'ContactPublishedMonth'
  7163. )),
  7164. $monthsRegex,
  7165. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7166. date('F', $now),
  7167. '/option',
  7168. '*/select',
  7169. '-',
  7170. array('select' => array(
  7171. 'name' => 'Contact[published][day]', 'id' => 'ContactPublishedDay'
  7172. )),
  7173. $daysRegex,
  7174. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7175. date('j', $now),
  7176. '/option',
  7177. '*/select',
  7178. '-',
  7179. array('select' => array(
  7180. 'name' => 'Contact[published][year]', 'id' => 'ContactPublishedYear'
  7181. )),
  7182. $yearsRegex,
  7183. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7184. date('Y', $now),
  7185. '*/select'
  7186. );
  7187. $this->assertTags($result, $expected);
  7188. $result = $this->Form->input('Contact.updated', array('div' => false));
  7189. $expected = array(
  7190. 'label' => array('for' => 'ContactUpdatedMonth'),
  7191. 'Updated',
  7192. '/label',
  7193. array('select' => array(
  7194. 'name' => 'Contact[updated][month]', 'id' => 'ContactUpdatedMonth'
  7195. )),
  7196. $monthsRegex,
  7197. array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
  7198. date('F', $now),
  7199. '/option',
  7200. '*/select',
  7201. '-',
  7202. array('select' => array(
  7203. 'name' => 'Contact[updated][day]', 'id' => 'ContactUpdatedDay'
  7204. )),
  7205. $daysRegex,
  7206. array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
  7207. date('j', $now),
  7208. '/option',
  7209. '*/select',
  7210. '-',
  7211. array('select' => array(
  7212. 'name' => 'Contact[updated][year]', 'id' => 'ContactUpdatedYear'
  7213. )),
  7214. $yearsRegex,
  7215. array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
  7216. date('Y', $now),
  7217. '*/select'
  7218. );
  7219. $this->assertTags($result, $expected);
  7220. $result = $this->Form->input('UserForm.stuff');
  7221. $expected = array(
  7222. 'div' => array('class' => 'input text'),
  7223. 'label' => array('for' => 'UserFormStuff'),
  7224. 'Stuff',
  7225. '/label',
  7226. 'input' => array(
  7227. 'type' => 'text', 'name' => 'UserForm[stuff]',
  7228. 'id' => 'UserFormStuff', 'maxlength' => 10
  7229. ),
  7230. '/div'
  7231. );
  7232. $this->assertTags($result, $expected);
  7233. }
  7234. /**
  7235. * testForMagicInputNonExistingNorValidated method
  7236. *
  7237. * @return void
  7238. */
  7239. public function testForMagicInputNonExistingNorValidated() {
  7240. $this->markTestIncomplete('Need to revisit once models work again.');
  7241. $encoding = strtolower(Configure::read('App.encoding'));
  7242. $result = $this->Form->create('Contact');
  7243. $expected = array(
  7244. 'form' => array(
  7245. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7246. 'accept-charset' => $encoding
  7247. ),
  7248. 'div' => array('style' => 'display:none;'),
  7249. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7250. '/div'
  7251. );
  7252. $this->assertTags($result, $expected);
  7253. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7254. $expected = array(
  7255. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7256. 'Non Existing Nor Validated',
  7257. '/label',
  7258. 'input' => array(
  7259. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7260. 'id' => 'ContactNonExistingNorValidated'
  7261. )
  7262. );
  7263. $this->assertTags($result, $expected);
  7264. $result = $this->Form->input('Contact.non_existing_nor_validated', array(
  7265. 'div' => false, 'value' => 'my value'
  7266. ));
  7267. $expected = array(
  7268. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7269. 'Non Existing Nor Validated',
  7270. '/label',
  7271. 'input' => array(
  7272. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7273. 'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
  7274. )
  7275. );
  7276. $this->assertTags($result, $expected);
  7277. $this->Form->request->data = array(
  7278. 'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
  7279. ));
  7280. $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
  7281. $expected = array(
  7282. 'label' => array('for' => 'ContactNonExistingNorValidated'),
  7283. 'Non Existing Nor Validated',
  7284. '/label',
  7285. 'input' => array(
  7286. 'type' => 'text', 'name' => 'Contact[non_existing_nor_validated]',
  7287. 'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
  7288. )
  7289. );
  7290. $this->assertTags($result, $expected);
  7291. }
  7292. /**
  7293. * testFormMagicInputLabel method
  7294. *
  7295. * @return void
  7296. */
  7297. public function testFormMagicInputLabel() {
  7298. $this->markTestIncomplete('Need to revisit once models work again.');
  7299. $encoding = strtolower(Configure::read('App.encoding'));
  7300. $result = $this->Form->create('Contact');
  7301. $expected = array(
  7302. 'form' => array(
  7303. 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
  7304. 'accept-charset' => $encoding
  7305. ),
  7306. 'div' => array('style' => 'display:none;'),
  7307. 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  7308. '/div'
  7309. );
  7310. $this->assertTags($result, $expected);
  7311. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
  7312. $this->assertTags($result, array('input' => array(
  7313. 'name' => 'Contact[name]', 'type' => 'text',
  7314. 'id' => 'ContactName', 'maxlength' => '255')
  7315. ));
  7316. $result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
  7317. $expected = array(
  7318. 'label' => array('for' => 'ContactName'),
  7319. 'My label',
  7320. '/label',
  7321. 'input' => array(
  7322. 'type' => 'text', 'name' => 'Contact[name]',
  7323. 'id' => 'ContactName', 'maxlength' => '255'
  7324. )
  7325. );
  7326. $this->assertTags($result, $expected);
  7327. $result = $this->Form->input('Contact.name', array(
  7328. 'div' => false, 'label' => array('class' => 'mandatory')
  7329. ));
  7330. $expected = array(
  7331. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7332. 'Name',
  7333. '/label',
  7334. 'input' => array(
  7335. 'type' => 'text', 'name' => 'Contact[name]',
  7336. 'id' => 'ContactName', 'maxlength' => '255'
  7337. )
  7338. );
  7339. $this->assertTags($result, $expected);
  7340. $result = $this->Form->input('Contact.name', array(
  7341. 'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
  7342. ));
  7343. $expected = array(
  7344. 'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
  7345. 'My label',
  7346. '/label',
  7347. 'input' => array(
  7348. 'type' => 'text', 'name' => 'Contact[name]',
  7349. 'id' => 'ContactName', 'maxlength' => '255'
  7350. )
  7351. );
  7352. $this->assertTags($result, $expected);
  7353. $result = $this->Form->input('Contact.name', array(
  7354. 'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
  7355. ));
  7356. $expected = array(
  7357. 'label' => array('for' => 'my_id'),
  7358. 'Name',
  7359. '/label',
  7360. 'input' => array(
  7361. 'type' => 'text', 'name' => 'Contact[name]',
  7362. 'id' => 'my_id', 'maxlength' => '255'
  7363. )
  7364. );
  7365. $this->assertTags($result, $expected);
  7366. $result = $this->Form->input('1.id');
  7367. $this->assertTags($result, array('input' => array(
  7368. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7369. 'id' => 'Contact1Id'
  7370. )));
  7371. $result = $this->Form->input("1.name");
  7372. $expected = array(
  7373. 'div' => array('class' => 'input text'),
  7374. 'label' => array('for' => 'Contact1Name'),
  7375. 'Name',
  7376. '/label',
  7377. 'input' => array(
  7378. 'type' => 'text', 'name' => 'Contact[1][name]',
  7379. 'id' => 'Contact1Name', 'maxlength' => '255'
  7380. ),
  7381. '/div'
  7382. );
  7383. $this->assertTags($result, $expected);
  7384. $result = $this->Form->input('Contact.1.id');
  7385. $this->assertTags($result, array(
  7386. 'input' => array(
  7387. 'type' => 'hidden', 'name' => 'Contact[1][id]',
  7388. 'id' => 'Contact1Id'
  7389. )
  7390. ));
  7391. $result = $this->Form->input("Model.1.name");
  7392. $expected = array(
  7393. 'div' => array('class' => 'input text'),
  7394. 'label' => array('for' => 'Model1Name'),
  7395. 'Name',
  7396. '/label',
  7397. 'input' => array(
  7398. 'type' => 'text', 'name' => 'Model[1][name]',
  7399. 'id' => 'Model1Name'
  7400. ),
  7401. '/div'
  7402. );
  7403. $this->assertTags($result, $expected);
  7404. }
  7405. /**
  7406. * testFormEnd method
  7407. *
  7408. * @return void
  7409. */
  7410. public function testFormEnd() {
  7411. $this->markTestIncomplete('Need to revisit once models work again.');
  7412. $this->assertEquals('</form>', $this->Form->end());
  7413. $result = $this->Form->end('');
  7414. $expected = array(
  7415. 'div' => array('class' => 'submit'),
  7416. 'input' => array('type' => 'submit', 'value' => ''),
  7417. '/div',
  7418. '/form'
  7419. );
  7420. $this->assertTags($result, $expected);
  7421. $result = $this->Form->end(array('label' => ''));
  7422. $expected = array(
  7423. 'div' => array('class' => 'submit'),
  7424. 'input' => array('type' => 'submit', 'value' => ''),
  7425. '/div',
  7426. '/form'
  7427. );
  7428. $this->assertTags($result, $expected);
  7429. $result = $this->Form->end('save');
  7430. $expected = array(
  7431. 'div' => array('class' => 'submit'),
  7432. 'input' => array('type' => 'submit', 'value' => 'save'),
  7433. '/div',
  7434. '/form'
  7435. );
  7436. $this->assertTags($result, $expected);
  7437. $result = $this->Form->end(array('label' => 'save'));
  7438. $expected = array(
  7439. 'div' => array('class' => 'submit'),
  7440. 'input' => array('type' => 'submit', 'value' => 'save'),
  7441. '/div',
  7442. '/form'
  7443. );
  7444. $this->assertTags($result, $expected);
  7445. $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
  7446. $expected = array(
  7447. 'div' => array('class' => 'submit'),
  7448. 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
  7449. '/div',
  7450. '/form'
  7451. );
  7452. $this->assertTags($result, $expected);
  7453. $result = $this->Form->end(array('name' => 'Whatever'));
  7454. $expected = array(
  7455. 'div' => array('class' => 'submit'),
  7456. 'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
  7457. '/div',
  7458. '/form'
  7459. );
  7460. $this->assertTags($result, $expected);
  7461. $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
  7462. $expected = array(
  7463. 'div' => array('class' => 'good'),
  7464. 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
  7465. '/div',
  7466. '/form'
  7467. );
  7468. $this->assertTags($result, $expected);
  7469. $result = $this->Form->end(array(
  7470. 'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
  7471. ));
  7472. $expected = array(
  7473. 'div' => array('class' => 'good'),
  7474. 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
  7475. '/div',
  7476. '/form'
  7477. );
  7478. $this->assertTags($result, $expected);
  7479. }
  7480. /**
  7481. * testMultipleFormWithIdFields method
  7482. *
  7483. * @return void
  7484. */
  7485. public function testMultipleFormWithIdFields() {
  7486. $this->markTestIncomplete('Need to revisit once models work again.');
  7487. $this->Form->create('UserForm');
  7488. $result = $this->Form->input('id');
  7489. $this->assertTags($result, array('input' => array(
  7490. 'type' => 'hidden', 'name' => 'UserForm[id]', 'id' => 'UserFormId'
  7491. )));
  7492. $result = $this->Form->input('ValidateItem.id');
  7493. $this->assertTags($result, array('input' => array(
  7494. 'type' => 'hidden', 'name' => 'ValidateItem[id]',
  7495. 'id' => 'ValidateItemId'
  7496. )));
  7497. $result = $this->Form->input('ValidateUser.id');
  7498. $this->assertTags($result, array('input' => array(
  7499. 'type' => 'hidden', 'name' => 'ValidateUser[id]',
  7500. 'id' => 'ValidateUserId'
  7501. )));
  7502. }
  7503. /**
  7504. * testDbLessModel method
  7505. *
  7506. * @return void
  7507. */
  7508. public function testDbLessModel() {
  7509. $this->markTestIncomplete('Need to revisit once models work again.');
  7510. $this->Form->create('TestMail');
  7511. $result = $this->Form->input('name');
  7512. $expected = array(
  7513. 'div' => array('class' => 'input text'),
  7514. 'label' => array('for' => 'TestMailName'),
  7515. 'Name',
  7516. '/label',
  7517. 'input' => array(
  7518. 'name' => 'TestMail[name]', 'type' => 'text',
  7519. 'id' => 'TestMailName'
  7520. ),
  7521. '/div'
  7522. );
  7523. $this->assertTags($result, $expected);
  7524. $this->Form->create('TestMail');
  7525. $result = $this->Form->input('name');
  7526. $expected = array(
  7527. 'div' => array('class' => 'input text'),
  7528. 'label' => array('for' => 'TestMailName'),
  7529. 'Name',
  7530. '/label',
  7531. 'input' => array(
  7532. 'name' => 'TestMail[name]', 'type' => 'text',
  7533. 'id' => 'TestMailName'
  7534. ),
  7535. '/div'
  7536. );
  7537. $this->assertTags($result, $expected);
  7538. }
  7539. /**
  7540. * testBrokenness method
  7541. *
  7542. * @return void
  7543. */
  7544. public function testBrokenness() {
  7545. $this->markTestIncomplete('Need to revisit once models work again.');
  7546. /*
  7547. * #4 This test has two parents and four children. By default (as of r7117) both
  7548. * parents are show but the first parent is missing a child. This is the inconsistency
  7549. * in the default behaviour - one parent has all children, the other does not - dependent
  7550. * on the data values.
  7551. */
  7552. $result = $this->Form->select('Model.field', array(
  7553. 'Fred' => array(
  7554. 'freds_son_1' => 'Fred',
  7555. 'freds_son_2' => 'Freddie'
  7556. ),
  7557. 'Bert' => array(
  7558. 'berts_son_1' => 'Albert',
  7559. 'berts_son_2' => 'Bertie')
  7560. ),
  7561. array('showParents' => true, 'empty' => false)
  7562. );
  7563. $expected = array(
  7564. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7565. array('optgroup' => array('label' => 'Fred')),
  7566. array('option' => array('value' => 'freds_son_1')),
  7567. 'Fred',
  7568. '/option',
  7569. array('option' => array('value' => 'freds_son_2')),
  7570. 'Freddie',
  7571. '/option',
  7572. '/optgroup',
  7573. array('optgroup' => array('label' => 'Bert')),
  7574. array('option' => array('value' => 'berts_son_1')),
  7575. 'Albert',
  7576. '/option',
  7577. array('option' => array('value' => 'berts_son_2')),
  7578. 'Bertie',
  7579. '/option',
  7580. '/optgroup',
  7581. '/select'
  7582. );
  7583. $this->assertTags($result, $expected);
  7584. /*
  7585. * #2 This is structurally identical to the test above (#1) - only the parent name has
  7586. * changed, so we should expect the same select list data, just with a different name
  7587. * for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
  7588. * This is where data corruption can occur, because when a select value is missing from
  7589. * a list a form will substitute the first value in the list - without the user knowing.
  7590. * If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
  7591. * affect the availability of 3 => 'Three' as a valid option.
  7592. */
  7593. $options = array(1 => 'One', 2 => 'Two', 'Three' => array(
  7594. 3 => 'Three', 4 => 'Four', 5 => 'Five'
  7595. ));
  7596. $result = $this->Form->select(
  7597. 'Model.field', $options, array('showParents' => true, 'empty' => false)
  7598. );
  7599. $expected = array(
  7600. 'select' => array('name' => 'Model[field]', 'id' => 'ModelField'),
  7601. array('option' => array('value' => 1)),
  7602. 'One',
  7603. '/option',
  7604. array('option' => array('value' => 2)),
  7605. 'Two',
  7606. '/option',
  7607. array('optgroup' => array('label' => 'Three')),
  7608. array('option' => array('value' => 3)),
  7609. 'Three',
  7610. '/option',
  7611. array('option' => array('value' => 4)),
  7612. 'Four',
  7613. '/option',
  7614. array('option' => array('value' => 5)),
  7615. 'Five',
  7616. '/option',
  7617. '/optgroup',
  7618. '/select'
  7619. );
  7620. $this->assertTags($result, $expected);
  7621. }
  7622. /**
  7623. * Test the generation of fields for a multi record form.
  7624. *
  7625. * @return void
  7626. */
  7627. public function testMultiRecordForm() {
  7628. $this->markTestIncomplete('Need to revisit once models work again.');
  7629. $this->Form->create('ValidateProfile');
  7630. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
  7631. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
  7632. $expected = array(
  7633. 'div' => array('class' => 'input textarea'),
  7634. 'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
  7635. 'Name',
  7636. '/label',
  7637. 'textarea' => array(
  7638. 'id' => 'ValidateProfile1ValidateItem2Name',
  7639. 'name' => 'ValidateProfile[1][ValidateItem][2][name]',
  7640. 'cols' => 30,
  7641. 'rows' => 6
  7642. ),
  7643. 'Value',
  7644. '/textarea',
  7645. '/div'
  7646. );
  7647. $this->assertTags($result, $expected);
  7648. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
  7649. $expected = array(
  7650. 'div' => array('class' => 'input date'),
  7651. 'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
  7652. 'Created',
  7653. '/label',
  7654. array('select' => array(
  7655. 'name' => 'ValidateProfile[1][ValidateItem][2][created][month]',
  7656. 'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
  7657. )
  7658. ),
  7659. array('option' => array('value' => '')), '/option',
  7660. $this->dateRegex['monthsRegex'],
  7661. '/select', '-',
  7662. array('select' => array(
  7663. 'name' => 'ValidateProfile[1][ValidateItem][2][created][day]',
  7664. 'id' => 'ValidateProfile1ValidateItem2CreatedDay'
  7665. )
  7666. ),
  7667. array('option' => array('value' => '')), '/option',
  7668. $this->dateRegex['daysRegex'],
  7669. '/select', '-',
  7670. array('select' => array(
  7671. 'name' => 'ValidateProfile[1][ValidateItem][2][created][year]',
  7672. 'id' => 'ValidateProfile1ValidateItem2CreatedYear'
  7673. )
  7674. ),
  7675. array('option' => array('value' => '')), '/option',
  7676. $this->dateRegex['yearsRegex'],
  7677. '/select',
  7678. '/div'
  7679. );
  7680. $this->assertTags($result, $expected);
  7681. $ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
  7682. $this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
  7683. $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
  7684. $expected = array(
  7685. 'div' => array('class' => 'input select error'),
  7686. 'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
  7687. 'Profile',
  7688. '/label',
  7689. 'select' => array(
  7690. 'name' => 'ValidateProfile[1][ValidateItem][2][profile_id]',
  7691. 'id' => 'ValidateProfile1ValidateItem2ProfileId',
  7692. 'class' => 'form-error'
  7693. ),
  7694. '/select',
  7695. array('div' => array('class' => 'error-message')),
  7696. 'Error',
  7697. '/div',
  7698. '/div'
  7699. );
  7700. $this->assertTags($result, $expected);
  7701. }
  7702. /**
  7703. * test the correct display of multi-record form validation errors.
  7704. *
  7705. * @return void
  7706. */
  7707. public function testMultiRecordFormValidationErrors() {
  7708. $this->markTestIncomplete('Need to revisit once models work again.');
  7709. $this->Form->create('ValidateProfile');
  7710. $ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
  7711. $result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
  7712. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7713. $ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
  7714. $result = $this->Form->error('ValidateProfile.2.city');
  7715. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7716. $result = $this->Form->error('2.city');
  7717. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7718. }
  7719. /**
  7720. * test the correct display of multi-record form validation errors.
  7721. *
  7722. * @return void
  7723. */
  7724. public function testSaveManyRecordFormValidationErrors() {
  7725. $this->markTestIncomplete('Need to revisit once models work again.');
  7726. $this->Form->create('ValidateUser');
  7727. $ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
  7728. $result = $this->Form->error('0.ValidateUser.ValidateItem.name');
  7729. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
  7730. $ValidateUser->validationErrors[0]['city'] = array('Error in field city');
  7731. $result = $this->Form->error('ValidateUser.0.city');
  7732. $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
  7733. }
  7734. /**
  7735. * tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
  7736. *
  7737. * @return void
  7738. */
  7739. public function testInputTemplate() {
  7740. $this->markTestIncomplete('Need to revisit once models work again.');
  7741. $result = $this->Form->input('Contact.email', array(
  7742. 'type' => 'text', 'format' => array('input')
  7743. ));
  7744. $expected = array(
  7745. 'div' => array('class' => 'input text'),
  7746. 'input' => array(
  7747. 'type' => 'text', 'name' => 'Contact[email]',
  7748. 'id' => 'ContactEmail'
  7749. ),
  7750. '/div'
  7751. );
  7752. $this->assertTags($result, $expected);
  7753. $result = $this->Form->input('Contact.email', array(
  7754. 'type' => 'text', 'format' => array('input', 'label'),
  7755. 'label' => '<em>Email (required)</em>'
  7756. ));
  7757. $expected = array(
  7758. 'div' => array('class' => 'input text'),
  7759. array('input' => array(
  7760. 'type' => 'text', 'name' => 'Contact[email]',
  7761. 'id' => 'ContactEmail'
  7762. )),
  7763. 'label' => array('for' => 'ContactEmail'),
  7764. 'em' => array(),
  7765. 'Email (required)',
  7766. '/em',
  7767. '/label',
  7768. '/div'
  7769. );
  7770. $this->assertTags($result, $expected);
  7771. $result = $this->Form->input('Contact.email', array(
  7772. 'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
  7773. 'between' => '<div>Something in the middle</div>',
  7774. 'after' => '<span>Some text at the end</span>'
  7775. ));
  7776. $expected = array(
  7777. 'div' => array('class' => 'input text'),
  7778. array('input' => array(
  7779. 'type' => 'text', 'name' => 'Contact[email]',
  7780. 'id' => 'ContactEmail'
  7781. )),
  7782. array('div' => array()),
  7783. 'Something in the middle',
  7784. '/div',
  7785. 'label' => array('for' => 'ContactEmail'),
  7786. 'Email',
  7787. '/label',
  7788. 'span' => array(),
  7789. 'Some text at the end',
  7790. '/span',
  7791. '/div'
  7792. );
  7793. $this->assertTags($result, $expected);
  7794. $result = $this->Form->input('Contact.method', array(
  7795. 'type' => 'radio',
  7796. 'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
  7797. 'between' => 'I am between',
  7798. ));
  7799. $expected = array(
  7800. 'div' => array('class' => 'input radio'),
  7801. 'fieldset' => array(),
  7802. 'legend' => array(),
  7803. 'Method',
  7804. '/legend',
  7805. 'I am between',
  7806. 'input' => array(
  7807. 'type' => 'hidden', 'name' => 'Contact[method]',
  7808. 'value' => '', 'id' => 'ContactMethod_'
  7809. ),
  7810. array('input' => array(
  7811. 'type' => 'radio', 'name' => 'Contact[method]',
  7812. 'value' => 'email', 'id' => 'ContactMethodEmail'
  7813. )),
  7814. array('label' => array('for' => 'ContactMethodEmail')),
  7815. 'Email',
  7816. '/label',
  7817. array('input' => array(
  7818. 'type' => 'radio', 'name' => 'Contact[method]',
  7819. 'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
  7820. )),
  7821. array('label' => array('for' => 'ContactMethodPigeon')),
  7822. 'Pigeon',
  7823. '/label',
  7824. '/fieldset',
  7825. '/div',
  7826. );
  7827. $this->assertTags($result, $expected);
  7828. }
  7829. /**
  7830. * test that some html5 inputs + FormHelper::__call() work
  7831. *
  7832. * @return void
  7833. */
  7834. public function testHtml5Inputs() {
  7835. $result = $this->Form->email('User.email');
  7836. $expected = array(
  7837. 'input' => array('type' => 'email', 'name' => 'User[email]')
  7838. );
  7839. $this->assertTags($result, $expected);
  7840. $result = $this->Form->search('User.query');
  7841. $expected = array(
  7842. 'input' => array('type' => 'search', 'name' => 'User[query]')
  7843. );
  7844. $this->assertTags($result, $expected);
  7845. $result = $this->Form->search('User.query', array('value' => 'test'));
  7846. $expected = array(
  7847. 'input' => array('type' => 'search', 'name' => 'User[query]', 'value' => 'test')
  7848. );
  7849. $this->assertTags($result, $expected);
  7850. $result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
  7851. $expected = array(
  7852. 'input' => array('type' => 'text', 'name' => 'User[query]', 'value' => 'test')
  7853. );
  7854. $this->assertTags($result, $expected);
  7855. }
  7856. /**
  7857. * Test accessing html5 inputs through input().
  7858. *
  7859. * @return void
  7860. */
  7861. public function testHtml5InputWithInput() {
  7862. $this->markTestIncomplete('Need to revisit once models work again.');
  7863. $result = $this->Form->input('User.website', array(
  7864. 'type' => 'url',
  7865. 'value' => 'http://domain.tld',
  7866. 'div' => false,
  7867. 'label' => false));
  7868. $expected = array(
  7869. 'input' => array('type' => 'url', 'name' => 'User[website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
  7870. );
  7871. $this->assertTags($result, $expected);
  7872. }
  7873. /**
  7874. * Test errors when field name is missing.
  7875. *
  7876. * @expectedException Cake\Error\Exception
  7877. * @return void
  7878. */
  7879. public function testHtml5InputException() {
  7880. $this->Form->email();
  7881. }
  7882. /**
  7883. * Tests that a model can be loaded from the model names passed in the request object
  7884. *
  7885. * @return void
  7886. */
  7887. public function testIntrospectModelFromRequest() {
  7888. $this->markTestIncomplete('Need to revisit once models work again.');
  7889. $this->loadFixtures('Post');
  7890. App::build(array(
  7891. 'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
  7892. ));
  7893. Plugin::load('TestPlugin');
  7894. $this->Form->request['models'] = array(
  7895. 'TestPluginPost' => array(
  7896. 'plugin' => 'TestPlugin',
  7897. 'className' => 'TestPluginPost'
  7898. )
  7899. );
  7900. $this->Form->create('TestPluginPost');
  7901. Plugin::unload();
  7902. }
  7903. /**
  7904. * Tests that it is possible to set the validation errors directly in the helper for a field
  7905. *
  7906. * @return void
  7907. */
  7908. public function testCustomValidationErrors() {
  7909. $this->markTestIncomplete('Need to revisit once models work again.');
  7910. $this->Form->validationErrors['Thing']['field'] = 'Badness!';
  7911. $result = $this->Form->error('Thing.field', null, array('wrap' => false));
  7912. $this->assertEquals('Badness!', $result);
  7913. }
  7914. /**
  7915. * Tests that the 'on' key validates as expected on create
  7916. *
  7917. * @return void
  7918. */
  7919. public function testRequiredOnCreate() {
  7920. $this->markTestIncomplete('Need to revisit once models work again.');
  7921. $this->Form->create('Contact');
  7922. $result = $this->Form->input('Contact.imrequiredonupdate');
  7923. $expected = array(
  7924. 'div' => array('class' => 'input text'),
  7925. 'label' => array('for' => 'ContactImrequiredonupdate'),
  7926. 'Imrequiredonupdate',
  7927. '/label',
  7928. 'input' => array(
  7929. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  7930. 'id' => 'ContactImrequiredonupdate'
  7931. ),
  7932. '/div'
  7933. );
  7934. $this->assertTags($result, $expected);
  7935. $result = $this->Form->input('Contact.imrequiredoncreate');
  7936. $expected = array(
  7937. 'div' => array('class' => 'input text required'),
  7938. 'label' => array('for' => 'ContactImrequiredoncreate'),
  7939. 'Imrequiredoncreate',
  7940. '/label',
  7941. 'input' => array(
  7942. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  7943. 'id' => 'ContactImrequiredoncreate',
  7944. 'required' => 'required'
  7945. ),
  7946. '/div'
  7947. );
  7948. $this->assertTags($result, $expected);
  7949. $result = $this->Form->input('Contact.imrequiredonboth');
  7950. $expected = array(
  7951. 'div' => array('class' => 'input text required'),
  7952. 'label' => array('for' => 'ContactImrequiredonboth'),
  7953. 'Imrequiredonboth',
  7954. '/label',
  7955. 'input' => array(
  7956. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  7957. 'id' => 'ContactImrequiredonboth',
  7958. 'required' => 'required'
  7959. ),
  7960. '/div'
  7961. );
  7962. $this->assertTags($result, $expected);
  7963. $this->Form->inputDefaults(array('required' => false));
  7964. $result = $this->Form->input('Contact.imrequired');
  7965. $expected = array(
  7966. 'div' => array('class' => 'input text'),
  7967. 'label' => array('for' => 'ContactImrequired'),
  7968. 'Imrequired',
  7969. '/label',
  7970. 'input' => array(
  7971. 'type' => 'text', 'name' => 'Contact[imrequired]',
  7972. 'id' => 'ContactImrequired'
  7973. ),
  7974. '/div'
  7975. );
  7976. $this->assertTags($result, $expected);
  7977. $result = $this->Form->input('Contact.imrequired', array('required' => false));
  7978. $this->assertTags($result, $expected);
  7979. $result = $this->Form->input('Contact.imrequired', array('required' => true));
  7980. $expected = array(
  7981. 'div' => array('class' => 'input text required'),
  7982. 'label' => array('for' => 'ContactImrequired'),
  7983. 'Imrequired',
  7984. '/label',
  7985. 'input' => array(
  7986. 'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
  7987. 'id' => 'ContactImrequired'
  7988. ),
  7989. '/div'
  7990. );
  7991. $this->assertTags($result, $expected);
  7992. $result = $this->Form->input('Contact.imrequired', array('required' => null));
  7993. $this->assertTags($result, $expected);
  7994. }
  7995. /**
  7996. * Tests that the 'on' key validates as expected on update
  7997. *
  7998. * @return void
  7999. */
  8000. public function testRequiredOnUpdate() {
  8001. $this->markTestIncomplete('Need to revisit once models work again.');
  8002. $this->Form->request->data['Contact']['id'] = 1;
  8003. $this->Form->create('Contact');
  8004. $result = $this->Form->input('Contact.imrequiredonupdate');
  8005. $expected = array(
  8006. 'div' => array('class' => 'input text required'),
  8007. 'label' => array('for' => 'ContactImrequiredonupdate'),
  8008. 'Imrequiredonupdate',
  8009. '/label',
  8010. 'input' => array(
  8011. 'type' => 'text', 'name' => 'Contact[imrequiredonupdate]',
  8012. 'id' => 'ContactImrequiredonupdate',
  8013. 'required' => 'required'
  8014. ),
  8015. '/div'
  8016. );
  8017. $this->assertTags($result, $expected);
  8018. $result = $this->Form->input('Contact.imrequiredoncreate');
  8019. $expected = array(
  8020. 'div' => array('class' => 'input text'),
  8021. 'label' => array('for' => 'ContactImrequiredoncreate'),
  8022. 'Imrequiredoncreate',
  8023. '/label',
  8024. 'input' => array(
  8025. 'type' => 'text', 'name' => 'Contact[imrequiredoncreate]',
  8026. 'id' => 'ContactImrequiredoncreate'
  8027. ),
  8028. '/div'
  8029. );
  8030. $this->assertTags($result, $expected);
  8031. $result = $this->Form->input('Contact.imrequiredonboth');
  8032. $expected = array(
  8033. 'div' => array('class' => 'input text required'),
  8034. 'label' => array('for' => 'ContactImrequiredonboth'),
  8035. 'Imrequiredonboth',
  8036. '/label',
  8037. 'input' => array(
  8038. 'type' => 'text', 'name' => 'Contact[imrequiredonboth]',
  8039. 'id' => 'ContactImrequiredonboth',
  8040. 'required' => 'required'
  8041. ),
  8042. '/div'
  8043. );
  8044. $this->assertTags($result, $expected);
  8045. $result = $this->Form->input('Contact.imrequired');
  8046. $expected = array(
  8047. 'div' => array('class' => 'input text required'),
  8048. 'label' => array('for' => 'ContactImrequired'),
  8049. 'Imrequired',
  8050. '/label',
  8051. 'input' => array(
  8052. 'type' => 'text', 'name' => 'Contact[imrequired]',
  8053. 'id' => 'ContactImrequired',
  8054. 'required' => 'required'
  8055. ),
  8056. '/div'
  8057. );
  8058. $this->assertTags($result, $expected);
  8059. }
  8060. /**
  8061. * Test inputDefaults setter and getter
  8062. *
  8063. * @return void
  8064. */
  8065. public function testInputDefaults() {
  8066. $this->markTestIncomplete('Need to revisit once models work again.');
  8067. $this->Form->create('Contact');
  8068. $this->Form->inputDefaults(array(
  8069. 'label' => false,
  8070. 'div' => array(
  8071. 'style' => 'color: #000;'
  8072. )
  8073. ));
  8074. $result = $this->Form->input('Contact.field1');
  8075. $expected = array(
  8076. 'div' => array('class' => 'input text', 'style' => 'color: #000;'),
  8077. 'input' => array(
  8078. 'type' => 'text', 'name' => 'Contact[field1]',
  8079. 'id' => 'ContactField1'
  8080. ),
  8081. '/div'
  8082. );
  8083. $this->assertTags($result, $expected);
  8084. $this->Form->inputDefaults(array(
  8085. 'div' => false,
  8086. 'label' => 'Label',
  8087. ));
  8088. $result = $this->Form->input('Contact.field1');
  8089. $expected = array(
  8090. 'label' => array('for' => 'ContactField1'),
  8091. 'Label',
  8092. '/label',
  8093. 'input' => array(
  8094. 'type' => 'text', 'name' => 'Contact[field1]',
  8095. 'id' => 'ContactField1'
  8096. ),
  8097. );
  8098. $this->assertTags($result, $expected);
  8099. $this->Form->inputDefaults(array(
  8100. 'label' => false,
  8101. ), true);
  8102. $result = $this->Form->input('Contact.field1');
  8103. $expected = array(
  8104. 'input' => array(
  8105. 'type' => 'text', 'name' => 'Contact[field1]',
  8106. 'id' => 'ContactField1'
  8107. ),
  8108. );
  8109. $this->assertTags($result, $expected);
  8110. $result = $this->Form->inputDefaults();
  8111. $expected = array(
  8112. 'div' => false,
  8113. 'label' => false,
  8114. );
  8115. $this->assertEquals($expected, $result);
  8116. }
  8117. }