ModelReadTest.php 203 KB

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