ModelReadTest.php 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687
  1. <?php
  2. /**
  3. * ModelReadTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Model
  16. * @since CakePHP(tm) v 1.2.0.4206
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
  20. /**
  21. * ModelReadTest
  22. *
  23. * @package Cake.Test.Case.Model
  24. */
  25. class ModelReadTest extends BaseModelTest {
  26. /**
  27. * testFetchingNonUniqueFKJoinTableRecords()
  28. *
  29. * Tests if the results are properly returned in the case there are non-unique FK's
  30. * in the join table but another fields value is different. For example:
  31. * something_id | something_else_id | doomed = 1
  32. * something_id | something_else_id | doomed = 0
  33. * Should return both records and not just one.
  34. *
  35. * @return void
  36. */
  37. public function testFetchingNonUniqueFKJoinTableRecords() {
  38. $this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
  39. $Something = new Something();
  40. $joinThingData = array(
  41. 'JoinThing' => array(
  42. 'something_id' => 1,
  43. 'something_else_id' => 2,
  44. 'doomed' => '0',
  45. 'created' => '2007-03-18 10:39:23',
  46. 'updated' => '2007-03-18 10:41:31'
  47. )
  48. );
  49. $Something->JoinThing->create($joinThingData);
  50. $Something->JoinThing->save();
  51. $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
  52. $this->assertEquals($result[0]['JoinThing']['doomed'], true);
  53. $this->assertEquals($result[1]['JoinThing']['doomed'], false);
  54. $result = $Something->find('first');
  55. $this->assertEquals(count($result['SomethingElse']), 2);
  56. $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']);
  57. $this->assertTrue(in_array(true, $doomed));
  58. $this->assertTrue(in_array(false, $doomed));
  59. }
  60. /**
  61. * testGroupBy method
  62. *
  63. * These tests will never pass with Postgres or Oracle as all fields in a select must be
  64. * part of an aggregate function or in the GROUP BY statement.
  65. *
  66. * @return void
  67. */
  68. public function testGroupBy() {
  69. $db = ConnectionManager::getDataSource('test');
  70. $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver;
  71. $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.';
  72. $this->skipIf($isStrictGroupBy, $message);
  73. $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid');
  74. $Thread = new Thread();
  75. $Product = new Product();
  76. $result = $Thread->find('all', array(
  77. 'group' => 'Thread.project_id',
  78. 'order' => 'Thread.id ASC'
  79. ));
  80. $expected = array(
  81. array(
  82. 'Thread' => array(
  83. 'id' => 1,
  84. 'project_id' => 1,
  85. 'name' => 'Project 1, Thread 1'
  86. ),
  87. 'Project' => array(
  88. 'id' => 1,
  89. 'name' => 'Project 1'
  90. ),
  91. 'Message' => array(
  92. array(
  93. 'id' => 1,
  94. 'thread_id' => 1,
  95. 'name' => 'Thread 1, Message 1'
  96. ))),
  97. array(
  98. 'Thread' => array(
  99. 'id' => 3,
  100. 'project_id' => 2,
  101. 'name' => 'Project 2, Thread 1'
  102. ),
  103. 'Project' => array(
  104. 'id' => 2,
  105. 'name' => 'Project 2'
  106. ),
  107. 'Message' => array(
  108. array(
  109. 'id' => 3,
  110. 'thread_id' => 3,
  111. 'name' => 'Thread 3, Message 1'
  112. ))));
  113. $this->assertEquals($expected, $result);
  114. $rows = $Thread->find('all', array(
  115. 'group' => 'Thread.project_id',
  116. 'fields' => array('Thread.project_id', 'COUNT(*) AS total')
  117. ));
  118. $result = array();
  119. foreach ($rows as $row) {
  120. $result[$row['Thread']['project_id']] = $row[0]['total'];
  121. }
  122. $expected = array(
  123. 1 => 2,
  124. 2 => 1
  125. );
  126. $this->assertEquals($expected, $result);
  127. $rows = $Thread->find('all', array(
  128. 'group' => 'Thread.project_id',
  129. 'fields' => array('Thread.project_id', 'COUNT(*) AS total'),
  130. 'order' => 'Thread.project_id'
  131. ));
  132. $result = array();
  133. foreach ($rows as $row) {
  134. $result[$row['Thread']['project_id']] = $row[0]['total'];
  135. }
  136. $expected = array(
  137. 1 => 2,
  138. 2 => 1
  139. );
  140. $this->assertEquals($expected, $result);
  141. $result = $Thread->find('all', array(
  142. 'conditions' => array('Thread.project_id' => 1),
  143. 'group' => 'Thread.project_id'
  144. ));
  145. $expected = array(
  146. array(
  147. 'Thread' => array(
  148. 'id' => 1,
  149. 'project_id' => 1,
  150. 'name' => 'Project 1, Thread 1'
  151. ),
  152. 'Project' => array(
  153. 'id' => 1,
  154. 'name' => 'Project 1'
  155. ),
  156. 'Message' => array(
  157. array(
  158. 'id' => 1,
  159. 'thread_id' => 1,
  160. 'name' => 'Thread 1, Message 1'
  161. ))));
  162. $this->assertEquals($expected, $result);
  163. $result = $Thread->find('all', array(
  164. 'conditions' => array('Thread.project_id' => 1),
  165. 'group' => 'Thread.project_id, Project.id'
  166. ));
  167. $this->assertEquals($expected, $result);
  168. $result = $Thread->find('all', array(
  169. 'conditions' => array('Thread.project_id' => 1),
  170. 'group' => 'project_id'
  171. ));
  172. $this->assertEquals($expected, $result);
  173. $result = $Thread->find('all', array(
  174. 'conditions' => array('Thread.project_id' => 1),
  175. 'group' => array('project_id')
  176. ));
  177. $this->assertEquals($expected, $result);
  178. $result = $Thread->find('all', array(
  179. 'conditions' => array('Thread.project_id' => 1),
  180. 'group' => array('project_id', 'Project.id')
  181. ));
  182. $this->assertEquals($expected, $result);
  183. $result = $Thread->find('all', array(
  184. 'conditions' => array('Thread.project_id' => 1),
  185. 'group' => array('Thread.project_id', 'Project.id')
  186. ));
  187. $this->assertEquals($expected, $result);
  188. $expected = array(
  189. array('Product' => array('type' => 'Clothing'), array('price' => 32)),
  190. array('Product' => array('type' => 'Food'), array('price' => 9)),
  191. array('Product' => array('type' => 'Music'), array('price' => 4)),
  192. array('Product' => array('type' => 'Toy'), array('price' => 3))
  193. );
  194. $result = $Product->find('all',array(
  195. 'fields' => array('Product.type', 'MIN(Product.price) as price'),
  196. 'group' => 'Product.type',
  197. 'order' => 'Product.type ASC'
  198. ));
  199. $this->assertEquals($expected, $result);
  200. $result = $Product->find('all', array(
  201. 'fields' => array('Product.type', 'MIN(Product.price) as price'),
  202. 'group' => array('Product.type'),
  203. 'order' => 'Product.type ASC'));
  204. $this->assertEquals($expected, $result);
  205. }
  206. /**
  207. * testOldQuery method
  208. *
  209. * @return void
  210. */
  211. public function testOldQuery() {
  212. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
  213. $Article = new Article();
  214. $query = 'SELECT title FROM ';
  215. $query .= $this->db->fullTableName('articles');
  216. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)';
  217. $results = $Article->query($query);
  218. $this->assertTrue(is_array($results));
  219. $this->assertEquals(count($results), 2);
  220. $query = 'SELECT title, body FROM ';
  221. $query .= $this->db->fullTableName('articles');
  222. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1';
  223. $results = $Article->query($query, false);
  224. $this->assertFalse($this->db->getQueryCache($query));
  225. $this->assertTrue(is_array($results));
  226. $query = 'SELECT title, id FROM ';
  227. $query .= $this->db->fullTableName('articles');
  228. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  229. $query .= '.published = ' . $this->db->value('Y');
  230. $results = $Article->query($query, true);
  231. $result = $this->db->getQueryCache($query);
  232. $this->assertFalse(empty($result));
  233. $this->assertTrue(is_array($results));
  234. }
  235. /**
  236. * testPreparedQuery method
  237. *
  238. * @return void
  239. */
  240. public function testPreparedQuery() {
  241. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag');
  242. $Article = new Article();
  243. $query = 'SELECT title, published FROM ';
  244. $query .= $this->db->fullTableName('articles');
  245. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  246. $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?';
  247. $params = array(1, 'Y');
  248. $result = $Article->query($query, $params);
  249. $expected = array(
  250. '0' => array(
  251. $this->db->fullTableName('articles', false, false) => array(
  252. 'title' => 'First Article', 'published' => 'Y')
  253. ));
  254. if (isset($result[0][0])) {
  255. $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)];
  256. unset($expected[0][$this->db->fullTableName('articles', false, false)]);
  257. }
  258. $this->assertEquals($expected, $result);
  259. $result = $this->db->getQueryCache($query, $params);
  260. $this->assertFalse(empty($result));
  261. $query = 'SELECT id, created FROM ';
  262. $query .= $this->db->fullTableName('articles');
  263. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?';
  264. $params = array('First Article');
  265. $result = $Article->query($query, $params, false);
  266. $this->assertTrue(is_array($result));
  267. $this->assertTrue(
  268. isset($result[0][$this->db->fullTableName('articles', false, false)])
  269. || isset($result[0][0])
  270. );
  271. $result = $this->db->getQueryCache($query, $params);
  272. $this->assertTrue(empty($result));
  273. $query = 'SELECT title FROM ';
  274. $query .= $this->db->fullTableName('articles');
  275. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?';
  276. $params = array('%First%');
  277. $result = $Article->query($query, $params);
  278. $this->assertTrue(is_array($result));
  279. $this->assertTrue(
  280. isset($result[0][$this->db->fullTableName('articles', false, false)]['title'])
  281. || isset($result[0][0]['title'])
  282. );
  283. //related to ticket #5035
  284. $query = 'SELECT title FROM ';
  285. $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?';
  286. $params = array('First? Article', 'Y');
  287. $Article->query($query, $params);
  288. $result = $this->db->getQueryCache($query, $params);
  289. $this->assertFalse($result === false);
  290. }
  291. /**
  292. * testParameterMismatch method
  293. *
  294. * @expectedException PDOException
  295. * @return void
  296. */
  297. public function testParameterMismatch() {
  298. $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not accept real prepared statements, no way to check this');
  299. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag');
  300. $Article = new Article();
  301. $query = 'SELECT * FROM ' . $this->db->fullTableName('articles');
  302. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  303. $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?';
  304. $params = array('Y');
  305. $result = $Article->query($query, $params);
  306. }
  307. /**
  308. * testVeryStrangeUseCase method
  309. *
  310. * @expectedException PDOException
  311. * @return void
  312. */
  313. public function testVeryStrangeUseCase() {
  314. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag');
  315. $Article = new Article();
  316. $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?';
  317. $param = array(
  318. $this->db->fullTableName('articles'),
  319. $this->db->fullTableName('articles') . '.user_id', '3',
  320. $this->db->fullTableName('articles') . '.published', 'Y'
  321. );
  322. $result = $Article->query($query, $param);
  323. }
  324. /**
  325. * testRecursiveUnbind method
  326. *
  327. * @return void
  328. */
  329. public function testRecursiveUnbind() {
  330. $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.');
  331. $this->loadFixtures('Apple', 'Sample');
  332. $TestModel = new Apple();
  333. $TestModel->recursive = 2;
  334. $result = $TestModel->find('all');
  335. $expected = array(
  336. array(
  337. 'Apple' => array(
  338. 'id' => 1,
  339. 'apple_id' => 2,
  340. 'color' => 'Red 1',
  341. 'name' => 'Red Apple 1',
  342. 'created' => '2006-11-22 10:38:58',
  343. 'date' => '1951-01-04',
  344. 'modified' => '2006-12-01 13:31:26',
  345. 'mytime' => '22:57:17'
  346. ),
  347. 'Parent' => array(
  348. 'id' => 2,
  349. 'apple_id' => 1,
  350. 'color' => 'Bright Red 1',
  351. 'name' => 'Bright Red Apple',
  352. 'created' => '2006-11-22 10:43:13',
  353. 'date' => '2014-01-01',
  354. 'modified' => '2006-11-30 18:38:10',
  355. 'mytime' => '22:57:17',
  356. 'Parent' => array(
  357. 'id' => 1,
  358. 'apple_id' => 2,
  359. 'color' => 'Red 1',
  360. 'name' => 'Red Apple 1',
  361. 'created' => '2006-11-22 10:38:58',
  362. 'date' => '1951-01-04',
  363. 'modified' => '2006-12-01 13:31:26',
  364. 'mytime' => '22:57:17'
  365. ),
  366. 'Sample' => array(
  367. 'id' => 2,
  368. 'apple_id' => 2,
  369. 'name' => 'sample2'
  370. ),
  371. 'Child' => array(
  372. array(
  373. 'id' => 1,
  374. 'apple_id' => 2,
  375. 'color' => 'Red 1',
  376. 'name' => 'Red Apple 1',
  377. 'created' => '2006-11-22 10:38:58',
  378. 'date' => '1951-01-04',
  379. 'modified' => '2006-12-01 13:31:26',
  380. 'mytime' => '22:57:17'
  381. ),
  382. array(
  383. 'id' => 3,
  384. 'apple_id' => 2,
  385. 'color' => 'blue green',
  386. 'name' => 'green blue',
  387. 'created' => '2006-12-25 05:13:36',
  388. 'date' => '2006-12-25',
  389. 'modified' => '2006-12-25 05:23:24',
  390. 'mytime' => '22:57:17'
  391. ),
  392. array(
  393. 'id' => 4,
  394. 'apple_id' => 2,
  395. 'color' => 'Blue Green',
  396. 'name' => 'Test Name',
  397. 'created' => '2006-12-25 05:23:36',
  398. 'date' => '2006-12-25',
  399. 'modified' => '2006-12-25 05:23:36',
  400. 'mytime' => '22:57:17'
  401. ))),
  402. 'Sample' => array(
  403. 'id' => '',
  404. 'apple_id' => '',
  405. 'name' => ''
  406. ),
  407. 'Child' => array(
  408. array(
  409. 'id' => 2,
  410. 'apple_id' => 1,
  411. 'color' => 'Bright Red 1',
  412. 'name' => 'Bright Red Apple',
  413. 'created' => '2006-11-22 10:43:13',
  414. 'date' => '2014-01-01',
  415. 'modified' => '2006-11-30 18:38:10',
  416. 'mytime' => '22:57:17',
  417. 'Parent' => array(
  418. 'id' => 1,
  419. 'apple_id' => 2,
  420. 'color' => 'Red 1',
  421. 'name' => 'Red Apple 1',
  422. 'created' => '2006-11-22 10:38:58',
  423. 'date' => '1951-01-04',
  424. 'modified' => '2006-12-01 13:31:26',
  425. 'mytime' => '22:57:17'
  426. ),
  427. 'Sample' => array(
  428. 'id' => 2,
  429. 'apple_id' => 2,
  430. 'name' => 'sample2'
  431. ),
  432. 'Child' => array(
  433. array(
  434. 'id' => 1,
  435. 'apple_id' => 2,
  436. 'color' => 'Red 1',
  437. 'name' => 'Red Apple 1',
  438. 'created' => '2006-11-22 10:38:58',
  439. 'date' => '1951-01-04',
  440. 'modified' => '2006-12-01 13:31:26',
  441. 'mytime' => '22:57:17'
  442. ),
  443. array(
  444. 'id' => 3,
  445. 'apple_id' => 2,
  446. 'color' => 'blue green',
  447. 'name' => 'green blue',
  448. 'created' => '2006-12-25 05:13:36',
  449. 'date' => '2006-12-25',
  450. 'modified' => '2006-12-25 05:23:24',
  451. 'mytime' => '22:57:17'
  452. ),
  453. array(
  454. 'id' => 4,
  455. 'apple_id' => 2,
  456. 'color' => 'Blue Green',
  457. 'name' => 'Test Name',
  458. 'created' => '2006-12-25 05:23:36',
  459. 'date' => '2006-12-25',
  460. 'modified' => '2006-12-25 05:23:36',
  461. 'mytime' => '22:57:17'
  462. ))))),
  463. array(
  464. 'Apple' => array(
  465. 'id' => 2,
  466. 'apple_id' => 1,
  467. 'color' => 'Bright Red 1',
  468. 'name' => 'Bright Red Apple',
  469. 'created' => '2006-11-22 10:43:13',
  470. 'date' => '2014-01-01',
  471. 'modified' => '2006-11-30 18:38:10',
  472. 'mytime' => '22:57:17'
  473. ),
  474. 'Parent' => array(
  475. 'id' => 1,
  476. 'apple_id' => 2,
  477. 'color' => 'Red 1',
  478. 'name' => 'Red Apple 1',
  479. 'created' => '2006-11-22 10:38:58',
  480. 'date' => '1951-01-04',
  481. 'modified' => '2006-12-01 13:31:26',
  482. 'mytime' => '22:57:17',
  483. 'Parent' => array(
  484. 'id' => 2,
  485. 'apple_id' => 1,
  486. 'color' => 'Bright Red 1',
  487. 'name' => 'Bright Red Apple',
  488. 'created' => '2006-11-22 10:43:13',
  489. 'date' => '2014-01-01',
  490. 'modified' => '2006-11-30 18:38:10',
  491. 'mytime' => '22:57:17'
  492. ),
  493. 'Sample' => array(),
  494. 'Child' => array(
  495. array(
  496. 'id' => 2,
  497. 'apple_id' => 1,
  498. 'color' => 'Bright Red 1',
  499. 'name' => 'Bright Red Apple',
  500. 'created' => '2006-11-22 10:43:13',
  501. 'date' => '2014-01-01',
  502. 'modified' => '2006-11-30 18:38:10',
  503. 'mytime' => '22:57:17'
  504. ))),
  505. 'Sample' => array(
  506. 'id' => 2,
  507. 'apple_id' => 2,
  508. 'name' => 'sample2',
  509. 'Apple' => array(
  510. 'id' => 2,
  511. 'apple_id' => 1,
  512. 'color' => 'Bright Red 1',
  513. 'name' => 'Bright Red Apple',
  514. 'created' => '2006-11-22 10:43:13',
  515. 'date' => '2014-01-01',
  516. 'modified' => '2006-11-30 18:38:10',
  517. 'mytime' => '22:57:17'
  518. )),
  519. 'Child' => array(
  520. array(
  521. 'id' => 1,
  522. 'apple_id' => 2,
  523. 'color' => 'Red 1',
  524. 'name' => 'Red Apple 1',
  525. 'created' => '2006-11-22 10:38:58',
  526. 'date' => '1951-01-04',
  527. 'modified' => '2006-12-01 13:31:26',
  528. 'mytime' => '22:57:17',
  529. 'Parent' => array(
  530. 'id' => 2,
  531. 'apple_id' => 1,
  532. 'color' => 'Bright Red 1',
  533. 'name' => 'Bright Red Apple',
  534. 'created' => '2006-11-22 10:43:13',
  535. 'date' => '2014-01-01',
  536. 'modified' => '2006-11-30 18:38:10',
  537. 'mytime' => '22:57:17'
  538. ),
  539. 'Sample' => array(),
  540. 'Child' => array(
  541. array(
  542. 'id' => 2,
  543. 'apple_id' => 1,
  544. 'color' => 'Bright Red 1',
  545. 'name' => 'Bright Red Apple',
  546. 'created' => '2006-11-22 10:43:13',
  547. 'date' => '2014-01-01',
  548. 'modified' => '2006-11-30 18:38:10',
  549. 'mytime' => '22:57:17'
  550. ))),
  551. array(
  552. 'id' => 3,
  553. 'apple_id' => 2,
  554. 'color' => 'blue green',
  555. 'name' => 'green blue',
  556. 'created' => '2006-12-25 05:13:36',
  557. 'date' => '2006-12-25',
  558. 'modified' => '2006-12-25 05:23:24',
  559. 'mytime' => '22:57:17',
  560. 'Parent' => array(
  561. 'id' => 2,
  562. 'apple_id' => 1,
  563. 'color' => 'Bright Red 1',
  564. 'name' => 'Bright Red Apple',
  565. 'created' => '2006-11-22 10:43:13',
  566. 'date' => '2014-01-01',
  567. 'modified' => '2006-11-30 18:38:10',
  568. 'mytime' => '22:57:17'
  569. ),
  570. 'Sample' => array(
  571. 'id' => 1,
  572. 'apple_id' => 3,
  573. 'name' => 'sample1'
  574. )),
  575. array(
  576. 'id' => 4,
  577. 'apple_id' => 2,
  578. 'color' => 'Blue Green',
  579. 'name' => 'Test Name',
  580. 'created' => '2006-12-25 05:23:36',
  581. 'date' => '2006-12-25',
  582. 'modified' => '2006-12-25 05:23:36',
  583. 'mytime' => '22:57:17',
  584. 'Parent' => array(
  585. 'id' => 2,
  586. 'apple_id' => 1,
  587. 'color' => 'Bright Red 1',
  588. 'name' => 'Bright Red Apple',
  589. 'created' => '2006-11-22 10:43:13',
  590. 'date' => '2014-01-01',
  591. 'modified' => '2006-11-30 18:38:10',
  592. 'mytime' => '22:57:17'
  593. ),
  594. 'Sample' => array(
  595. 'id' => 3,
  596. 'apple_id' => 4,
  597. 'name' => 'sample3'
  598. ),
  599. 'Child' => array(
  600. array(
  601. 'id' => 6,
  602. 'apple_id' => 4,
  603. 'color' => 'My new appleOrange',
  604. 'name' => 'My new apple',
  605. 'created' => '2006-12-25 05:29:39',
  606. 'date' => '2006-12-25',
  607. 'modified' => '2006-12-25 05:29:39',
  608. 'mytime' => '22:57:17'
  609. ))))),
  610. array(
  611. 'Apple' => array(
  612. 'id' => 3,
  613. 'apple_id' => 2,
  614. 'color' => 'blue green',
  615. 'name' => 'green blue',
  616. 'created' => '2006-12-25 05:13:36',
  617. 'date' => '2006-12-25',
  618. 'modified' => '2006-12-25 05:23:24',
  619. 'mytime' => '22:57:17'
  620. ),
  621. 'Parent' => array(
  622. 'id' => 2,
  623. 'apple_id' => 1,
  624. 'color' => 'Bright Red 1',
  625. 'name' => 'Bright Red Apple',
  626. 'created' => '2006-11-22 10:43:13',
  627. 'date' => '2014-01-01',
  628. 'modified' => '2006-11-30 18:38:10',
  629. 'mytime' => '22:57:17',
  630. 'Parent' => array(
  631. 'id' => 1,
  632. 'apple_id' => 2,
  633. 'color' => 'Red 1',
  634. 'name' => 'Red Apple 1',
  635. 'created' => '2006-11-22 10:38:58',
  636. 'date' => '1951-01-04',
  637. 'modified' => '2006-12-01 13:31:26',
  638. 'mytime' => '22:57:17'
  639. ),
  640. 'Sample' => array(
  641. 'id' => 2,
  642. 'apple_id' => 2,
  643. 'name' => 'sample2'
  644. ),
  645. 'Child' => array(
  646. array(
  647. 'id' => 1,
  648. 'apple_id' => 2,
  649. 'color' => 'Red 1',
  650. 'name' => 'Red Apple 1',
  651. 'created' => '2006-11-22 10:38:58',
  652. 'date' => '1951-01-04',
  653. 'modified' => '2006-12-01 13:31:26',
  654. 'mytime' => '22:57:17'
  655. ),
  656. array(
  657. 'id' => 3,
  658. 'apple_id' => 2,
  659. 'color' => 'blue green',
  660. 'name' => 'green blue',
  661. 'created' => '2006-12-25 05:13:36',
  662. 'date' => '2006-12-25',
  663. 'modified' => '2006-12-25 05:23:24',
  664. 'mytime' => '22:57:17'
  665. ),
  666. array(
  667. 'id' => 4,
  668. 'apple_id' => 2,
  669. 'color' => 'Blue Green',
  670. 'name' => 'Test Name',
  671. 'created' => '2006-12-25 05:23:36',
  672. 'date' => '2006-12-25',
  673. 'modified' => '2006-12-25 05:23:36',
  674. 'mytime' => '22:57:17'
  675. ))),
  676. 'Sample' => array(
  677. 'id' => 1,
  678. 'apple_id' => 3,
  679. 'name' => 'sample1',
  680. 'Apple' => array(
  681. 'id' => 3,
  682. 'apple_id' => 2,
  683. 'color' => 'blue green',
  684. 'name' => 'green blue',
  685. 'created' => '2006-12-25 05:13:36',
  686. 'date' => '2006-12-25',
  687. 'modified' => '2006-12-25 05:23:24',
  688. 'mytime' => '22:57:17'
  689. )),
  690. 'Child' => array()
  691. ),
  692. array(
  693. 'Apple' => array(
  694. 'id' => 4,
  695. 'apple_id' => 2,
  696. 'color' => 'Blue Green',
  697. 'name' => 'Test Name',
  698. 'created' => '2006-12-25 05:23:36',
  699. 'date' => '2006-12-25',
  700. 'modified' => '2006-12-25 05:23:36',
  701. 'mytime' => '22:57:17'
  702. ),
  703. 'Parent' => array(
  704. 'id' => 2,
  705. 'apple_id' => 1,
  706. 'color' => 'Bright Red 1',
  707. 'name' => 'Bright Red Apple',
  708. 'created' => '2006-11-22 10:43:13',
  709. 'date' => '2014-01-01',
  710. 'modified' => '2006-11-30 18:38:10',
  711. 'mytime' => '22:57:17',
  712. 'Parent' => array(
  713. 'id' => 1,
  714. 'apple_id' => 2,
  715. 'color' => 'Red 1',
  716. 'name' => 'Red Apple 1',
  717. 'created' => '2006-11-22 10:38:58',
  718. 'date' => '1951-01-04',
  719. 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
  720. 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
  721. 'Child' => array(
  722. array(
  723. 'id' => 1,
  724. 'apple_id' => 2,
  725. 'color' => 'Red 1',
  726. 'name' => 'Red Apple 1',
  727. 'created' => '2006-11-22 10:38:58',
  728. 'date' => '1951-01-04',
  729. 'modified' => '2006-12-01 13:31:26',
  730. 'mytime' => '22:57:17'
  731. ),
  732. array(
  733. 'id' => 3,
  734. 'apple_id' => 2,
  735. 'color' => 'blue green',
  736. 'name' => 'green blue',
  737. 'created' => '2006-12-25 05:13:36',
  738. 'date' => '2006-12-25',
  739. 'modified' => '2006-12-25 05:23:24',
  740. 'mytime' => '22:57:17'
  741. ),
  742. array(
  743. 'id' => 4,
  744. 'apple_id' => 2,
  745. 'color' => 'Blue Green',
  746. 'name' => 'Test Name',
  747. 'created' => '2006-12-25 05:23:36',
  748. 'date' => '2006-12-25',
  749. 'modified' => '2006-12-25 05:23:36',
  750. 'mytime' => '22:57:17'
  751. ))),
  752. 'Sample' => array(
  753. 'id' => 3,
  754. 'apple_id' => 4,
  755. 'name' => 'sample3',
  756. 'Apple' => array(
  757. 'id' => 4,
  758. 'apple_id' => 2,
  759. 'color' => 'Blue Green',
  760. 'name' => 'Test Name',
  761. 'created' => '2006-12-25 05:23:36',
  762. 'date' => '2006-12-25',
  763. 'modified' => '2006-12-25 05:23:36',
  764. 'mytime' => '22:57:17'
  765. )),
  766. 'Child' => array(
  767. array(
  768. 'id' => 6,
  769. 'apple_id' => 4,
  770. 'color' => 'My new appleOrange',
  771. 'name' => 'My new apple',
  772. 'created' => '2006-12-25 05:29:39',
  773. 'date' => '2006-12-25',
  774. 'modified' => '2006-12-25 05:29:39',
  775. 'mytime' => '22:57:17',
  776. 'Parent' => array(
  777. 'id' => 4,
  778. 'apple_id' => 2,
  779. 'color' => 'Blue Green',
  780. 'name' => 'Test Name',
  781. 'created' => '2006-12-25 05:23:36',
  782. 'date' => '2006-12-25',
  783. 'modified' => '2006-12-25 05:23:36',
  784. 'mytime' => '22:57:17'
  785. ),
  786. 'Sample' => array(),
  787. 'Child' => array(
  788. array(
  789. 'id' => 7,
  790. 'apple_id' => 6,
  791. 'color' => 'Some wierd color',
  792. 'name' => 'Some odd color',
  793. 'created' => '2006-12-25 05:34:21',
  794. 'date' => '2006-12-25',
  795. 'modified' => '2006-12-25 05:34:21',
  796. 'mytime' => '22:57:17'
  797. ))))),
  798. array(
  799. 'Apple' => array(
  800. 'id' => 5,
  801. 'apple_id' => 5,
  802. 'color' => 'Green',
  803. 'name' => 'Blue Green',
  804. 'created' => '2006-12-25 05:24:06',
  805. 'date' => '2006-12-25',
  806. 'modified' => '2006-12-25 05:29:16',
  807. 'mytime' => '22:57:17'
  808. ),
  809. 'Parent' => array(
  810. 'id' => 5,
  811. 'apple_id' => 5,
  812. 'color' => 'Green',
  813. 'name' => 'Blue Green',
  814. 'created' => '2006-12-25 05:24:06',
  815. 'date' => '2006-12-25',
  816. 'modified' => '2006-12-25 05:29:16',
  817. 'mytime' => '22:57:17',
  818. 'Parent' => array(
  819. 'id' => 5,
  820. 'apple_id' => 5,
  821. 'color' => 'Green',
  822. 'name' => 'Blue Green',
  823. 'created' => '2006-12-25 05:24:06',
  824. 'date' => '2006-12-25',
  825. 'modified' => '2006-12-25 05:29:16',
  826. 'mytime' => '22:57:17'
  827. ),
  828. 'Sample' => array(
  829. 'id' => 4,
  830. 'apple_id' => 5,
  831. 'name' => 'sample4'
  832. ),
  833. 'Child' => array(
  834. array(
  835. 'id' => 5,
  836. 'apple_id' => 5,
  837. 'color' => 'Green',
  838. 'name' => 'Blue Green',
  839. 'created' => '2006-12-25 05:24:06',
  840. 'date' => '2006-12-25',
  841. 'modified' => '2006-12-25 05:29:16',
  842. 'mytime' => '22:57:17'
  843. ))),
  844. 'Sample' => array(
  845. 'id' => 4,
  846. 'apple_id' => 5,
  847. 'name' => 'sample4',
  848. 'Apple' => array(
  849. 'id' => 5,
  850. 'apple_id' => 5,
  851. 'color' => 'Green',
  852. 'name' => 'Blue Green',
  853. 'created' => '2006-12-25 05:24:06',
  854. 'date' => '2006-12-25',
  855. 'modified' => '2006-12-25 05:29:16',
  856. 'mytime' => '22:57:17'
  857. )),
  858. 'Child' => array(
  859. array(
  860. 'id' => 5,
  861. 'apple_id' => 5,
  862. 'color' => 'Green',
  863. 'name' => 'Blue Green',
  864. 'created' => '2006-12-25 05:24:06',
  865. 'date' => '2006-12-25',
  866. 'modified' => '2006-12-25 05:29:16',
  867. 'mytime' => '22:57:17',
  868. 'Parent' => array(
  869. 'id' => 5,
  870. 'apple_id' => 5,
  871. 'color' => 'Green',
  872. 'name' => 'Blue Green',
  873. 'created' => '2006-12-25 05:24:06',
  874. 'date' => '2006-12-25',
  875. 'modified' => '2006-12-25 05:29:16',
  876. 'mytime' => '22:57:17'
  877. ),
  878. 'Sample' => array(
  879. 'id' => 4,
  880. 'apple_id' => 5,
  881. 'name' => 'sample4'
  882. ),
  883. 'Child' => array(
  884. array(
  885. 'id' => 5,
  886. 'apple_id' => 5,
  887. 'color' => 'Green',
  888. 'name' => 'Blue Green',
  889. 'created' => '2006-12-25 05:24:06',
  890. 'date' => '2006-12-25',
  891. 'modified' => '2006-12-25 05:29:16',
  892. 'mytime' => '22:57:17'
  893. ))))),
  894. array(
  895. 'Apple' => array(
  896. 'id' => 6,
  897. 'apple_id' => 4,
  898. 'color' => 'My new appleOrange',
  899. 'name' => 'My new apple',
  900. 'created' => '2006-12-25 05:29:39',
  901. 'date' => '2006-12-25',
  902. 'modified' => '2006-12-25 05:29:39',
  903. 'mytime' => '22:57:17'
  904. ),
  905. 'Parent' => array(
  906. 'id' => 4,
  907. 'apple_id' => 2,
  908. 'color' => 'Blue Green',
  909. 'name' => 'Test Name',
  910. 'created' => '2006-12-25 05:23:36',
  911. 'date' => '2006-12-25',
  912. 'modified' => '2006-12-25 05:23:36',
  913. 'mytime' => '22:57:17',
  914. 'Parent' => array(
  915. 'id' => 2,
  916. 'apple_id' => 1,
  917. 'color' => 'Bright Red 1',
  918. 'name' => 'Bright Red Apple',
  919. 'created' => '2006-11-22 10:43:13',
  920. 'date' => '2014-01-01',
  921. 'modified' => '2006-11-30 18:38:10',
  922. 'mytime' => '22:57:17'
  923. ),
  924. 'Sample' => array(
  925. 'id' => 3,
  926. 'apple_id' => 4,
  927. 'name' => 'sample3'
  928. ),
  929. 'Child' => array(
  930. array(
  931. 'id' => 6,
  932. 'apple_id' => 4,
  933. 'color' => 'My new appleOrange',
  934. 'name' => 'My new apple',
  935. 'created' => '2006-12-25 05:29:39',
  936. 'date' => '2006-12-25',
  937. 'modified' => '2006-12-25 05:29:39',
  938. 'mytime' => '22:57:17'
  939. ))),
  940. 'Sample' => array(
  941. 'id' => '',
  942. 'apple_id' => '',
  943. 'name' => ''
  944. ),
  945. 'Child' => array(
  946. array(
  947. 'id' => 7,
  948. 'apple_id' => 6,
  949. 'color' => 'Some wierd color',
  950. 'name' => 'Some odd color',
  951. 'created' => '2006-12-25 05:34:21',
  952. 'date' => '2006-12-25',
  953. 'modified' => '2006-12-25 05:34:21',
  954. 'mytime' => '22:57:17',
  955. 'Parent' => array(
  956. 'id' => 6,
  957. 'apple_id' => 4,
  958. 'color' => 'My new appleOrange',
  959. 'name' => 'My new apple',
  960. 'created' => '2006-12-25 05:29:39',
  961. 'date' => '2006-12-25',
  962. 'modified' => '2006-12-25 05:29:39',
  963. 'mytime' => '22:57:17'
  964. ),
  965. 'Sample' => array()
  966. ))),
  967. array(
  968. 'Apple' => array(
  969. 'id' => 7,
  970. 'apple_id' => 6,
  971. 'color' =>
  972. 'Some wierd color',
  973. 'name' => 'Some odd color',
  974. 'created' => '2006-12-25 05:34:21',
  975. 'date' => '2006-12-25',
  976. 'modified' => '2006-12-25 05:34:21',
  977. 'mytime' => '22:57:17'
  978. ),
  979. 'Parent' => array(
  980. 'id' => 6,
  981. 'apple_id' => 4,
  982. 'color' => 'My new appleOrange',
  983. 'name' => 'My new apple',
  984. 'created' => '2006-12-25 05:29:39',
  985. 'date' => '2006-12-25',
  986. 'modified' => '2006-12-25 05:29:39',
  987. 'mytime' => '22:57:17',
  988. 'Parent' => array(
  989. 'id' => 4,
  990. 'apple_id' => 2,
  991. 'color' => 'Blue Green',
  992. 'name' => 'Test Name',
  993. 'created' => '2006-12-25 05:23:36',
  994. 'date' => '2006-12-25',
  995. 'modified' => '2006-12-25 05:23:36',
  996. 'mytime' => '22:57:17'
  997. ),
  998. 'Sample' => array(),
  999. 'Child' => array(
  1000. array(
  1001. 'id' => 7,
  1002. 'apple_id' => 6,
  1003. 'color' => 'Some wierd color',
  1004. 'name' => 'Some odd color',
  1005. 'created' => '2006-12-25 05:34:21',
  1006. 'date' => '2006-12-25',
  1007. 'modified' => '2006-12-25 05:34:21',
  1008. 'mytime' => '22:57:17'
  1009. ))),
  1010. 'Sample' => array(
  1011. 'id' => '',
  1012. 'apple_id' => '',
  1013. 'name' => ''
  1014. ),
  1015. 'Child' => array()));
  1016. $this->assertEquals($expected, $result);
  1017. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1018. $this->assertTrue($result);
  1019. $result = $TestModel->find('all');
  1020. $expected = array(
  1021. array(
  1022. 'Apple' => array(
  1023. 'id' => 1,
  1024. 'apple_id' => 2,
  1025. 'color' => 'Red 1',
  1026. 'name' => 'Red Apple 1',
  1027. 'created' => '2006-11-22 10:38:58',
  1028. 'date' => '1951-01-04',
  1029. 'modified' => '2006-12-01 13:31:26',
  1030. 'mytime' => '22:57:17'),
  1031. 'Parent' => array(
  1032. 'id' => 2,
  1033. 'apple_id' => 1,
  1034. 'color' => 'Bright Red 1',
  1035. 'name' => 'Bright Red Apple',
  1036. 'created' => '2006-11-22 10:43:13',
  1037. 'date' => '2014-01-01',
  1038. 'modified' => '2006-11-30 18:38:10',
  1039. 'mytime' => '22:57:17',
  1040. 'Parent' => array(
  1041. 'id' => 1,
  1042. 'apple_id' => 2,
  1043. 'color' => 'Red 1',
  1044. 'name' => 'Red Apple 1',
  1045. 'created' => '2006-11-22 10:38:58',
  1046. 'date' => '1951-01-04',
  1047. 'modified' => '2006-12-01 13:31:26',
  1048. 'mytime' => '22:57:17'
  1049. ),
  1050. 'Child' => array(
  1051. array(
  1052. 'id' => 1,
  1053. 'apple_id' => 2,
  1054. 'color' => 'Red 1',
  1055. 'name' => 'Red Apple 1',
  1056. 'created' => '2006-11-22 10:38:58',
  1057. 'date' => '1951-01-04',
  1058. 'modified' => '2006-12-01 13:31:26',
  1059. 'mytime' => '22:57:17'
  1060. ),
  1061. array(
  1062. 'id' => 3,
  1063. 'apple_id' => 2,
  1064. 'color' => 'blue green',
  1065. 'name' => 'green blue',
  1066. 'created' => '2006-12-25 05:13:36',
  1067. 'date' => '2006-12-25',
  1068. 'modified' => '2006-12-25 05:23:24',
  1069. 'mytime' => '22:57:17'
  1070. ),
  1071. array(
  1072. 'id' => 4,
  1073. 'apple_id' => 2,
  1074. 'color' => 'Blue Green',
  1075. 'name' => 'Test Name',
  1076. 'created' => '2006-12-25 05:23:36',
  1077. 'date' => '2006-12-25',
  1078. 'modified' => '2006-12-25 05:23:36',
  1079. 'mytime' => '22:57:17'
  1080. ))),
  1081. 'Sample' => array(
  1082. 'id' => '',
  1083. 'apple_id' => '',
  1084. 'name' => ''
  1085. ),
  1086. 'Child' => array(
  1087. array(
  1088. 'id' => 2,
  1089. 'apple_id' => 1,
  1090. 'color' => 'Bright Red 1',
  1091. 'name' => 'Bright Red Apple',
  1092. 'created' => '2006-11-22 10:43:13',
  1093. 'date' => '2014-01-01',
  1094. 'modified' => '2006-11-30 18:38:10',
  1095. 'mytime' => '22:57:17',
  1096. 'Parent' => array(
  1097. 'id' => 1,
  1098. 'apple_id' => 2,
  1099. 'color' => 'Red 1',
  1100. 'name' => 'Red Apple 1',
  1101. 'created' => '2006-11-22 10:38:58',
  1102. 'date' => '1951-01-04',
  1103. 'modified' => '2006-12-01 13:31:26',
  1104. 'mytime' => '22:57:17'
  1105. ),
  1106. 'Sample' => array(
  1107. 'id' => 2,
  1108. 'apple_id' => 2,
  1109. 'name' => 'sample2'
  1110. ),
  1111. 'Child' => array(
  1112. array(
  1113. 'id' => 1,
  1114. 'apple_id' => 2,
  1115. 'color' => 'Red 1',
  1116. 'name' => 'Red Apple 1',
  1117. 'created' => '2006-11-22 10:38:58',
  1118. 'date' => '1951-01-04',
  1119. 'modified' => '2006-12-01 13:31:26',
  1120. 'mytime' => '22:57:17'
  1121. ),
  1122. array(
  1123. 'id' => 3,
  1124. 'apple_id' => 2,
  1125. 'color' => 'blue green',
  1126. 'name' => 'green blue',
  1127. 'created' => '2006-12-25 05:13:36',
  1128. 'date' => '2006-12-25',
  1129. 'modified' => '2006-12-25 05:23:24',
  1130. 'mytime' => '22:57:17'
  1131. ),
  1132. array(
  1133. 'id' => 4,
  1134. 'apple_id' => 2,
  1135. 'color' => 'Blue Green',
  1136. 'name' => 'Test Name',
  1137. 'created' => '2006-12-25 05:23:36',
  1138. 'date' => '2006-12-25',
  1139. 'modified' => '2006-12-25 05:23:36',
  1140. 'mytime' => '22:57:17'
  1141. ))))),
  1142. array(
  1143. 'Apple' => array(
  1144. 'id' => 2,
  1145. 'apple_id' => 1,
  1146. 'color' => 'Bright Red 1',
  1147. 'name' => 'Bright Red Apple',
  1148. 'created' => '2006-11-22 10:43:13',
  1149. 'date' => '2014-01-01',
  1150. 'modified' => '2006-11-30 18:38:10',
  1151. 'mytime' => '22:57:17'
  1152. ),
  1153. 'Parent' => array(
  1154. 'id' => 1,
  1155. 'apple_id' => 2,
  1156. 'color' => 'Red 1',
  1157. 'name' => 'Red Apple 1',
  1158. 'created' => '2006-11-22 10:38:58',
  1159. 'date' => '1951-01-04',
  1160. 'modified' => '2006-12-01 13:31:26',
  1161. 'mytime' => '22:57:17',
  1162. 'Parent' => array(
  1163. 'id' => 2,
  1164. 'apple_id' => 1,
  1165. 'color' => 'Bright Red 1',
  1166. 'name' => 'Bright Red Apple',
  1167. 'created' => '2006-11-22 10:43:13',
  1168. 'date' => '2014-01-01',
  1169. 'modified' => '2006-11-30 18:38:10',
  1170. 'mytime' => '22:57:17'
  1171. ),
  1172. 'Child' => array(
  1173. array(
  1174. 'id' => 2,
  1175. 'apple_id' => 1,
  1176. 'color' => 'Bright Red 1',
  1177. 'name' => 'Bright Red Apple',
  1178. 'created' => '2006-11-22 10:43:13',
  1179. 'date' => '2014-01-01',
  1180. 'modified' => '2006-11-30 18:38:10',
  1181. 'mytime' => '22:57:17'
  1182. ))),
  1183. 'Sample' => array(
  1184. 'id' => 2,
  1185. 'apple_id' => 2,
  1186. 'name' => 'sample2',
  1187. 'Apple' => array(
  1188. 'id' => 2,
  1189. 'apple_id' => 1,
  1190. 'color' => 'Bright Red 1',
  1191. 'name' => 'Bright Red Apple',
  1192. 'created' => '2006-11-22 10:43:13',
  1193. 'date' => '2014-01-01',
  1194. 'modified' => '2006-11-30 18:38:10',
  1195. 'mytime' => '22:57:17'
  1196. )),
  1197. 'Child' => array(
  1198. array(
  1199. 'id' => 1,
  1200. 'apple_id' => 2,
  1201. 'color' => 'Red 1',
  1202. 'name' => 'Red Apple 1',
  1203. 'created' => '2006-11-22 10:38:58',
  1204. 'date' => '1951-01-04',
  1205. 'modified' => '2006-12-01 13:31:26',
  1206. 'mytime' => '22:57:17',
  1207. 'Parent' => array(
  1208. 'id' => 2,
  1209. 'apple_id' => 1,
  1210. 'color' => 'Bright Red 1',
  1211. 'name' => 'Bright Red Apple',
  1212. 'created' => '2006-11-22 10:43:13',
  1213. 'date' => '2014-01-01',
  1214. 'modified' => '2006-11-30 18:38:10',
  1215. 'mytime' => '22:57:17'
  1216. ),
  1217. 'Sample' => array(),
  1218. 'Child' => array(
  1219. array(
  1220. 'id' => 2,
  1221. 'apple_id' => 1,
  1222. 'color' => 'Bright Red 1',
  1223. 'name' => 'Bright Red Apple',
  1224. 'created' => '2006-11-22 10:43:13',
  1225. 'date' => '2014-01-01', 'modified' =>
  1226. '2006-11-30 18:38:10',
  1227. 'mytime' => '22:57:17'
  1228. ))),
  1229. array(
  1230. 'id' => 3,
  1231. 'apple_id' => 2,
  1232. 'color' => 'blue green',
  1233. 'name' => 'green blue',
  1234. 'created' => '2006-12-25 05:13:36',
  1235. 'date' => '2006-12-25',
  1236. 'modified' => '2006-12-25 05:23:24',
  1237. 'mytime' => '22:57:17',
  1238. 'Parent' => array(
  1239. 'id' => 2,
  1240. 'apple_id' => 1,
  1241. 'color' => 'Bright Red 1',
  1242. 'name' => 'Bright Red Apple',
  1243. 'created' => '2006-11-22 10:43:13',
  1244. 'date' => '2014-01-01',
  1245. 'modified' => '2006-11-30 18:38:10',
  1246. 'mytime' => '22:57:17'
  1247. ),
  1248. 'Sample' => array(
  1249. 'id' => 1,
  1250. 'apple_id' => 3,
  1251. 'name' => 'sample1'
  1252. )),
  1253. array(
  1254. 'id' => 4,
  1255. 'apple_id' => 2,
  1256. 'color' => 'Blue Green',
  1257. 'name' => 'Test Name',
  1258. 'created' => '2006-12-25 05:23:36',
  1259. 'date' => '2006-12-25',
  1260. 'modified' => '2006-12-25 05:23:36',
  1261. 'mytime' => '22:57:17',
  1262. 'Parent' => array(
  1263. 'id' => 2,
  1264. 'apple_id' => 1,
  1265. 'color' => 'Bright Red 1',
  1266. 'name' => 'Bright Red Apple',
  1267. 'created' => '2006-11-22 10:43:13',
  1268. 'date' => '2014-01-01',
  1269. 'modified' => '2006-11-30 18:38:10',
  1270. 'mytime' => '22:57:17'
  1271. ),
  1272. 'Sample' => array(
  1273. 'id' => 3,
  1274. 'apple_id' => 4,
  1275. 'name' => 'sample3'
  1276. ),
  1277. 'Child' => array(
  1278. array(
  1279. 'id' => 6,
  1280. 'apple_id' => 4,
  1281. 'color' => 'My new appleOrange',
  1282. 'name' => 'My new apple',
  1283. 'created' => '2006-12-25 05:29:39',
  1284. 'date' => '2006-12-25',
  1285. 'modified' => '2006-12-25 05:29:39',
  1286. 'mytime' => '22:57:17'
  1287. ))))),
  1288. array(
  1289. 'Apple' => array(
  1290. 'id' => 3,
  1291. 'apple_id' => 2,
  1292. 'color' => 'blue green',
  1293. 'name' => 'green blue',
  1294. 'created' => '2006-12-25 05:13:36',
  1295. 'date' => '2006-12-25',
  1296. 'modified' => '2006-12-25 05:23:24',
  1297. 'mytime' => '22:57:17'
  1298. ),
  1299. 'Parent' => array(
  1300. 'id' => 2,
  1301. 'apple_id' => 1,
  1302. 'color' => 'Bright Red 1',
  1303. 'name' => 'Bright Red Apple',
  1304. 'created' => '2006-11-22 10:43:13',
  1305. 'date' => '2014-01-01',
  1306. 'modified' => '2006-11-30 18:38:10',
  1307. 'mytime' => '22:57:17',
  1308. 'Parent' => array(
  1309. 'id' => 1,
  1310. 'apple_id' => 2,
  1311. 'color' => 'Red 1',
  1312. 'name' => 'Red Apple 1',
  1313. 'created' => '2006-11-22 10:38:58',
  1314. 'date' => '1951-01-04',
  1315. 'modified' => '2006-12-01 13:31:26',
  1316. 'mytime' => '22:57:17'
  1317. ),
  1318. 'Child' => array(
  1319. array(
  1320. 'id' => 1,
  1321. 'apple_id' => 2,
  1322. 'color' => 'Red 1',
  1323. 'name' => 'Red Apple 1',
  1324. 'created' => '2006-11-22 10:38:58',
  1325. 'date' => '1951-01-04',
  1326. 'modified' => '2006-12-01 13:31:26',
  1327. 'mytime' => '22:57:17'
  1328. ),
  1329. array(
  1330. 'id' => 3,
  1331. 'apple_id' => 2,
  1332. 'color' => 'blue green',
  1333. 'name' => 'green blue',
  1334. 'created' => '2006-12-25 05:13:36',
  1335. 'date' => '2006-12-25',
  1336. 'modified' => '2006-12-25 05:23:24',
  1337. 'mytime' => '22:57:17'
  1338. ),
  1339. array(
  1340. 'id' => 4,
  1341. 'apple_id' => 2,
  1342. 'color' => 'Blue Green',
  1343. 'name' => 'Test Name',
  1344. 'created' => '2006-12-25 05:23:36',
  1345. 'date' => '2006-12-25',
  1346. 'modified' => '2006-12-25 05:23:36',
  1347. 'mytime' => '22:57:17'
  1348. ))),
  1349. 'Sample' => array(
  1350. 'id' => 1,
  1351. 'apple_id' => 3,
  1352. 'name' => 'sample1',
  1353. 'Apple' => array(
  1354. 'id' => 3,
  1355. 'apple_id' => 2,
  1356. 'color' => 'blue green',
  1357. 'name' => 'green blue',
  1358. 'created' => '2006-12-25 05:13:36',
  1359. 'date' => '2006-12-25',
  1360. 'modified' => '2006-12-25 05:23:24',
  1361. 'mytime' => '22:57:17'
  1362. )),
  1363. 'Child' => array()
  1364. ),
  1365. array(
  1366. 'Apple' => array(
  1367. 'id' => 4,
  1368. 'apple_id' => 2,
  1369. 'color' => 'Blue Green',
  1370. 'name' => 'Test Name',
  1371. 'created' => '2006-12-25 05:23:36',
  1372. 'date' => '2006-12-25',
  1373. 'modified' => '2006-12-25 05:23:36',
  1374. 'mytime' => '22:57:17'
  1375. ),
  1376. 'Parent' => array(
  1377. 'id' => 2,
  1378. 'apple_id' => 1,
  1379. 'color' => 'Bright Red 1',
  1380. 'name' => 'Bright Red Apple',
  1381. 'created' => '2006-11-22 10:43:13',
  1382. 'date' => '2014-01-01',
  1383. 'modified' => '2006-11-30 18:38:10',
  1384. 'mytime' => '22:57:17',
  1385. 'Parent' => array(
  1386. 'id' => 1,
  1387. 'apple_id' => 2,
  1388. 'color' => 'Red 1',
  1389. 'name' => 'Red Apple 1',
  1390. 'created' => '2006-11-22 10:38:58',
  1391. 'date' => '1951-01-04',
  1392. 'modified' => '2006-12-01 13:31:26',
  1393. 'mytime' => '22:57:17'
  1394. ),
  1395. 'Child' => array(
  1396. array(
  1397. 'id' => 1,
  1398. 'apple_id' => 2,
  1399. 'color' => 'Red 1',
  1400. 'name' => 'Red Apple 1',
  1401. 'created' => '2006-11-22 10:38:58',
  1402. 'date' => '1951-01-04',
  1403. 'modified' => '2006-12-01 13:31:26',
  1404. 'mytime' => '22:57:17'
  1405. ),
  1406. array(
  1407. 'id' => 3,
  1408. 'apple_id' => 2,
  1409. 'color' => 'blue green',
  1410. 'name' => 'green blue',
  1411. 'created' => '2006-12-25 05:13:36',
  1412. 'date' => '2006-12-25',
  1413. 'modified' => '2006-12-25 05:23:24',
  1414. 'mytime' => '22:57:17'
  1415. ),
  1416. array(
  1417. 'id' => 4,
  1418. 'apple_id' => 2,
  1419. 'color' => 'Blue Green',
  1420. 'name' => 'Test Name',
  1421. 'created' => '2006-12-25 05:23:36',
  1422. 'date' => '2006-12-25',
  1423. 'modified' => '2006-12-25 05:23:36',
  1424. 'mytime' => '22:57:17'
  1425. ))),
  1426. 'Sample' => array(
  1427. 'id' => 3,
  1428. 'apple_id' => 4,
  1429. 'name' => 'sample3',
  1430. 'Apple' => array(
  1431. 'id' => 4,
  1432. 'apple_id' => 2,
  1433. 'color' => 'Blue Green',
  1434. 'name' => 'Test Name',
  1435. 'created' => '2006-12-25 05:23:36',
  1436. 'date' => '2006-12-25',
  1437. 'modified' => '2006-12-25 05:23:36',
  1438. 'mytime' => '22:57:17'
  1439. )),
  1440. 'Child' => array(
  1441. array(
  1442. 'id' => 6,
  1443. 'apple_id' => 4,
  1444. 'color' => 'My new appleOrange',
  1445. 'name' => 'My new apple',
  1446. 'created' => '2006-12-25 05:29:39',
  1447. 'date' => '2006-12-25',
  1448. 'modified' => '2006-12-25 05:29:39',
  1449. 'mytime' => '22:57:17',
  1450. 'Parent' => array(
  1451. 'id' => 4,
  1452. 'apple_id' => 2,
  1453. 'color' => 'Blue Green',
  1454. 'name' => 'Test Name',
  1455. 'created' => '2006-12-25 05:23:36',
  1456. 'date' => '2006-12-25',
  1457. 'modified' => '2006-12-25 05:23:36',
  1458. 'mytime' => '22:57:17'
  1459. ),
  1460. 'Sample' => array(),
  1461. 'Child' => array(
  1462. array(
  1463. 'id' => 7,
  1464. 'apple_id' => 6,
  1465. 'color' => 'Some wierd color',
  1466. 'name' => 'Some odd color',
  1467. 'created' => '2006-12-25 05:34:21',
  1468. 'date' => '2006-12-25',
  1469. 'modified' => '2006-12-25 05:34:21',
  1470. 'mytime' => '22:57:17'
  1471. ))))),
  1472. array(
  1473. 'Apple' => array(
  1474. 'id' => 5,
  1475. 'apple_id' => 5,
  1476. 'color' => 'Green',
  1477. 'name' => 'Blue Green',
  1478. 'created' => '2006-12-25 05:24:06',
  1479. 'date' => '2006-12-25',
  1480. 'modified' => '2006-12-25 05:29:16',
  1481. 'mytime' => '22:57:17'
  1482. ),
  1483. 'Parent' => array(
  1484. 'id' => 5,
  1485. 'apple_id' => 5,
  1486. 'color' => 'Green',
  1487. 'name' => 'Blue Green',
  1488. 'created' => '2006-12-25 05:24:06',
  1489. 'date' => '2006-12-25',
  1490. 'modified' => '2006-12-25 05:29:16',
  1491. 'mytime' => '22:57:17',
  1492. 'Parent' => array(
  1493. 'id' => 5,
  1494. 'apple_id' => 5,
  1495. 'color' => 'Green',
  1496. 'name' => 'Blue Green',
  1497. 'created' => '2006-12-25 05:24:06',
  1498. 'date' => '2006-12-25',
  1499. 'modified' => '2006-12-25 05:29:16',
  1500. 'mytime' => '22:57:17'
  1501. ),
  1502. 'Child' => array(
  1503. array(
  1504. 'id' => 5,
  1505. 'apple_id' => 5,
  1506. 'color' => 'Green',
  1507. 'name' => 'Blue Green',
  1508. 'created' => '2006-12-25 05:24:06',
  1509. 'date' => '2006-12-25',
  1510. 'modified' => '2006-12-25 05:29:16',
  1511. 'mytime' => '22:57:17'
  1512. ))),
  1513. 'Sample' => array(
  1514. 'id' => 4,
  1515. 'apple_id' => 5,
  1516. 'name' => 'sample4',
  1517. 'Apple' => array(
  1518. 'id' => 5,
  1519. 'apple_id' => 5,
  1520. 'color' => 'Green',
  1521. 'name' => 'Blue Green',
  1522. 'created' => '2006-12-25 05:24:06',
  1523. 'date' => '2006-12-25',
  1524. 'modified' => '2006-12-25 05:29:16',
  1525. 'mytime' => '22:57:17'
  1526. )),
  1527. 'Child' => array(
  1528. array(
  1529. 'id' => 5,
  1530. 'apple_id' => 5,
  1531. 'color' => 'Green',
  1532. 'name' => 'Blue Green',
  1533. 'created' => '2006-12-25 05:24:06',
  1534. 'date' => '2006-12-25',
  1535. 'modified' => '2006-12-25 05:29:16',
  1536. 'mytime' => '22:57:17',
  1537. 'Parent' => array(
  1538. 'id' => 5,
  1539. 'apple_id' => 5,
  1540. 'color' => 'Green',
  1541. 'name' => 'Blue Green',
  1542. 'created' => '2006-12-25 05:24:06',
  1543. 'date' => '2006-12-25',
  1544. 'modified' => '2006-12-25 05:29:16',
  1545. 'mytime' => '22:57:17'
  1546. ),
  1547. 'Sample' => array(
  1548. 'id' => 4,
  1549. 'apple_id' => 5,
  1550. 'name' => 'sample4'
  1551. ),
  1552. 'Child' => array(
  1553. array(
  1554. 'id' => 5,
  1555. 'apple_id' => 5,
  1556. 'color' => 'Green',
  1557. 'name' => 'Blue Green',
  1558. 'created' => '2006-12-25 05:24:06',
  1559. 'date' => '2006-12-25',
  1560. 'modified' => '2006-12-25 05:29:16',
  1561. 'mytime' => '22:57:17'
  1562. ))))),
  1563. array(
  1564. 'Apple' => array(
  1565. 'id' => 6,
  1566. 'apple_id' => 4,
  1567. 'color' => 'My new appleOrange',
  1568. 'name' => 'My new apple',
  1569. 'created' => '2006-12-25 05:29:39',
  1570. 'date' => '2006-12-25',
  1571. 'modified' => '2006-12-25 05:29:39',
  1572. 'mytime' => '22:57:17'
  1573. ),
  1574. 'Parent' => array(
  1575. 'id' => 4,
  1576. 'apple_id' => 2,
  1577. 'color' => 'Blue Green',
  1578. 'name' => 'Test Name',
  1579. 'created' => '2006-12-25 05:23:36',
  1580. 'date' => '2006-12-25',
  1581. 'modified' => '2006-12-25 05:23:36',
  1582. 'mytime' => '22:57:17',
  1583. 'Parent' => array(
  1584. 'id' => 2,
  1585. 'apple_id' => 1,
  1586. 'color' => 'Bright Red 1',
  1587. 'name' => 'Bright Red Apple',
  1588. 'created' => '2006-11-22 10:43:13',
  1589. 'date' => '2014-01-01',
  1590. 'modified' => '2006-11-30 18:38:10',
  1591. 'mytime' => '22:57:17'
  1592. ),
  1593. 'Child' => array(
  1594. array(
  1595. 'id' => 6,
  1596. 'apple_id' => 4,
  1597. 'color' => 'My new appleOrange',
  1598. 'name' => 'My new apple',
  1599. 'created' => '2006-12-25 05:29:39',
  1600. 'date' => '2006-12-25',
  1601. 'modified' => '2006-12-25 05:29:39',
  1602. 'mytime' => '22:57:17'
  1603. ))),
  1604. 'Sample' => array(
  1605. 'id' => '',
  1606. 'apple_id' => '',
  1607. 'name' => ''
  1608. ),
  1609. 'Child' => array(
  1610. array(
  1611. 'id' => 7,
  1612. 'apple_id' => 6,
  1613. 'color' => 'Some wierd color',
  1614. 'name' => 'Some odd color',
  1615. 'created' => '2006-12-25 05:34:21',
  1616. 'date' => '2006-12-25',
  1617. 'modified' => '2006-12-25 05:34:21',
  1618. 'mytime' => '22:57:17',
  1619. 'Parent' => array(
  1620. 'id' => 6,
  1621. 'apple_id' => 4,
  1622. 'color' => 'My new appleOrange',
  1623. 'name' => 'My new apple',
  1624. 'created' => '2006-12-25 05:29:39',
  1625. 'date' => '2006-12-25',
  1626. 'modified' => '2006-12-25 05:29:39',
  1627. 'mytime' => '22:57:17'
  1628. ),
  1629. 'Sample' => array()
  1630. ))),
  1631. array(
  1632. 'Apple' => array(
  1633. 'id' => 7,
  1634. 'apple_id' => 6,
  1635. 'color' => 'Some wierd color',
  1636. 'name' => 'Some odd color',
  1637. 'created' => '2006-12-25 05:34:21',
  1638. 'date' => '2006-12-25',
  1639. 'modified' => '2006-12-25 05:34:21',
  1640. 'mytime' => '22:57:17'
  1641. ),
  1642. 'Parent' => array(
  1643. 'id' => 6,
  1644. 'apple_id' => 4,
  1645. 'color' => 'My new appleOrange',
  1646. 'name' => 'My new apple',
  1647. 'created' => '2006-12-25 05:29:39',
  1648. 'date' => '2006-12-25',
  1649. 'modified' => '2006-12-25 05:29:39',
  1650. 'mytime' => '22:57:17',
  1651. 'Parent' => array(
  1652. 'id' => 4,
  1653. 'apple_id' => 2,
  1654. 'color' => 'Blue Green',
  1655. 'name' => 'Test Name',
  1656. 'created' => '2006-12-25 05:23:36',
  1657. 'date' => '2006-12-25',
  1658. 'modified' => '2006-12-25 05:23:36',
  1659. 'mytime' => '22:57:17'
  1660. ),
  1661. 'Child' => array(
  1662. array(
  1663. 'id' => 7,
  1664. 'apple_id' => 6,
  1665. 'color' => 'Some wierd color',
  1666. 'name' => 'Some odd color',
  1667. 'created' => '2006-12-25 05:34:21',
  1668. 'date' => '2006-12-25',
  1669. 'modified' => '2006-12-25 05:34:21',
  1670. 'mytime' => '22:57:17'
  1671. ))),
  1672. 'Sample' => array(
  1673. 'id' => '',
  1674. 'apple_id' => '',
  1675. 'name' => ''
  1676. ),
  1677. 'Child' => array()
  1678. ));
  1679. $this->assertEquals($expected, $result);
  1680. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1681. $this->assertTrue($result);
  1682. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  1683. $this->assertTrue($result);
  1684. $result = $TestModel->find('all');
  1685. $expected = array(
  1686. array(
  1687. 'Apple' => array(
  1688. 'id' => 1,
  1689. 'apple_id' => 2,
  1690. 'color' => 'Red 1',
  1691. 'name' => 'Red Apple 1',
  1692. 'created' => '2006-11-22 10:38:58',
  1693. 'date' => '1951-01-04',
  1694. 'modified' => '2006-12-01 13:31:26',
  1695. 'mytime' => '22:57:17'
  1696. ),
  1697. 'Parent' => array(
  1698. 'id' => 2,
  1699. 'apple_id' => 1,
  1700. 'color' => 'Bright Red 1',
  1701. 'name' => 'Bright Red Apple',
  1702. 'created' => '2006-11-22 10:43:13',
  1703. 'date' => '2014-01-01',
  1704. 'modified' => '2006-11-30 18:38:10',
  1705. 'mytime' => '22:57:17',
  1706. 'Parent' => array(
  1707. 'id' => 1,
  1708. 'apple_id' => 2,
  1709. 'color' => 'Red 1',
  1710. 'name' => 'Red Apple 1',
  1711. 'created' => '2006-11-22 10:38:58',
  1712. 'date' => '1951-01-04',
  1713. 'modified' => '2006-12-01 13:31:26',
  1714. 'mytime' => '22:57:17'
  1715. ),
  1716. 'Child' => array(
  1717. array(
  1718. 'id' => 1,
  1719. 'apple_id' => 2,
  1720. 'color' => 'Red 1',
  1721. 'name' => 'Red Apple 1',
  1722. 'created' => '2006-11-22 10:38:58',
  1723. 'date' => '1951-01-04',
  1724. 'modified' => '2006-12-01 13:31:26',
  1725. 'mytime' => '22:57:17'
  1726. ),
  1727. array(
  1728. 'id' => 3,
  1729. 'apple_id' => 2,
  1730. 'color' => 'blue green',
  1731. 'name' => 'green blue',
  1732. 'created' => '2006-12-25 05:13:36',
  1733. 'date' => '2006-12-25',
  1734. 'modified' => '2006-12-25 05:23:24',
  1735. 'mytime' => '22:57:17'
  1736. ),
  1737. array(
  1738. 'id' => 4,
  1739. 'apple_id' => 2,
  1740. 'color' => 'Blue Green',
  1741. 'name' => 'Test Name',
  1742. 'created' => '2006-12-25 05:23:36',
  1743. 'date' => '2006-12-25',
  1744. 'modified' => '2006-12-25 05:23:36',
  1745. 'mytime' => '22:57:17'
  1746. ))),
  1747. 'Sample' => array(
  1748. 'id' => '',
  1749. 'apple_id' => '',
  1750. 'name' => ''
  1751. )),
  1752. array(
  1753. 'Apple' => array(
  1754. 'id' => 2,
  1755. 'apple_id' => 1,
  1756. 'color' => 'Bright Red 1',
  1757. 'name' => 'Bright Red Apple',
  1758. 'created' => '2006-11-22 10:43:13',
  1759. 'date' => '2014-01-01',
  1760. 'modified' => '2006-11-30 18:38:10',
  1761. 'mytime' => '22:57:17'
  1762. ),
  1763. 'Parent' => array(
  1764. 'id' => 1,
  1765. 'apple_id' => 2,
  1766. 'color' => 'Red 1',
  1767. 'name' => 'Red Apple 1',
  1768. 'created' => '2006-11-22 10:38:58',
  1769. 'date' => '1951-01-04',
  1770. 'modified' => '2006-12-01 13:31:26',
  1771. 'mytime' => '22:57:17',
  1772. 'Parent' => array(
  1773. 'id' => 2,
  1774. 'apple_id' => 1,
  1775. 'color' => 'Bright Red 1',
  1776. 'name' => 'Bright Red Apple',
  1777. 'created' => '2006-11-22 10:43:13',
  1778. 'date' => '2014-01-01',
  1779. 'modified' => '2006-11-30 18:38:10',
  1780. 'mytime' => '22:57:17'
  1781. ),
  1782. 'Child' => array(
  1783. array(
  1784. 'id' => 2,
  1785. 'apple_id' => 1,
  1786. 'color' => 'Bright Red 1',
  1787. 'name' => 'Bright Red Apple',
  1788. 'created' => '2006-11-22 10:43:13',
  1789. 'date' => '2014-01-01',
  1790. 'modified' => '2006-11-30 18:38:10',
  1791. 'mytime' => '22:57:17'
  1792. ))),
  1793. 'Sample' => array(
  1794. 'id' => 2,
  1795. 'apple_id' => 2,
  1796. 'name' => 'sample2',
  1797. 'Apple' => array(
  1798. 'id' => 2,
  1799. 'apple_id' => 1,
  1800. 'color' => 'Bright Red 1',
  1801. 'name' => 'Bright Red Apple',
  1802. 'created' => '2006-11-22 10:43:13',
  1803. 'date' => '2014-01-01',
  1804. 'modified' => '2006-11-30 18:38:10',
  1805. 'mytime' => '22:57:17'
  1806. ))),
  1807. array(
  1808. 'Apple' => array(
  1809. 'id' => 3,
  1810. 'apple_id' => 2,
  1811. 'color' => 'blue green',
  1812. 'name' => 'green blue',
  1813. 'created' => '2006-12-25 05:13:36',
  1814. 'date' => '2006-12-25',
  1815. 'modified' => '2006-12-25 05:23:24',
  1816. 'mytime' => '22:57:17'
  1817. ),
  1818. 'Parent' => array(
  1819. 'id' => 2,
  1820. 'apple_id' => 1,
  1821. 'color' => 'Bright Red 1',
  1822. 'name' => 'Bright Red Apple',
  1823. 'created' => '2006-11-22 10:43:13',
  1824. 'date' => '2014-01-01',
  1825. 'modified' => '2006-11-30 18:38:10',
  1826. 'mytime' => '22:57:17',
  1827. 'Parent' => array(
  1828. 'id' => 1,
  1829. 'apple_id' => 2,
  1830. 'color' => 'Red 1',
  1831. 'name' => 'Red Apple 1',
  1832. 'created' => '2006-11-22 10:38:58',
  1833. 'date' => '1951-01-04',
  1834. 'modified' => '2006-12-01 13:31:26',
  1835. 'mytime' => '22:57:17'
  1836. ),
  1837. 'Child' => array(
  1838. array(
  1839. 'id' => 1,
  1840. 'apple_id' => 2,
  1841. 'color' => 'Red 1',
  1842. 'name' => 'Red Apple 1',
  1843. 'created' => '2006-11-22 10:38:58',
  1844. 'date' => '1951-01-04',
  1845. 'modified' => '2006-12-01 13:31:26',
  1846. 'mytime' => '22:57:17'
  1847. ),
  1848. array(
  1849. 'id' => 3,
  1850. 'apple_id' => 2,
  1851. 'color' => 'blue green',
  1852. 'name' => 'green blue',
  1853. 'created' => '2006-12-25 05:13:36',
  1854. 'date' => '2006-12-25',
  1855. 'modified' => '2006-12-25 05:23:24',
  1856. 'mytime' => '22:57:17'
  1857. ),
  1858. array(
  1859. 'id' => 4,
  1860. 'apple_id' => 2,
  1861. 'color' => 'Blue Green',
  1862. 'name' => 'Test Name',
  1863. 'created' => '2006-12-25 05:23:36',
  1864. 'date' => '2006-12-25',
  1865. 'modified' => '2006-12-25 05:23:36',
  1866. 'mytime' => '22:57:17'
  1867. ))),
  1868. 'Sample' => array(
  1869. 'id' => 1,
  1870. 'apple_id' => 3,
  1871. 'name' => 'sample1',
  1872. 'Apple' => array(
  1873. 'id' => 3,
  1874. 'apple_id' => 2,
  1875. 'color' => 'blue green',
  1876. 'name' => 'green blue',
  1877. 'created' => '2006-12-25 05:13:36',
  1878. 'date' => '2006-12-25',
  1879. 'modified' => '2006-12-25 05:23:24',
  1880. 'mytime' => '22:57:17'
  1881. ))),
  1882. array(
  1883. 'Apple' => array(
  1884. 'id' => 4,
  1885. 'apple_id' => 2,
  1886. 'color' => 'Blue Green',
  1887. 'name' => 'Test Name',
  1888. 'created' => '2006-12-25 05:23:36',
  1889. 'date' => '2006-12-25',
  1890. 'modified' => '2006-12-25 05:23:36',
  1891. 'mytime' => '22:57:17'
  1892. ),
  1893. 'Parent' => array(
  1894. 'id' => 2,
  1895. 'apple_id' => 1,
  1896. 'color' => 'Bright Red 1',
  1897. 'name' => 'Bright Red Apple',
  1898. 'created' => '2006-11-22 10:43:13',
  1899. 'date' => '2014-01-01',
  1900. 'modified' => '2006-11-30 18:38:10',
  1901. 'mytime' => '22:57:17',
  1902. 'Parent' => array(
  1903. 'id' => 1,
  1904. 'apple_id' => 2,
  1905. 'color' => 'Red 1',
  1906. 'name' => 'Red Apple 1',
  1907. 'created' => '2006-11-22 10:38:58',
  1908. 'date' => '1951-01-04',
  1909. 'modified' => '2006-12-01 13:31:26',
  1910. 'mytime' => '22:57:17'
  1911. ),
  1912. 'Child' => array(
  1913. array(
  1914. 'id' => 1,
  1915. 'apple_id' => 2,
  1916. 'color' => 'Red 1',
  1917. 'name' => 'Red Apple 1',
  1918. 'created' => '2006-11-22 10:38:58',
  1919. 'date' => '1951-01-04',
  1920. 'modified' => '2006-12-01 13:31:26',
  1921. 'mytime' => '22:57:17'
  1922. ),
  1923. array(
  1924. 'id' => 3,
  1925. 'apple_id' => 2,
  1926. 'color' => 'blue green',
  1927. 'name' => 'green blue',
  1928. 'created' => '2006-12-25 05:13:36',
  1929. 'date' => '2006-12-25',
  1930. 'modified' => '2006-12-25 05:23:24',
  1931. 'mytime' => '22:57:17'
  1932. ),
  1933. array(
  1934. 'id' => 4,
  1935. 'apple_id' => 2,
  1936. 'color' => 'Blue Green',
  1937. 'name' => 'Test Name',
  1938. 'created' => '2006-12-25 05:23:36',
  1939. 'date' => '2006-12-25',
  1940. 'modified' => '2006-12-25 05:23:36',
  1941. 'mytime' => '22:57:17'
  1942. ))),
  1943. 'Sample' => array(
  1944. 'id' => 3,
  1945. 'apple_id' => 4,
  1946. 'name' => 'sample3',
  1947. 'Apple' => array(
  1948. 'id' => 4,
  1949. 'apple_id' => 2,
  1950. 'color' => 'Blue Green',
  1951. 'name' => 'Test Name',
  1952. 'created' => '2006-12-25 05:23:36',
  1953. 'date' => '2006-12-25',
  1954. 'modified' => '2006-12-25 05:23:36',
  1955. 'mytime' => '22:57:17'
  1956. ))),
  1957. array(
  1958. 'Apple' => array(
  1959. 'id' => 5,
  1960. 'apple_id' => 5,
  1961. 'color' => 'Green',
  1962. 'name' => 'Blue Green',
  1963. 'created' => '2006-12-25 05:24:06',
  1964. 'date' => '2006-12-25',
  1965. 'modified' => '2006-12-25 05:29:16',
  1966. 'mytime' => '22:57:17'
  1967. ),
  1968. 'Parent' => array(
  1969. 'id' => 5,
  1970. 'apple_id' => 5,
  1971. 'color' => 'Green',
  1972. 'name' => 'Blue Green',
  1973. 'created' => '2006-12-25 05:24:06',
  1974. 'date' => '2006-12-25',
  1975. 'modified' => '2006-12-25 05:29:16',
  1976. 'mytime' => '22:57:17',
  1977. 'Parent' => array(
  1978. 'id' => 5,
  1979. 'apple_id' => 5,
  1980. 'color' => 'Green',
  1981. 'name' => 'Blue Green',
  1982. 'created' => '2006-12-25 05:24:06',
  1983. 'date' => '2006-12-25',
  1984. 'modified' => '2006-12-25 05:29:16',
  1985. 'mytime' => '22:57:17'
  1986. ),
  1987. 'Child' => array(
  1988. array(
  1989. 'id' => 5,
  1990. 'apple_id' => 5,
  1991. 'color' => 'Green',
  1992. 'name' => 'Blue Green',
  1993. 'created' => '2006-12-25 05:24:06',
  1994. 'date' => '2006-12-25',
  1995. 'modified' => '2006-12-25 05:29:16',
  1996. 'mytime' => '22:57:17'
  1997. ))),
  1998. 'Sample' => array(
  1999. 'id' => 4,
  2000. 'apple_id' => 5,
  2001. 'name' => 'sample4',
  2002. 'Apple' => array(
  2003. 'id' => 5,
  2004. 'apple_id' => 5,
  2005. 'color' => 'Green',
  2006. 'name' => 'Blue Green',
  2007. 'created' => '2006-12-25 05:24:06',
  2008. 'date' => '2006-12-25',
  2009. 'modified' => '2006-12-25 05:29:16',
  2010. 'mytime' => '22:57:17'
  2011. ))),
  2012. array(
  2013. 'Apple' => array(
  2014. 'id' => 6,
  2015. 'apple_id' => 4,
  2016. 'color' => 'My new appleOrange',
  2017. 'name' => 'My new apple',
  2018. 'created' => '2006-12-25 05:29:39',
  2019. 'date' => '2006-12-25',
  2020. 'modified' => '2006-12-25 05:29:39',
  2021. 'mytime' => '22:57:17'
  2022. ),
  2023. 'Parent' => array(
  2024. 'id' => 4,
  2025. 'apple_id' => 2,
  2026. 'color' => 'Blue Green',
  2027. 'name' => 'Test Name',
  2028. 'created' => '2006-12-25 05:23:36',
  2029. 'date' => '2006-12-25',
  2030. 'modified' => '2006-12-25 05:23:36',
  2031. 'mytime' => '22:57:17',
  2032. 'Parent' => array(
  2033. 'id' => 2,
  2034. 'apple_id' => 1,
  2035. 'color' => 'Bright Red 1',
  2036. 'name' => 'Bright Red Apple',
  2037. 'created' => '2006-11-22 10:43:13',
  2038. 'date' => '2014-01-01',
  2039. 'modified' => '2006-11-30 18:38:10',
  2040. 'mytime' => '22:57:17'
  2041. ),
  2042. 'Child' => array(
  2043. array(
  2044. 'id' => 6,
  2045. 'apple_id' => 4,
  2046. 'color' => 'My new appleOrange',
  2047. 'name' => 'My new apple',
  2048. 'created' => '2006-12-25 05:29:39',
  2049. 'date' => '2006-12-25',
  2050. 'modified' => '2006-12-25 05:29:39',
  2051. 'mytime' => '22:57:17'
  2052. ))),
  2053. 'Sample' => array(
  2054. 'id' => '',
  2055. 'apple_id' => '',
  2056. 'name' => ''
  2057. )),
  2058. array(
  2059. 'Apple' => array(
  2060. 'id' => 7,
  2061. 'apple_id' => 6,
  2062. 'color' => 'Some wierd color',
  2063. 'name' => 'Some odd color',
  2064. 'created' => '2006-12-25 05:34:21',
  2065. 'date' => '2006-12-25',
  2066. 'modified' => '2006-12-25 05:34:21',
  2067. 'mytime' => '22:57:17'
  2068. ),
  2069. 'Parent' => array(
  2070. 'id' => 6,
  2071. 'apple_id' => 4,
  2072. 'color' => 'My new appleOrange',
  2073. 'name' => 'My new apple',
  2074. 'created' => '2006-12-25 05:29:39',
  2075. 'date' => '2006-12-25',
  2076. 'modified' => '2006-12-25 05:29:39',
  2077. 'mytime' => '22:57:17',
  2078. 'Parent' => array(
  2079. 'id' => 4,
  2080. 'apple_id' => 2,
  2081. 'color' => 'Blue Green',
  2082. 'name' => 'Test Name',
  2083. 'created' => '2006-12-25 05:23:36',
  2084. 'date' => '2006-12-25',
  2085. 'modified' => '2006-12-25 05:23:36',
  2086. 'mytime' => '22:57:17'
  2087. ),
  2088. 'Child' => array(
  2089. array(
  2090. 'id' => 7,
  2091. 'apple_id' => 6,
  2092. 'color' => 'Some wierd color',
  2093. 'name' => 'Some odd color',
  2094. 'created' => '2006-12-25 05:34:21',
  2095. 'date' => '2006-12-25',
  2096. 'modified' => '2006-12-25 05:34:21',
  2097. 'mytime' => '22:57:17'
  2098. ))),
  2099. 'Sample' => array(
  2100. 'id' => '',
  2101. 'apple_id' => '',
  2102. 'name' => ''
  2103. )));
  2104. $this->assertEquals($expected, $result);
  2105. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  2106. $this->assertTrue($result);
  2107. $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple')));
  2108. $this->assertTrue($result);
  2109. $result = $TestModel->find('all');
  2110. $expected = array(
  2111. array(
  2112. 'Apple' => array(
  2113. 'id' => 1,
  2114. 'apple_id' => 2,
  2115. 'color' => 'Red 1',
  2116. 'name' => 'Red Apple 1',
  2117. 'created' => '2006-11-22 10:38:58',
  2118. 'date' => '1951-01-04',
  2119. 'modified' => '2006-12-01 13:31:26',
  2120. 'mytime' => '22:57:17'
  2121. ),
  2122. 'Parent' => array(
  2123. 'id' => 2,
  2124. 'apple_id' => 1,
  2125. 'color' => 'Bright Red 1',
  2126. 'name' => 'Bright Red Apple',
  2127. 'created' => '2006-11-22 10:43:13',
  2128. 'date' => '2014-01-01',
  2129. 'modified' => '2006-11-30 18:38:10',
  2130. 'mytime' => '22:57:17',
  2131. 'Parent' => array(
  2132. 'id' => 1,
  2133. 'apple_id' => 2,
  2134. 'color' => 'Red 1',
  2135. 'name' => 'Red Apple 1',
  2136. 'created' => '2006-11-22 10:38:58',
  2137. 'date' => '1951-01-04',
  2138. 'modified' => '2006-12-01 13:31:26',
  2139. 'mytime' => '22:57:17'
  2140. ),
  2141. 'Sample' => array(
  2142. 'id' => 2,
  2143. 'apple_id' => 2,
  2144. 'name' => 'sample2'
  2145. ),
  2146. 'Child' => array(
  2147. array(
  2148. 'id' => 1,
  2149. 'apple_id' => 2,
  2150. 'color' => 'Red 1',
  2151. 'name' => 'Red Apple 1',
  2152. 'created' => '2006-11-22 10:38:58',
  2153. 'date' => '1951-01-04',
  2154. 'modified' => '2006-12-01 13:31:26',
  2155. 'mytime' => '22:57:17'
  2156. ),
  2157. array(
  2158. 'id' => 3,
  2159. 'apple_id' => 2,
  2160. 'color' => 'blue green',
  2161. 'name' => 'green blue',
  2162. 'created' => '2006-12-25 05:13:36',
  2163. 'date' => '2006-12-25',
  2164. 'modified' => '2006-12-25 05:23:24',
  2165. 'mytime' => '22:57:17'
  2166. ),
  2167. array(
  2168. 'id' => 4,
  2169. 'apple_id' => 2,
  2170. 'color' => 'Blue Green',
  2171. 'name' => 'Test Name',
  2172. 'created' => '2006-12-25 05:23:36',
  2173. 'date' => '2006-12-25',
  2174. 'modified' => '2006-12-25 05:23:36',
  2175. 'mytime' => '22:57:17'
  2176. ))),
  2177. 'Sample' => array(
  2178. 'id' => '',
  2179. 'apple_id' => '',
  2180. 'name' => ''
  2181. )),
  2182. array(
  2183. 'Apple' => array(
  2184. 'id' => 2,
  2185. 'apple_id' => 1,
  2186. 'color' => 'Bright Red 1',
  2187. 'name' => 'Bright Red Apple',
  2188. 'created' => '2006-11-22 10:43:13',
  2189. 'date' => '2014-01-01',
  2190. 'modified' => '2006-11-30 18:38:10',
  2191. 'mytime' => '22:57:17'
  2192. ),
  2193. 'Parent' => array(
  2194. 'id' => 1,
  2195. 'apple_id' => 2,
  2196. 'color' => 'Red 1',
  2197. 'name' => 'Red Apple 1',
  2198. 'created' => '2006-11-22 10:38:58',
  2199. 'date' => '1951-01-04',
  2200. 'modified' => '2006-12-01 13:31:26',
  2201. 'mytime' => '22:57:17',
  2202. 'Parent' => array(
  2203. 'id' => 2,
  2204. 'apple_id' => 1,
  2205. 'color' => 'Bright Red 1',
  2206. 'name' => 'Bright Red Apple',
  2207. 'created' => '2006-11-22 10:43:13',
  2208. 'date' => '2014-01-01',
  2209. 'modified' => '2006-11-30 18:38:10',
  2210. 'mytime' => '22:57:17'
  2211. ),
  2212. 'Sample' => array(),
  2213. 'Child' => array(
  2214. array(
  2215. 'id' => 2,
  2216. 'apple_id' => 1,
  2217. 'color' => 'Bright Red 1',
  2218. 'name' => 'Bright Red Apple',
  2219. 'created' => '2006-11-22 10:43:13',
  2220. 'date' => '2014-01-01',
  2221. 'modified' => '2006-11-30 18:38:10',
  2222. 'mytime' => '22:57:17'
  2223. ))),
  2224. 'Sample' => array(
  2225. 'id' => 2,
  2226. 'apple_id' => 2,
  2227. 'name' => 'sample2'
  2228. )),
  2229. array(
  2230. 'Apple' => array(
  2231. 'id' => 3,
  2232. 'apple_id' => 2,
  2233. 'color' => 'blue green',
  2234. 'name' => 'green blue',
  2235. 'created' => '2006-12-25 05:13:36',
  2236. 'date' => '2006-12-25',
  2237. 'modified' => '2006-12-25 05:23:24',
  2238. 'mytime' => '22:57:17'
  2239. ),
  2240. 'Parent' => array(
  2241. 'id' => 2,
  2242. 'apple_id' => 1,
  2243. 'color' => 'Bright Red 1',
  2244. 'name' => 'Bright Red Apple',
  2245. 'created' => '2006-11-22 10:43:13',
  2246. 'date' => '2014-01-01',
  2247. 'modified' => '2006-11-30 18:38:10',
  2248. 'mytime' => '22:57:17',
  2249. 'Parent' => array(
  2250. 'id' => 1,
  2251. 'apple_id' => 2,
  2252. 'color' => 'Red 1',
  2253. 'name' => 'Red Apple 1',
  2254. 'created' => '2006-11-22 10:38:58',
  2255. 'date' => '1951-01-04',
  2256. 'modified' => '2006-12-01 13:31:26',
  2257. 'mytime' => '22:57:17'
  2258. ),
  2259. 'Sample' => array(
  2260. 'id' => 2,
  2261. 'apple_id' => 2,
  2262. 'name' => 'sample2'
  2263. ),
  2264. 'Child' => array(
  2265. array(
  2266. 'id' => 1,
  2267. 'apple_id' => 2,
  2268. 'color' => 'Red 1',
  2269. 'name' => 'Red Apple 1',
  2270. 'created' => '2006-11-22 10:38:58',
  2271. 'date' => '1951-01-04',
  2272. 'modified' => '2006-12-01 13:31:26',
  2273. 'mytime' => '22:57:17'
  2274. ),
  2275. array(
  2276. 'id' => 3,
  2277. 'apple_id' => 2,
  2278. 'color' => 'blue green',
  2279. 'name' => 'green blue',
  2280. 'created' => '2006-12-25 05:13:36',
  2281. 'date' => '2006-12-25',
  2282. 'modified' => '2006-12-25 05:23:24',
  2283. 'mytime' => '22:57:17'
  2284. ),
  2285. array(
  2286. 'id' => 4,
  2287. 'apple_id' => 2,
  2288. 'color' => 'Blue Green',
  2289. 'name' => 'Test Name',
  2290. 'created' => '2006-12-25 05:23:36',
  2291. 'date' => '2006-12-25',
  2292. 'modified' => '2006-12-25 05:23:36',
  2293. 'mytime' => '22:57:17'
  2294. ))),
  2295. 'Sample' => array(
  2296. 'id' => 1,
  2297. 'apple_id' => 3,
  2298. 'name' => 'sample1'
  2299. )),
  2300. array(
  2301. 'Apple' => array(
  2302. 'id' => 4,
  2303. 'apple_id' => 2,
  2304. 'color' => 'Blue Green',
  2305. 'name' => 'Test Name',
  2306. 'created' => '2006-12-25 05:23:36',
  2307. 'date' => '2006-12-25',
  2308. 'modified' => '2006-12-25 05:23:36',
  2309. 'mytime' => '22:57:17'
  2310. ),
  2311. 'Parent' => array(
  2312. 'id' => 2,
  2313. 'apple_id' => 1,
  2314. 'color' => 'Bright Red 1',
  2315. 'name' => 'Bright Red Apple',
  2316. 'created' => '2006-11-22 10:43:13',
  2317. 'date' => '2014-01-01',
  2318. 'modified' => '2006-11-30 18:38:10',
  2319. 'mytime' => '22:57:17',
  2320. 'Parent' => array(
  2321. 'id' => 1,
  2322. 'apple_id' => 2,
  2323. 'color' => 'Red 1',
  2324. 'name' => 'Red Apple 1',
  2325. 'created' => '2006-11-22 10:38:58',
  2326. 'date' => '1951-01-04',
  2327. 'modified' => '2006-12-01 13:31:26',
  2328. 'mytime' => '22:57:17'
  2329. ),
  2330. 'Sample' => array(
  2331. 'id' => 2,
  2332. 'apple_id' => 2,
  2333. 'name' => 'sample2'
  2334. ),
  2335. 'Child' => array(
  2336. array(
  2337. 'id' => 1,
  2338. 'apple_id' => 2,
  2339. 'color' => 'Red 1',
  2340. 'name' => 'Red Apple 1',
  2341. 'created' => '2006-11-22 10:38:58',
  2342. 'date' => '1951-01-04',
  2343. 'modified' => '2006-12-01 13:31:26',
  2344. 'mytime' => '22:57:17'
  2345. ),
  2346. array(
  2347. 'id' => 3,
  2348. 'apple_id' => 2,
  2349. 'color' => 'blue green',
  2350. 'name' => 'green blue',
  2351. 'created' => '2006-12-25 05:13:36',
  2352. 'date' => '2006-12-25',
  2353. 'modified' => '2006-12-25 05:23:24',
  2354. 'mytime' => '22:57:17'
  2355. ),
  2356. array(
  2357. 'id' => 4,
  2358. 'apple_id' => 2,
  2359. 'color' => 'Blue Green',
  2360. 'name' => 'Test Name',
  2361. 'created' => '2006-12-25 05:23:36',
  2362. 'date' => '2006-12-25',
  2363. 'modified' => '2006-12-25 05:23:36',
  2364. 'mytime' => '22:57:17'
  2365. ))),
  2366. 'Sample' => array(
  2367. 'id' => 3,
  2368. 'apple_id' => 4,
  2369. 'name' => 'sample3'
  2370. )),
  2371. array(
  2372. 'Apple' => array(
  2373. 'id' => 5,
  2374. 'apple_id' => 5,
  2375. 'color' => 'Green',
  2376. 'name' => 'Blue Green',
  2377. 'created' => '2006-12-25 05:24:06',
  2378. 'date' => '2006-12-25',
  2379. 'modified' => '2006-12-25 05:29:16',
  2380. 'mytime' => '22:57:17'
  2381. ),
  2382. 'Parent' => array(
  2383. 'id' => 5,
  2384. 'apple_id' => 5,
  2385. 'color' => 'Green',
  2386. 'name' => 'Blue Green',
  2387. 'created' => '2006-12-25 05:24:06',
  2388. 'date' => '2006-12-25',
  2389. 'modified' => '2006-12-25 05:29:16',
  2390. 'mytime' => '22:57:17',
  2391. 'Parent' => array(
  2392. 'id' => 5,
  2393. 'apple_id' => 5,
  2394. 'color' => 'Green',
  2395. 'name' => 'Blue Green',
  2396. 'created' => '2006-12-25 05:24:06',
  2397. 'date' => '2006-12-25',
  2398. 'modified' => '2006-12-25 05:29:16',
  2399. 'mytime' => '22:57:17'
  2400. ),
  2401. 'Sample' => array(
  2402. 'id' => 4,
  2403. 'apple_id' => 5,
  2404. 'name' => 'sample4'
  2405. ),
  2406. 'Child' => array(
  2407. array(
  2408. 'id' => 5,
  2409. 'apple_id' => 5,
  2410. 'color' => 'Green',
  2411. 'name' => 'Blue Green',
  2412. 'created' => '2006-12-25 05:24:06',
  2413. 'date' => '2006-12-25',
  2414. 'modified' => '2006-12-25 05:29:16',
  2415. 'mytime' => '22:57:17'
  2416. ))),
  2417. 'Sample' => array(
  2418. 'id' => 4,
  2419. 'apple_id' => 5,
  2420. 'name' => 'sample4'
  2421. )),
  2422. array(
  2423. 'Apple' => array(
  2424. 'id' => 6,
  2425. 'apple_id' => 4,
  2426. 'color' => 'My new appleOrange',
  2427. 'name' => 'My new apple',
  2428. 'created' => '2006-12-25 05:29:39',
  2429. 'date' => '2006-12-25',
  2430. 'modified' => '2006-12-25 05:29:39',
  2431. 'mytime' => '22:57:17'
  2432. ),
  2433. 'Parent' => array(
  2434. 'id' => 4,
  2435. 'apple_id' => 2,
  2436. 'color' => 'Blue Green',
  2437. 'name' => 'Test Name',
  2438. 'created' => '2006-12-25 05:23:36',
  2439. 'date' => '2006-12-25',
  2440. 'modified' => '2006-12-25 05:23:36',
  2441. 'mytime' => '22:57:17',
  2442. 'Parent' => array(
  2443. 'id' => 2,
  2444. 'apple_id' => 1,
  2445. 'color' => 'Bright Red 1',
  2446. 'name' => 'Bright Red Apple',
  2447. 'created' => '2006-11-22 10:43:13',
  2448. 'date' => '2014-01-01',
  2449. 'modified' => '2006-11-30 18:38:10',
  2450. 'mytime' => '22:57:17'
  2451. ),
  2452. 'Sample' => array(
  2453. 'id' => 3,
  2454. 'apple_id' => 4,
  2455. 'name' => 'sample3'
  2456. ),
  2457. 'Child' => array(
  2458. array(
  2459. 'id' => 6,
  2460. 'apple_id' => 4,
  2461. 'color' => 'My new appleOrange',
  2462. 'name' => 'My new apple',
  2463. 'created' => '2006-12-25 05:29:39',
  2464. 'date' => '2006-12-25',
  2465. 'modified' => '2006-12-25 05:29:39',
  2466. 'mytime' => '22:57:17'
  2467. ))),
  2468. 'Sample' => array(
  2469. 'id' => '',
  2470. 'apple_id' => '',
  2471. 'name' => ''
  2472. )),
  2473. array(
  2474. 'Apple' => array(
  2475. 'id' => 7,
  2476. 'apple_id' => 6,
  2477. 'color' => 'Some wierd color',
  2478. 'name' => 'Some odd color',
  2479. 'created' => '2006-12-25 05:34:21',
  2480. 'date' => '2006-12-25',
  2481. 'modified' => '2006-12-25 05:34:21',
  2482. 'mytime' => '22:57:17'
  2483. ),
  2484. 'Parent' => array(
  2485. 'id' => 6,
  2486. 'apple_id' => 4,
  2487. 'color' => 'My new appleOrange',
  2488. 'name' => 'My new apple',
  2489. 'created' => '2006-12-25 05:29:39',
  2490. 'date' => '2006-12-25',
  2491. 'modified' => '2006-12-25 05:29:39',
  2492. 'mytime' => '22:57:17',
  2493. 'Parent' => array(
  2494. 'id' => 4,
  2495. 'apple_id' => 2,
  2496. 'color' => 'Blue Green',
  2497. 'name' => 'Test Name',
  2498. 'created' => '2006-12-25 05:23:36',
  2499. 'date' => '2006-12-25',
  2500. 'modified' => '2006-12-25 05:23:36',
  2501. 'mytime' => '22:57:17'
  2502. ),
  2503. 'Sample' => array(),
  2504. 'Child' => array(
  2505. array(
  2506. 'id' => 7,
  2507. 'apple_id' => 6,
  2508. 'color' => 'Some wierd color',
  2509. 'name' => 'Some odd color',
  2510. 'created' => '2006-12-25 05:34:21',
  2511. 'date' => '2006-12-25',
  2512. 'modified' => '2006-12-25 05:34:21',
  2513. 'mytime' => '22:57:17'
  2514. ))),
  2515. 'Sample' => array(
  2516. 'id' => '',
  2517. 'apple_id' => '',
  2518. 'name' => ''
  2519. )));
  2520. $this->assertEquals($expected, $result);
  2521. $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent')));
  2522. $this->assertTrue($result);
  2523. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  2524. $this->assertTrue($result);
  2525. $result = $TestModel->find('all');
  2526. $expected = array(
  2527. array(
  2528. 'Apple' => array(
  2529. 'id' => 1,
  2530. 'apple_id' => 2,
  2531. 'color' => 'Red 1',
  2532. 'name' => 'Red Apple 1',
  2533. 'created' => '2006-11-22 10:38:58',
  2534. 'date' => '1951-01-04',
  2535. 'modified' => '2006-12-01 13:31:26',
  2536. 'mytime' => '22:57:17'
  2537. ),
  2538. 'Parent' => array(
  2539. 'id' => 2,
  2540. 'apple_id' => 1,
  2541. 'color' => 'Bright Red 1',
  2542. 'name' => 'Bright Red Apple',
  2543. 'created' => '2006-11-22 10:43:13',
  2544. 'date' => '2014-01-01',
  2545. 'modified' => '2006-11-30 18:38:10',
  2546. 'mytime' => '22:57:17',
  2547. 'Sample' => array(
  2548. 'id' => 2,
  2549. 'apple_id' => 2,
  2550. 'name' => 'sample2'
  2551. ),
  2552. 'Child' => array(
  2553. array(
  2554. 'id' => 1,
  2555. 'apple_id' => 2,
  2556. 'color' => 'Red 1',
  2557. 'name' => 'Red Apple 1',
  2558. 'created' => '2006-11-22 10:38:58',
  2559. 'date' => '1951-01-04',
  2560. 'modified' => '2006-12-01 13:31:26',
  2561. 'mytime' => '22:57:17'
  2562. ),
  2563. array(
  2564. 'id' => 3,
  2565. 'apple_id' => 2,
  2566. 'color' => 'blue green',
  2567. 'name' => 'green blue',
  2568. 'created' => '2006-12-25 05:13:36',
  2569. 'date' => '2006-12-25',
  2570. 'modified' => '2006-12-25 05:23:24',
  2571. 'mytime' => '22:57:17'
  2572. ),
  2573. array(
  2574. 'id' => 4,
  2575. 'apple_id' => 2,
  2576. 'color' => 'Blue Green',
  2577. 'name' => 'Test Name',
  2578. 'created' => '2006-12-25 05:23:36',
  2579. 'date' => '2006-12-25',
  2580. 'modified' => '2006-12-25 05:23:36',
  2581. 'mytime' => '22:57:17'
  2582. ))),
  2583. 'Sample' => array(
  2584. 'id' => '',
  2585. 'apple_id' => '',
  2586. 'name' => ''
  2587. )),
  2588. array(
  2589. 'Apple' => array(
  2590. 'id' => 2,
  2591. 'apple_id' => 1,
  2592. 'color' => 'Bright Red 1',
  2593. 'name' => 'Bright Red Apple',
  2594. 'created' => '2006-11-22 10:43:13',
  2595. 'date' => '2014-01-01',
  2596. 'modified' => '2006-11-30 18:38:10',
  2597. 'mytime' => '22:57:17'
  2598. ),
  2599. 'Parent' => array(
  2600. 'id' => 1,
  2601. 'apple_id' => 2,
  2602. 'color' => 'Red 1',
  2603. 'name' => 'Red Apple 1',
  2604. 'created' => '2006-11-22 10:38:58',
  2605. 'date' => '1951-01-04',
  2606. 'modified' => '2006-12-01 13:31:26',
  2607. 'mytime' => '22:57:17',
  2608. 'Sample' => array(),
  2609. 'Child' => array(
  2610. array(
  2611. 'id' => 2,
  2612. 'apple_id' => 1,
  2613. 'color' => 'Bright Red 1',
  2614. 'name' => 'Bright Red Apple',
  2615. 'created' => '2006-11-22 10:43:13',
  2616. 'date' => '2014-01-01',
  2617. 'modified' => '2006-11-30 18:38:10',
  2618. 'mytime' => '22:57:17'
  2619. ))),
  2620. 'Sample' => array(
  2621. 'id' => 2,
  2622. 'apple_id' => 2,
  2623. 'name' => 'sample2',
  2624. 'Apple' => array(
  2625. 'id' => 2,
  2626. 'apple_id' => 1,
  2627. 'color' => 'Bright Red 1',
  2628. 'name' => 'Bright Red Apple',
  2629. 'created' => '2006-11-22 10:43:13',
  2630. 'date' => '2014-01-01',
  2631. 'modified' => '2006-11-30 18:38:10',
  2632. 'mytime' => '22:57:17'
  2633. ))),
  2634. array(
  2635. 'Apple' => array(
  2636. 'id' => 3,
  2637. 'apple_id' => 2,
  2638. 'color' => 'blue green',
  2639. 'name' => 'green blue',
  2640. 'created' => '2006-12-25 05:13:36',
  2641. 'date' => '2006-12-25',
  2642. 'modified' => '2006-12-25 05:23:24',
  2643. 'mytime' => '22:57:17'
  2644. ),
  2645. 'Parent' => array(
  2646. 'id' => 2,
  2647. 'apple_id' => 1,
  2648. 'color' => 'Bright Red 1',
  2649. 'name' => 'Bright Red Apple',
  2650. 'created' => '2006-11-22 10:43:13',
  2651. 'date' => '2014-01-01',
  2652. 'modified' => '2006-11-30 18:38:10',
  2653. 'mytime' => '22:57:17',
  2654. 'Sample' => array(
  2655. 'id' => 2,
  2656. 'apple_id' => 2,
  2657. 'name' => 'sample2'
  2658. ),
  2659. 'Child' => array(
  2660. array(
  2661. 'id' => 1,
  2662. 'apple_id' => 2,
  2663. 'color' => 'Red 1',
  2664. 'name' => 'Red Apple 1',
  2665. 'created' => '2006-11-22 10:38:58',
  2666. 'date' => '1951-01-04',
  2667. 'modified' => '2006-12-01 13:31:26',
  2668. 'mytime' => '22:57:17'
  2669. ),
  2670. array(
  2671. 'id' => 3,
  2672. 'apple_id' => 2,
  2673. 'color' => 'blue green',
  2674. 'name' => 'green blue',
  2675. 'created' => '2006-12-25 05:13:36',
  2676. 'date' => '2006-12-25',
  2677. 'modified' => '2006-12-25 05:23:24',
  2678. 'mytime' => '22:57:17'
  2679. ),
  2680. array(
  2681. 'id' => 4,
  2682. 'apple_id' => 2,
  2683. 'color' => 'Blue Green',
  2684. 'name' => 'Test Name',
  2685. 'created' => '2006-12-25 05:23:36',
  2686. 'date' => '2006-12-25',
  2687. 'modified' => '2006-12-25 05:23:36',
  2688. 'mytime' => '22:57:17'
  2689. ))),
  2690. 'Sample' => array(
  2691. 'id' => 1,
  2692. 'apple_id' => 3,
  2693. 'name' => 'sample1',
  2694. 'Apple' => array(
  2695. 'id' => 3,
  2696. 'apple_id' => 2,
  2697. 'color' => 'blue green',
  2698. 'name' => 'green blue',
  2699. 'created' => '2006-12-25 05:13:36',
  2700. 'date' => '2006-12-25',
  2701. 'modified' => '2006-12-25 05:23:24',
  2702. 'mytime' => '22:57:17'
  2703. ))),
  2704. array(
  2705. 'Apple' => array(
  2706. 'id' => 4,
  2707. 'apple_id' => 2,
  2708. 'color' => 'Blue Green',
  2709. 'name' => 'Test Name',
  2710. 'created' => '2006-12-25 05:23:36',
  2711. 'date' => '2006-12-25',
  2712. 'modified' => '2006-12-25 05:23:36',
  2713. 'mytime' => '22:57:17'
  2714. ),
  2715. 'Parent' => array(
  2716. 'id' => 2,
  2717. 'apple_id' => 1,
  2718. 'color' => 'Bright Red 1',
  2719. 'name' => 'Bright Red Apple',
  2720. 'created' => '2006-11-22 10:43:13',
  2721. 'date' => '2014-01-01',
  2722. 'modified' => '2006-11-30 18:38:10',
  2723. 'mytime' => '22:57:17',
  2724. 'Sample' => array(
  2725. 'id' => 2,
  2726. 'apple_id' => 2,
  2727. 'name' => 'sample2'
  2728. ),
  2729. 'Child' => array(
  2730. array(
  2731. 'id' => 1,
  2732. 'apple_id' => 2,
  2733. 'color' => 'Red 1',
  2734. 'name' => 'Red Apple 1',
  2735. 'created' => '2006-11-22 10:38:58',
  2736. 'date' => '1951-01-04',
  2737. 'modified' => '2006-12-01 13:31:26',
  2738. 'mytime' => '22:57:17'
  2739. ),
  2740. array(
  2741. 'id' => 3,
  2742. 'apple_id' => 2,
  2743. 'color' => 'blue green',
  2744. 'name' => 'green blue',
  2745. 'created' => '2006-12-25 05:13:36',
  2746. 'date' => '2006-12-25',
  2747. 'modified' => '2006-12-25 05:23:24',
  2748. 'mytime' => '22:57:17'
  2749. ),
  2750. array(
  2751. 'id' => 4,
  2752. 'apple_id' => 2,
  2753. 'color' => 'Blue Green',
  2754. 'name' => 'Test Name',
  2755. 'created' => '2006-12-25 05:23:36',
  2756. 'date' => '2006-12-25',
  2757. 'modified' => '2006-12-25 05:23:36',
  2758. 'mytime' => '22:57:17'
  2759. ))),
  2760. 'Sample' => array(
  2761. 'id' => 3,
  2762. 'apple_id' => 4,
  2763. 'name' => 'sample3',
  2764. 'Apple' => array(
  2765. 'id' => 4,
  2766. 'apple_id' => 2,
  2767. 'color' => 'Blue Green',
  2768. 'name' => 'Test Name',
  2769. 'created' => '2006-12-25 05:23:36',
  2770. 'date' => '2006-12-25',
  2771. 'modified' => '2006-12-25 05:23:36',
  2772. 'mytime' => '22:57:17'
  2773. ))),
  2774. array(
  2775. 'Apple' => array(
  2776. 'id' => 5,
  2777. 'apple_id' => 5,
  2778. 'color' => 'Green',
  2779. 'name' => 'Blue Green',
  2780. 'created' => '2006-12-25 05:24:06',
  2781. 'date' => '2006-12-25',
  2782. 'modified' =>
  2783. '2006-12-25 05:29:16',
  2784. 'mytime' => '22:57:17'
  2785. ),
  2786. 'Parent' => array(
  2787. 'id' => 5,
  2788. 'apple_id' => 5,
  2789. 'color' => 'Green',
  2790. 'name' => 'Blue Green',
  2791. 'created' => '2006-12-25 05:24:06',
  2792. 'date' => '2006-12-25',
  2793. 'modified' => '2006-12-25 05:29:16',
  2794. 'mytime' => '22:57:17',
  2795. 'Sample' => array(
  2796. 'id' => 4,
  2797. 'apple_id' => 5,
  2798. 'name' => 'sample4'
  2799. ),
  2800. 'Child' => array(
  2801. array(
  2802. 'id' => 5,
  2803. 'apple_id' => 5,
  2804. 'color' => 'Green',
  2805. 'name' => 'Blue Green',
  2806. 'created' => '2006-12-25 05:24:06',
  2807. 'date' => '2006-12-25',
  2808. 'modified' => '2006-12-25 05:29:16',
  2809. 'mytime' => '22:57:17'
  2810. ))),
  2811. 'Sample' => array(
  2812. 'id' => 4,
  2813. 'apple_id' => 5,
  2814. 'name' => 'sample4',
  2815. 'Apple' => array(
  2816. 'id' => 5,
  2817. 'apple_id' => 5,
  2818. 'color' => 'Green',
  2819. 'name' => 'Blue Green',
  2820. 'created' => '2006-12-25 05:24:06',
  2821. 'date' => '2006-12-25',
  2822. 'modified' => '2006-12-25 05:29:16',
  2823. 'mytime' => '22:57:17'
  2824. ))),
  2825. array(
  2826. 'Apple' => array(
  2827. 'id' => 6,
  2828. 'apple_id' => 4,
  2829. 'color' => 'My new appleOrange',
  2830. 'name' => 'My new apple',
  2831. 'created' => '2006-12-25 05:29:39',
  2832. 'date' => '2006-12-25',
  2833. 'modified' => '2006-12-25 05:29:39',
  2834. 'mytime' => '22:57:17'),
  2835. 'Parent' => array(
  2836. 'id' => 4,
  2837. 'apple_id' => 2,
  2838. 'color' => 'Blue Green',
  2839. 'name' => 'Test Name',
  2840. 'created' => '2006-12-25 05:23:36',
  2841. 'date' => '2006-12-25',
  2842. 'modified' => '2006-12-25 05:23:36',
  2843. 'mytime' => '22:57:17',
  2844. 'Sample' => array(
  2845. 'id' => 3,
  2846. 'apple_id' => 4,
  2847. 'name' => 'sample3'
  2848. ),
  2849. 'Child' => array(
  2850. array(
  2851. 'id' => 6,
  2852. 'apple_id' => 4,
  2853. 'color' => 'My new appleOrange',
  2854. 'name' => 'My new apple',
  2855. 'created' => '2006-12-25 05:29:39',
  2856. 'date' => '2006-12-25',
  2857. 'modified' => '2006-12-25 05:29:39',
  2858. 'mytime' => '22:57:17'
  2859. ))),
  2860. 'Sample' => array(
  2861. 'id' => '',
  2862. 'apple_id' => '',
  2863. 'name' => ''
  2864. )),
  2865. array(
  2866. 'Apple' => array(
  2867. 'id' => 7,
  2868. 'apple_id' => 6,
  2869. 'color' => 'Some wierd color',
  2870. 'name' => 'Some odd color',
  2871. 'created' => '2006-12-25 05:34:21',
  2872. 'date' => '2006-12-25',
  2873. 'modified' => '2006-12-25 05:34:21',
  2874. 'mytime' => '22:57:17'
  2875. ),
  2876. 'Parent' => array(
  2877. 'id' => 6,
  2878. 'apple_id' => 4,
  2879. 'color' => 'My new appleOrange',
  2880. 'name' => 'My new apple',
  2881. 'created' => '2006-12-25 05:29:39',
  2882. 'date' => '2006-12-25',
  2883. 'modified' => '2006-12-25 05:29:39',
  2884. 'mytime' => '22:57:17',
  2885. 'Sample' => array(),
  2886. 'Child' => array(
  2887. array(
  2888. 'id' => 7,
  2889. 'apple_id' => 6,
  2890. 'color' => 'Some wierd color',
  2891. 'name' => 'Some odd color',
  2892. 'created' => '2006-12-25 05:34:21',
  2893. 'date' => '2006-12-25', 'modified' =>
  2894. '2006-12-25 05:34:21',
  2895. 'mytime' => '22:57:17'
  2896. ))),
  2897. 'Sample' => array(
  2898. 'id' => '',
  2899. 'apple_id' => '',
  2900. 'name' => ''
  2901. )));
  2902. $this->assertEquals($expected, $result);
  2903. }
  2904. /**
  2905. * testSelfAssociationAfterFind method
  2906. *
  2907. * @return void
  2908. */
  2909. public function testSelfAssociationAfterFind() {
  2910. $this->loadFixtures('Apple', 'Sample');
  2911. $afterFindModel = new NodeAfterFind();
  2912. $afterFindModel->recursive = 3;
  2913. $afterFindData = $afterFindModel->find('all');
  2914. $duplicateModel = new NodeAfterFind();
  2915. $duplicateModel->recursive = 3;
  2916. $duplicateModelData = $duplicateModel->find('all');
  2917. $noAfterFindModel = new NodeNoAfterFind();
  2918. $noAfterFindModel->recursive = 3;
  2919. $noAfterFindData = $noAfterFindModel->find('all');
  2920. $this->assertFalse($afterFindModel == $noAfterFindModel);
  2921. $this->assertEquals($afterFindData, $noAfterFindData);
  2922. }
  2923. /**
  2924. * testFindAllThreaded method
  2925. *
  2926. * @return void
  2927. */
  2928. public function testFindAllThreaded() {
  2929. $this->loadFixtures('Category');
  2930. $TestModel = new Category();
  2931. $result = $TestModel->find('threaded');
  2932. $expected = array(
  2933. array(
  2934. 'Category' => array(
  2935. 'id' => '1',
  2936. 'parent_id' => '0',
  2937. 'name' => 'Category 1',
  2938. 'created' => '2007-03-18 15:30:23',
  2939. 'updated' => '2007-03-18 15:32:31'
  2940. ),
  2941. 'children' => array(
  2942. array(
  2943. 'Category' => array(
  2944. 'id' => '2',
  2945. 'parent_id' => '1',
  2946. 'name' => 'Category 1.1',
  2947. 'created' => '2007-03-18 15:30:23',
  2948. 'updated' => '2007-03-18 15:32:31'
  2949. ),
  2950. 'children' => array(
  2951. array('Category' => array(
  2952. 'id' => '7',
  2953. 'parent_id' => '2',
  2954. 'name' => 'Category 1.1.1',
  2955. 'created' => '2007-03-18 15:30:23',
  2956. 'updated' => '2007-03-18 15:32:31'),
  2957. 'children' => array()),
  2958. array('Category' => array(
  2959. 'id' => '8',
  2960. 'parent_id' => '2',
  2961. 'name' => 'Category 1.1.2',
  2962. 'created' => '2007-03-18 15:30:23',
  2963. 'updated' => '2007-03-18 15:32:31'),
  2964. 'children' => array()))
  2965. ),
  2966. array(
  2967. 'Category' => array(
  2968. 'id' => '3',
  2969. 'parent_id' => '1',
  2970. 'name' => 'Category 1.2',
  2971. 'created' => '2007-03-18 15:30:23',
  2972. 'updated' => '2007-03-18 15:32:31'
  2973. ),
  2974. 'children' => array()
  2975. )
  2976. )
  2977. ),
  2978. array(
  2979. 'Category' => array(
  2980. 'id' => '4',
  2981. 'parent_id' => '0',
  2982. 'name' => 'Category 2',
  2983. 'created' => '2007-03-18 15:30:23',
  2984. 'updated' => '2007-03-18 15:32:31'
  2985. ),
  2986. 'children' => array()
  2987. ),
  2988. array(
  2989. 'Category' => array(
  2990. 'id' => '5',
  2991. 'parent_id' => '0',
  2992. 'name' => 'Category 3',
  2993. 'created' => '2007-03-18 15:30:23',
  2994. 'updated' => '2007-03-18 15:32:31'
  2995. ),
  2996. 'children' => array(
  2997. array(
  2998. 'Category' => array(
  2999. 'id' => '6',
  3000. 'parent_id' => '5',
  3001. 'name' => 'Category 3.1',
  3002. 'created' => '2007-03-18 15:30:23',
  3003. 'updated' => '2007-03-18 15:32:31'
  3004. ),
  3005. 'children' => array()
  3006. )
  3007. )
  3008. )
  3009. );
  3010. $this->assertEquals($expected, $result);
  3011. $result = $TestModel->find('threaded', array(
  3012. 'conditions' => array('Category.name LIKE' => 'Category 1%')
  3013. ));
  3014. $expected = array(
  3015. array(
  3016. 'Category' => array(
  3017. 'id' => '1',
  3018. 'parent_id' => '0',
  3019. 'name' => 'Category 1',
  3020. 'created' => '2007-03-18 15:30:23',
  3021. 'updated' => '2007-03-18 15:32:31'
  3022. ),
  3023. 'children' => array(
  3024. array(
  3025. 'Category' => array(
  3026. 'id' => '2',
  3027. 'parent_id' => '1',
  3028. 'name' => 'Category 1.1',
  3029. 'created' => '2007-03-18 15:30:23',
  3030. 'updated' => '2007-03-18 15:32:31'
  3031. ),
  3032. 'children' => array(
  3033. array('Category' => array(
  3034. 'id' => '7',
  3035. 'parent_id' => '2',
  3036. 'name' => 'Category 1.1.1',
  3037. 'created' => '2007-03-18 15:30:23',
  3038. 'updated' => '2007-03-18 15:32:31'),
  3039. 'children' => array()),
  3040. array('Category' => array(
  3041. 'id' => '8',
  3042. 'parent_id' => '2',
  3043. 'name' => 'Category 1.1.2',
  3044. 'created' => '2007-03-18 15:30:23',
  3045. 'updated' => '2007-03-18 15:32:31'),
  3046. 'children' => array()))
  3047. ),
  3048. array(
  3049. 'Category' => array(
  3050. 'id' => '3',
  3051. 'parent_id' => '1',
  3052. 'name' => 'Category 1.2',
  3053. 'created' => '2007-03-18 15:30:23',
  3054. 'updated' => '2007-03-18 15:32:31'
  3055. ),
  3056. 'children' => array()
  3057. )
  3058. )
  3059. )
  3060. );
  3061. $this->assertEquals($expected, $result);
  3062. $result = $TestModel->find('threaded', array(
  3063. 'fields' => 'id, parent_id, name'
  3064. ));
  3065. $expected = array(
  3066. array(
  3067. 'Category' => array(
  3068. 'id' => '1',
  3069. 'parent_id' => '0',
  3070. 'name' => 'Category 1'
  3071. ),
  3072. 'children' => array(
  3073. array(
  3074. 'Category' => array(
  3075. 'id' => '2',
  3076. 'parent_id' => '1',
  3077. 'name' => 'Category 1.1'
  3078. ),
  3079. 'children' => array(
  3080. array('Category' => array(
  3081. 'id' => '7',
  3082. 'parent_id' => '2',
  3083. 'name' => 'Category 1.1.1'),
  3084. 'children' => array()),
  3085. array('Category' => array(
  3086. 'id' => '8',
  3087. 'parent_id' => '2',
  3088. 'name' => 'Category 1.1.2'),
  3089. 'children' => array()))
  3090. ),
  3091. array(
  3092. 'Category' => array(
  3093. 'id' => '3',
  3094. 'parent_id' => '1',
  3095. 'name' => 'Category 1.2'
  3096. ),
  3097. 'children' => array()
  3098. )
  3099. )
  3100. ),
  3101. array(
  3102. 'Category' => array(
  3103. 'id' => '4',
  3104. 'parent_id' => '0',
  3105. 'name' => 'Category 2'
  3106. ),
  3107. 'children' => array()
  3108. ),
  3109. array(
  3110. 'Category' => array(
  3111. 'id' => '5',
  3112. 'parent_id' => '0',
  3113. 'name' => 'Category 3'
  3114. ),
  3115. 'children' => array(
  3116. array(
  3117. 'Category' => array(
  3118. 'id' => '6',
  3119. 'parent_id' => '5',
  3120. 'name' => 'Category 3.1'
  3121. ),
  3122. 'children' => array()
  3123. )
  3124. )
  3125. )
  3126. );
  3127. $this->assertEquals($expected, $result);
  3128. $result = $TestModel->find('threaded', array('order' => 'id DESC'));
  3129. $expected = array(
  3130. array(
  3131. 'Category' => array(
  3132. 'id' => 5,
  3133. 'parent_id' => 0,
  3134. 'name' => 'Category 3',
  3135. 'created' => '2007-03-18 15:30:23',
  3136. 'updated' => '2007-03-18 15:32:31'
  3137. ),
  3138. 'children' => array(
  3139. array(
  3140. 'Category' => array(
  3141. 'id' => 6,
  3142. 'parent_id' => 5,
  3143. 'name' => 'Category 3.1',
  3144. 'created' => '2007-03-18 15:30:23',
  3145. 'updated' => '2007-03-18 15:32:31'
  3146. ),
  3147. 'children' => array()
  3148. )
  3149. )
  3150. ),
  3151. array(
  3152. 'Category' => array(
  3153. 'id' => 4,
  3154. 'parent_id' => 0,
  3155. 'name' => 'Category 2',
  3156. 'created' => '2007-03-18 15:30:23',
  3157. 'updated' => '2007-03-18 15:32:31'
  3158. ),
  3159. 'children' => array()
  3160. ),
  3161. array(
  3162. 'Category' => array(
  3163. 'id' => 1,
  3164. 'parent_id' => 0,
  3165. 'name' => 'Category 1',
  3166. 'created' => '2007-03-18 15:30:23',
  3167. 'updated' => '2007-03-18 15:32:31'
  3168. ),
  3169. 'children' => array(
  3170. array(
  3171. 'Category' => array(
  3172. 'id' => 3,
  3173. 'parent_id' => 1,
  3174. 'name' => 'Category 1.2',
  3175. 'created' => '2007-03-18 15:30:23',
  3176. 'updated' => '2007-03-18 15:32:31'
  3177. ),
  3178. 'children' => array()
  3179. ),
  3180. array(
  3181. 'Category' => array(
  3182. 'id' => 2,
  3183. 'parent_id' => 1,
  3184. 'name' => 'Category 1.1',
  3185. 'created' => '2007-03-18 15:30:23',
  3186. 'updated' => '2007-03-18 15:32:31'
  3187. ),
  3188. 'children' => array(
  3189. array('Category' => array(
  3190. 'id' => '8',
  3191. 'parent_id' => '2',
  3192. 'name' => 'Category 1.1.2',
  3193. 'created' => '2007-03-18 15:30:23',
  3194. 'updated' => '2007-03-18 15:32:31'),
  3195. 'children' => array()),
  3196. array('Category' => array(
  3197. 'id' => '7',
  3198. 'parent_id' => '2',
  3199. 'name' => 'Category 1.1.1',
  3200. 'created' => '2007-03-18 15:30:23',
  3201. 'updated' => '2007-03-18 15:32:31'),
  3202. 'children' => array()))
  3203. )
  3204. )
  3205. )
  3206. );
  3207. $this->assertEquals($expected, $result);
  3208. $result = $TestModel->find('threaded', array(
  3209. 'conditions' => array('Category.name LIKE' => 'Category 3%')
  3210. ));
  3211. $expected = array(
  3212. array(
  3213. 'Category' => array(
  3214. 'id' => '5',
  3215. 'parent_id' => '0',
  3216. 'name' => 'Category 3',
  3217. 'created' => '2007-03-18 15:30:23',
  3218. 'updated' => '2007-03-18 15:32:31'
  3219. ),
  3220. 'children' => array(
  3221. array(
  3222. 'Category' => array(
  3223. 'id' => '6',
  3224. 'parent_id' => '5',
  3225. 'name' => 'Category 3.1',
  3226. 'created' => '2007-03-18 15:30:23',
  3227. 'updated' => '2007-03-18 15:32:31'
  3228. ),
  3229. 'children' => array()
  3230. )
  3231. )
  3232. )
  3233. );
  3234. $this->assertEquals($expected, $result);
  3235. $result = $TestModel->find('threaded', array(
  3236. 'conditions' => array('Category.name LIKE' => 'Category 1.1%')
  3237. ));
  3238. $expected = array(
  3239. array('Category' =>
  3240. array(
  3241. 'id' => '2',
  3242. 'parent_id' => '1',
  3243. 'name' => 'Category 1.1',
  3244. 'created' => '2007-03-18 15:30:23',
  3245. 'updated' => '2007-03-18 15:32:31'),
  3246. 'children' => array(
  3247. array('Category' => array(
  3248. 'id' => '7',
  3249. 'parent_id' => '2',
  3250. 'name' => 'Category 1.1.1',
  3251. 'created' => '2007-03-18 15:30:23',
  3252. 'updated' => '2007-03-18 15:32:31'),
  3253. 'children' => array()),
  3254. array('Category' => array(
  3255. 'id' => '8',
  3256. 'parent_id' => '2',
  3257. 'name' => 'Category 1.1.2',
  3258. 'created' => '2007-03-18 15:30:23',
  3259. 'updated' => '2007-03-18 15:32:31'),
  3260. 'children' => array()))));
  3261. $this->assertEquals($expected, $result);
  3262. $result = $TestModel->find('threaded', array(
  3263. 'fields' => 'id, parent_id, name',
  3264. 'conditions' => array('Category.id !=' => 2)
  3265. ));
  3266. $expected = array(
  3267. array(
  3268. 'Category' => array(
  3269. 'id' => '1',
  3270. 'parent_id' => '0',
  3271. 'name' => 'Category 1'
  3272. ),
  3273. 'children' => array(
  3274. array(
  3275. 'Category' => array(
  3276. 'id' => '3',
  3277. 'parent_id' => '1',
  3278. 'name' => 'Category 1.2'
  3279. ),
  3280. 'children' => array()
  3281. )
  3282. )
  3283. ),
  3284. array(
  3285. 'Category' => array(
  3286. 'id' => '4',
  3287. 'parent_id' => '0',
  3288. 'name' => 'Category 2'
  3289. ),
  3290. 'children' => array()
  3291. ),
  3292. array(
  3293. 'Category' => array(
  3294. 'id' => '5',
  3295. 'parent_id' => '0',
  3296. 'name' => 'Category 3'
  3297. ),
  3298. 'children' => array(
  3299. array(
  3300. 'Category' => array(
  3301. 'id' => '6',
  3302. 'parent_id' => '5',
  3303. 'name' => 'Category 3.1'
  3304. ),
  3305. 'children' => array()
  3306. )
  3307. )
  3308. )
  3309. );
  3310. $this->assertEquals($expected, $result);
  3311. $result = $TestModel->find('all', array(
  3312. 'fields' => 'id, name, parent_id',
  3313. 'conditions' => array('Category.id !=' => 1)
  3314. ));
  3315. $expected = array(
  3316. array('Category' => array(
  3317. 'id' => '2',
  3318. 'name' => 'Category 1.1',
  3319. 'parent_id' => '1'
  3320. )),
  3321. array('Category' => array(
  3322. 'id' => '3',
  3323. 'name' => 'Category 1.2',
  3324. 'parent_id' => '1'
  3325. )),
  3326. array('Category' => array(
  3327. 'id' => '4',
  3328. 'name' => 'Category 2',
  3329. 'parent_id' => '0'
  3330. )),
  3331. array('Category' => array(
  3332. 'id' => '5',
  3333. 'name' => 'Category 3',
  3334. 'parent_id' => '0'
  3335. )),
  3336. array('Category' => array(
  3337. 'id' => '6',
  3338. 'name' => 'Category 3.1',
  3339. 'parent_id' => '5'
  3340. )),
  3341. array('Category' => array(
  3342. 'id' => '7',
  3343. 'name' => 'Category 1.1.1',
  3344. 'parent_id' => '2'
  3345. )),
  3346. array('Category' => array(
  3347. 'id' => '8',
  3348. 'name' => 'Category 1.1.2',
  3349. 'parent_id' => '2'
  3350. )));
  3351. $this->assertEquals($expected, $result);
  3352. $result = $TestModel->find('threaded', array(
  3353. 'fields' => 'id, parent_id, name',
  3354. 'conditions' => array('Category.id !=' => 1)
  3355. ));
  3356. $expected = array(
  3357. array(
  3358. 'Category' => array(
  3359. 'id' => '2',
  3360. 'parent_id' => '1',
  3361. 'name' => 'Category 1.1'
  3362. ),
  3363. 'children' => array(
  3364. array('Category' => array(
  3365. 'id' => '7',
  3366. 'parent_id' => '2',
  3367. 'name' => 'Category 1.1.1'),
  3368. 'children' => array()),
  3369. array('Category' => array(
  3370. 'id' => '8',
  3371. 'parent_id' => '2',
  3372. 'name' => 'Category 1.1.2'),
  3373. 'children' => array()))
  3374. ),
  3375. array(
  3376. 'Category' => array(
  3377. 'id' => '3',
  3378. 'parent_id' => '1',
  3379. 'name' => 'Category 1.2'
  3380. ),
  3381. 'children' => array()
  3382. )
  3383. );
  3384. $this->assertEquals($expected, $result);
  3385. }
  3386. /**
  3387. * test find('neighbors')
  3388. *
  3389. * @return void
  3390. */
  3391. public function testFindNeighbors() {
  3392. $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
  3393. $TestModel = new Article();
  3394. $TestModel->id = 1;
  3395. $result = $TestModel->find('neighbors', array('fields' => array('id')));
  3396. $this->assertNull($result['prev']);
  3397. $this->assertEquals($result['next']['Article'], array('id' => 2));
  3398. $this->assertEquals(count($result['next']['Comment']), 2);
  3399. $this->assertEquals(count($result['next']['Tag']), 2);
  3400. $TestModel->id = 2;
  3401. $TestModel->recursive = 0;
  3402. $result = $TestModel->find('neighbors', array(
  3403. 'fields' => array('id')
  3404. ));
  3405. $expected = array(
  3406. 'prev' => array(
  3407. 'Article' => array(
  3408. 'id' => 1
  3409. )),
  3410. 'next' => array(
  3411. 'Article' => array(
  3412. 'id' => 3
  3413. )));
  3414. $this->assertEquals($expected, $result);
  3415. $TestModel->id = 3;
  3416. $TestModel->recursive = 1;
  3417. $result = $TestModel->find('neighbors', array('fields' => array('id')));
  3418. $this->assertNull($result['next']);
  3419. $this->assertEquals($result['prev']['Article'], array('id' => 2));
  3420. $this->assertEquals(count($result['prev']['Comment']), 2);
  3421. $this->assertEquals(count($result['prev']['Tag']), 2);
  3422. $TestModel->id = 1;
  3423. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3424. $expected = array(
  3425. 'prev' => null,
  3426. 'next' => array(
  3427. 'Article' => array(
  3428. 'id' => 2,
  3429. 'user_id' => 3,
  3430. 'title' => 'Second Article',
  3431. 'body' => 'Second Article Body',
  3432. 'published' => 'Y',
  3433. 'created' => '2007-03-18 10:41:23',
  3434. 'updated' => '2007-03-18 10:43:31'
  3435. )
  3436. )
  3437. );
  3438. $this->assertEquals($expected, $result);
  3439. $TestModel->id = 2;
  3440. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3441. $expected = array(
  3442. 'prev' => array(
  3443. 'Article' => array(
  3444. 'id' => 1,
  3445. 'user_id' => 1,
  3446. 'title' => 'First Article',
  3447. 'body' => 'First Article Body',
  3448. 'published' => 'Y',
  3449. 'created' => '2007-03-18 10:39:23',
  3450. 'updated' => '2007-03-18 10:41:31'
  3451. )
  3452. ),
  3453. 'next' => array(
  3454. 'Article' => array(
  3455. 'id' => 3,
  3456. 'user_id' => 1,
  3457. 'title' => 'Third Article',
  3458. 'body' => 'Third Article Body',
  3459. 'published' => 'Y',
  3460. 'created' => '2007-03-18 10:43:23',
  3461. 'updated' => '2007-03-18 10:45:31'
  3462. )
  3463. )
  3464. );
  3465. $this->assertEquals($expected, $result);
  3466. $TestModel->id = 3;
  3467. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3468. $expected = array(
  3469. 'prev' => array(
  3470. 'Article' => array(
  3471. 'id' => 2,
  3472. 'user_id' => 3,
  3473. 'title' => 'Second Article',
  3474. 'body' => 'Second Article Body',
  3475. 'published' => 'Y',
  3476. 'created' => '2007-03-18 10:41:23',
  3477. 'updated' => '2007-03-18 10:43:31'
  3478. )
  3479. ),
  3480. 'next' => null
  3481. );
  3482. $this->assertEquals($expected, $result);
  3483. $TestModel->recursive = 0;
  3484. $TestModel->id = 1;
  3485. $one = $TestModel->read();
  3486. $TestModel->id = 2;
  3487. $two = $TestModel->read();
  3488. $TestModel->id = 3;
  3489. $three = $TestModel->read();
  3490. $TestModel->id = 1;
  3491. $result = $TestModel->find('neighbors');
  3492. $expected = array('prev' => null, 'next' => $two);
  3493. $this->assertEquals($expected, $result);
  3494. $TestModel->id = 2;
  3495. $result = $TestModel->find('neighbors');
  3496. $expected = array('prev' => $one, 'next' => $three);
  3497. $this->assertEquals($expected, $result);
  3498. $TestModel->id = 3;
  3499. $result = $TestModel->find('neighbors');
  3500. $expected = array('prev' => $two, 'next' => null);
  3501. $this->assertEquals($expected, $result);
  3502. $TestModel->recursive = 2;
  3503. $TestModel->id = 1;
  3504. $one = $TestModel->read();
  3505. $TestModel->id = 2;
  3506. $two = $TestModel->read();
  3507. $TestModel->id = 3;
  3508. $three = $TestModel->read();
  3509. $TestModel->id = 1;
  3510. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3511. $expected = array('prev' => null, 'next' => $two);
  3512. $this->assertEquals($expected, $result);
  3513. $TestModel->id = 2;
  3514. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3515. $expected = array('prev' => $one, 'next' => $three);
  3516. $this->assertEquals($expected, $result);
  3517. $TestModel->id = 3;
  3518. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3519. $expected = array('prev' => $two, 'next' => null);
  3520. $this->assertEquals($expected, $result);
  3521. }
  3522. /**
  3523. * testFindCombinedRelations method
  3524. *
  3525. * @return void
  3526. */
  3527. public function testFindCombinedRelations() {
  3528. $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.');
  3529. $this->loadFixtures('Apple', 'Sample');
  3530. $TestModel = new Apple();
  3531. $result = $TestModel->find('all');
  3532. $expected = array(
  3533. array(
  3534. 'Apple' => array(
  3535. 'id' => '1',
  3536. 'apple_id' => '2',
  3537. 'color' => 'Red 1',
  3538. 'name' => 'Red Apple 1',
  3539. 'created' => '2006-11-22 10:38:58',
  3540. 'date' => '1951-01-04',
  3541. 'modified' => '2006-12-01 13:31:26',
  3542. 'mytime' => '22:57:17'
  3543. ),
  3544. 'Parent' => array(
  3545. 'id' => '2',
  3546. 'apple_id' => '1',
  3547. 'color' => 'Bright Red 1',
  3548. 'name' => 'Bright Red Apple',
  3549. 'created' => '2006-11-22 10:43:13',
  3550. 'date' => '2014-01-01',
  3551. 'modified' => '2006-11-30 18:38:10',
  3552. 'mytime' => '22:57:17'
  3553. ),
  3554. 'Sample' => array(
  3555. 'id' => null,
  3556. 'apple_id' => null,
  3557. 'name' => null
  3558. ),
  3559. 'Child' => array(
  3560. array(
  3561. 'id' => '2',
  3562. 'apple_id' => '1',
  3563. 'color' => 'Bright Red 1',
  3564. 'name' => 'Bright Red Apple',
  3565. 'created' => '2006-11-22 10:43:13',
  3566. 'date' => '2014-01-01',
  3567. 'modified' => '2006-11-30 18:38:10',
  3568. 'mytime' => '22:57:17'
  3569. ))),
  3570. array(
  3571. 'Apple' => array(
  3572. 'id' => '2',
  3573. 'apple_id' => '1',
  3574. 'color' => 'Bright Red 1',
  3575. 'name' => 'Bright Red Apple',
  3576. 'created' => '2006-11-22 10:43:13',
  3577. 'date' => '2014-01-01',
  3578. 'modified' => '2006-11-30 18:38:10',
  3579. 'mytime' => '22:57:17'
  3580. ),
  3581. 'Parent' => array(
  3582. 'id' => '1',
  3583. 'apple_id' => '2',
  3584. 'color' => 'Red 1',
  3585. 'name' => 'Red Apple 1',
  3586. 'created' => '2006-11-22 10:38:58',
  3587. 'date' => '1951-01-04',
  3588. 'modified' => '2006-12-01 13:31:26',
  3589. 'mytime' => '22:57:17'
  3590. ),
  3591. 'Sample' => array(
  3592. 'id' => '2',
  3593. 'apple_id' => '2',
  3594. 'name' => 'sample2'
  3595. ),
  3596. 'Child' => array(
  3597. array(
  3598. 'id' => '1',
  3599. 'apple_id' => '2',
  3600. 'color' => 'Red 1',
  3601. 'name' => 'Red Apple 1',
  3602. 'created' => '2006-11-22 10:38:58',
  3603. 'date' => '1951-01-04',
  3604. 'modified' => '2006-12-01 13:31:26',
  3605. 'mytime' => '22:57:17'
  3606. ),
  3607. array(
  3608. 'id' => '3',
  3609. 'apple_id' => '2',
  3610. 'color' => 'blue green',
  3611. 'name' => 'green blue',
  3612. 'created' => '2006-12-25 05:13:36',
  3613. 'date' => '2006-12-25',
  3614. 'modified' => '2006-12-25 05:23:24',
  3615. 'mytime' => '22:57:17'
  3616. ),
  3617. array(
  3618. 'id' => '4',
  3619. 'apple_id' => '2',
  3620. 'color' => 'Blue Green',
  3621. 'name' => 'Test Name',
  3622. 'created' => '2006-12-25 05:23:36',
  3623. 'date' => '2006-12-25',
  3624. 'modified' => '2006-12-25 05:23:36',
  3625. 'mytime' => '22:57:17'
  3626. ))),
  3627. array(
  3628. 'Apple' => array(
  3629. 'id' => '3',
  3630. 'apple_id' => '2',
  3631. 'color' => 'blue green',
  3632. 'name' => 'green blue',
  3633. 'created' => '2006-12-25 05:13:36',
  3634. 'date' => '2006-12-25',
  3635. 'modified' => '2006-12-25 05:23:24',
  3636. 'mytime' => '22:57:17'
  3637. ),
  3638. 'Parent' => array(
  3639. 'id' => '2',
  3640. 'apple_id' => '1',
  3641. 'color' => 'Bright Red 1',
  3642. 'name' => 'Bright Red Apple',
  3643. 'created' => '2006-11-22 10:43:13',
  3644. 'date' => '2014-01-01',
  3645. 'modified' => '2006-11-30 18:38:10',
  3646. 'mytime' => '22:57:17'
  3647. ),
  3648. 'Sample' => array(
  3649. 'id' => '1',
  3650. 'apple_id' => '3',
  3651. 'name' => 'sample1'
  3652. ),
  3653. 'Child' => array()
  3654. ),
  3655. array(
  3656. 'Apple' => array(
  3657. 'id' => '4',
  3658. 'apple_id' => '2',
  3659. 'color' => 'Blue Green',
  3660. 'name' => 'Test Name',
  3661. 'created' => '2006-12-25 05:23:36',
  3662. 'date' => '2006-12-25',
  3663. 'modified' => '2006-12-25 05:23:36',
  3664. 'mytime' => '22:57:17'
  3665. ),
  3666. 'Parent' => array(
  3667. 'id' => '2',
  3668. 'apple_id' => '1',
  3669. 'color' => 'Bright Red 1',
  3670. 'name' => 'Bright Red Apple',
  3671. 'created' => '2006-11-22 10:43:13',
  3672. 'date' => '2014-01-01',
  3673. 'modified' => '2006-11-30 18:38:10',
  3674. 'mytime' => '22:57:17'
  3675. ),
  3676. 'Sample' => array(
  3677. 'id' => '3',
  3678. 'apple_id' => '4',
  3679. 'name' => 'sample3'
  3680. ),
  3681. 'Child' => array(
  3682. array(
  3683. 'id' => '6',
  3684. 'apple_id' => '4',
  3685. 'color' => 'My new appleOrange',
  3686. 'name' => 'My new apple',
  3687. 'created' => '2006-12-25 05:29:39',
  3688. 'date' => '2006-12-25',
  3689. 'modified' => '2006-12-25 05:29:39',
  3690. 'mytime' => '22:57:17'
  3691. ))),
  3692. array(
  3693. 'Apple' => array(
  3694. 'id' => '5',
  3695. 'apple_id' => '5',
  3696. 'color' => 'Green',
  3697. 'name' => 'Blue Green',
  3698. 'created' => '2006-12-25 05:24:06',
  3699. 'date' => '2006-12-25',
  3700. 'modified' => '2006-12-25 05:29:16',
  3701. 'mytime' => '22:57:17'
  3702. ),
  3703. 'Parent' => array(
  3704. 'id' => '5',
  3705. 'apple_id' => '5',
  3706. 'color' => 'Green',
  3707. 'name' => 'Blue Green',
  3708. 'created' => '2006-12-25 05:24:06',
  3709. 'date' => '2006-12-25',
  3710. 'modified' => '2006-12-25 05:29:16',
  3711. 'mytime' => '22:57:17'
  3712. ),
  3713. 'Sample' => array(
  3714. 'id' => '4',
  3715. 'apple_id' => '5',
  3716. 'name' => 'sample4'
  3717. ),
  3718. 'Child' => array(
  3719. array(
  3720. 'id' => '5',
  3721. 'apple_id' => '5',
  3722. 'color' => 'Green',
  3723. 'name' => 'Blue Green',
  3724. 'created' => '2006-12-25 05:24:06',
  3725. 'date' => '2006-12-25',
  3726. 'modified' => '2006-12-25 05:29:16',
  3727. 'mytime' => '22:57:17'
  3728. ))),
  3729. array(
  3730. 'Apple' => array(
  3731. 'id' => '6',
  3732. 'apple_id' => '4',
  3733. 'color' => 'My new appleOrange',
  3734. 'name' => 'My new apple',
  3735. 'created' => '2006-12-25 05:29:39',
  3736. 'date' => '2006-12-25',
  3737. 'modified' => '2006-12-25 05:29:39',
  3738. 'mytime' => '22:57:17'
  3739. ),
  3740. 'Parent' => array(
  3741. 'id' => '4',
  3742. 'apple_id' => '2',
  3743. 'color' => 'Blue Green',
  3744. 'name' => 'Test Name',
  3745. 'created' => '2006-12-25 05:23:36',
  3746. 'date' => '2006-12-25',
  3747. 'modified' => '2006-12-25 05:23:36',
  3748. 'mytime' => '22:57:17'
  3749. ),
  3750. 'Sample' => array(
  3751. 'id' => null,
  3752. 'apple_id' => null,
  3753. 'name' => null
  3754. ),
  3755. 'Child' => array(
  3756. array(
  3757. 'id' => '7',
  3758. 'apple_id' => '6',
  3759. 'color' => 'Some wierd color',
  3760. 'name' => 'Some odd color',
  3761. 'created' => '2006-12-25 05:34:21',
  3762. 'date' => '2006-12-25',
  3763. 'modified' => '2006-12-25 05:34:21',
  3764. 'mytime' => '22:57:17'
  3765. ))),
  3766. array(
  3767. 'Apple' => array(
  3768. 'id' => '7',
  3769. 'apple_id' => '6',
  3770. 'color' => 'Some wierd color',
  3771. 'name' => 'Some odd color',
  3772. 'created' => '2006-12-25 05:34:21',
  3773. 'date' => '2006-12-25',
  3774. 'modified' => '2006-12-25 05:34:21',
  3775. 'mytime' => '22:57:17'
  3776. ),
  3777. 'Parent' => array(
  3778. 'id' => '6',
  3779. 'apple_id' => '4',
  3780. 'color' => 'My new appleOrange',
  3781. 'name' => 'My new apple',
  3782. 'created' => '2006-12-25 05:29:39',
  3783. 'date' => '2006-12-25',
  3784. 'modified' => '2006-12-25 05:29:39',
  3785. 'mytime' => '22:57:17'
  3786. ),
  3787. 'Sample' => array(
  3788. 'id' => null,
  3789. 'apple_id' => null,
  3790. 'name' => null
  3791. ),
  3792. 'Child' => array()
  3793. ));
  3794. $this->assertEquals($expected, $result);
  3795. }
  3796. /**
  3797. * testSaveEmpty method
  3798. *
  3799. * @return void
  3800. */
  3801. public function testSaveEmpty() {
  3802. $this->loadFixtures('Thread');
  3803. $TestModel = new Thread();
  3804. $data = array();
  3805. $expected = $TestModel->save($data);
  3806. $this->assertFalse($expected);
  3807. }
  3808. /**
  3809. * testFindAllWithConditionInChildQuery
  3810. *
  3811. * @todo external conditions like this are going to need to be revisited at some point
  3812. * @return void
  3813. */
  3814. public function testFindAllWithConditionInChildQuery() {
  3815. $this->loadFixtures('Basket', 'FilmFile');
  3816. $TestModel = new Basket();
  3817. $recursive = 3;
  3818. $result = $TestModel->find('all', compact('recursive'));
  3819. $expected = array(
  3820. array(
  3821. 'Basket' => array(
  3822. 'id' => 1,
  3823. 'type' => 'nonfile',
  3824. 'name' => 'basket1',
  3825. 'object_id' => 1,
  3826. 'user_id' => 1,
  3827. ),
  3828. 'FilmFile' => array(
  3829. 'id' => '',
  3830. 'name' => '',
  3831. )
  3832. ),
  3833. array(
  3834. 'Basket' => array(
  3835. 'id' => 2,
  3836. 'type' => 'file',
  3837. 'name' => 'basket2',
  3838. 'object_id' => 2,
  3839. 'user_id' => 1,
  3840. ),
  3841. 'FilmFile' => array(
  3842. 'id' => 2,
  3843. 'name' => 'two',
  3844. )
  3845. ),
  3846. );
  3847. $this->assertEquals($expected, $result);
  3848. }
  3849. /**
  3850. * testFindAllWithConditionsHavingMixedDataTypes method
  3851. *
  3852. * @return void
  3853. */
  3854. public function testFindAllWithConditionsHavingMixedDataTypes() {
  3855. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag');
  3856. $TestModel = new Article();
  3857. $expected = array(
  3858. array(
  3859. 'Article' => array(
  3860. 'id' => 1,
  3861. 'user_id' => 1,
  3862. 'title' => 'First Article',
  3863. 'body' => 'First Article Body',
  3864. 'published' => 'Y',
  3865. 'created' => '2007-03-18 10:39:23',
  3866. 'updated' => '2007-03-18 10:41:31'
  3867. )
  3868. ),
  3869. array(
  3870. 'Article' => array(
  3871. 'id' => 2,
  3872. 'user_id' => 3,
  3873. 'title' => 'Second Article',
  3874. 'body' => 'Second Article Body',
  3875. 'published' => 'Y',
  3876. 'created' => '2007-03-18 10:41:23',
  3877. 'updated' => '2007-03-18 10:43:31'
  3878. )
  3879. )
  3880. );
  3881. $conditions = array('id' => array('1', 2));
  3882. $recursive = -1;
  3883. $order = 'Article.id ASC';
  3884. $result = $TestModel->find('all', compact('conditions', 'recursive', 'order'));
  3885. $this->assertEquals($expected, $result);
  3886. $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.');
  3887. $conditions = array('id' => array('1', 2, '3.0'));
  3888. $order = 'Article.id ASC';
  3889. $result = $TestModel->find('all', compact('recursive', 'conditions', 'order'));
  3890. $expected = array(
  3891. array(
  3892. 'Article' => array(
  3893. 'id' => 1,
  3894. 'user_id' => 1,
  3895. 'title' => 'First Article',
  3896. 'body' => 'First Article Body',
  3897. 'published' => 'Y',
  3898. 'created' => '2007-03-18 10:39:23',
  3899. 'updated' => '2007-03-18 10:41:31'
  3900. )
  3901. ),
  3902. array(
  3903. 'Article' => array(
  3904. 'id' => 2,
  3905. 'user_id' => 3,
  3906. 'title' => 'Second Article',
  3907. 'body' => 'Second Article Body',
  3908. 'published' => 'Y',
  3909. 'created' => '2007-03-18 10:41:23',
  3910. 'updated' => '2007-03-18 10:43:31'
  3911. )
  3912. ),
  3913. array(
  3914. 'Article' => array(
  3915. 'id' => 3,
  3916. 'user_id' => 1,
  3917. 'title' => 'Third Article',
  3918. 'body' => 'Third Article Body',
  3919. 'published' => 'Y',
  3920. 'created' => '2007-03-18 10:43:23',
  3921. 'updated' => '2007-03-18 10:45:31'
  3922. )
  3923. )
  3924. );
  3925. $this->assertEquals($expected, $result);
  3926. }
  3927. /**
  3928. * testBindUnbind method
  3929. *
  3930. * @return void
  3931. */
  3932. public function testBindUnbind() {
  3933. $this->loadFixtures(
  3934. 'User',
  3935. 'Comment',
  3936. 'FeatureSet',
  3937. 'DeviceType',
  3938. 'DeviceTypeCategory',
  3939. 'ExteriorTypeCategory',
  3940. 'Device',
  3941. 'Document',
  3942. 'DocumentDirectory'
  3943. );
  3944. $TestModel = new User();
  3945. $result = $TestModel->hasMany;
  3946. $expected = array();
  3947. $this->assertEquals($expected, $result);
  3948. $result = $TestModel->bindModel(array('hasMany' => array('Comment')));
  3949. $this->assertTrue($result);
  3950. $result = $TestModel->find('all', array(
  3951. 'fields' => 'User.id, User.user'
  3952. ));
  3953. $expected = array(
  3954. array(
  3955. 'User' => array(
  3956. 'id' => '1',
  3957. 'user' => 'mariano'
  3958. ),
  3959. 'Comment' => array(
  3960. array(
  3961. 'id' => '3',
  3962. 'article_id' => '1',
  3963. 'user_id' => '1',
  3964. 'comment' => 'Third Comment for First Article',
  3965. 'published' => 'Y',
  3966. 'created' => '2007-03-18 10:49:23',
  3967. 'updated' => '2007-03-18 10:51:31'
  3968. ),
  3969. array(
  3970. 'id' => '4',
  3971. 'article_id' => '1',
  3972. 'user_id' => '1',
  3973. 'comment' => 'Fourth Comment for First Article',
  3974. 'published' => 'N',
  3975. 'created' => '2007-03-18 10:51:23',
  3976. 'updated' => '2007-03-18 10:53:31'
  3977. ),
  3978. array(
  3979. 'id' => '5',
  3980. 'article_id' => '2',
  3981. 'user_id' => '1',
  3982. 'comment' => 'First Comment for Second Article',
  3983. 'published' => 'Y',
  3984. 'created' => '2007-03-18 10:53:23',
  3985. 'updated' => '2007-03-18 10:55:31'
  3986. ))),
  3987. array(
  3988. 'User' => array(
  3989. 'id' => '2',
  3990. 'user' => 'nate'
  3991. ),
  3992. 'Comment' => array(
  3993. array(
  3994. 'id' => '1',
  3995. 'article_id' => '1',
  3996. 'user_id' => '2',
  3997. 'comment' => 'First Comment for First Article',
  3998. 'published' => 'Y',
  3999. 'created' => '2007-03-18 10:45:23',
  4000. 'updated' => '2007-03-18 10:47:31'
  4001. ),
  4002. array(
  4003. 'id' => '6',
  4004. 'article_id' => '2',
  4005. 'user_id' => '2',
  4006. 'comment' => 'Second Comment for Second Article',
  4007. 'published' => 'Y',
  4008. 'created' => '2007-03-18 10:55:23',
  4009. 'updated' => '2007-03-18 10:57:31'
  4010. ))),
  4011. array(
  4012. 'User' => array(
  4013. 'id' => '3',
  4014. 'user' => 'larry'
  4015. ),
  4016. 'Comment' => array()
  4017. ),
  4018. array(
  4019. 'User' => array(
  4020. 'id' => '4',
  4021. 'user' => 'garrett'
  4022. ),
  4023. 'Comment' => array(
  4024. array(
  4025. 'id' => '2',
  4026. 'article_id' => '1',
  4027. 'user_id' => '4',
  4028. 'comment' => 'Second Comment for First Article',
  4029. 'published' => 'Y',
  4030. 'created' => '2007-03-18 10:47:23',
  4031. 'updated' => '2007-03-18 10:49:31'
  4032. ))));
  4033. $this->assertEquals($expected, $result);
  4034. $TestModel->resetAssociations();
  4035. $result = $TestModel->hasMany;
  4036. $this->assertEquals($result, array());
  4037. $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false);
  4038. $this->assertTrue($result);
  4039. $result = $TestModel->find('all', array(
  4040. 'fields' => 'User.id, User.user'
  4041. ));
  4042. $expected = array(
  4043. array(
  4044. 'User' => array(
  4045. 'id' => '1',
  4046. 'user' => 'mariano'
  4047. ),
  4048. 'Comment' => array(
  4049. array(
  4050. 'id' => '3',
  4051. 'article_id' => '1',
  4052. 'user_id' => '1',
  4053. 'comment' => 'Third Comment for First Article',
  4054. 'published' => 'Y',
  4055. 'created' => '2007-03-18 10:49:23',
  4056. 'updated' => '2007-03-18 10:51:31'
  4057. ),
  4058. array(
  4059. 'id' => '4',
  4060. 'article_id' => '1',
  4061. 'user_id' => '1',
  4062. 'comment' => 'Fourth Comment for First Article',
  4063. 'published' => 'N',
  4064. 'created' => '2007-03-18 10:51:23',
  4065. 'updated' => '2007-03-18 10:53:31'
  4066. ),
  4067. array(
  4068. 'id' => '5',
  4069. 'article_id' => '2',
  4070. 'user_id' => '1',
  4071. 'comment' => 'First Comment for Second Article',
  4072. 'published' => 'Y',
  4073. 'created' => '2007-03-18 10:53:23',
  4074. 'updated' => '2007-03-18 10:55:31'
  4075. ))),
  4076. array(
  4077. 'User' => array(
  4078. 'id' => '2',
  4079. 'user' => 'nate'
  4080. ),
  4081. 'Comment' => array(
  4082. array(
  4083. 'id' => '1',
  4084. 'article_id' => '1',
  4085. 'user_id' => '2',
  4086. 'comment' => 'First Comment for First Article',
  4087. 'published' => 'Y',
  4088. 'created' => '2007-03-18 10:45:23',
  4089. 'updated' => '2007-03-18 10:47:31'
  4090. ),
  4091. array(
  4092. 'id' => '6',
  4093. 'article_id' => '2',
  4094. 'user_id' => '2',
  4095. 'comment' => 'Second Comment for Second Article',
  4096. 'published' => 'Y',
  4097. 'created' => '2007-03-18 10:55:23',
  4098. 'updated' => '2007-03-18 10:57:31'
  4099. ))),
  4100. array(
  4101. 'User' => array(
  4102. 'id' => '3',
  4103. 'user' => 'larry'
  4104. ),
  4105. 'Comment' => array()
  4106. ),
  4107. array(
  4108. 'User' => array(
  4109. 'id' => '4',
  4110. 'user' => 'garrett'
  4111. ),
  4112. 'Comment' => array(
  4113. array(
  4114. 'id' => '2',
  4115. 'article_id' => '1',
  4116. 'user_id' => '4',
  4117. 'comment' => 'Second Comment for First Article',
  4118. 'published' => 'Y',
  4119. 'created' => '2007-03-18 10:47:23',
  4120. 'updated' => '2007-03-18 10:49:31'
  4121. ))));
  4122. $this->assertEquals($expected, $result);
  4123. $result = $TestModel->hasMany;
  4124. $expected = array(
  4125. 'Comment' => array(
  4126. 'className' => 'Comment',
  4127. 'foreignKey' => 'user_id',
  4128. 'conditions' => null,
  4129. 'fields' => null,
  4130. 'order' => null,
  4131. 'limit' => null,
  4132. 'offset' => null,
  4133. 'dependent' => null,
  4134. 'exclusive' => null,
  4135. 'finderQuery' => null,
  4136. 'counterQuery' => null
  4137. ));
  4138. $this->assertEquals($expected, $result);
  4139. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4140. $this->assertTrue($result);
  4141. $result = $TestModel->hasMany;
  4142. $expected = array();
  4143. $this->assertEquals($expected, $result);
  4144. $result = $TestModel->find('all', array(
  4145. 'fields' => 'User.id, User.user'
  4146. ));
  4147. $expected = array(
  4148. array('User' => array('id' => '1', 'user' => 'mariano')),
  4149. array('User' => array('id' => '2', 'user' => 'nate')),
  4150. array('User' => array('id' => '3', 'user' => 'larry')),
  4151. array('User' => array('id' => '4', 'user' => 'garrett')));
  4152. $this->assertEquals($expected, $result);
  4153. $result = $TestModel->find('all', array(
  4154. 'fields' => 'User.id, User.user'
  4155. ));
  4156. $expected = array(
  4157. array(
  4158. 'User' => array(
  4159. 'id' => '1',
  4160. 'user' => 'mariano'
  4161. ),
  4162. 'Comment' => array(
  4163. array(
  4164. 'id' => '3',
  4165. 'article_id' => '1',
  4166. 'user_id' => '1',
  4167. 'comment' => 'Third Comment for First Article',
  4168. 'published' => 'Y',
  4169. 'created' => '2007-03-18 10:49:23',
  4170. 'updated' => '2007-03-18 10:51:31'
  4171. ),
  4172. array(
  4173. 'id' => '4',
  4174. 'article_id' => '1',
  4175. 'user_id' => '1',
  4176. 'comment' => 'Fourth Comment for First Article',
  4177. 'published' => 'N',
  4178. 'created' => '2007-03-18 10:51:23',
  4179. 'updated' => '2007-03-18 10:53:31'
  4180. ),
  4181. array(
  4182. 'id' => '5',
  4183. 'article_id' => '2',
  4184. 'user_id' => '1',
  4185. 'comment' => 'First Comment for Second Article',
  4186. 'published' => 'Y',
  4187. 'created' => '2007-03-18 10:53:23',
  4188. 'updated' => '2007-03-18 10:55:31'
  4189. ))),
  4190. array(
  4191. 'User' => array(
  4192. 'id' => '2',
  4193. 'user' => 'nate'
  4194. ),
  4195. 'Comment' => array(
  4196. array(
  4197. 'id' => '1',
  4198. 'article_id' => '1',
  4199. 'user_id' => '2',
  4200. 'comment' => 'First Comment for First Article',
  4201. 'published' => 'Y',
  4202. 'created' => '2007-03-18 10:45:23',
  4203. 'updated' => '2007-03-18 10:47:31'
  4204. ),
  4205. array(
  4206. 'id' => '6',
  4207. 'article_id' => '2',
  4208. 'user_id' => '2',
  4209. 'comment' => 'Second Comment for Second Article',
  4210. 'published' => 'Y',
  4211. 'created' => '2007-03-18 10:55:23',
  4212. 'updated' => '2007-03-18 10:57:31'
  4213. ))),
  4214. array(
  4215. 'User' => array(
  4216. 'id' => '3',
  4217. 'user' => 'larry'
  4218. ),
  4219. 'Comment' => array()
  4220. ),
  4221. array(
  4222. 'User' => array(
  4223. 'id' => '4',
  4224. 'user' => 'garrett'
  4225. ),
  4226. 'Comment' => array(
  4227. array(
  4228. 'id' => '2',
  4229. 'article_id' => '1',
  4230. 'user_id' => '4',
  4231. 'comment' =>
  4232. 'Second Comment for First Article',
  4233. 'published' => 'Y',
  4234. 'created' => '2007-03-18 10:47:23',
  4235. 'updated' => '2007-03-18 10:49:31'
  4236. ))));
  4237. $this->assertEquals($expected, $result);
  4238. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false);
  4239. $this->assertTrue($result);
  4240. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4241. $expected = array(
  4242. array('User' => array('id' => '1', 'user' => 'mariano')),
  4243. array('User' => array('id' => '2', 'user' => 'nate')),
  4244. array('User' => array('id' => '3', 'user' => 'larry')),
  4245. array('User' => array('id' => '4', 'user' => 'garrett')));
  4246. $this->assertEquals($expected, $result);
  4247. $result = $TestModel->hasMany;
  4248. $expected = array();
  4249. $this->assertEquals($expected, $result);
  4250. $result = $TestModel->bindModel(array('hasMany' => array(
  4251. 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'')
  4252. )));
  4253. $this->assertTrue($result);
  4254. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4255. $expected = array(
  4256. array(
  4257. 'User' => array(
  4258. 'id' => '1',
  4259. 'user' => 'mariano'
  4260. ),
  4261. 'Comment' => array(
  4262. array(
  4263. 'id' => '3',
  4264. 'article_id' => '1',
  4265. 'user_id' => '1',
  4266. 'comment' => 'Third Comment for First Article',
  4267. 'published' => 'Y',
  4268. 'created' => '2007-03-18 10:49:23',
  4269. 'updated' => '2007-03-18 10:51:31'
  4270. ),
  4271. array(
  4272. 'id' => '5',
  4273. 'article_id' => '2',
  4274. 'user_id' => '1',
  4275. 'comment' => 'First Comment for Second Article',
  4276. 'published' => 'Y',
  4277. 'created' => '2007-03-18 10:53:23',
  4278. 'updated' => '2007-03-18 10:55:31'
  4279. ))),
  4280. array(
  4281. 'User' => array(
  4282. 'id' => '2',
  4283. 'user' => 'nate'
  4284. ),
  4285. 'Comment' => array(
  4286. array(
  4287. 'id' => '1',
  4288. 'article_id' => '1',
  4289. 'user_id' => '2',
  4290. 'comment' => 'First Comment for First Article',
  4291. 'published' => 'Y',
  4292. 'created' => '2007-03-18 10:45:23',
  4293. 'updated' => '2007-03-18 10:47:31'
  4294. ),
  4295. array(
  4296. 'id' => '6',
  4297. 'article_id' => '2',
  4298. 'user_id' => '2',
  4299. 'comment' => 'Second Comment for Second Article',
  4300. 'published' => 'Y',
  4301. 'created' => '2007-03-18 10:55:23',
  4302. 'updated' => '2007-03-18 10:57:31'
  4303. ))),
  4304. array(
  4305. 'User' => array(
  4306. 'id' => '3',
  4307. 'user' => 'larry'
  4308. ),
  4309. 'Comment' => array()
  4310. ),
  4311. array(
  4312. 'User' => array(
  4313. 'id' => '4',
  4314. 'user' => 'garrett'
  4315. ),
  4316. 'Comment' => array(
  4317. array(
  4318. 'id' => '2',
  4319. 'article_id' => '1',
  4320. 'user_id' => '4',
  4321. 'comment' => 'Second Comment for First Article',
  4322. 'published' => 'Y',
  4323. 'created' => '2007-03-18 10:47:23',
  4324. 'updated' => '2007-03-18 10:49:31'
  4325. ))));
  4326. $this->assertEquals($expected, $result);
  4327. $TestModel2 = new DeviceType();
  4328. $expected = array(
  4329. 'className' => 'FeatureSet',
  4330. 'foreignKey' => 'feature_set_id',
  4331. 'conditions' => '',
  4332. 'fields' => '',
  4333. 'order' => '',
  4334. 'counterCache' => ''
  4335. );
  4336. $this->assertEquals($TestModel2->belongsTo['FeatureSet'], $expected);
  4337. $TestModel2->bindModel(array(
  4338. 'belongsTo' => array(
  4339. 'FeatureSet' => array(
  4340. 'className' => 'FeatureSet',
  4341. 'conditions' => array('active' => true)
  4342. )
  4343. )
  4344. ));
  4345. $expected['conditions'] = array('active' => true);
  4346. $this->assertEquals($TestModel2->belongsTo['FeatureSet'], $expected);
  4347. $TestModel2->bindModel(array(
  4348. 'belongsTo' => array(
  4349. 'FeatureSet' => array(
  4350. 'className' => 'FeatureSet',
  4351. 'foreignKey' => false,
  4352. 'conditions' => array('Feature.name' => 'DeviceType.name')
  4353. )
  4354. )
  4355. ));
  4356. $expected['conditions'] = array('Feature.name' => 'DeviceType.name');
  4357. $expected['foreignKey'] = false;
  4358. $this->assertEquals($TestModel2->belongsTo['FeatureSet'], $expected);
  4359. $TestModel2->bindModel(array(
  4360. 'hasMany' => array(
  4361. 'NewFeatureSet' => array(
  4362. 'className' => 'FeatureSet',
  4363. 'conditions' => array('active' => true)
  4364. )
  4365. )
  4366. ));
  4367. $expected = array(
  4368. 'className' => 'FeatureSet',
  4369. 'conditions' => array('active' => true),
  4370. 'foreignKey' => 'device_type_id',
  4371. 'fields' => '',
  4372. 'order' => '',
  4373. 'limit' => '',
  4374. 'offset' => '',
  4375. 'dependent' => '',
  4376. 'exclusive' => '',
  4377. 'finderQuery' => '',
  4378. 'counterQuery' => ''
  4379. );
  4380. $this->assertEquals($TestModel2->hasMany['NewFeatureSet'], $expected);
  4381. $this->assertTrue(is_object($TestModel2->NewFeatureSet));
  4382. }
  4383. /**
  4384. * testBindMultipleTimes method
  4385. *
  4386. * @return void
  4387. */
  4388. public function testBindMultipleTimes() {
  4389. $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag');
  4390. $TestModel = new User();
  4391. $result = $TestModel->hasMany;
  4392. $expected = array();
  4393. $this->assertEquals($expected, $result);
  4394. $result = $TestModel->bindModel(array(
  4395. 'hasMany' => array(
  4396. 'Items' => array('className' => 'Comment')
  4397. )));
  4398. $this->assertTrue($result);
  4399. $result = $TestModel->find('all', array(
  4400. 'fields' => 'User.id, User.user'
  4401. ));
  4402. $expected = array(
  4403. array(
  4404. 'User' => array(
  4405. 'id' => '1',
  4406. 'user' => 'mariano'
  4407. ),
  4408. 'Items' => array(
  4409. array(
  4410. 'id' => '3',
  4411. 'article_id' => '1',
  4412. 'user_id' => '1',
  4413. 'comment' => 'Third Comment for First Article',
  4414. 'published' => 'Y',
  4415. 'created' => '2007-03-18 10:49:23',
  4416. 'updated' => '2007-03-18 10:51:31'
  4417. ),
  4418. array(
  4419. 'id' => '4',
  4420. 'article_id' => '1',
  4421. 'user_id' => '1',
  4422. 'comment' => 'Fourth Comment for First Article',
  4423. 'published' => 'N',
  4424. 'created' => '2007-03-18 10:51:23',
  4425. 'updated' => '2007-03-18 10:53:31'
  4426. ),
  4427. array(
  4428. 'id' => '5',
  4429. 'article_id' => '2',
  4430. 'user_id' => '1',
  4431. 'comment' => 'First Comment for Second Article',
  4432. 'published' => 'Y',
  4433. 'created' => '2007-03-18 10:53:23',
  4434. 'updated' => '2007-03-18 10:55:31'
  4435. ))),
  4436. array(
  4437. 'User' => array(
  4438. 'id' => '2',
  4439. 'user' => 'nate'
  4440. ),
  4441. 'Items' => array(
  4442. array(
  4443. 'id' => '1',
  4444. 'article_id' => '1',
  4445. 'user_id' => '2',
  4446. 'comment' => 'First Comment for First Article',
  4447. 'published' => 'Y',
  4448. 'created' => '2007-03-18 10:45:23',
  4449. 'updated' => '2007-03-18 10:47:31'
  4450. ),
  4451. array(
  4452. 'id' => '6',
  4453. 'article_id' => '2',
  4454. 'user_id' => '2',
  4455. 'comment' => 'Second Comment for Second Article',
  4456. 'published' => 'Y',
  4457. 'created' => '2007-03-18 10:55:23',
  4458. 'updated' => '2007-03-18 10:57:31'
  4459. ))),
  4460. array(
  4461. 'User' => array(
  4462. 'id' => '3',
  4463. 'user' => 'larry'
  4464. ),
  4465. 'Items' => array()
  4466. ),
  4467. array(
  4468. 'User' => array(
  4469. 'id' => '4',
  4470. 'user' => 'garrett'
  4471. ),
  4472. 'Items' => array(
  4473. array(
  4474. 'id' => '2',
  4475. 'article_id' => '1',
  4476. 'user_id' => '4',
  4477. 'comment' => 'Second Comment for First Article',
  4478. 'published' => 'Y',
  4479. 'created' => '2007-03-18 10:47:23',
  4480. 'updated' => '2007-03-18 10:49:31'
  4481. ))));
  4482. $this->assertEquals($expected, $result);
  4483. $result = $TestModel->bindModel(array(
  4484. 'hasMany' => array(
  4485. 'Items' => array('className' => 'Article')
  4486. )));
  4487. $this->assertTrue($result);
  4488. $result = $TestModel->find('all', array(
  4489. 'fields' => 'User.id, User.user'
  4490. ));
  4491. $expected = array(
  4492. array(
  4493. 'User' => array(
  4494. 'id' => '1',
  4495. 'user' => 'mariano'
  4496. ),
  4497. 'Items' => array(
  4498. array(
  4499. 'id' => 1,
  4500. 'user_id' => 1,
  4501. 'title' => 'First Article',
  4502. 'body' => 'First Article Body',
  4503. 'published' => 'Y',
  4504. 'created' => '2007-03-18 10:39:23',
  4505. 'updated' => '2007-03-18 10:41:31'
  4506. ),
  4507. array(
  4508. 'id' => 3,
  4509. 'user_id' => 1,
  4510. 'title' => 'Third Article',
  4511. 'body' => 'Third Article Body',
  4512. 'published' => 'Y',
  4513. 'created' => '2007-03-18 10:43:23',
  4514. 'updated' => '2007-03-18 10:45:31'
  4515. ))),
  4516. array(
  4517. 'User' => array(
  4518. 'id' => '2',
  4519. 'user' => 'nate'
  4520. ),
  4521. 'Items' => array()
  4522. ),
  4523. array(
  4524. 'User' => array(
  4525. 'id' => '3',
  4526. 'user' => 'larry'
  4527. ),
  4528. 'Items' => array(
  4529. array(
  4530. 'id' => 2,
  4531. 'user_id' => 3,
  4532. 'title' => 'Second Article',
  4533. 'body' => 'Second Article Body',
  4534. 'published' => 'Y',
  4535. 'created' => '2007-03-18 10:41:23',
  4536. 'updated' => '2007-03-18 10:43:31'
  4537. ))),
  4538. array(
  4539. 'User' => array(
  4540. 'id' => '4',
  4541. 'user' => 'garrett'
  4542. ),
  4543. 'Items' => array()
  4544. ));
  4545. $this->assertEquals($expected, $result);
  4546. }
  4547. /**
  4548. * test that multiple reset = true calls to bindModel() result in the original associations.
  4549. *
  4550. * @return void
  4551. */
  4552. public function testBindModelMultipleTimesResetCorrectly() {
  4553. $this->loadFixtures('User', 'Comment', 'Article');
  4554. $TestModel = new User();
  4555. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4556. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4557. $TestModel->resetAssociations();
  4558. $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind');
  4559. }
  4560. /**
  4561. * testBindMultipleTimes method with different reset settings
  4562. *
  4563. * @return void
  4564. */
  4565. public function testBindMultipleTimesWithDifferentResetSettings() {
  4566. $this->loadFixtures('User', 'Comment', 'Article');
  4567. $TestModel = new User();
  4568. $result = $TestModel->hasMany;
  4569. $expected = array();
  4570. $this->assertEquals($expected, $result);
  4571. $result = $TestModel->bindModel(array(
  4572. 'hasMany' => array('Comment')
  4573. ));
  4574. $this->assertTrue($result);
  4575. $result = $TestModel->bindModel(
  4576. array('hasMany' => array('Article')),
  4577. false
  4578. );
  4579. $this->assertTrue($result);
  4580. $result = array_keys($TestModel->hasMany);
  4581. $expected = array('Comment', 'Article');
  4582. $this->assertEquals($expected, $result);
  4583. $TestModel->resetAssociations();
  4584. $result = array_keys($TestModel->hasMany);
  4585. $expected = array('Article');
  4586. $this->assertEquals($expected, $result);
  4587. }
  4588. /**
  4589. * test that bindModel behaves with Custom primary Key associations
  4590. *
  4591. * @return void
  4592. */
  4593. public function testBindWithCustomPrimaryKey() {
  4594. $this->loadFixtures('Story', 'StoriesTag', 'Tag');
  4595. $Model = ClassRegistry::init('StoriesTag');
  4596. $Model->bindModel(array(
  4597. 'belongsTo' => array(
  4598. 'Tag' => array(
  4599. 'className' => 'Tag',
  4600. 'foreignKey' => 'story'
  4601. ))));
  4602. $result = $Model->find('all');
  4603. $this->assertFalse(empty($result));
  4604. }
  4605. /**
  4606. * test that calling unbindModel() with reset == true multiple times
  4607. * leaves associations in the correct state.
  4608. *
  4609. * @return void
  4610. */
  4611. public function testUnbindMultipleTimesResetCorrectly() {
  4612. $this->loadFixtures('User', 'Comment', 'Article');
  4613. $TestModel = new Article10();
  4614. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4615. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4616. $TestModel->resetAssociations();
  4617. $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed');
  4618. }
  4619. /**
  4620. * testBindMultipleTimes method with different reset settings
  4621. *
  4622. * @return void
  4623. */
  4624. public function testUnBindMultipleTimesWithDifferentResetSettings() {
  4625. $this->loadFixtures('User', 'Comment', 'Article');
  4626. $TestModel = new Comment();
  4627. $result = array_keys($TestModel->belongsTo);
  4628. $expected = array('Article', 'User');
  4629. $this->assertEquals($expected, $result);
  4630. $result = $TestModel->unbindModel(array(
  4631. 'belongsTo' => array('User')
  4632. ));
  4633. $this->assertTrue($result);
  4634. $result = $TestModel->unbindModel(
  4635. array('belongsTo' => array('Article')),
  4636. false
  4637. );
  4638. $this->assertTrue($result);
  4639. $result = array_keys($TestModel->belongsTo);
  4640. $expected = array();
  4641. $this->assertEquals($expected, $result);
  4642. $TestModel->resetAssociations();
  4643. $result = array_keys($TestModel->belongsTo);
  4644. $expected = array('User');
  4645. $this->assertEquals($expected, $result);
  4646. }
  4647. /**
  4648. * testAssociationAfterFind method
  4649. *
  4650. * @return void
  4651. */
  4652. public function testAssociationAfterFind() {
  4653. $this->loadFixtures('Post', 'Author', 'Comment');
  4654. $TestModel = new Post();
  4655. $result = $TestModel->find('all');
  4656. $expected = array(
  4657. array(
  4658. 'Post' => array(
  4659. 'id' => '1',
  4660. 'author_id' => '1',
  4661. 'title' => 'First Post',
  4662. 'body' => 'First Post Body',
  4663. 'published' => 'Y',
  4664. 'created' => '2007-03-18 10:39:23',
  4665. 'updated' => '2007-03-18 10:41:31'
  4666. ),
  4667. 'Author' => array(
  4668. 'id' => '1',
  4669. 'user' => 'mariano',
  4670. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4671. 'created' => '2007-03-17 01:16:23',
  4672. 'updated' => '2007-03-17 01:18:31',
  4673. 'test' => 'working'
  4674. )),
  4675. array(
  4676. 'Post' => array(
  4677. 'id' => '2',
  4678. 'author_id' => '3',
  4679. 'title' => 'Second Post',
  4680. 'body' => 'Second Post Body',
  4681. 'published' => 'Y',
  4682. 'created' => '2007-03-18 10:41:23',
  4683. 'updated' => '2007-03-18 10:43:31'
  4684. ),
  4685. 'Author' => array(
  4686. 'id' => '3',
  4687. 'user' => 'larry',
  4688. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4689. 'created' => '2007-03-17 01:20:23',
  4690. 'updated' => '2007-03-17 01:22:31',
  4691. 'test' => 'working'
  4692. )),
  4693. array(
  4694. 'Post' => array(
  4695. 'id' => '3',
  4696. 'author_id' => '1',
  4697. 'title' => 'Third Post',
  4698. 'body' => 'Third Post Body',
  4699. 'published' => 'Y',
  4700. 'created' => '2007-03-18 10:43:23',
  4701. 'updated' => '2007-03-18 10:45:31'
  4702. ),
  4703. 'Author' => array(
  4704. 'id' => '1',
  4705. 'user' => 'mariano',
  4706. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4707. 'created' => '2007-03-17 01:16:23',
  4708. 'updated' => '2007-03-17 01:18:31',
  4709. 'test' => 'working'
  4710. )));
  4711. $this->assertEquals($expected, $result);
  4712. unset($TestModel);
  4713. $Author = new Author();
  4714. $Author->Post->bindModel(array(
  4715. 'hasMany' => array(
  4716. 'Comment' => array(
  4717. 'className' => 'ModifiedComment',
  4718. 'foreignKey' => 'article_id',
  4719. )
  4720. )));
  4721. $result = $Author->find('all', array(
  4722. 'conditions' => array('Author.id' => 1),
  4723. 'recursive' => 2
  4724. ));
  4725. $expected = array(
  4726. 'id' => 1,
  4727. 'article_id' => 1,
  4728. 'user_id' => 2,
  4729. 'comment' => 'First Comment for First Article',
  4730. 'published' => 'Y',
  4731. 'created' => '2007-03-18 10:45:23',
  4732. 'updated' => '2007-03-18 10:47:31',
  4733. 'callback' => 'Fire'
  4734. );
  4735. $this->assertEquals($result[0]['Post'][0]['Comment'][0], $expected);
  4736. }
  4737. /**
  4738. * Tests that callbacks can be properly disabled
  4739. *
  4740. * @return void
  4741. */
  4742. public function testCallbackDisabling() {
  4743. $this->loadFixtures('Author');
  4744. $TestModel = new ModifiedAuthor();
  4745. $result = Set::extract($TestModel->find('all'), '/Author/user');
  4746. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4747. $this->assertEquals($expected, $result);
  4748. $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user');
  4749. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4750. $this->assertEquals($expected, $result);
  4751. $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user');
  4752. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4753. $this->assertEquals($expected, $result);
  4754. $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user');
  4755. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4756. $this->assertEquals($expected, $result);
  4757. }
  4758. /**
  4759. * testAssociationAfterFindCallbacksDisabled method
  4760. *
  4761. * @return void
  4762. */
  4763. public function testAssociationAfterFindCalbacksDisabled() {
  4764. $this->loadFixtures('Post', 'Author', 'Comment');
  4765. $TestModel = new Post();
  4766. $result = $TestModel->find('all', array('callbacks' => false));
  4767. $expected = array(
  4768. array(
  4769. 'Post' => array(
  4770. 'id' => '1',
  4771. 'author_id' => '1',
  4772. 'title' => 'First Post',
  4773. 'body' => 'First Post Body',
  4774. 'published' => 'Y',
  4775. 'created' => '2007-03-18 10:39:23',
  4776. 'updated' => '2007-03-18 10:41:31'
  4777. ),
  4778. 'Author' => array(
  4779. 'id' => '1',
  4780. 'user' => 'mariano',
  4781. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4782. 'created' => '2007-03-17 01:16:23',
  4783. 'updated' => '2007-03-17 01:18:31'
  4784. )),
  4785. array(
  4786. 'Post' => array(
  4787. 'id' => '2',
  4788. 'author_id' => '3',
  4789. 'title' => 'Second Post',
  4790. 'body' => 'Second Post Body',
  4791. 'published' => 'Y',
  4792. 'created' => '2007-03-18 10:41:23',
  4793. 'updated' => '2007-03-18 10:43:31'
  4794. ),
  4795. 'Author' => array(
  4796. 'id' => '3',
  4797. 'user' => 'larry',
  4798. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4799. 'created' => '2007-03-17 01:20:23',
  4800. 'updated' => '2007-03-17 01:22:31'
  4801. )),
  4802. array(
  4803. 'Post' => array(
  4804. 'id' => '3',
  4805. 'author_id' => '1',
  4806. 'title' => 'Third Post',
  4807. 'body' => 'Third Post Body',
  4808. 'published' => 'Y',
  4809. 'created' => '2007-03-18 10:43:23',
  4810. 'updated' => '2007-03-18 10:45:31'
  4811. ),
  4812. 'Author' => array(
  4813. 'id' => '1',
  4814. 'user' => 'mariano',
  4815. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4816. 'created' => '2007-03-17 01:16:23',
  4817. 'updated' => '2007-03-17 01:18:31'
  4818. )));
  4819. $this->assertEquals($expected, $result);
  4820. unset($TestModel);
  4821. $Author = new Author();
  4822. $Author->Post->bindModel(array(
  4823. 'hasMany' => array(
  4824. 'Comment' => array(
  4825. 'className' => 'ModifiedComment',
  4826. 'foreignKey' => 'article_id',
  4827. )
  4828. )));
  4829. $result = $Author->find('all', array(
  4830. 'conditions' => array('Author.id' => 1),
  4831. 'recursive' => 2,
  4832. 'callbacks' => false
  4833. ));
  4834. $expected = array(
  4835. 'id' => 1,
  4836. 'article_id' => 1,
  4837. 'user_id' => 2,
  4838. 'comment' => 'First Comment for First Article',
  4839. 'published' => 'Y',
  4840. 'created' => '2007-03-18 10:45:23',
  4841. 'updated' => '2007-03-18 10:47:31'
  4842. );
  4843. $this->assertEquals($result[0]['Post'][0]['Comment'][0], $expected);
  4844. }
  4845. /**
  4846. * Tests that the database configuration assigned to the model can be changed using
  4847. * (before|after)Find callbacks
  4848. *
  4849. * @return void
  4850. */
  4851. public function testCallbackSourceChange() {
  4852. $this->loadFixtures('Post');
  4853. $TestModel = new Post();
  4854. $this->assertEquals(3, count($TestModel->find('all')));
  4855. }
  4856. /**
  4857. * testCallbackSourceChangeUnknownDatasource method
  4858. *
  4859. * @expectedException MissingDatasourceConfigException
  4860. * @return void
  4861. */
  4862. public function testCallbackSourceChangeUnknownDatasource() {
  4863. $this->loadFixtures('Post', 'Author');
  4864. $TestModel = new Post();
  4865. $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
  4866. }
  4867. /**
  4868. * testMultipleBelongsToWithSameClass method
  4869. *
  4870. * @return void
  4871. */
  4872. public function testMultipleBelongsToWithSameClass() {
  4873. $this->loadFixtures(
  4874. 'DeviceType',
  4875. 'DeviceTypeCategory',
  4876. 'FeatureSet',
  4877. 'ExteriorTypeCategory',
  4878. 'Document',
  4879. 'Device',
  4880. 'DocumentDirectory'
  4881. );
  4882. $DeviceType = new DeviceType();
  4883. $DeviceType->recursive = 2;
  4884. $result = $DeviceType->read(null, 1);
  4885. $expected = array(
  4886. 'DeviceType' => array(
  4887. 'id' => 1,
  4888. 'device_type_category_id' => 1,
  4889. 'feature_set_id' => 1,
  4890. 'exterior_type_category_id' => 1,
  4891. 'image_id' => 1,
  4892. 'extra1_id' => 1,
  4893. 'extra2_id' => 1,
  4894. 'name' => 'DeviceType 1',
  4895. 'order' => 0
  4896. ),
  4897. 'Image' => array(
  4898. 'id' => 1,
  4899. 'document_directory_id' => 1,
  4900. 'name' => 'Document 1',
  4901. 'DocumentDirectory' => array(
  4902. 'id' => 1,
  4903. 'name' => 'DocumentDirectory 1'
  4904. )),
  4905. 'Extra1' => array(
  4906. 'id' => 1,
  4907. 'document_directory_id' => 1,
  4908. 'name' => 'Document 1',
  4909. 'DocumentDirectory' => array(
  4910. 'id' => 1,
  4911. 'name' => 'DocumentDirectory 1'
  4912. )),
  4913. 'Extra2' => array(
  4914. 'id' => 1,
  4915. 'document_directory_id' => 1,
  4916. 'name' => 'Document 1',
  4917. 'DocumentDirectory' => array(
  4918. 'id' => 1,
  4919. 'name' => 'DocumentDirectory 1'
  4920. )),
  4921. 'DeviceTypeCategory' => array(
  4922. 'id' => 1,
  4923. 'name' => 'DeviceTypeCategory 1'
  4924. ),
  4925. 'FeatureSet' => array(
  4926. 'id' => 1,
  4927. 'name' => 'FeatureSet 1'
  4928. ),
  4929. 'ExteriorTypeCategory' => array(
  4930. 'id' => 1,
  4931. 'image_id' => 1,
  4932. 'name' => 'ExteriorTypeCategory 1',
  4933. 'Image' => array(
  4934. 'id' => 1,
  4935. 'device_type_id' => 1,
  4936. 'name' => 'Device 1',
  4937. 'typ' => 1
  4938. )),
  4939. 'Device' => array(
  4940. array(
  4941. 'id' => 1,
  4942. 'device_type_id' => 1,
  4943. 'name' => 'Device 1',
  4944. 'typ' => 1
  4945. ),
  4946. array(
  4947. 'id' => 2,
  4948. 'device_type_id' => 1,
  4949. 'name' => 'Device 2',
  4950. 'typ' => 1
  4951. ),
  4952. array(
  4953. 'id' => 3,
  4954. 'device_type_id' => 1,
  4955. 'name' => 'Device 3',
  4956. 'typ' => 2
  4957. )));
  4958. $this->assertEquals($expected, $result);
  4959. }
  4960. /**
  4961. * testHabtmRecursiveBelongsTo method
  4962. *
  4963. * @return void
  4964. */
  4965. public function testHabtmRecursiveBelongsTo() {
  4966. $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
  4967. $Portfolio = new Portfolio();
  4968. $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3));
  4969. $expected = array(
  4970. 'Portfolio' => array(
  4971. 'id' => 2,
  4972. 'seller_id' => 1,
  4973. 'name' => 'Portfolio 2'
  4974. ),
  4975. 'Item' => array(
  4976. array(
  4977. 'id' => 2,
  4978. 'syfile_id' => 2,
  4979. 'published' => false,
  4980. 'name' => 'Item 2',
  4981. 'ItemsPortfolio' => array(
  4982. 'id' => 2,
  4983. 'item_id' => 2,
  4984. 'portfolio_id' => 2
  4985. ),
  4986. 'Syfile' => array(
  4987. 'id' => 2,
  4988. 'image_id' => 2,
  4989. 'name' => 'Syfile 2',
  4990. 'item_count' => null,
  4991. 'Image' => array(
  4992. 'id' => 2,
  4993. 'name' => 'Image 2'
  4994. )
  4995. )),
  4996. array(
  4997. 'id' => 6,
  4998. 'syfile_id' => 6,
  4999. 'published' => false,
  5000. 'name' => 'Item 6',
  5001. 'ItemsPortfolio' => array(
  5002. 'id' => 6,
  5003. 'item_id' => 6,
  5004. 'portfolio_id' => 2
  5005. ),
  5006. 'Syfile' => array(
  5007. 'id' => 6,
  5008. 'image_id' => null,
  5009. 'name' => 'Syfile 6',
  5010. 'item_count' => null,
  5011. 'Image' => array()
  5012. ))));
  5013. $this->assertEquals($expected, $result);
  5014. }
  5015. /**
  5016. * testNonNumericHabtmJoinKey method
  5017. *
  5018. * @return void
  5019. */
  5020. public function testNonNumericHabtmJoinKey() {
  5021. $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author');
  5022. $Post = new Post();
  5023. $Post->bindModel(array(
  5024. 'hasAndBelongsToMany' => array('Tag')
  5025. ));
  5026. $Post->Tag->primaryKey = 'tag';
  5027. $result = $Post->find('all');
  5028. $expected = array(
  5029. array(
  5030. 'Post' => array(
  5031. 'id' => '1',
  5032. 'author_id' => '1',
  5033. 'title' => 'First Post',
  5034. 'body' => 'First Post Body',
  5035. 'published' => 'Y',
  5036. 'created' => '2007-03-18 10:39:23',
  5037. 'updated' => '2007-03-18 10:41:31'
  5038. ),
  5039. 'Author' => array(
  5040. 'id' => 1,
  5041. 'user' => 'mariano',
  5042. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5043. 'created' => '2007-03-17 01:16:23',
  5044. 'updated' => '2007-03-17 01:18:31',
  5045. 'test' => 'working'
  5046. ),
  5047. 'Tag' => array(
  5048. array(
  5049. 'id' => '1',
  5050. 'tag' => 'tag1',
  5051. 'created' => '2007-03-18 12:22:23',
  5052. 'updated' => '2007-03-18 12:24:31'
  5053. ),
  5054. array(
  5055. 'id' => '2',
  5056. 'tag' => 'tag2',
  5057. 'created' => '2007-03-18 12:24:23',
  5058. 'updated' => '2007-03-18 12:26:31'
  5059. ))),
  5060. array(
  5061. 'Post' => array(
  5062. 'id' => '2',
  5063. 'author_id' => '3',
  5064. 'title' => 'Second Post',
  5065. 'body' => 'Second Post Body',
  5066. 'published' => 'Y',
  5067. 'created' => '2007-03-18 10:41:23',
  5068. 'updated' => '2007-03-18 10:43:31'
  5069. ),
  5070. 'Author' => array(
  5071. 'id' => 3,
  5072. 'user' => 'larry',
  5073. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5074. 'created' => '2007-03-17 01:20:23',
  5075. 'updated' => '2007-03-17 01:22:31',
  5076. 'test' => 'working'
  5077. ),
  5078. 'Tag' => array(
  5079. array(
  5080. 'id' => '1',
  5081. 'tag' => 'tag1',
  5082. 'created' => '2007-03-18 12:22:23',
  5083. 'updated' => '2007-03-18 12:24:31'
  5084. ),
  5085. array(
  5086. 'id' => '3',
  5087. 'tag' => 'tag3',
  5088. 'created' => '2007-03-18 12:26:23',
  5089. 'updated' => '2007-03-18 12:28:31'
  5090. ))),
  5091. array(
  5092. 'Post' => array(
  5093. 'id' => '3',
  5094. 'author_id' => '1',
  5095. 'title' => 'Third Post',
  5096. 'body' => 'Third Post Body',
  5097. 'published' => 'Y',
  5098. 'created' => '2007-03-18 10:43:23',
  5099. 'updated' => '2007-03-18 10:45:31'
  5100. ),
  5101. 'Author' => array(
  5102. 'id' => 1,
  5103. 'user' => 'mariano',
  5104. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5105. 'created' => '2007-03-17 01:16:23',
  5106. 'updated' => '2007-03-17 01:18:31',
  5107. 'test' => 'working'
  5108. ),
  5109. 'Tag' => array()
  5110. ));
  5111. $this->assertEquals($expected, $result);
  5112. }
  5113. /**
  5114. * testHabtmFinderQuery method
  5115. *
  5116. * @return void
  5117. */
  5118. public function testHabtmFinderQuery() {
  5119. $this->loadFixtures('Article', 'Tag', 'ArticlesTag');
  5120. $Article = new Article();
  5121. $sql = $this->db->buildStatement(
  5122. array(
  5123. 'fields' => $this->db->fields($Article->Tag, null, array(
  5124. 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id'
  5125. )),
  5126. 'table' => $this->db->fullTableName('tags'),
  5127. 'alias' => 'Tag',
  5128. 'limit' => null,
  5129. 'offset' => null,
  5130. 'group' => null,
  5131. 'joins' => array(array(
  5132. 'alias' => 'ArticlesTag',
  5133. 'table' => 'articles_tags',
  5134. 'conditions' => array(
  5135. array("ArticlesTag.article_id" => '{$__cakeID__$}'),
  5136. array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
  5137. )
  5138. )),
  5139. 'conditions' => array(),
  5140. 'order' => null
  5141. ),
  5142. $Article
  5143. );
  5144. $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
  5145. $result = $Article->find('first');
  5146. $expected = array(
  5147. array(
  5148. 'id' => '1',
  5149. 'tag' => 'tag1'
  5150. ),
  5151. array(
  5152. 'id' => '2',
  5153. 'tag' => 'tag2'
  5154. ));
  5155. $this->assertEquals($result['Tag'], $expected);
  5156. }
  5157. /**
  5158. * testHabtmLimitOptimization method
  5159. *
  5160. * @return void
  5161. */
  5162. public function testHabtmLimitOptimization() {
  5163. $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag');
  5164. $TestModel = new Article();
  5165. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2;
  5166. $result = $TestModel->read(null, 2);
  5167. $expected = array(
  5168. 'Article' => array(
  5169. 'id' => '2',
  5170. 'user_id' => '3',
  5171. 'title' => 'Second Article',
  5172. 'body' => 'Second Article Body',
  5173. 'published' => 'Y',
  5174. 'created' => '2007-03-18 10:41:23',
  5175. 'updated' => '2007-03-18 10:43:31'
  5176. ),
  5177. 'User' => array(
  5178. 'id' => '3',
  5179. 'user' => 'larry',
  5180. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5181. 'created' => '2007-03-17 01:20:23',
  5182. 'updated' => '2007-03-17 01:22:31'
  5183. ),
  5184. 'Comment' => array(
  5185. array(
  5186. 'id' => '5',
  5187. 'article_id' => '2',
  5188. 'user_id' => '1',
  5189. 'comment' => 'First Comment for Second Article',
  5190. 'published' => 'Y',
  5191. 'created' => '2007-03-18 10:53:23',
  5192. 'updated' => '2007-03-18 10:55:31'
  5193. ),
  5194. array(
  5195. 'id' => '6',
  5196. 'article_id' => '2',
  5197. 'user_id' => '2',
  5198. 'comment' => 'Second Comment for Second Article',
  5199. 'published' => 'Y',
  5200. 'created' => '2007-03-18 10:55:23',
  5201. 'updated' => '2007-03-18 10:57:31'
  5202. )),
  5203. 'Tag' => array(
  5204. array(
  5205. 'id' => '1',
  5206. 'tag' => 'tag1',
  5207. 'created' => '2007-03-18 12:22:23',
  5208. 'updated' => '2007-03-18 12:24:31'
  5209. ),
  5210. array(
  5211. 'id' => '3',
  5212. 'tag' => 'tag3',
  5213. 'created' => '2007-03-18 12:26:23',
  5214. 'updated' => '2007-03-18 12:28:31'
  5215. )));
  5216. $this->assertEquals($expected, $result);
  5217. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1;
  5218. $result = $TestModel->read(null, 2);
  5219. unset($expected['Tag'][1]);
  5220. $this->assertEquals($expected, $result);
  5221. }
  5222. /**
  5223. * testHasManyLimitOptimization method
  5224. *
  5225. * @return void
  5226. */
  5227. public function testHasManyLimitOptimization() {
  5228. $this->loadFixtures('Project', 'Thread', 'Message', 'Bid');
  5229. $Project = new Project();
  5230. $Project->recursive = 3;
  5231. $result = $Project->find('all');
  5232. $expected = array(
  5233. array(
  5234. 'Project' => array(
  5235. 'id' => 1,
  5236. 'name' => 'Project 1'
  5237. ),
  5238. 'Thread' => array(
  5239. array(
  5240. 'id' => 1,
  5241. 'project_id' => 1,
  5242. 'name' => 'Project 1, Thread 1',
  5243. 'Project' => array(
  5244. 'id' => 1,
  5245. 'name' => 'Project 1',
  5246. 'Thread' => array(
  5247. array(
  5248. 'id' => 1,
  5249. 'project_id' => 1,
  5250. 'name' => 'Project 1, Thread 1'
  5251. ),
  5252. array(
  5253. 'id' => 2,
  5254. 'project_id' => 1,
  5255. 'name' => 'Project 1, Thread 2'
  5256. ))),
  5257. 'Message' => array(
  5258. array(
  5259. 'id' => 1,
  5260. 'thread_id' => 1,
  5261. 'name' => 'Thread 1, Message 1',
  5262. 'Bid' => array(
  5263. 'id' => 1,
  5264. 'message_id' => 1,
  5265. 'name' => 'Bid 1.1'
  5266. )))),
  5267. array(
  5268. 'id' => 2,
  5269. 'project_id' => 1,
  5270. 'name' => 'Project 1, Thread 2',
  5271. 'Project' => array(
  5272. 'id' => 1,
  5273. 'name' => 'Project 1',
  5274. 'Thread' => array(
  5275. array(
  5276. 'id' => 1,
  5277. 'project_id' => 1,
  5278. 'name' => 'Project 1, Thread 1'
  5279. ),
  5280. array(
  5281. 'id' => 2,
  5282. 'project_id' => 1,
  5283. 'name' => 'Project 1, Thread 2'
  5284. ))),
  5285. 'Message' => array(
  5286. array(
  5287. 'id' => 2,
  5288. 'thread_id' => 2,
  5289. 'name' => 'Thread 2, Message 1',
  5290. 'Bid' => array(
  5291. 'id' => 4,
  5292. 'message_id' => 2,
  5293. 'name' => 'Bid 2.1'
  5294. )))))),
  5295. array(
  5296. 'Project' => array(
  5297. 'id' => 2,
  5298. 'name' => 'Project 2'
  5299. ),
  5300. 'Thread' => array(
  5301. array(
  5302. 'id' => 3,
  5303. 'project_id' => 2,
  5304. 'name' => 'Project 2, Thread 1',
  5305. 'Project' => array(
  5306. 'id' => 2,
  5307. 'name' => 'Project 2',
  5308. 'Thread' => array(
  5309. array(
  5310. 'id' => 3,
  5311. 'project_id' => 2,
  5312. 'name' => 'Project 2, Thread 1'
  5313. ))),
  5314. 'Message' => array(
  5315. array(
  5316. 'id' => 3,
  5317. 'thread_id' => 3,
  5318. 'name' => 'Thread 3, Message 1',
  5319. 'Bid' => array(
  5320. 'id' => 3,
  5321. 'message_id' => 3,
  5322. 'name' => 'Bid 3.1'
  5323. )))))),
  5324. array(
  5325. 'Project' => array(
  5326. 'id' => 3,
  5327. 'name' => 'Project 3'
  5328. ),
  5329. 'Thread' => array()
  5330. ));
  5331. $this->assertEquals($expected, $result);
  5332. }
  5333. /**
  5334. * testFindAllRecursiveSelfJoin method
  5335. *
  5336. * @return void
  5337. */
  5338. public function testFindAllRecursiveSelfJoin() {
  5339. $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement');
  5340. $TestModel = new Home();
  5341. $TestModel->recursive = 2;
  5342. $result = $TestModel->find('all');
  5343. $expected = array(
  5344. array(
  5345. 'Home' => array(
  5346. 'id' => '1',
  5347. 'another_article_id' => '1',
  5348. 'advertisement_id' => '1',
  5349. 'title' => 'First Home',
  5350. 'created' => '2007-03-18 10:39:23',
  5351. 'updated' => '2007-03-18 10:41:31'
  5352. ),
  5353. 'AnotherArticle' => array(
  5354. 'id' => '1',
  5355. 'title' => 'First Article',
  5356. 'created' => '2007-03-18 10:39:23',
  5357. 'updated' => '2007-03-18 10:41:31',
  5358. 'Home' => array(
  5359. array(
  5360. 'id' => '1',
  5361. 'another_article_id' => '1',
  5362. 'advertisement_id' => '1',
  5363. 'title' => 'First Home',
  5364. 'created' => '2007-03-18 10:39:23',
  5365. 'updated' => '2007-03-18 10:41:31'
  5366. ))),
  5367. 'Advertisement' => array(
  5368. 'id' => '1',
  5369. 'title' => 'First Ad',
  5370. 'created' => '2007-03-18 10:39:23',
  5371. 'updated' => '2007-03-18 10:41:31',
  5372. 'Home' => array(
  5373. array(
  5374. 'id' => '1',
  5375. 'another_article_id' => '1',
  5376. 'advertisement_id' => '1',
  5377. 'title' => 'First Home',
  5378. 'created' => '2007-03-18 10:39:23',
  5379. 'updated' => '2007-03-18 10:41:31'
  5380. ),
  5381. array(
  5382. 'id' => '2',
  5383. 'another_article_id' => '3',
  5384. 'advertisement_id' => '1',
  5385. 'title' => 'Second Home',
  5386. 'created' => '2007-03-18 10:41:23',
  5387. 'updated' => '2007-03-18 10:43:31'
  5388. )))),
  5389. array(
  5390. 'Home' => array(
  5391. 'id' => '2',
  5392. 'another_article_id' => '3',
  5393. 'advertisement_id' => '1',
  5394. 'title' => 'Second Home',
  5395. 'created' => '2007-03-18 10:41:23',
  5396. 'updated' => '2007-03-18 10:43:31'
  5397. ),
  5398. 'AnotherArticle' => array(
  5399. 'id' => '3',
  5400. 'title' => 'Third Article',
  5401. 'created' => '2007-03-18 10:43:23',
  5402. 'updated' => '2007-03-18 10:45:31',
  5403. 'Home' => array(
  5404. array(
  5405. 'id' => '2',
  5406. 'another_article_id' => '3',
  5407. 'advertisement_id' => '1',
  5408. 'title' => 'Second Home',
  5409. 'created' => '2007-03-18 10:41:23',
  5410. 'updated' => '2007-03-18 10:43:31'
  5411. ))),
  5412. 'Advertisement' => array(
  5413. 'id' => '1',
  5414. 'title' => 'First Ad',
  5415. 'created' => '2007-03-18 10:39:23',
  5416. 'updated' => '2007-03-18 10:41:31',
  5417. 'Home' => array(
  5418. array(
  5419. 'id' => '1',
  5420. 'another_article_id' => '1',
  5421. 'advertisement_id' => '1',
  5422. 'title' => 'First Home',
  5423. 'created' => '2007-03-18 10:39:23',
  5424. 'updated' => '2007-03-18 10:41:31'
  5425. ),
  5426. array(
  5427. 'id' => '2',
  5428. 'another_article_id' => '3',
  5429. 'advertisement_id' => '1',
  5430. 'title' => 'Second Home',
  5431. 'created' => '2007-03-18 10:41:23',
  5432. 'updated' => '2007-03-18 10:43:31'
  5433. )))));
  5434. $this->assertEquals($expected, $result);
  5435. }
  5436. /**
  5437. * testFindAllRecursiveWithHabtm method
  5438. *
  5439. * @return void
  5440. */
  5441. public function testFindAllRecursiveWithHabtm() {
  5442. $this->loadFixtures(
  5443. 'MyCategoriesMyUsers',
  5444. 'MyCategoriesMyProducts',
  5445. 'MyCategory',
  5446. 'MyUser',
  5447. 'MyProduct'
  5448. );
  5449. $MyUser = new MyUser();
  5450. $MyUser->recursive = 2;
  5451. $result = $MyUser->find('all');
  5452. $expected = array(
  5453. array(
  5454. 'MyUser' => array('id' => '1', 'firstname' => 'userA'),
  5455. 'MyCategory' => array(
  5456. array(
  5457. 'id' => '1',
  5458. 'name' => 'A',
  5459. 'MyProduct' => array(
  5460. array(
  5461. 'id' => '1',
  5462. 'name' => 'book'
  5463. ))),
  5464. array(
  5465. 'id' => '3',
  5466. 'name' => 'C',
  5467. 'MyProduct' => array(
  5468. array(
  5469. 'id' => '2',
  5470. 'name' => 'computer'
  5471. ))))),
  5472. array(
  5473. 'MyUser' => array(
  5474. 'id' => '2',
  5475. 'firstname' => 'userB'
  5476. ),
  5477. 'MyCategory' => array(
  5478. array(
  5479. 'id' => '1',
  5480. 'name' => 'A',
  5481. 'MyProduct' => array(
  5482. array(
  5483. 'id' => '1',
  5484. 'name' => 'book'
  5485. ))),
  5486. array(
  5487. 'id' => '2',
  5488. 'name' => 'B',
  5489. 'MyProduct' => array(
  5490. array(
  5491. 'id' => '1',
  5492. 'name' => 'book'
  5493. ),
  5494. array(
  5495. 'id' => '2',
  5496. 'name' => 'computer'
  5497. ))))));
  5498. $this->assertEquals($expected, $result);
  5499. }
  5500. /**
  5501. * testReadFakeThread method
  5502. *
  5503. * @return void
  5504. */
  5505. public function testReadFakeThread() {
  5506. $this->loadFixtures('CategoryThread');
  5507. $TestModel = new CategoryThread();
  5508. $fullDebug = $this->db->fullDebug;
  5509. $this->db->fullDebug = true;
  5510. $TestModel->recursive = 6;
  5511. $TestModel->id = 7;
  5512. $result = $TestModel->read();
  5513. $expected = array(
  5514. 'CategoryThread' => array(
  5515. 'id' => 7,
  5516. 'parent_id' => 6,
  5517. 'name' => 'Category 2.1',
  5518. 'created' => '2007-03-18 15:30:23',
  5519. 'updated' => '2007-03-18 15:32:31'
  5520. ),
  5521. 'ParentCategory' => array(
  5522. 'id' => 6,
  5523. 'parent_id' => 5,
  5524. 'name' => 'Category 2',
  5525. 'created' => '2007-03-18 15:30:23',
  5526. 'updated' => '2007-03-18 15:32:31',
  5527. 'ParentCategory' => array(
  5528. 'id' => 5,
  5529. 'parent_id' => 4,
  5530. 'name' => 'Category 1.1.1.1',
  5531. 'created' => '2007-03-18 15:30:23',
  5532. 'updated' => '2007-03-18 15:32:31',
  5533. 'ParentCategory' => array(
  5534. 'id' => 4,
  5535. 'parent_id' => 3,
  5536. 'name' => 'Category 1.1.2',
  5537. 'created' => '2007-03-18 15:30:23',
  5538. 'updated' => '2007-03-18 15:32:31',
  5539. 'ParentCategory' => array(
  5540. 'id' => 3,
  5541. 'parent_id' => 2,
  5542. 'name' => 'Category 1.1.1',
  5543. 'created' => '2007-03-18 15:30:23',
  5544. 'updated' => '2007-03-18 15:32:31',
  5545. 'ParentCategory' => array(
  5546. 'id' => 2,
  5547. 'parent_id' => 1,
  5548. 'name' => 'Category 1.1',
  5549. 'created' => '2007-03-18 15:30:23',
  5550. 'updated' => '2007-03-18 15:32:31',
  5551. 'ParentCategory' => array(
  5552. 'id' => 1,
  5553. 'parent_id' => 0,
  5554. 'name' => 'Category 1',
  5555. 'created' => '2007-03-18 15:30:23',
  5556. 'updated' => '2007-03-18 15:32:31'
  5557. )))))));
  5558. $this->db->fullDebug = $fullDebug;
  5559. $this->assertEquals($expected, $result);
  5560. }
  5561. /**
  5562. * testFindFakeThread method
  5563. *
  5564. * @return void
  5565. */
  5566. public function testFindFakeThread() {
  5567. $this->loadFixtures('CategoryThread');
  5568. $TestModel = new CategoryThread();
  5569. $fullDebug = $this->db->fullDebug;
  5570. $this->db->fullDebug = true;
  5571. $TestModel->recursive = 6;
  5572. $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7)));
  5573. $expected = array(
  5574. 'CategoryThread' => array(
  5575. 'id' => 7,
  5576. 'parent_id' => 6,
  5577. 'name' => 'Category 2.1',
  5578. 'created' => '2007-03-18 15:30:23',
  5579. 'updated' => '2007-03-18 15:32:31'
  5580. ),
  5581. 'ParentCategory' => array(
  5582. 'id' => 6,
  5583. 'parent_id' => 5,
  5584. 'name' => 'Category 2',
  5585. 'created' => '2007-03-18 15:30:23',
  5586. 'updated' => '2007-03-18 15:32:31',
  5587. 'ParentCategory' => array(
  5588. 'id' => 5,
  5589. 'parent_id' => 4,
  5590. 'name' => 'Category 1.1.1.1',
  5591. 'created' => '2007-03-18 15:30:23',
  5592. 'updated' => '2007-03-18 15:32:31',
  5593. 'ParentCategory' => array(
  5594. 'id' => 4,
  5595. 'parent_id' => 3,
  5596. 'name' => 'Category 1.1.2',
  5597. 'created' => '2007-03-18 15:30:23',
  5598. 'updated' => '2007-03-18 15:32:31',
  5599. 'ParentCategory' => array(
  5600. 'id' => 3,
  5601. 'parent_id' => 2,
  5602. 'name' => 'Category 1.1.1',
  5603. 'created' => '2007-03-18 15:30:23',
  5604. 'updated' => '2007-03-18 15:32:31',
  5605. 'ParentCategory' => array(
  5606. 'id' => 2,
  5607. 'parent_id' => 1,
  5608. 'name' => 'Category 1.1',
  5609. 'created' => '2007-03-18 15:30:23',
  5610. 'updated' => '2007-03-18 15:32:31',
  5611. 'ParentCategory' => array(
  5612. 'id' => 1,
  5613. 'parent_id' => 0,
  5614. 'name' => 'Category 1',
  5615. 'created' => '2007-03-18 15:30:23',
  5616. 'updated' => '2007-03-18 15:32:31'
  5617. )))))));
  5618. $this->db->fullDebug = $fullDebug;
  5619. $this->assertEquals($expected, $result);
  5620. }
  5621. /**
  5622. * testFindAllFakeThread method
  5623. *
  5624. * @return void
  5625. */
  5626. public function testFindAllFakeThread() {
  5627. $this->loadFixtures('CategoryThread');
  5628. $TestModel = new CategoryThread();
  5629. $fullDebug = $this->db->fullDebug;
  5630. $this->db->fullDebug = true;
  5631. $TestModel->recursive = 6;
  5632. $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC');
  5633. $expected = array(
  5634. array(
  5635. 'CategoryThread' => array(
  5636. 'id' => 1,
  5637. 'parent_id' => 0,
  5638. 'name' => 'Category 1',
  5639. 'created' => '2007-03-18 15:30:23',
  5640. 'updated' => '2007-03-18 15:32:31'
  5641. ),
  5642. 'ParentCategory' => array(
  5643. 'id' => null,
  5644. 'parent_id' => null,
  5645. 'name' => null,
  5646. 'created' => null,
  5647. 'updated' => null,
  5648. 'ParentCategory' => array()
  5649. )),
  5650. array(
  5651. 'CategoryThread' => array(
  5652. 'id' => 2,
  5653. 'parent_id' => 1,
  5654. 'name' => 'Category 1.1',
  5655. 'created' => '2007-03-18 15:30:23',
  5656. 'updated' => '2007-03-18 15:32:31'
  5657. ),
  5658. 'ParentCategory' => array(
  5659. 'id' => 1,
  5660. 'parent_id' => 0,
  5661. 'name' => 'Category 1',
  5662. 'created' => '2007-03-18 15:30:23',
  5663. 'updated' => '2007-03-18 15:32:31',
  5664. 'ParentCategory' => array()
  5665. )),
  5666. array(
  5667. 'CategoryThread' => array(
  5668. 'id' => 3,
  5669. 'parent_id' => 2,
  5670. 'name' => 'Category 1.1.1',
  5671. 'created' => '2007-03-18 15:30:23',
  5672. 'updated' => '2007-03-18 15:32:31'
  5673. ),
  5674. 'ParentCategory' => array(
  5675. 'id' => 2,
  5676. 'parent_id' => 1,
  5677. 'name' => 'Category 1.1',
  5678. 'created' => '2007-03-18 15:30:23',
  5679. 'updated' => '2007-03-18 15:32:31',
  5680. 'ParentCategory' => array(
  5681. 'id' => 1,
  5682. 'parent_id' => 0,
  5683. 'name' => 'Category 1',
  5684. 'created' => '2007-03-18 15:30:23',
  5685. 'updated' => '2007-03-18 15:32:31',
  5686. 'ParentCategory' => array()
  5687. ))),
  5688. array(
  5689. 'CategoryThread' => array(
  5690. 'id' => 4,
  5691. 'parent_id' => 3,
  5692. 'name' => 'Category 1.1.2',
  5693. 'created' => '2007-03-18 15:30:23',
  5694. 'updated' => '2007-03-18 15:32:31'
  5695. ),
  5696. 'ParentCategory' => array(
  5697. 'id' => 3,
  5698. 'parent_id' => 2,
  5699. 'name' => 'Category 1.1.1',
  5700. 'created' => '2007-03-18 15:30:23',
  5701. 'updated' => '2007-03-18 15:32:31',
  5702. 'ParentCategory' => array(
  5703. 'id' => 2,
  5704. 'parent_id' => 1,
  5705. 'name' => 'Category 1.1',
  5706. 'created' => '2007-03-18 15:30:23',
  5707. 'updated' => '2007-03-18 15:32:31',
  5708. 'ParentCategory' => array(
  5709. 'id' => 1,
  5710. 'parent_id' => 0,
  5711. 'name' => 'Category 1',
  5712. 'created' => '2007-03-18 15:30:23',
  5713. 'updated' => '2007-03-18 15:32:31',
  5714. 'ParentCategory' => array()
  5715. )))),
  5716. array(
  5717. 'CategoryThread' => array(
  5718. 'id' => 5,
  5719. 'parent_id' => 4,
  5720. 'name' => 'Category 1.1.1.1',
  5721. 'created' => '2007-03-18 15:30:23',
  5722. 'updated' => '2007-03-18 15:32:31'
  5723. ),
  5724. 'ParentCategory' => array(
  5725. 'id' => 4,
  5726. 'parent_id' => 3,
  5727. 'name' => 'Category 1.1.2',
  5728. 'created' => '2007-03-18 15:30:23',
  5729. 'updated' => '2007-03-18 15:32:31',
  5730. 'ParentCategory' => array(
  5731. 'id' => 3,
  5732. 'parent_id' => 2,
  5733. 'name' => 'Category 1.1.1',
  5734. 'created' => '2007-03-18 15:30:23',
  5735. 'updated' => '2007-03-18 15:32:31',
  5736. 'ParentCategory' => array(
  5737. 'id' => 2,
  5738. 'parent_id' => 1,
  5739. 'name' => 'Category 1.1',
  5740. 'created' => '2007-03-18 15:30:23',
  5741. 'updated' => '2007-03-18 15:32:31',
  5742. 'ParentCategory' => array(
  5743. 'id' => 1,
  5744. 'parent_id' => 0,
  5745. 'name' => 'Category 1',
  5746. 'created' => '2007-03-18 15:30:23',
  5747. 'updated' => '2007-03-18 15:32:31',
  5748. 'ParentCategory' => array()
  5749. ))))),
  5750. array(
  5751. 'CategoryThread' => array(
  5752. 'id' => 6,
  5753. 'parent_id' => 5,
  5754. 'name' => 'Category 2',
  5755. 'created' => '2007-03-18 15:30:23',
  5756. 'updated' => '2007-03-18 15:32:31'
  5757. ),
  5758. 'ParentCategory' => array(
  5759. 'id' => 5,
  5760. 'parent_id' => 4,
  5761. 'name' => 'Category 1.1.1.1',
  5762. 'created' => '2007-03-18 15:30:23',
  5763. 'updated' => '2007-03-18 15:32:31',
  5764. 'ParentCategory' => array(
  5765. 'id' => 4,
  5766. 'parent_id' => 3,
  5767. 'name' => 'Category 1.1.2',
  5768. 'created' => '2007-03-18 15:30:23',
  5769. 'updated' => '2007-03-18 15:32:31',
  5770. 'ParentCategory' => array(
  5771. 'id' => 3,
  5772. 'parent_id' => 2,
  5773. 'name' => 'Category 1.1.1',
  5774. 'created' => '2007-03-18 15:30:23',
  5775. 'updated' => '2007-03-18 15:32:31',
  5776. 'ParentCategory' => array(
  5777. 'id' => 2,
  5778. 'parent_id' => 1,
  5779. 'name' => 'Category 1.1',
  5780. 'created' => '2007-03-18 15:30:23',
  5781. 'updated' => '2007-03-18 15:32:31',
  5782. 'ParentCategory' => array(
  5783. 'id' => 1,
  5784. 'parent_id' => 0,
  5785. 'name' => 'Category 1',
  5786. 'created' => '2007-03-18 15:30:23',
  5787. 'updated' => '2007-03-18 15:32:31',
  5788. 'ParentCategory' => array()
  5789. )))))),
  5790. array(
  5791. 'CategoryThread' => array(
  5792. 'id' => 7,
  5793. 'parent_id' => 6,
  5794. 'name' => 'Category 2.1',
  5795. 'created' => '2007-03-18 15:30:23',
  5796. 'updated' => '2007-03-18 15:32:31'
  5797. ),
  5798. 'ParentCategory' => array(
  5799. 'id' => 6,
  5800. 'parent_id' => 5,
  5801. 'name' => 'Category 2',
  5802. 'created' => '2007-03-18 15:30:23',
  5803. 'updated' => '2007-03-18 15:32:31',
  5804. 'ParentCategory' => array(
  5805. 'id' => 5,
  5806. 'parent_id' => 4,
  5807. 'name' => 'Category 1.1.1.1',
  5808. 'created' => '2007-03-18 15:30:23',
  5809. 'updated' => '2007-03-18 15:32:31',
  5810. 'ParentCategory' => array(
  5811. 'id' => 4,
  5812. 'parent_id' => 3,
  5813. 'name' => 'Category 1.1.2',
  5814. 'created' => '2007-03-18 15:30:23',
  5815. 'updated' => '2007-03-18 15:32:31',
  5816. 'ParentCategory' => array(
  5817. 'id' => 3,
  5818. 'parent_id' => 2,
  5819. 'name' => 'Category 1.1.1',
  5820. 'created' => '2007-03-18 15:30:23',
  5821. 'updated' => '2007-03-18 15:32:31',
  5822. 'ParentCategory' => array(
  5823. 'id' => 2,
  5824. 'parent_id' => 1,
  5825. 'name' => 'Category 1.1',
  5826. 'created' => '2007-03-18 15:30:23',
  5827. 'updated' => '2007-03-18 15:32:31',
  5828. 'ParentCategory' => array(
  5829. 'id' => 1,
  5830. 'parent_id' => 0,
  5831. 'name' => 'Category 1',
  5832. 'created' => '2007-03-18 15:30:23',
  5833. 'updated' => '2007-03-18 15:32:31'
  5834. ))))))));
  5835. $this->db->fullDebug = $fullDebug;
  5836. $this->assertEquals($expected, $result);
  5837. }
  5838. /**
  5839. * testConditionalNumerics method
  5840. *
  5841. * @return void
  5842. */
  5843. public function testConditionalNumerics() {
  5844. $this->loadFixtures('NumericArticle');
  5845. $NumericArticle = new NumericArticle();
  5846. $data = array('conditions' => array('title' => '12345abcde'));
  5847. $result = $NumericArticle->find('first', $data);
  5848. $this->assertTrue(!empty($result));
  5849. $data = array('conditions' => array('title' => '12345'));
  5850. $result = $NumericArticle->find('first', $data);
  5851. $this->assertTrue(empty($result));
  5852. }
  5853. /**
  5854. * test buildQuery()
  5855. *
  5856. * @return void
  5857. */
  5858. public function testBuildQuery() {
  5859. $this->loadFixtures('User');
  5860. $TestModel = new User();
  5861. $TestModel->cacheQueries = false;
  5862. $expected = array(
  5863. 'conditions' => array(
  5864. 'user' => 'larry'),
  5865. 'fields' => NULL,
  5866. 'joins' => array(),
  5867. 'limit' => NULL,
  5868. 'offset' => NULL,
  5869. 'order' => array(
  5870. 0 => NULL),
  5871. 'page' => 1,
  5872. 'group' => NULL,
  5873. 'callbacks' => true,
  5874. 'returnQuery' => true);
  5875. $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry')));
  5876. $this->assertEquals($expected, $result);
  5877. }
  5878. /**
  5879. * test find('all') method
  5880. *
  5881. * @return void
  5882. */
  5883. public function testFindAll() {
  5884. $this->loadFixtures('User');
  5885. $TestModel = new User();
  5886. $TestModel->cacheQueries = false;
  5887. $result = $TestModel->find('all');
  5888. $expected = array(
  5889. array(
  5890. 'User' => array(
  5891. 'id' => '1',
  5892. 'user' => 'mariano',
  5893. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5894. 'created' => '2007-03-17 01:16:23',
  5895. 'updated' => '2007-03-17 01:18:31'
  5896. )),
  5897. array(
  5898. 'User' => array(
  5899. 'id' => '2',
  5900. 'user' => 'nate',
  5901. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5902. 'created' => '2007-03-17 01:18:23',
  5903. 'updated' => '2007-03-17 01:20:31'
  5904. )),
  5905. array(
  5906. 'User' => array(
  5907. 'id' => '3',
  5908. 'user' => 'larry',
  5909. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5910. 'created' => '2007-03-17 01:20:23',
  5911. 'updated' => '2007-03-17 01:22:31'
  5912. )),
  5913. array(
  5914. 'User' => array(
  5915. 'id' => '4',
  5916. 'user' => 'garrett',
  5917. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5918. 'created' => '2007-03-17 01:22:23',
  5919. 'updated' => '2007-03-17 01:24:31'
  5920. )));
  5921. $this->assertEquals($expected, $result);
  5922. $result = $TestModel->find('all', array('conditions' => 'User.id > 2'));
  5923. $expected = array(
  5924. array(
  5925. 'User' => array(
  5926. 'id' => '3',
  5927. 'user' => 'larry',
  5928. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5929. 'created' => '2007-03-17 01:20:23',
  5930. 'updated' => '2007-03-17 01:22:31'
  5931. )),
  5932. array(
  5933. 'User' => array(
  5934. 'id' => '4',
  5935. 'user' => 'garrett',
  5936. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5937. 'created' => '2007-03-17 01:22:23',
  5938. 'updated' => '2007-03-17 01:24:31'
  5939. )));
  5940. $this->assertEquals($expected, $result);
  5941. $result = $TestModel->find('all', array(
  5942. 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%')
  5943. ));
  5944. $expected = array(
  5945. array(
  5946. 'User' => array(
  5947. 'id' => '3',
  5948. 'user' => 'larry',
  5949. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5950. 'created' => '2007-03-17 01:20:23',
  5951. 'updated' => '2007-03-17 01:22:31'
  5952. )),
  5953. array(
  5954. 'User' => array(
  5955. 'id' => '4',
  5956. 'user' => 'garrett',
  5957. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5958. 'created' => '2007-03-17 01:22:23',
  5959. 'updated' => '2007-03-17 01:24:31'
  5960. )));
  5961. $this->assertEquals($expected, $result);
  5962. $result = $TestModel->find('all', array('conditions' => array('User.id' => '0')));
  5963. $expected = array();
  5964. $this->assertEquals($expected, $result);
  5965. $result = $TestModel->find('all', array(
  5966. 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%')
  5967. )));
  5968. $expected = array(
  5969. array(
  5970. 'User' => array(
  5971. 'id' => '1',
  5972. 'user' => 'mariano',
  5973. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5974. 'created' => '2007-03-17 01:16:23',
  5975. 'updated' => '2007-03-17 01:18:31'
  5976. )),
  5977. array(
  5978. 'User' => array(
  5979. 'id' => '2',
  5980. 'user' => 'nate',
  5981. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5982. 'created' => '2007-03-17 01:18:23',
  5983. 'updated' => '2007-03-17 01:20:31'
  5984. )),
  5985. array(
  5986. 'User' => array(
  5987. 'id' => '3',
  5988. 'user' => 'larry',
  5989. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5990. 'created' => '2007-03-17 01:20:23',
  5991. 'updated' => '2007-03-17 01:22:31'
  5992. )),
  5993. array(
  5994. 'User' => array(
  5995. 'id' => '4',
  5996. 'user' => 'garrett',
  5997. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5998. 'created' => '2007-03-17 01:22:23',
  5999. 'updated' => '2007-03-17 01:24:31'
  6000. )));
  6001. $this->assertEquals($expected, $result);
  6002. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  6003. $expected = array(
  6004. array('User' => array('id' => '1', 'user' => 'mariano')),
  6005. array('User' => array('id' => '2', 'user' => 'nate')),
  6006. array('User' => array('id' => '3', 'user' => 'larry')),
  6007. array('User' => array('id' => '4', 'user' => 'garrett')));
  6008. $this->assertEquals($expected, $result);
  6009. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC'));
  6010. $expected = array(
  6011. array('User' => array('user' => 'garrett')),
  6012. array('User' => array('user' => 'larry')),
  6013. array('User' => array('user' => 'mariano')),
  6014. array('User' => array('user' => 'nate')));
  6015. $this->assertEquals($expected, $result);
  6016. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC'));
  6017. $expected = array(
  6018. array('User' => array('user' => 'nate')),
  6019. array('User' => array('user' => 'mariano')),
  6020. array('User' => array('user' => 'larry')),
  6021. array('User' => array('user' => 'garrett')));
  6022. $this->assertEquals($expected, $result);
  6023. $result = $TestModel->find('all', array('limit' => 3, 'page' => 1));
  6024. $expected = array(
  6025. array(
  6026. 'User' => array(
  6027. 'id' => '1',
  6028. 'user' => 'mariano',
  6029. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6030. 'created' => '2007-03-17 01:16:23',
  6031. 'updated' => '2007-03-17 01:18:31'
  6032. )),
  6033. array(
  6034. 'User' => array(
  6035. 'id' => '2',
  6036. 'user' => 'nate',
  6037. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6038. 'created' => '2007-03-17 01:18:23',
  6039. 'updated' => '2007-03-17 01:20:31'
  6040. )),
  6041. array(
  6042. 'User' => array(
  6043. 'id' => '3',
  6044. 'user' => 'larry',
  6045. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6046. 'created' => '2007-03-17 01:20:23',
  6047. 'updated' => '2007-03-17 01:22:31'
  6048. )));
  6049. $this->assertEquals($expected, $result);
  6050. $ids = array(4 => 1, 5 => 3);
  6051. $result = $TestModel->find('all', array(
  6052. 'conditions' => array('User.id' => $ids),
  6053. 'order' => 'User.id'
  6054. ));
  6055. $expected = array(
  6056. array(
  6057. 'User' => array(
  6058. 'id' => '1',
  6059. 'user' => 'mariano',
  6060. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6061. 'created' => '2007-03-17 01:16:23',
  6062. 'updated' => '2007-03-17 01:18:31'
  6063. )),
  6064. array(
  6065. 'User' => array(
  6066. 'id' => '3',
  6067. 'user' => 'larry',
  6068. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6069. 'created' => '2007-03-17 01:20:23',
  6070. 'updated' => '2007-03-17 01:22:31'
  6071. )));
  6072. $this->assertEquals($expected, $result);
  6073. // These tests are expected to fail on SQL Server since the LIMIT/OFFSET
  6074. // hack can't handle small record counts.
  6075. if (!($this->db instanceof Sqlserver)) {
  6076. $result = $TestModel->find('all', array('limit' => 3, 'page' => 2));
  6077. $expected = array(
  6078. array(
  6079. 'User' => array(
  6080. 'id' => '4',
  6081. 'user' => 'garrett',
  6082. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6083. 'created' => '2007-03-17 01:22:23',
  6084. 'updated' => '2007-03-17 01:24:31'
  6085. )));
  6086. $this->assertEquals($expected, $result);
  6087. $result = $TestModel->find('all', array('limit' => 3, 'page' => 3));
  6088. $expected = array();
  6089. $this->assertEquals($expected, $result);
  6090. }
  6091. }
  6092. /**
  6093. * test find('list') method
  6094. *
  6095. * @return void
  6096. */
  6097. public function testGenerateFindList() {
  6098. $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment');
  6099. $TestModel = new Article();
  6100. $TestModel->displayField = 'title';
  6101. $result = $TestModel->find('list', array(
  6102. 'order' => 'Article.title ASC'
  6103. ));
  6104. $expected = array(
  6105. 1 => 'First Article',
  6106. 2 => 'Second Article',
  6107. 3 => 'Third Article'
  6108. );
  6109. $this->assertEquals($expected, $result);
  6110. $db = ConnectionManager::getDataSource('test');
  6111. if ($db instanceof Mysql) {
  6112. $result = $TestModel->find('list', array(
  6113. 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC')
  6114. ));
  6115. $expected = array(
  6116. 1 => 'First Article',
  6117. 3 => 'Third Article',
  6118. 2 => 'Second Article'
  6119. );
  6120. $this->assertEquals($expected, $result);
  6121. }
  6122. $result = Set::combine(
  6123. $TestModel->find('all', array(
  6124. 'order' => 'Article.title ASC',
  6125. 'fields' => array('id', 'title')
  6126. )),
  6127. '{n}.Article.id', '{n}.Article.title'
  6128. );
  6129. $expected = array(
  6130. 1 => 'First Article',
  6131. 2 => 'Second Article',
  6132. 3 => 'Third Article'
  6133. );
  6134. $this->assertEquals($expected, $result);
  6135. $result = Set::combine(
  6136. $TestModel->find('all', array(
  6137. 'order' => 'Article.title ASC'
  6138. )),
  6139. '{n}.Article.id', '{n}.Article'
  6140. );
  6141. $expected = array(
  6142. 1 => array(
  6143. 'id' => 1,
  6144. 'user_id' => 1,
  6145. 'title' => 'First Article',
  6146. 'body' => 'First Article Body',
  6147. 'published' => 'Y',
  6148. 'created' => '2007-03-18 10:39:23',
  6149. 'updated' => '2007-03-18 10:41:31'
  6150. ),
  6151. 2 => array(
  6152. 'id' => 2,
  6153. 'user_id' => 3,
  6154. 'title' => 'Second Article',
  6155. 'body' => 'Second Article Body',
  6156. 'published' => 'Y',
  6157. 'created' => '2007-03-18 10:41:23',
  6158. 'updated' => '2007-03-18 10:43:31'
  6159. ),
  6160. 3 => array(
  6161. 'id' => 3,
  6162. 'user_id' => 1,
  6163. 'title' => 'Third Article',
  6164. 'body' => 'Third Article Body',
  6165. 'published' => 'Y',
  6166. 'created' => '2007-03-18 10:43:23',
  6167. 'updated' => '2007-03-18 10:45:31'
  6168. ));
  6169. $this->assertEquals($expected, $result);
  6170. $result = Set::combine(
  6171. $TestModel->find('all', array(
  6172. 'order' => 'Article.title ASC'
  6173. )),
  6174. '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
  6175. );
  6176. $expected = array(
  6177. 1 => array(
  6178. 1 => array(
  6179. 'id' => 1,
  6180. 'user_id' => 1,
  6181. 'title' => 'First Article',
  6182. 'body' => 'First Article Body',
  6183. 'published' => 'Y',
  6184. 'created' => '2007-03-18 10:39:23',
  6185. 'updated' => '2007-03-18 10:41:31'
  6186. ),
  6187. 3 => array(
  6188. 'id' => 3,
  6189. 'user_id' => 1,
  6190. 'title' => 'Third Article',
  6191. 'body' => 'Third Article Body',
  6192. 'published' => 'Y',
  6193. 'created' => '2007-03-18 10:43:23',
  6194. 'updated' => '2007-03-18 10:45:31'
  6195. )),
  6196. 3 => array(
  6197. 2 => array(
  6198. 'id' => 2,
  6199. 'user_id' => 3,
  6200. 'title' => 'Second Article',
  6201. 'body' => 'Second Article Body',
  6202. 'published' => 'Y',
  6203. 'created' => '2007-03-18 10:41:23',
  6204. 'updated' => '2007-03-18 10:43:31'
  6205. )));
  6206. $this->assertEquals($expected, $result);
  6207. $result = Set::combine(
  6208. $TestModel->find('all', array(
  6209. 'order' => 'Article.title ASC',
  6210. 'fields' => array('id', 'title', 'user_id')
  6211. )),
  6212. '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
  6213. );
  6214. $expected = array(
  6215. 1 => array(
  6216. 1 => 'First Article',
  6217. 3 => 'Third Article'
  6218. ),
  6219. 3 => array(
  6220. 2 => 'Second Article'
  6221. ));
  6222. $this->assertEquals($expected, $result);
  6223. $TestModel = new Apple();
  6224. $expected = array(
  6225. 1 => 'Red Apple 1',
  6226. 2 => 'Bright Red Apple',
  6227. 3 => 'green blue',
  6228. 4 => 'Test Name',
  6229. 5 => 'Blue Green',
  6230. 6 => 'My new apple',
  6231. 7 => 'Some odd color'
  6232. );
  6233. $this->assertEquals($TestModel->find('list'), $expected);
  6234. $this->assertEquals($TestModel->Parent->find('list'), $expected);
  6235. $TestModel = new Post();
  6236. $result = $TestModel->find('list', array(
  6237. 'fields' => 'Post.title'
  6238. ));
  6239. $expected = array(
  6240. 1 => 'First Post',
  6241. 2 => 'Second Post',
  6242. 3 => 'Third Post'
  6243. );
  6244. $this->assertEquals($expected, $result);
  6245. $result = $TestModel->find('list', array(
  6246. 'fields' => 'title'
  6247. ));
  6248. $expected = array(
  6249. 1 => 'First Post',
  6250. 2 => 'Second Post',
  6251. 3 => 'Third Post'
  6252. );
  6253. $this->assertEquals($expected, $result);
  6254. $result = $TestModel->find('list', array(
  6255. 'fields' => array('title', 'id')
  6256. ));
  6257. $expected = array(
  6258. 'First Post' => '1',
  6259. 'Second Post' => '2',
  6260. 'Third Post' => '3'
  6261. );
  6262. $this->assertEquals($expected, $result);
  6263. $result = $TestModel->find('list', array(
  6264. 'fields' => array('title', 'id', 'created')
  6265. ));
  6266. $expected = array(
  6267. '2007-03-18 10:39:23' => array(
  6268. 'First Post' => '1'
  6269. ),
  6270. '2007-03-18 10:41:23' => array(
  6271. 'Second Post' => '2'
  6272. ),
  6273. '2007-03-18 10:43:23' => array(
  6274. 'Third Post' => '3'
  6275. ),
  6276. );
  6277. $this->assertEquals($expected, $result);
  6278. $result = $TestModel->find('list', array(
  6279. 'fields' => array('Post.body')
  6280. ));
  6281. $expected = array(
  6282. 1 => 'First Post Body',
  6283. 2 => 'Second Post Body',
  6284. 3 => 'Third Post Body'
  6285. );
  6286. $this->assertEquals($expected, $result);
  6287. $result = $TestModel->find('list', array(
  6288. 'fields' => array('Post.title', 'Post.body')
  6289. ));
  6290. $expected = array(
  6291. 'First Post' => 'First Post Body',
  6292. 'Second Post' => 'Second Post Body',
  6293. 'Third Post' => 'Third Post Body'
  6294. );
  6295. $this->assertEquals($expected, $result);
  6296. $result = $TestModel->find('list', array(
  6297. 'fields' => array('Post.id', 'Post.title', 'Author.user'),
  6298. 'recursive' => 1
  6299. ));
  6300. $expected = array(
  6301. 'mariano' => array(
  6302. 1 => 'First Post',
  6303. 3 => 'Third Post'
  6304. ),
  6305. 'larry' => array(
  6306. 2 => 'Second Post'
  6307. ));
  6308. $this->assertEquals($expected, $result);
  6309. $TestModel = new User();
  6310. $result = $TestModel->find('list', array(
  6311. 'fields' => array('User.user', 'User.password')
  6312. ));
  6313. $expected = array(
  6314. 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6315. 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6316. 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6317. 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6318. );
  6319. $this->assertEquals($expected, $result);
  6320. $TestModel = new ModifiedAuthor();
  6321. $result = $TestModel->find('list', array(
  6322. 'fields' => array('Author.id', 'Author.user')
  6323. ));
  6324. $expected = array(
  6325. 1 => 'mariano (CakePHP)',
  6326. 2 => 'nate (CakePHP)',
  6327. 3 => 'larry (CakePHP)',
  6328. 4 => 'garrett (CakePHP)'
  6329. );
  6330. $this->assertEquals($expected, $result);
  6331. $TestModel = new Article();
  6332. $TestModel->displayField = 'title';
  6333. $result = $TestModel->find('list', array(
  6334. 'conditions' => array('User.user' => 'mariano'),
  6335. 'recursive' => 0
  6336. ));
  6337. $expected = array(
  6338. 1 => 'First Article',
  6339. 3 => 'Third Article'
  6340. );
  6341. $this->assertEquals($expected, $result);
  6342. }
  6343. /**
  6344. * testFindField method
  6345. *
  6346. * @return void
  6347. */
  6348. public function testFindField() {
  6349. $this->loadFixtures('User');
  6350. $TestModel = new User();
  6351. $TestModel->id = 1;
  6352. $result = $TestModel->field('user');
  6353. $this->assertEquals($result, 'mariano');
  6354. $result = $TestModel->field('User.user');
  6355. $this->assertEquals($result, 'mariano');
  6356. $TestModel->id = false;
  6357. $result = $TestModel->field('user', array(
  6358. 'user' => 'mariano'
  6359. ));
  6360. $this->assertEquals($result, 'mariano');
  6361. $result = $TestModel->field('COUNT(*) AS count', true);
  6362. $this->assertEquals($result, 4);
  6363. $result = $TestModel->field('COUNT(*)', true);
  6364. $this->assertEquals($result, 4);
  6365. }
  6366. /**
  6367. * testFindUnique method
  6368. *
  6369. * @return void
  6370. */
  6371. public function testFindUnique() {
  6372. $this->loadFixtures('User');
  6373. $TestModel = new User();
  6374. $this->assertFalse($TestModel->isUnique(array(
  6375. 'user' => 'nate'
  6376. )));
  6377. $TestModel->id = 2;
  6378. $this->assertTrue($TestModel->isUnique(array(
  6379. 'user' => 'nate'
  6380. )));
  6381. $this->assertFalse($TestModel->isUnique(array(
  6382. 'user' => 'nate',
  6383. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6384. )));
  6385. }
  6386. /**
  6387. * test find('count') method
  6388. *
  6389. * @return void
  6390. */
  6391. public function testFindCount() {
  6392. $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag');
  6393. $TestModel = new User();
  6394. $this->db->getLog(false, true);
  6395. $result = $TestModel->find('count');
  6396. $this->assertEquals($result, 4);
  6397. $this->db->getLog(false, true);
  6398. $fullDebug = $this->db->fullDebug;
  6399. $this->db->fullDebug = true;
  6400. $TestModel->order = 'User.id';
  6401. $result = $TestModel->find('count');
  6402. $this->assertEquals($result, 4);
  6403. $log = $this->db->getLog();
  6404. $this->assertTrue(isset($log['log'][0]['query']));
  6405. $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']);
  6406. $Article = new Article();
  6407. $Article->recursive = -1;
  6408. $expected = count($Article->find('all', array(
  6409. 'fields' => array('Article.user_id'),
  6410. 'group' => 'Article.user_id')
  6411. ));
  6412. $result = $Article->find('count', array('group' => array('Article.user_id')));
  6413. $this->assertEquals($expected, $result);
  6414. }
  6415. /**
  6416. * Test that find('first') does not use the id set to the object.
  6417. *
  6418. * @return void
  6419. */
  6420. public function testFindFirstNoIdUsed() {
  6421. $this->loadFixtures('Project');
  6422. $Project = new Project();
  6423. $Project->id = 3;
  6424. $result = $Project->find('first');
  6425. $this->assertEquals($result['Project']['name'], 'Project 1', 'Wrong record retrieved');
  6426. }
  6427. /**
  6428. * test find with COUNT(DISTINCT field)
  6429. *
  6430. * @return void
  6431. */
  6432. public function testFindCountDistinct() {
  6433. $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
  6434. $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
  6435. $this->loadFixtures('Project');
  6436. $TestModel = new Project();
  6437. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6438. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6439. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6440. $result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
  6441. $this->assertEquals($result, 4);
  6442. }
  6443. /**
  6444. * Test find(count) with Db::expression
  6445. *
  6446. * @return void
  6447. */
  6448. public function testFindCountWithDbExpressions() {
  6449. $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');
  6450. $this->loadFixtures('Project', 'Thread');
  6451. $db = ConnectionManager::getDataSource('test');
  6452. $TestModel = new Project();
  6453. $result = $TestModel->find('count', array('conditions' => array(
  6454. $db->expression('Project.name = \'Project 3\'')
  6455. )));
  6456. $this->assertEquals($result, 1);
  6457. $result = $TestModel->find('count', array('conditions' => array(
  6458. 'Project.name' => $db->expression('\'Project 3\'')
  6459. )));
  6460. $this->assertEquals($result, 1);
  6461. }
  6462. /**
  6463. * testFindMagic method
  6464. *
  6465. * @return void
  6466. */
  6467. public function testFindMagic() {
  6468. $this->loadFixtures('User');
  6469. $TestModel = new User();
  6470. $result = $TestModel->findByUser('mariano');
  6471. $expected = array(
  6472. 'User' => array(
  6473. 'id' => '1',
  6474. 'user' => 'mariano',
  6475. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6476. 'created' => '2007-03-17 01:16:23',
  6477. 'updated' => '2007-03-17 01:18:31'
  6478. ));
  6479. $this->assertEquals($expected, $result);
  6480. $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99');
  6481. $expected = array('User' => array(
  6482. 'id' => '1',
  6483. 'user' => 'mariano',
  6484. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6485. 'created' => '2007-03-17 01:16:23',
  6486. 'updated' => '2007-03-17 01:18:31'
  6487. ));
  6488. $this->assertEquals($expected, $result);
  6489. }
  6490. /**
  6491. * testRead method
  6492. *
  6493. * @return void
  6494. */
  6495. public function testRead() {
  6496. $this->loadFixtures('User', 'Article');
  6497. $TestModel = new User();
  6498. $result = $TestModel->read();
  6499. $this->assertFalse($result);
  6500. $TestModel->id = 2;
  6501. $result = $TestModel->read();
  6502. $expected = array(
  6503. 'User' => array(
  6504. 'id' => '2',
  6505. 'user' => 'nate',
  6506. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6507. 'created' => '2007-03-17 01:18:23',
  6508. 'updated' => '2007-03-17 01:20:31'
  6509. ));
  6510. $this->assertEquals($expected, $result);
  6511. $result = $TestModel->read(null, 2);
  6512. $expected = array(
  6513. 'User' => array(
  6514. 'id' => '2',
  6515. 'user' => 'nate',
  6516. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6517. 'created' => '2007-03-17 01:18:23',
  6518. 'updated' => '2007-03-17 01:20:31'
  6519. ));
  6520. $this->assertEquals($expected, $result);
  6521. $TestModel->id = 2;
  6522. $result = $TestModel->read(array('id', 'user'));
  6523. $expected = array('User' => array('id' => '2', 'user' => 'nate'));
  6524. $this->assertEquals($expected, $result);
  6525. $result = $TestModel->read('id, user', 2);
  6526. $expected = array(
  6527. 'User' => array(
  6528. 'id' => '2',
  6529. 'user' => 'nate'
  6530. ));
  6531. $this->assertEquals($expected, $result);
  6532. $result = $TestModel->bindModel(array('hasMany' => array('Article')));
  6533. $this->assertTrue($result);
  6534. $TestModel->id = 1;
  6535. $result = $TestModel->read('id, user');
  6536. $expected = array(
  6537. 'User' => array(
  6538. 'id' => '1',
  6539. 'user' => 'mariano'
  6540. ),
  6541. 'Article' => array(
  6542. array(
  6543. 'id' => '1',
  6544. 'user_id' => '1',
  6545. 'title' => 'First Article',
  6546. 'body' => 'First Article Body',
  6547. 'published' => 'Y',
  6548. 'created' => '2007-03-18 10:39:23',
  6549. 'updated' => '2007-03-18 10:41:31'
  6550. ),
  6551. array(
  6552. 'id' => '3',
  6553. 'user_id' => '1',
  6554. 'title' => 'Third Article',
  6555. 'body' => 'Third Article Body',
  6556. 'published' => 'Y',
  6557. 'created' => '2007-03-18 10:43:23',
  6558. 'updated' => '2007-03-18 10:45:31'
  6559. )));
  6560. $this->assertEquals($expected, $result);
  6561. }
  6562. /**
  6563. * testRecursiveRead method
  6564. *
  6565. * @return void
  6566. */
  6567. public function testRecursiveRead() {
  6568. $this->loadFixtures(
  6569. 'User',
  6570. 'Article',
  6571. 'Comment',
  6572. 'Tag',
  6573. 'ArticlesTag',
  6574. 'Featured',
  6575. 'ArticleFeatured'
  6576. );
  6577. $TestModel = new User();
  6578. $result = $TestModel->bindModel(array('hasMany' => array('Article')), false);
  6579. $this->assertTrue($result);
  6580. $TestModel->recursive = 0;
  6581. $result = $TestModel->read('id, user', 1);
  6582. $expected = array(
  6583. 'User' => array('id' => '1', 'user' => 'mariano'),
  6584. );
  6585. $this->assertEquals($expected, $result);
  6586. $TestModel->recursive = 1;
  6587. $result = $TestModel->read('id, user', 1);
  6588. $expected = array(
  6589. 'User' => array(
  6590. 'id' => '1',
  6591. 'user' => 'mariano'
  6592. ),
  6593. 'Article' => array(
  6594. array(
  6595. 'id' => '1',
  6596. 'user_id' => '1',
  6597. 'title' => 'First Article',
  6598. 'body' => 'First Article Body',
  6599. 'published' => 'Y',
  6600. 'created' => '2007-03-18 10:39:23',
  6601. 'updated' => '2007-03-18 10:41:31'
  6602. ),
  6603. array(
  6604. 'id' => '3',
  6605. 'user_id' => '1',
  6606. 'title' => 'Third Article',
  6607. 'body' => 'Third Article Body',
  6608. 'published' => 'Y',
  6609. 'created' => '2007-03-18 10:43:23',
  6610. 'updated' => '2007-03-18 10:45:31'
  6611. )));
  6612. $this->assertEquals($expected, $result);
  6613. $TestModel->recursive = 2;
  6614. $result = $TestModel->read('id, user', 3);
  6615. $expected = array(
  6616. 'User' => array(
  6617. 'id' => '3',
  6618. 'user' => 'larry'
  6619. ),
  6620. 'Article' => array(
  6621. array(
  6622. 'id' => '2',
  6623. 'user_id' => '3',
  6624. 'title' => 'Second Article',
  6625. 'body' => 'Second Article Body',
  6626. 'published' => 'Y',
  6627. 'created' => '2007-03-18 10:41:23',
  6628. 'updated' => '2007-03-18 10:43:31',
  6629. 'User' => array(
  6630. 'id' => '3',
  6631. 'user' => 'larry',
  6632. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6633. 'created' => '2007-03-17 01:20:23',
  6634. 'updated' => '2007-03-17 01:22:31'
  6635. ),
  6636. 'Comment' => array(
  6637. array(
  6638. 'id' => '5',
  6639. 'article_id' => '2',
  6640. 'user_id' => '1',
  6641. 'comment' => 'First Comment for Second Article',
  6642. 'published' => 'Y',
  6643. 'created' => '2007-03-18 10:53:23',
  6644. 'updated' => '2007-03-18 10:55:31'
  6645. ),
  6646. array(
  6647. 'id' => '6',
  6648. 'article_id' => '2',
  6649. 'user_id' => '2',
  6650. 'comment' => 'Second Comment for Second Article',
  6651. 'published' => 'Y',
  6652. 'created' => '2007-03-18 10:55:23',
  6653. 'updated' => '2007-03-18 10:57:31'
  6654. )),
  6655. 'Tag' => array(
  6656. array(
  6657. 'id' => '1',
  6658. 'tag' => 'tag1',
  6659. 'created' => '2007-03-18 12:22:23',
  6660. 'updated' => '2007-03-18 12:24:31'
  6661. ),
  6662. array(
  6663. 'id' => '3',
  6664. 'tag' => 'tag3',
  6665. 'created' => '2007-03-18 12:26:23',
  6666. 'updated' => '2007-03-18 12:28:31'
  6667. )))));
  6668. $this->assertEquals($expected, $result);
  6669. }
  6670. public function testRecursiveFindAll() {
  6671. $this->loadFixtures(
  6672. 'User',
  6673. 'Article',
  6674. 'Comment',
  6675. 'Tag',
  6676. 'ArticlesTag',
  6677. 'Attachment',
  6678. 'ArticleFeatured',
  6679. 'ArticleFeaturedsTags',
  6680. 'Featured',
  6681. 'Category'
  6682. );
  6683. $TestModel = new Article();
  6684. $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1)));
  6685. $expected = array(
  6686. array(
  6687. 'Article' => array(
  6688. 'id' => '1',
  6689. 'user_id' => '1',
  6690. 'title' => 'First Article',
  6691. 'body' => 'First Article Body',
  6692. 'published' => 'Y',
  6693. 'created' => '2007-03-18 10:39:23',
  6694. 'updated' => '2007-03-18 10:41:31'
  6695. ),
  6696. 'User' => array(
  6697. 'id' => '1',
  6698. 'user' => 'mariano',
  6699. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6700. 'created' => '2007-03-17 01:16:23',
  6701. 'updated' => '2007-03-17 01:18:31'
  6702. ),
  6703. 'Comment' => array(
  6704. array(
  6705. 'id' => '1',
  6706. 'article_id' => '1',
  6707. 'user_id' => '2',
  6708. 'comment' => 'First Comment for First Article',
  6709. 'published' => 'Y',
  6710. 'created' => '2007-03-18 10:45:23',
  6711. 'updated' => '2007-03-18 10:47:31'
  6712. ),
  6713. array(
  6714. 'id' => '2',
  6715. 'article_id' => '1',
  6716. 'user_id' => '4',
  6717. 'comment' => 'Second Comment for First Article',
  6718. 'published' => 'Y',
  6719. 'created' => '2007-03-18 10:47:23',
  6720. 'updated' => '2007-03-18 10:49:31'
  6721. ),
  6722. array(
  6723. 'id' => '3',
  6724. 'article_id' => '1',
  6725. 'user_id' => '1',
  6726. 'comment' => 'Third Comment for First Article',
  6727. 'published' => 'Y',
  6728. 'created' => '2007-03-18 10:49:23',
  6729. 'updated' => '2007-03-18 10:51:31'
  6730. ),
  6731. array(
  6732. 'id' => '4',
  6733. 'article_id' => '1',
  6734. 'user_id' => '1',
  6735. 'comment' => 'Fourth Comment for First Article',
  6736. 'published' => 'N',
  6737. 'created' => '2007-03-18 10:51:23',
  6738. 'updated' => '2007-03-18 10:53:31'
  6739. )
  6740. ),
  6741. 'Tag' => array(
  6742. array(
  6743. 'id' => '1',
  6744. 'tag' => 'tag1',
  6745. 'created' => '2007-03-18 12:22:23',
  6746. 'updated' => '2007-03-18 12:24:31'
  6747. ),
  6748. array(
  6749. 'id' => '2',
  6750. 'tag' => 'tag2',
  6751. 'created' => '2007-03-18 12:24:23',
  6752. 'updated' => '2007-03-18 12:26:31'
  6753. ))),
  6754. array(
  6755. 'Article' => array(
  6756. 'id' => '3',
  6757. 'user_id' => '1',
  6758. 'title' => 'Third Article',
  6759. 'body' => 'Third Article Body',
  6760. 'published' => 'Y',
  6761. 'created' => '2007-03-18 10:43:23',
  6762. 'updated' => '2007-03-18 10:45:31'
  6763. ),
  6764. 'User' => array(
  6765. 'id' => '1',
  6766. 'user' => 'mariano',
  6767. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6768. 'created' => '2007-03-17 01:16:23',
  6769. 'updated' => '2007-03-17 01:18:31'
  6770. ),
  6771. 'Comment' => array(),
  6772. 'Tag' => array()
  6773. )
  6774. );
  6775. $this->assertEquals($expected, $result);
  6776. $result = $TestModel->find('all', array(
  6777. 'conditions' => array('Article.user_id' => 3),
  6778. 'limit' => 1,
  6779. 'recursive' => 2
  6780. ));
  6781. $expected = array(
  6782. array(
  6783. 'Article' => array(
  6784. 'id' => '2',
  6785. 'user_id' => '3',
  6786. 'title' => 'Second Article',
  6787. 'body' => 'Second Article Body',
  6788. 'published' => 'Y',
  6789. 'created' => '2007-03-18 10:41:23',
  6790. 'updated' => '2007-03-18 10:43:31'
  6791. ),
  6792. 'User' => array(
  6793. 'id' => '3',
  6794. 'user' => 'larry',
  6795. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6796. 'created' => '2007-03-17 01:20:23',
  6797. 'updated' => '2007-03-17 01:22:31'
  6798. ),
  6799. 'Comment' => array(
  6800. array(
  6801. 'id' => '5',
  6802. 'article_id' => '2',
  6803. 'user_id' => '1',
  6804. 'comment' => 'First Comment for Second Article',
  6805. 'published' => 'Y',
  6806. 'created' => '2007-03-18 10:53:23',
  6807. 'updated' => '2007-03-18 10:55:31',
  6808. 'Article' => array(
  6809. 'id' => '2',
  6810. 'user_id' => '3',
  6811. 'title' => 'Second Article',
  6812. 'body' => 'Second Article Body',
  6813. 'published' => 'Y',
  6814. 'created' => '2007-03-18 10:41:23',
  6815. 'updated' => '2007-03-18 10:43:31'
  6816. ),
  6817. 'User' => array(
  6818. 'id' => '1',
  6819. 'user' => 'mariano',
  6820. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6821. 'created' => '2007-03-17 01:16:23',
  6822. 'updated' => '2007-03-17 01:18:31'
  6823. ),
  6824. 'Attachment' => array(
  6825. 'id' => '1',
  6826. 'comment_id' => 5,
  6827. 'attachment' => 'attachment.zip',
  6828. 'created' => '2007-03-18 10:51:23',
  6829. 'updated' => '2007-03-18 10:53:31'
  6830. )
  6831. ),
  6832. array(
  6833. 'id' => '6',
  6834. 'article_id' => '2',
  6835. 'user_id' => '2',
  6836. 'comment' => 'Second Comment for Second Article',
  6837. 'published' => 'Y',
  6838. 'created' => '2007-03-18 10:55:23',
  6839. 'updated' => '2007-03-18 10:57:31',
  6840. 'Article' => array(
  6841. 'id' => '2',
  6842. 'user_id' => '3',
  6843. 'title' => 'Second Article',
  6844. 'body' => 'Second Article Body',
  6845. 'published' => 'Y',
  6846. 'created' => '2007-03-18 10:41:23',
  6847. 'updated' => '2007-03-18 10:43:31'
  6848. ),
  6849. 'User' => array(
  6850. 'id' => '2',
  6851. 'user' => 'nate',
  6852. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6853. 'created' => '2007-03-17 01:18:23',
  6854. 'updated' => '2007-03-17 01:20:31'
  6855. ),
  6856. 'Attachment' => array()
  6857. )
  6858. ),
  6859. 'Tag' => array(
  6860. array(
  6861. 'id' => '1',
  6862. 'tag' => 'tag1',
  6863. 'created' => '2007-03-18 12:22:23',
  6864. 'updated' => '2007-03-18 12:24:31'
  6865. ),
  6866. array(
  6867. 'id' => '3',
  6868. 'tag' => 'tag3',
  6869. 'created' => '2007-03-18 12:26:23',
  6870. 'updated' => '2007-03-18 12:28:31'
  6871. ))));
  6872. $this->assertEquals($expected, $result);
  6873. $Featured = new Featured();
  6874. $Featured->recursive = 2;
  6875. $Featured->bindModel(array(
  6876. 'belongsTo' => array(
  6877. 'ArticleFeatured' => array(
  6878. 'conditions' => "ArticleFeatured.published = 'Y'",
  6879. 'fields' => 'id, title, user_id, published'
  6880. )
  6881. )
  6882. ));
  6883. $Featured->ArticleFeatured->unbindModel(array(
  6884. 'hasMany' => array('Attachment', 'Comment'),
  6885. 'hasAndBelongsToMany' => array('Tag'))
  6886. );
  6887. $orderBy = 'ArticleFeatured.id ASC';
  6888. $result = $Featured->find('all', array(
  6889. 'order' => $orderBy, 'limit' => 3
  6890. ));
  6891. $expected = array(
  6892. array(
  6893. 'Featured' => array(
  6894. 'id' => '1',
  6895. 'article_featured_id' => '1',
  6896. 'category_id' => '1',
  6897. 'published_date' => '2007-03-31 10:39:23',
  6898. 'end_date' => '2007-05-15 10:39:23',
  6899. 'created' => '2007-03-18 10:39:23',
  6900. 'updated' => '2007-03-18 10:41:31'
  6901. ),
  6902. 'ArticleFeatured' => array(
  6903. 'id' => '1',
  6904. 'title' => 'First Article',
  6905. 'user_id' => '1',
  6906. 'published' => 'Y',
  6907. 'User' => array(
  6908. 'id' => '1',
  6909. 'user' => 'mariano',
  6910. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6911. 'created' => '2007-03-17 01:16:23',
  6912. 'updated' => '2007-03-17 01:18:31'
  6913. ),
  6914. 'Category' => array(),
  6915. 'Featured' => array(
  6916. 'id' => '1',
  6917. 'article_featured_id' => '1',
  6918. 'category_id' => '1',
  6919. 'published_date' => '2007-03-31 10:39:23',
  6920. 'end_date' => '2007-05-15 10:39:23',
  6921. 'created' => '2007-03-18 10:39:23',
  6922. 'updated' => '2007-03-18 10:41:31'
  6923. )),
  6924. 'Category' => array(
  6925. 'id' => '1',
  6926. 'parent_id' => '0',
  6927. 'name' => 'Category 1',
  6928. 'created' => '2007-03-18 15:30:23',
  6929. 'updated' => '2007-03-18 15:32:31'
  6930. )),
  6931. array(
  6932. 'Featured' => array(
  6933. 'id' => '2',
  6934. 'article_featured_id' => '2',
  6935. 'category_id' => '1',
  6936. 'published_date' => '2007-03-31 10:39:23',
  6937. 'end_date' => '2007-05-15 10:39:23',
  6938. 'created' => '2007-03-18 10:39:23',
  6939. 'updated' => '2007-03-18 10:41:31'
  6940. ),
  6941. 'ArticleFeatured' => array(
  6942. 'id' => '2',
  6943. 'title' => 'Second Article',
  6944. 'user_id' => '3',
  6945. 'published' => 'Y',
  6946. 'User' => array(
  6947. 'id' => '3',
  6948. 'user' => 'larry',
  6949. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6950. 'created' => '2007-03-17 01:20:23',
  6951. 'updated' => '2007-03-17 01:22:31'
  6952. ),
  6953. 'Category' => array(),
  6954. 'Featured' => array(
  6955. 'id' => '2',
  6956. 'article_featured_id' => '2',
  6957. 'category_id' => '1',
  6958. 'published_date' => '2007-03-31 10:39:23',
  6959. 'end_date' => '2007-05-15 10:39:23',
  6960. 'created' => '2007-03-18 10:39:23',
  6961. 'updated' => '2007-03-18 10:41:31'
  6962. )),
  6963. 'Category' => array(
  6964. 'id' => '1',
  6965. 'parent_id' => '0',
  6966. 'name' => 'Category 1',
  6967. 'created' => '2007-03-18 15:30:23',
  6968. 'updated' => '2007-03-18 15:32:31'
  6969. )));
  6970. $this->assertEquals($expected, $result);
  6971. }
  6972. /**
  6973. * testRecursiveFindAllWithLimit method
  6974. *
  6975. * @return void
  6976. */
  6977. public function testRecursiveFindAllWithLimit() {
  6978. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
  6979. $TestModel = new Article();
  6980. $TestModel->hasMany['Comment']['limit'] = 2;
  6981. $result = $TestModel->find('all', array(
  6982. 'conditions' => array('Article.user_id' => 1)
  6983. ));
  6984. $expected = array(
  6985. array(
  6986. 'Article' => array(
  6987. 'id' => '1',
  6988. 'user_id' => '1',
  6989. 'title' => 'First Article',
  6990. 'body' => 'First Article Body',
  6991. 'published' => 'Y',
  6992. 'created' => '2007-03-18 10:39:23',
  6993. 'updated' => '2007-03-18 10:41:31'
  6994. ),
  6995. 'User' => array(
  6996. 'id' => '1',
  6997. 'user' => 'mariano',
  6998. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6999. 'created' => '2007-03-17 01:16:23',
  7000. 'updated' => '2007-03-17 01:18:31'
  7001. ),
  7002. 'Comment' => array(
  7003. array(
  7004. 'id' => '1',
  7005. 'article_id' => '1',
  7006. 'user_id' => '2',
  7007. 'comment' => 'First Comment for First Article',
  7008. 'published' => 'Y',
  7009. 'created' => '2007-03-18 10:45:23',
  7010. 'updated' => '2007-03-18 10:47:31'
  7011. ),
  7012. array(
  7013. 'id' => '2',
  7014. 'article_id' => '1',
  7015. 'user_id' => '4',
  7016. 'comment' => 'Second Comment for First Article',
  7017. 'published' => 'Y',
  7018. 'created' => '2007-03-18 10:47:23',
  7019. 'updated' => '2007-03-18 10:49:31'
  7020. ),
  7021. ),
  7022. 'Tag' => array(
  7023. array(
  7024. 'id' => '1',
  7025. 'tag' => 'tag1',
  7026. 'created' => '2007-03-18 12:22:23',
  7027. 'updated' => '2007-03-18 12:24:31'
  7028. ),
  7029. array(
  7030. 'id' => '2',
  7031. 'tag' => 'tag2',
  7032. 'created' => '2007-03-18 12:24:23',
  7033. 'updated' => '2007-03-18 12:26:31'
  7034. ))),
  7035. array(
  7036. 'Article' => array(
  7037. 'id' => '3',
  7038. 'user_id' => '1',
  7039. 'title' => 'Third Article',
  7040. 'body' => 'Third Article Body',
  7041. 'published' => 'Y',
  7042. 'created' => '2007-03-18 10:43:23',
  7043. 'updated' => '2007-03-18 10:45:31'
  7044. ),
  7045. 'User' => array(
  7046. 'id' => '1',
  7047. 'user' => 'mariano',
  7048. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7049. 'created' => '2007-03-17 01:16:23',
  7050. 'updated' => '2007-03-17 01:18:31'
  7051. ),
  7052. 'Comment' => array(),
  7053. 'Tag' => array()
  7054. )
  7055. );
  7056. $this->assertEquals($expected, $result);
  7057. $TestModel->hasMany['Comment']['limit'] = 1;
  7058. $result = $TestModel->find('all', array(
  7059. 'conditions' => array('Article.user_id' => 3),
  7060. 'limit' => 1,
  7061. 'recursive' => 2
  7062. ));
  7063. $expected = array(
  7064. array(
  7065. 'Article' => array(
  7066. 'id' => '2',
  7067. 'user_id' => '3',
  7068. 'title' => 'Second Article',
  7069. 'body' => 'Second Article Body',
  7070. 'published' => 'Y',
  7071. 'created' => '2007-03-18 10:41:23',
  7072. 'updated' => '2007-03-18 10:43:31'
  7073. ),
  7074. 'User' => array(
  7075. 'id' => '3',
  7076. 'user' => 'larry',
  7077. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7078. 'created' => '2007-03-17 01:20:23',
  7079. 'updated' => '2007-03-17 01:22:31'
  7080. ),
  7081. 'Comment' => array(
  7082. array(
  7083. 'id' => '5',
  7084. 'article_id' => '2',
  7085. 'user_id' => '1',
  7086. 'comment' => 'First Comment for Second Article',
  7087. 'published' => 'Y',
  7088. 'created' => '2007-03-18 10:53:23',
  7089. 'updated' => '2007-03-18 10:55:31',
  7090. 'Article' => array(
  7091. 'id' => '2',
  7092. 'user_id' => '3',
  7093. 'title' => 'Second Article',
  7094. 'body' => 'Second Article Body',
  7095. 'published' => 'Y',
  7096. 'created' => '2007-03-18 10:41:23',
  7097. 'updated' => '2007-03-18 10:43:31'
  7098. ),
  7099. 'User' => array(
  7100. 'id' => '1',
  7101. 'user' => 'mariano',
  7102. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7103. 'created' => '2007-03-17 01:16:23',
  7104. 'updated' => '2007-03-17 01:18:31'
  7105. ),
  7106. 'Attachment' => array(
  7107. 'id' => '1',
  7108. 'comment_id' => 5,
  7109. 'attachment' => 'attachment.zip',
  7110. 'created' => '2007-03-18 10:51:23',
  7111. 'updated' => '2007-03-18 10:53:31'
  7112. )
  7113. )
  7114. ),
  7115. 'Tag' => array(
  7116. array(
  7117. 'id' => '1',
  7118. 'tag' => 'tag1',
  7119. 'created' => '2007-03-18 12:22:23',
  7120. 'updated' => '2007-03-18 12:24:31'
  7121. ),
  7122. array(
  7123. 'id' => '3',
  7124. 'tag' => 'tag3',
  7125. 'created' => '2007-03-18 12:26:23',
  7126. 'updated' => '2007-03-18 12:28:31'
  7127. )
  7128. )
  7129. )
  7130. );
  7131. $this->assertEquals($expected, $result);
  7132. }
  7133. /**
  7134. * Testing availability of $this->findQueryType in Model callbacks
  7135. *
  7136. * @return void
  7137. */
  7138. public function testFindQueryTypeInCallbacks() {
  7139. $this->loadFixtures('Comment');
  7140. $Comment = new AgainModifiedComment();
  7141. $comments = $Comment->find('all');
  7142. $this->assertEquals($comments[0]['Comment']['querytype'], 'all');
  7143. $comments = $Comment->find('first');
  7144. $this->assertEquals($comments['Comment']['querytype'], 'first');
  7145. }
  7146. /**
  7147. * testVirtualFields()
  7148. *
  7149. * Test correct fetching of virtual fields
  7150. * currently is not possible to do Relation.virtualField
  7151. *
  7152. * @return void
  7153. */
  7154. public function testVirtualFields() {
  7155. $this->loadFixtures('Post', 'Author');
  7156. $Post = ClassRegistry::init('Post');
  7157. $Post->virtualFields = array('two' => "1 + 1");
  7158. $result = $Post->find('first');
  7159. $this->assertEquals($result['Post']['two'], 2);
  7160. // SQL Server does not support operators in expressions
  7161. if (!($this->db instanceof Sqlserver)) {
  7162. $Post->Author->virtualFields = array('false' => '1 = 2');
  7163. $result = $Post->find('first');
  7164. $this->assertEquals($result['Post']['two'], 2);
  7165. $this->assertFalse((bool)$result['Author']['false']);
  7166. }
  7167. $result = $Post->find('first',array('fields' => array('author_id')));
  7168. $this->assertFalse(isset($result['Post']['two']));
  7169. $this->assertFalse(isset($result['Author']['false']));
  7170. $result = $Post->find('first',array('fields' => array('author_id', 'two')));
  7171. $this->assertEquals($result['Post']['two'], 2);
  7172. $this->assertFalse(isset($result['Author']['false']));
  7173. $result = $Post->find('first',array('fields' => array('two')));
  7174. $this->assertEquals($result['Post']['two'], 2);
  7175. $Post->id = 1;
  7176. $result = $Post->field('two');
  7177. $this->assertEquals($result, 2);
  7178. $result = $Post->find('first',array(
  7179. 'conditions' => array('two' => 2),
  7180. 'limit' => 1
  7181. ));
  7182. $this->assertEquals($result['Post']['two'], 2);
  7183. $result = $Post->find('first',array(
  7184. 'conditions' => array('two <' => 3),
  7185. 'limit' => 1
  7186. ));
  7187. $this->assertEquals($result['Post']['two'], 2);
  7188. $result = $Post->find('first',array(
  7189. 'conditions' => array('NOT' => array('two >' => 3)),
  7190. 'limit' => 1
  7191. ));
  7192. $this->assertEquals($result['Post']['two'], 2);
  7193. $dbo = $Post->getDataSource();
  7194. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7195. $result = $Post->find('first', array(
  7196. 'conditions' => array('other_field' => 3),
  7197. 'limit' => 1
  7198. ));
  7199. $this->assertEquals($result['Post']['id'], 2);
  7200. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7201. $result = $Post->find('all', array(
  7202. 'fields' => array($dbo->calculate($Post, 'max', array('other_field')))
  7203. ));
  7204. $this->assertEquals($result[0][0]['other_field'], 4);
  7205. ClassRegistry::flush();
  7206. $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
  7207. $Writing->virtualFields = array('two' => "1 + 1");
  7208. $result = $Writing->find('first');
  7209. $this->assertEquals($result['Writing']['two'], 2);
  7210. $Post->create();
  7211. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7212. $result = $Post->field('other_field');
  7213. $this->assertEquals($result, 4);
  7214. }
  7215. /**
  7216. * testVirtualFieldsOrder()
  7217. *
  7218. * Test correct order on virtual fields
  7219. *
  7220. * @return void
  7221. */
  7222. public function testVirtualFieldsOrder() {
  7223. $this->loadFixtures('Post', 'Author');
  7224. $Post = ClassRegistry::init('Post');
  7225. $Post->virtualFields = array('other_field' => '10 - Post.id');
  7226. $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC')));
  7227. $expected = array(
  7228. '3' => 'Third Post',
  7229. '2' => 'Second Post',
  7230. '1' => 'First Post'
  7231. );
  7232. $this->assertEquals($expected, $result);
  7233. $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC')));
  7234. $expected = array(
  7235. '1' => 'First Post',
  7236. '2' => 'Second Post',
  7237. '3' => 'Third Post'
  7238. );
  7239. $this->assertEquals($expected, $result);
  7240. $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id');
  7241. $result = $Post->find('all');
  7242. $result = Set::extract('{n}.Author.joined', $result);
  7243. $expected = array(1, 6, 3);
  7244. $this->assertEquals($expected, $result);
  7245. $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC')));
  7246. $result = Set::extract('{n}.Author.joined', $result);
  7247. $expected = array(1, 3, 6);
  7248. $this->assertEquals($expected, $result);
  7249. $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC')));
  7250. $result = Set::extract('{n}.Author.joined', $result);
  7251. $expected = array(6, 3, 1);
  7252. $this->assertEquals($expected, $result);
  7253. }
  7254. /**
  7255. * testVirtualFieldsMysql()
  7256. *
  7257. * Test correct fetching of virtual fields
  7258. * currently is not possible to do Relation.virtualField
  7259. *
  7260. */
  7261. public function testVirtualFieldsMysql() {
  7262. $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFieds test only compatible with Mysql.');
  7263. $this->loadFixtures('Post', 'Author');
  7264. $Post = ClassRegistry::init('Post');
  7265. $Post->create();
  7266. $Post->virtualFields = array(
  7267. 'low_title' => 'lower(Post.title)',
  7268. 'unique_test_field' => 'COUNT(Post.id)'
  7269. );
  7270. $expectation = array(
  7271. 'Post' => array(
  7272. 'low_title' => 'first post',
  7273. 'unique_test_field' => 1
  7274. )
  7275. );
  7276. $result = $Post->find('first', array(
  7277. 'fields' => array_keys($Post->virtualFields),
  7278. 'group' => array('low_title')
  7279. ));
  7280. $this->assertEquals($result, $expectation);
  7281. $Author = ClassRegistry::init('Author');
  7282. $Author->virtualFields = array(
  7283. 'full_name' => 'CONCAT(Author.user, " ", Author.id)'
  7284. );
  7285. $result = $Author->find('first', array(
  7286. 'conditions' => array('Author.user' => 'mariano'),
  7287. 'fields' => array('Author.password', 'Author.full_name'),
  7288. 'recursive' => -1
  7289. ));
  7290. $this->assertTrue(isset($result['Author']['full_name']));
  7291. $result = $Author->find('first', array(
  7292. 'conditions' => array('Author.user' => 'mariano'),
  7293. 'fields' => array('Author.full_name', 'Author.password'),
  7294. 'recursive' => -1
  7295. ));
  7296. $this->assertTrue(isset($result['Author']['full_name']));
  7297. }
  7298. /**
  7299. * test that virtual fields work when they don't contain functions.
  7300. *
  7301. * @return void
  7302. */
  7303. public function testVirtualFieldAsAString() {
  7304. $this->loadFixtures('Post', 'Author');
  7305. $Post = new Post();
  7306. $Post->virtualFields = array(
  7307. 'writer' => 'Author.user'
  7308. );
  7309. $result = $Post->find('first');
  7310. $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
  7311. }
  7312. /**
  7313. * test that isVirtualField will accept both aliased and non aliased fieldnames
  7314. *
  7315. * @return void
  7316. */
  7317. public function testIsVirtualField() {
  7318. $this->loadFixtures('Post');
  7319. $Post = ClassRegistry::init('Post');
  7320. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7321. $this->assertTrue($Post->isVirtualField('other_field'));
  7322. $this->assertTrue($Post->isVirtualField('Post.other_field'));
  7323. $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.');
  7324. $this->assertFalse($Post->isVirtualField('id'));
  7325. $this->assertFalse($Post->isVirtualField('Post.id'));
  7326. $this->assertFalse($Post->isVirtualField(array()));
  7327. }
  7328. /**
  7329. * test that getting virtual fields works with and without model alias attached
  7330. *
  7331. * @return void
  7332. */
  7333. public function testGetVirtualField() {
  7334. $this->loadFixtures('Post');
  7335. $Post = ClassRegistry::init('Post');
  7336. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7337. $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']);
  7338. $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
  7339. }
  7340. }