ModelReadTest.php 205 KB

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