ModelReadTest.php 203 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905
  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. * Test find(neighbors) with missing fields so no neighbors are found.
  3634. *
  3635. * @return
  3636. */
  3637. public function testFindNeighborsNoPrev() {
  3638. $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
  3639. $Article = new Article();
  3640. $result = $Article->find('neighbors', array(
  3641. 'field' => 'Article.title',
  3642. 'value' => 'Second Article',
  3643. 'fields' => array('id'),
  3644. 'conditions' => array(
  3645. 'Article.title LIKE' => '%Article%'
  3646. ),
  3647. 'recursive' => 0,
  3648. ));
  3649. $expected = array(
  3650. 'prev' => null,
  3651. 'next' => null
  3652. );
  3653. $this->assertEquals($expected, $result);
  3654. }
  3655. /**
  3656. * testFindCombinedRelations method
  3657. *
  3658. * @return void
  3659. */
  3660. public function testFindCombinedRelations() {
  3661. $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.');
  3662. $this->loadFixtures('Apple', 'Sample');
  3663. $TestModel = new Apple();
  3664. $result = $TestModel->find('all');
  3665. $expected = array(
  3666. array(
  3667. 'Apple' => array(
  3668. 'id' => '1',
  3669. 'apple_id' => '2',
  3670. 'color' => 'Red 1',
  3671. 'name' => 'Red Apple 1',
  3672. 'created' => '2006-11-22 10:38:58',
  3673. 'date' => '1951-01-04',
  3674. 'modified' => '2006-12-01 13:31:26',
  3675. 'mytime' => '22:57:17'
  3676. ),
  3677. 'Parent' => array(
  3678. 'id' => '2',
  3679. 'apple_id' => '1',
  3680. 'color' => 'Bright Red 1',
  3681. 'name' => 'Bright Red Apple',
  3682. 'created' => '2006-11-22 10:43:13',
  3683. 'date' => '2014-01-01',
  3684. 'modified' => '2006-11-30 18:38:10',
  3685. 'mytime' => '22:57:17'
  3686. ),
  3687. 'Sample' => array(
  3688. 'id' => null,
  3689. 'apple_id' => null,
  3690. 'name' => null
  3691. ),
  3692. 'Child' => array(
  3693. array(
  3694. 'id' => '2',
  3695. 'apple_id' => '1',
  3696. 'color' => 'Bright Red 1',
  3697. 'name' => 'Bright Red Apple',
  3698. 'created' => '2006-11-22 10:43:13',
  3699. 'date' => '2014-01-01',
  3700. 'modified' => '2006-11-30 18:38:10',
  3701. 'mytime' => '22:57:17'
  3702. ))),
  3703. array(
  3704. 'Apple' => array(
  3705. 'id' => '2',
  3706. 'apple_id' => '1',
  3707. 'color' => 'Bright Red 1',
  3708. 'name' => 'Bright Red Apple',
  3709. 'created' => '2006-11-22 10:43:13',
  3710. 'date' => '2014-01-01',
  3711. 'modified' => '2006-11-30 18:38:10',
  3712. 'mytime' => '22:57:17'
  3713. ),
  3714. 'Parent' => array(
  3715. 'id' => '1',
  3716. 'apple_id' => '2',
  3717. 'color' => 'Red 1',
  3718. 'name' => 'Red Apple 1',
  3719. 'created' => '2006-11-22 10:38:58',
  3720. 'date' => '1951-01-04',
  3721. 'modified' => '2006-12-01 13:31:26',
  3722. 'mytime' => '22:57:17'
  3723. ),
  3724. 'Sample' => array(
  3725. 'id' => '2',
  3726. 'apple_id' => '2',
  3727. 'name' => 'sample2'
  3728. ),
  3729. 'Child' => array(
  3730. array(
  3731. 'id' => '1',
  3732. 'apple_id' => '2',
  3733. 'color' => 'Red 1',
  3734. 'name' => 'Red Apple 1',
  3735. 'created' => '2006-11-22 10:38:58',
  3736. 'date' => '1951-01-04',
  3737. 'modified' => '2006-12-01 13:31:26',
  3738. 'mytime' => '22:57:17'
  3739. ),
  3740. array(
  3741. 'id' => '3',
  3742. 'apple_id' => '2',
  3743. 'color' => 'blue green',
  3744. 'name' => 'green blue',
  3745. 'created' => '2006-12-25 05:13:36',
  3746. 'date' => '2006-12-25',
  3747. 'modified' => '2006-12-25 05:23:24',
  3748. 'mytime' => '22:57:17'
  3749. ),
  3750. array(
  3751. 'id' => '4',
  3752. 'apple_id' => '2',
  3753. 'color' => 'Blue Green',
  3754. 'name' => 'Test Name',
  3755. 'created' => '2006-12-25 05:23:36',
  3756. 'date' => '2006-12-25',
  3757. 'modified' => '2006-12-25 05:23:36',
  3758. 'mytime' => '22:57:17'
  3759. ))),
  3760. array(
  3761. 'Apple' => array(
  3762. 'id' => '3',
  3763. 'apple_id' => '2',
  3764. 'color' => 'blue green',
  3765. 'name' => 'green blue',
  3766. 'created' => '2006-12-25 05:13:36',
  3767. 'date' => '2006-12-25',
  3768. 'modified' => '2006-12-25 05:23:24',
  3769. 'mytime' => '22:57:17'
  3770. ),
  3771. 'Parent' => array(
  3772. 'id' => '2',
  3773. 'apple_id' => '1',
  3774. 'color' => 'Bright Red 1',
  3775. 'name' => 'Bright Red Apple',
  3776. 'created' => '2006-11-22 10:43:13',
  3777. 'date' => '2014-01-01',
  3778. 'modified' => '2006-11-30 18:38:10',
  3779. 'mytime' => '22:57:17'
  3780. ),
  3781. 'Sample' => array(
  3782. 'id' => '1',
  3783. 'apple_id' => '3',
  3784. 'name' => 'sample1'
  3785. ),
  3786. 'Child' => array()
  3787. ),
  3788. array(
  3789. 'Apple' => array(
  3790. 'id' => '4',
  3791. 'apple_id' => '2',
  3792. 'color' => 'Blue Green',
  3793. 'name' => 'Test Name',
  3794. 'created' => '2006-12-25 05:23:36',
  3795. 'date' => '2006-12-25',
  3796. 'modified' => '2006-12-25 05:23:36',
  3797. 'mytime' => '22:57:17'
  3798. ),
  3799. 'Parent' => array(
  3800. 'id' => '2',
  3801. 'apple_id' => '1',
  3802. 'color' => 'Bright Red 1',
  3803. 'name' => 'Bright Red Apple',
  3804. 'created' => '2006-11-22 10:43:13',
  3805. 'date' => '2014-01-01',
  3806. 'modified' => '2006-11-30 18:38:10',
  3807. 'mytime' => '22:57:17'
  3808. ),
  3809. 'Sample' => array(
  3810. 'id' => '3',
  3811. 'apple_id' => '4',
  3812. 'name' => 'sample3'
  3813. ),
  3814. 'Child' => array(
  3815. array(
  3816. 'id' => '6',
  3817. 'apple_id' => '4',
  3818. 'color' => 'My new appleOrange',
  3819. 'name' => 'My new apple',
  3820. 'created' => '2006-12-25 05:29:39',
  3821. 'date' => '2006-12-25',
  3822. 'modified' => '2006-12-25 05:29:39',
  3823. 'mytime' => '22:57:17'
  3824. ))),
  3825. array(
  3826. 'Apple' => array(
  3827. 'id' => '5',
  3828. 'apple_id' => '5',
  3829. 'color' => 'Green',
  3830. 'name' => 'Blue Green',
  3831. 'created' => '2006-12-25 05:24:06',
  3832. 'date' => '2006-12-25',
  3833. 'modified' => '2006-12-25 05:29:16',
  3834. 'mytime' => '22:57:17'
  3835. ),
  3836. 'Parent' => array(
  3837. 'id' => '5',
  3838. 'apple_id' => '5',
  3839. 'color' => 'Green',
  3840. 'name' => 'Blue Green',
  3841. 'created' => '2006-12-25 05:24:06',
  3842. 'date' => '2006-12-25',
  3843. 'modified' => '2006-12-25 05:29:16',
  3844. 'mytime' => '22:57:17'
  3845. ),
  3846. 'Sample' => array(
  3847. 'id' => '4',
  3848. 'apple_id' => '5',
  3849. 'name' => 'sample4'
  3850. ),
  3851. 'Child' => array(
  3852. array(
  3853. 'id' => '5',
  3854. 'apple_id' => '5',
  3855. 'color' => 'Green',
  3856. 'name' => 'Blue Green',
  3857. 'created' => '2006-12-25 05:24:06',
  3858. 'date' => '2006-12-25',
  3859. 'modified' => '2006-12-25 05:29:16',
  3860. 'mytime' => '22:57:17'
  3861. ))),
  3862. array(
  3863. 'Apple' => array(
  3864. 'id' => '6',
  3865. 'apple_id' => '4',
  3866. 'color' => 'My new appleOrange',
  3867. 'name' => 'My new apple',
  3868. 'created' => '2006-12-25 05:29:39',
  3869. 'date' => '2006-12-25',
  3870. 'modified' => '2006-12-25 05:29:39',
  3871. 'mytime' => '22:57:17'
  3872. ),
  3873. 'Parent' => array(
  3874. 'id' => '4',
  3875. 'apple_id' => '2',
  3876. 'color' => 'Blue Green',
  3877. 'name' => 'Test Name',
  3878. 'created' => '2006-12-25 05:23:36',
  3879. 'date' => '2006-12-25',
  3880. 'modified' => '2006-12-25 05:23:36',
  3881. 'mytime' => '22:57:17'
  3882. ),
  3883. 'Sample' => array(
  3884. 'id' => null,
  3885. 'apple_id' => null,
  3886. 'name' => null
  3887. ),
  3888. 'Child' => array(
  3889. array(
  3890. 'id' => '7',
  3891. 'apple_id' => '6',
  3892. 'color' => 'Some wierd color',
  3893. 'name' => 'Some odd color',
  3894. 'created' => '2006-12-25 05:34:21',
  3895. 'date' => '2006-12-25',
  3896. 'modified' => '2006-12-25 05:34:21',
  3897. 'mytime' => '22:57:17'
  3898. ))),
  3899. array(
  3900. 'Apple' => array(
  3901. 'id' => '7',
  3902. 'apple_id' => '6',
  3903. 'color' => 'Some wierd color',
  3904. 'name' => 'Some odd color',
  3905. 'created' => '2006-12-25 05:34:21',
  3906. 'date' => '2006-12-25',
  3907. 'modified' => '2006-12-25 05:34:21',
  3908. 'mytime' => '22:57:17'
  3909. ),
  3910. 'Parent' => array(
  3911. 'id' => '6',
  3912. 'apple_id' => '4',
  3913. 'color' => 'My new appleOrange',
  3914. 'name' => 'My new apple',
  3915. 'created' => '2006-12-25 05:29:39',
  3916. 'date' => '2006-12-25',
  3917. 'modified' => '2006-12-25 05:29:39',
  3918. 'mytime' => '22:57:17'
  3919. ),
  3920. 'Sample' => array(
  3921. 'id' => null,
  3922. 'apple_id' => null,
  3923. 'name' => null
  3924. ),
  3925. 'Child' => array()
  3926. ));
  3927. $this->assertEquals($expected, $result);
  3928. }
  3929. /**
  3930. * testSaveEmpty method
  3931. *
  3932. * @return void
  3933. */
  3934. public function testSaveEmpty() {
  3935. $this->loadFixtures('Thread');
  3936. $TestModel = new Thread();
  3937. $data = array();
  3938. $expected = $TestModel->save($data);
  3939. $this->assertFalse($expected);
  3940. }
  3941. /**
  3942. * testFindAllWithConditionInChildQuery
  3943. *
  3944. * @todo external conditions like this are going to need to be revisited at some point
  3945. * @return void
  3946. */
  3947. public function testFindAllWithConditionInChildQuery() {
  3948. $this->loadFixtures('Basket', 'FilmFile');
  3949. $TestModel = new Basket();
  3950. $recursive = 3;
  3951. $result = $TestModel->find('all', compact('recursive'));
  3952. $expected = array(
  3953. array(
  3954. 'Basket' => array(
  3955. 'id' => 1,
  3956. 'type' => 'nonfile',
  3957. 'name' => 'basket1',
  3958. 'object_id' => 1,
  3959. 'user_id' => 1,
  3960. ),
  3961. 'FilmFile' => array(
  3962. 'id' => '',
  3963. 'name' => '',
  3964. )
  3965. ),
  3966. array(
  3967. 'Basket' => array(
  3968. 'id' => 2,
  3969. 'type' => 'file',
  3970. 'name' => 'basket2',
  3971. 'object_id' => 2,
  3972. 'user_id' => 1,
  3973. ),
  3974. 'FilmFile' => array(
  3975. 'id' => 2,
  3976. 'name' => 'two',
  3977. )
  3978. ),
  3979. );
  3980. $this->assertEquals($expected, $result);
  3981. }
  3982. /**
  3983. * testFindAllWithConditionsHavingMixedDataTypes method
  3984. *
  3985. * @return void
  3986. */
  3987. public function testFindAllWithConditionsHavingMixedDataTypes() {
  3988. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag');
  3989. $TestModel = new Article();
  3990. $expected = array(
  3991. array(
  3992. 'Article' => array(
  3993. 'id' => 1,
  3994. 'user_id' => 1,
  3995. 'title' => 'First Article',
  3996. 'body' => 'First Article Body',
  3997. 'published' => 'Y',
  3998. 'created' => '2007-03-18 10:39:23',
  3999. 'updated' => '2007-03-18 10:41:31'
  4000. )
  4001. ),
  4002. array(
  4003. 'Article' => array(
  4004. 'id' => 2,
  4005. 'user_id' => 3,
  4006. 'title' => 'Second Article',
  4007. 'body' => 'Second Article Body',
  4008. 'published' => 'Y',
  4009. 'created' => '2007-03-18 10:41:23',
  4010. 'updated' => '2007-03-18 10:43:31'
  4011. )
  4012. )
  4013. );
  4014. $conditions = array('id' => array('1', 2));
  4015. $recursive = -1;
  4016. $order = 'Article.id ASC';
  4017. $result = $TestModel->find('all', compact('conditions', 'recursive', 'order'));
  4018. $this->assertEquals($expected, $result);
  4019. $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.');
  4020. $conditions = array('id' => array('1', 2, '3.0'));
  4021. $order = 'Article.id ASC';
  4022. $result = $TestModel->find('all', compact('recursive', 'conditions', 'order'));
  4023. $expected = array(
  4024. array(
  4025. 'Article' => array(
  4026. 'id' => 1,
  4027. 'user_id' => 1,
  4028. 'title' => 'First Article',
  4029. 'body' => 'First Article Body',
  4030. 'published' => 'Y',
  4031. 'created' => '2007-03-18 10:39:23',
  4032. 'updated' => '2007-03-18 10:41:31'
  4033. )
  4034. ),
  4035. array(
  4036. 'Article' => array(
  4037. 'id' => 2,
  4038. 'user_id' => 3,
  4039. 'title' => 'Second Article',
  4040. 'body' => 'Second Article Body',
  4041. 'published' => 'Y',
  4042. 'created' => '2007-03-18 10:41:23',
  4043. 'updated' => '2007-03-18 10:43:31'
  4044. )
  4045. ),
  4046. array(
  4047. 'Article' => array(
  4048. 'id' => 3,
  4049. 'user_id' => 1,
  4050. 'title' => 'Third Article',
  4051. 'body' => 'Third Article Body',
  4052. 'published' => 'Y',
  4053. 'created' => '2007-03-18 10:43:23',
  4054. 'updated' => '2007-03-18 10:45:31'
  4055. )
  4056. )
  4057. );
  4058. $this->assertEquals($expected, $result);
  4059. }
  4060. /**
  4061. * testBindUnbind method
  4062. *
  4063. * @return void
  4064. */
  4065. public function testBindUnbind() {
  4066. $this->loadFixtures(
  4067. 'User',
  4068. 'Comment',
  4069. 'FeatureSet',
  4070. 'DeviceType',
  4071. 'DeviceTypeCategory',
  4072. 'ExteriorTypeCategory',
  4073. 'Device',
  4074. 'Document',
  4075. 'DocumentDirectory'
  4076. );
  4077. $TestModel = new User();
  4078. $result = $TestModel->hasMany;
  4079. $expected = array();
  4080. $this->assertEquals($expected, $result);
  4081. $result = $TestModel->bindModel(array('hasMany' => array('Comment')));
  4082. $this->assertTrue($result);
  4083. $result = $TestModel->find('all', array(
  4084. 'fields' => 'User.id, User.user'
  4085. ));
  4086. $expected = array(
  4087. array(
  4088. 'User' => array(
  4089. 'id' => '1',
  4090. 'user' => 'mariano'
  4091. ),
  4092. 'Comment' => array(
  4093. array(
  4094. 'id' => '3',
  4095. 'article_id' => '1',
  4096. 'user_id' => '1',
  4097. 'comment' => 'Third Comment for First Article',
  4098. 'published' => 'Y',
  4099. 'created' => '2007-03-18 10:49:23',
  4100. 'updated' => '2007-03-18 10:51:31'
  4101. ),
  4102. array(
  4103. 'id' => '4',
  4104. 'article_id' => '1',
  4105. 'user_id' => '1',
  4106. 'comment' => 'Fourth Comment for First Article',
  4107. 'published' => 'N',
  4108. 'created' => '2007-03-18 10:51:23',
  4109. 'updated' => '2007-03-18 10:53:31'
  4110. ),
  4111. array(
  4112. 'id' => '5',
  4113. 'article_id' => '2',
  4114. 'user_id' => '1',
  4115. 'comment' => 'First Comment for Second Article',
  4116. 'published' => 'Y',
  4117. 'created' => '2007-03-18 10:53:23',
  4118. 'updated' => '2007-03-18 10:55:31'
  4119. ))),
  4120. array(
  4121. 'User' => array(
  4122. 'id' => '2',
  4123. 'user' => 'nate'
  4124. ),
  4125. 'Comment' => array(
  4126. array(
  4127. 'id' => '1',
  4128. 'article_id' => '1',
  4129. 'user_id' => '2',
  4130. 'comment' => 'First Comment for First Article',
  4131. 'published' => 'Y',
  4132. 'created' => '2007-03-18 10:45:23',
  4133. 'updated' => '2007-03-18 10:47:31'
  4134. ),
  4135. array(
  4136. 'id' => '6',
  4137. 'article_id' => '2',
  4138. 'user_id' => '2',
  4139. 'comment' => 'Second Comment for Second Article',
  4140. 'published' => 'Y',
  4141. 'created' => '2007-03-18 10:55:23',
  4142. 'updated' => '2007-03-18 10:57:31'
  4143. ))),
  4144. array(
  4145. 'User' => array(
  4146. 'id' => '3',
  4147. 'user' => 'larry'
  4148. ),
  4149. 'Comment' => array()
  4150. ),
  4151. array(
  4152. 'User' => array(
  4153. 'id' => '4',
  4154. 'user' => 'garrett'
  4155. ),
  4156. 'Comment' => array(
  4157. array(
  4158. 'id' => '2',
  4159. 'article_id' => '1',
  4160. 'user_id' => '4',
  4161. 'comment' => 'Second Comment for First Article',
  4162. 'published' => 'Y',
  4163. 'created' => '2007-03-18 10:47:23',
  4164. 'updated' => '2007-03-18 10:49:31'
  4165. ))));
  4166. $this->assertEquals($expected, $result);
  4167. $TestModel->resetAssociations();
  4168. $result = $TestModel->hasMany;
  4169. $this->assertEquals(array(), $result);
  4170. $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false);
  4171. $this->assertTrue($result);
  4172. $result = $TestModel->find('all', array(
  4173. 'fields' => 'User.id, User.user'
  4174. ));
  4175. $expected = array(
  4176. array(
  4177. 'User' => array(
  4178. 'id' => '1',
  4179. 'user' => 'mariano'
  4180. ),
  4181. 'Comment' => array(
  4182. array(
  4183. 'id' => '3',
  4184. 'article_id' => '1',
  4185. 'user_id' => '1',
  4186. 'comment' => 'Third Comment for First Article',
  4187. 'published' => 'Y',
  4188. 'created' => '2007-03-18 10:49:23',
  4189. 'updated' => '2007-03-18 10:51:31'
  4190. ),
  4191. array(
  4192. 'id' => '4',
  4193. 'article_id' => '1',
  4194. 'user_id' => '1',
  4195. 'comment' => 'Fourth Comment for First Article',
  4196. 'published' => 'N',
  4197. 'created' => '2007-03-18 10:51:23',
  4198. 'updated' => '2007-03-18 10:53:31'
  4199. ),
  4200. array(
  4201. 'id' => '5',
  4202. 'article_id' => '2',
  4203. 'user_id' => '1',
  4204. 'comment' => 'First Comment for Second Article',
  4205. 'published' => 'Y',
  4206. 'created' => '2007-03-18 10:53:23',
  4207. 'updated' => '2007-03-18 10:55:31'
  4208. ))),
  4209. array(
  4210. 'User' => array(
  4211. 'id' => '2',
  4212. 'user' => 'nate'
  4213. ),
  4214. 'Comment' => array(
  4215. array(
  4216. 'id' => '1',
  4217. 'article_id' => '1',
  4218. 'user_id' => '2',
  4219. 'comment' => 'First Comment for First Article',
  4220. 'published' => 'Y',
  4221. 'created' => '2007-03-18 10:45:23',
  4222. 'updated' => '2007-03-18 10:47:31'
  4223. ),
  4224. array(
  4225. 'id' => '6',
  4226. 'article_id' => '2',
  4227. 'user_id' => '2',
  4228. 'comment' => 'Second Comment for Second Article',
  4229. 'published' => 'Y',
  4230. 'created' => '2007-03-18 10:55:23',
  4231. 'updated' => '2007-03-18 10:57:31'
  4232. ))),
  4233. array(
  4234. 'User' => array(
  4235. 'id' => '3',
  4236. 'user' => 'larry'
  4237. ),
  4238. 'Comment' => array()
  4239. ),
  4240. array(
  4241. 'User' => array(
  4242. 'id' => '4',
  4243. 'user' => 'garrett'
  4244. ),
  4245. 'Comment' => array(
  4246. array(
  4247. 'id' => '2',
  4248. 'article_id' => '1',
  4249. 'user_id' => '4',
  4250. 'comment' => 'Second Comment for First Article',
  4251. 'published' => 'Y',
  4252. 'created' => '2007-03-18 10:47:23',
  4253. 'updated' => '2007-03-18 10:49:31'
  4254. ))));
  4255. $this->assertEquals($expected, $result);
  4256. $result = $TestModel->hasMany;
  4257. $expected = array(
  4258. 'Comment' => array(
  4259. 'className' => 'Comment',
  4260. 'foreignKey' => 'user_id',
  4261. 'conditions' => null,
  4262. 'fields' => null,
  4263. 'order' => null,
  4264. 'limit' => null,
  4265. 'offset' => null,
  4266. 'dependent' => null,
  4267. 'exclusive' => null,
  4268. 'finderQuery' => null,
  4269. 'counterQuery' => null
  4270. ));
  4271. $this->assertEquals($expected, $result);
  4272. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4273. $this->assertTrue($result);
  4274. $result = $TestModel->hasMany;
  4275. $expected = array();
  4276. $this->assertEquals($expected, $result);
  4277. $result = $TestModel->find('all', array(
  4278. 'fields' => 'User.id, User.user'
  4279. ));
  4280. $expected = array(
  4281. array('User' => array('id' => '1', 'user' => 'mariano')),
  4282. array('User' => array('id' => '2', 'user' => 'nate')),
  4283. array('User' => array('id' => '3', 'user' => 'larry')),
  4284. array('User' => array('id' => '4', 'user' => 'garrett')));
  4285. $this->assertEquals($expected, $result);
  4286. $result = $TestModel->find('all', array(
  4287. 'fields' => 'User.id, User.user'
  4288. ));
  4289. $expected = array(
  4290. array(
  4291. 'User' => array(
  4292. 'id' => '1',
  4293. 'user' => 'mariano'
  4294. ),
  4295. 'Comment' => array(
  4296. array(
  4297. 'id' => '3',
  4298. 'article_id' => '1',
  4299. 'user_id' => '1',
  4300. 'comment' => 'Third Comment for First Article',
  4301. 'published' => 'Y',
  4302. 'created' => '2007-03-18 10:49:23',
  4303. 'updated' => '2007-03-18 10:51:31'
  4304. ),
  4305. array(
  4306. 'id' => '4',
  4307. 'article_id' => '1',
  4308. 'user_id' => '1',
  4309. 'comment' => 'Fourth Comment for First Article',
  4310. 'published' => 'N',
  4311. 'created' => '2007-03-18 10:51:23',
  4312. 'updated' => '2007-03-18 10:53:31'
  4313. ),
  4314. array(
  4315. 'id' => '5',
  4316. 'article_id' => '2',
  4317. 'user_id' => '1',
  4318. 'comment' => 'First Comment for Second Article',
  4319. 'published' => 'Y',
  4320. 'created' => '2007-03-18 10:53:23',
  4321. 'updated' => '2007-03-18 10:55:31'
  4322. ))),
  4323. array(
  4324. 'User' => array(
  4325. 'id' => '2',
  4326. 'user' => 'nate'
  4327. ),
  4328. 'Comment' => array(
  4329. array(
  4330. 'id' => '1',
  4331. 'article_id' => '1',
  4332. 'user_id' => '2',
  4333. 'comment' => 'First Comment for First Article',
  4334. 'published' => 'Y',
  4335. 'created' => '2007-03-18 10:45:23',
  4336. 'updated' => '2007-03-18 10:47:31'
  4337. ),
  4338. array(
  4339. 'id' => '6',
  4340. 'article_id' => '2',
  4341. 'user_id' => '2',
  4342. 'comment' => 'Second Comment for Second Article',
  4343. 'published' => 'Y',
  4344. 'created' => '2007-03-18 10:55:23',
  4345. 'updated' => '2007-03-18 10:57:31'
  4346. ))),
  4347. array(
  4348. 'User' => array(
  4349. 'id' => '3',
  4350. 'user' => 'larry'
  4351. ),
  4352. 'Comment' => array()
  4353. ),
  4354. array(
  4355. 'User' => array(
  4356. 'id' => '4',
  4357. 'user' => 'garrett'
  4358. ),
  4359. 'Comment' => array(
  4360. array(
  4361. 'id' => '2',
  4362. 'article_id' => '1',
  4363. 'user_id' => '4',
  4364. 'comment' =>
  4365. 'Second Comment for First Article',
  4366. 'published' => 'Y',
  4367. 'created' => '2007-03-18 10:47:23',
  4368. 'updated' => '2007-03-18 10:49:31'
  4369. ))));
  4370. $this->assertEquals($expected, $result);
  4371. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false);
  4372. $this->assertTrue($result);
  4373. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4374. $expected = array(
  4375. array('User' => array('id' => '1', 'user' => 'mariano')),
  4376. array('User' => array('id' => '2', 'user' => 'nate')),
  4377. array('User' => array('id' => '3', 'user' => 'larry')),
  4378. array('User' => array('id' => '4', 'user' => 'garrett')));
  4379. $this->assertEquals($expected, $result);
  4380. $result = $TestModel->hasMany;
  4381. $expected = array();
  4382. $this->assertEquals($expected, $result);
  4383. $result = $TestModel->bindModel(array('hasMany' => array(
  4384. 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'')
  4385. )));
  4386. $this->assertTrue($result);
  4387. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4388. $expected = array(
  4389. array(
  4390. 'User' => array(
  4391. 'id' => '1',
  4392. 'user' => 'mariano'
  4393. ),
  4394. 'Comment' => array(
  4395. array(
  4396. 'id' => '3',
  4397. 'article_id' => '1',
  4398. 'user_id' => '1',
  4399. 'comment' => 'Third Comment for First Article',
  4400. 'published' => 'Y',
  4401. 'created' => '2007-03-18 10:49:23',
  4402. 'updated' => '2007-03-18 10:51:31'
  4403. ),
  4404. array(
  4405. 'id' => '5',
  4406. 'article_id' => '2',
  4407. 'user_id' => '1',
  4408. 'comment' => 'First Comment for Second Article',
  4409. 'published' => 'Y',
  4410. 'created' => '2007-03-18 10:53:23',
  4411. 'updated' => '2007-03-18 10:55:31'
  4412. ))),
  4413. array(
  4414. 'User' => array(
  4415. 'id' => '2',
  4416. 'user' => 'nate'
  4417. ),
  4418. 'Comment' => array(
  4419. array(
  4420. 'id' => '1',
  4421. 'article_id' => '1',
  4422. 'user_id' => '2',
  4423. 'comment' => 'First Comment for First Article',
  4424. 'published' => 'Y',
  4425. 'created' => '2007-03-18 10:45:23',
  4426. 'updated' => '2007-03-18 10:47:31'
  4427. ),
  4428. array(
  4429. 'id' => '6',
  4430. 'article_id' => '2',
  4431. 'user_id' => '2',
  4432. 'comment' => 'Second Comment for Second Article',
  4433. 'published' => 'Y',
  4434. 'created' => '2007-03-18 10:55:23',
  4435. 'updated' => '2007-03-18 10:57:31'
  4436. ))),
  4437. array(
  4438. 'User' => array(
  4439. 'id' => '3',
  4440. 'user' => 'larry'
  4441. ),
  4442. 'Comment' => array()
  4443. ),
  4444. array(
  4445. 'User' => array(
  4446. 'id' => '4',
  4447. 'user' => 'garrett'
  4448. ),
  4449. 'Comment' => array(
  4450. array(
  4451. 'id' => '2',
  4452. 'article_id' => '1',
  4453. 'user_id' => '4',
  4454. 'comment' => 'Second Comment for First Article',
  4455. 'published' => 'Y',
  4456. 'created' => '2007-03-18 10:47:23',
  4457. 'updated' => '2007-03-18 10:49:31'
  4458. ))));
  4459. $this->assertEquals($expected, $result);
  4460. $TestModel2 = new DeviceType();
  4461. $expected = array(
  4462. 'className' => 'FeatureSet',
  4463. 'foreignKey' => 'feature_set_id',
  4464. 'conditions' => '',
  4465. 'fields' => '',
  4466. 'order' => '',
  4467. 'counterCache' => ''
  4468. );
  4469. $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']);
  4470. $TestModel2->bindModel(array(
  4471. 'belongsTo' => array(
  4472. 'FeatureSet' => array(
  4473. 'className' => 'FeatureSet',
  4474. 'conditions' => array('active' => true)
  4475. )
  4476. )
  4477. ));
  4478. $expected['conditions'] = array('active' => true);
  4479. $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']);
  4480. $TestModel2->bindModel(array(
  4481. 'belongsTo' => array(
  4482. 'FeatureSet' => array(
  4483. 'className' => 'FeatureSet',
  4484. 'foreignKey' => false,
  4485. 'conditions' => array('Feature.name' => 'DeviceType.name')
  4486. )
  4487. )
  4488. ));
  4489. $expected['conditions'] = array('Feature.name' => 'DeviceType.name');
  4490. $expected['foreignKey'] = false;
  4491. $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']);
  4492. $TestModel2->bindModel(array(
  4493. 'hasMany' => array(
  4494. 'NewFeatureSet' => array(
  4495. 'className' => 'FeatureSet',
  4496. 'conditions' => array('active' => true)
  4497. )
  4498. )
  4499. ));
  4500. $expected = array(
  4501. 'className' => 'FeatureSet',
  4502. 'conditions' => array('active' => true),
  4503. 'foreignKey' => 'device_type_id',
  4504. 'fields' => '',
  4505. 'order' => '',
  4506. 'limit' => '',
  4507. 'offset' => '',
  4508. 'dependent' => '',
  4509. 'exclusive' => '',
  4510. 'finderQuery' => '',
  4511. 'counterQuery' => ''
  4512. );
  4513. $this->assertEquals($expected, $TestModel2->hasMany['NewFeatureSet']);
  4514. $this->assertTrue(is_object($TestModel2->NewFeatureSet));
  4515. }
  4516. /**
  4517. * testBindMultipleTimes method
  4518. *
  4519. * @return void
  4520. */
  4521. public function testBindMultipleTimes() {
  4522. $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag');
  4523. $TestModel = new User();
  4524. $result = $TestModel->hasMany;
  4525. $expected = array();
  4526. $this->assertEquals($expected, $result);
  4527. $result = $TestModel->bindModel(array(
  4528. 'hasMany' => array(
  4529. 'Items' => array('className' => 'Comment')
  4530. )));
  4531. $this->assertTrue($result);
  4532. $result = $TestModel->find('all', array(
  4533. 'fields' => 'User.id, User.user'
  4534. ));
  4535. $expected = array(
  4536. array(
  4537. 'User' => array(
  4538. 'id' => '1',
  4539. 'user' => 'mariano'
  4540. ),
  4541. 'Items' => array(
  4542. array(
  4543. 'id' => '3',
  4544. 'article_id' => '1',
  4545. 'user_id' => '1',
  4546. 'comment' => 'Third Comment for First Article',
  4547. 'published' => 'Y',
  4548. 'created' => '2007-03-18 10:49:23',
  4549. 'updated' => '2007-03-18 10:51:31'
  4550. ),
  4551. array(
  4552. 'id' => '4',
  4553. 'article_id' => '1',
  4554. 'user_id' => '1',
  4555. 'comment' => 'Fourth Comment for First Article',
  4556. 'published' => 'N',
  4557. 'created' => '2007-03-18 10:51:23',
  4558. 'updated' => '2007-03-18 10:53:31'
  4559. ),
  4560. array(
  4561. 'id' => '5',
  4562. 'article_id' => '2',
  4563. 'user_id' => '1',
  4564. 'comment' => 'First Comment for Second Article',
  4565. 'published' => 'Y',
  4566. 'created' => '2007-03-18 10:53:23',
  4567. 'updated' => '2007-03-18 10:55:31'
  4568. ))),
  4569. array(
  4570. 'User' => array(
  4571. 'id' => '2',
  4572. 'user' => 'nate'
  4573. ),
  4574. 'Items' => array(
  4575. array(
  4576. 'id' => '1',
  4577. 'article_id' => '1',
  4578. 'user_id' => '2',
  4579. 'comment' => 'First Comment for First Article',
  4580. 'published' => 'Y',
  4581. 'created' => '2007-03-18 10:45:23',
  4582. 'updated' => '2007-03-18 10:47:31'
  4583. ),
  4584. array(
  4585. 'id' => '6',
  4586. 'article_id' => '2',
  4587. 'user_id' => '2',
  4588. 'comment' => 'Second Comment for Second Article',
  4589. 'published' => 'Y',
  4590. 'created' => '2007-03-18 10:55:23',
  4591. 'updated' => '2007-03-18 10:57:31'
  4592. ))),
  4593. array(
  4594. 'User' => array(
  4595. 'id' => '3',
  4596. 'user' => 'larry'
  4597. ),
  4598. 'Items' => array()
  4599. ),
  4600. array(
  4601. 'User' => array(
  4602. 'id' => '4',
  4603. 'user' => 'garrett'
  4604. ),
  4605. 'Items' => array(
  4606. array(
  4607. 'id' => '2',
  4608. 'article_id' => '1',
  4609. 'user_id' => '4',
  4610. 'comment' => 'Second Comment for First Article',
  4611. 'published' => 'Y',
  4612. 'created' => '2007-03-18 10:47:23',
  4613. 'updated' => '2007-03-18 10:49:31'
  4614. ))));
  4615. $this->assertEquals($expected, $result);
  4616. $result = $TestModel->bindModel(array(
  4617. 'hasMany' => array(
  4618. 'Items' => array('className' => 'Article')
  4619. )));
  4620. $this->assertTrue($result);
  4621. $result = $TestModel->find('all', array(
  4622. 'fields' => 'User.id, User.user'
  4623. ));
  4624. $expected = array(
  4625. array(
  4626. 'User' => array(
  4627. 'id' => '1',
  4628. 'user' => 'mariano'
  4629. ),
  4630. 'Items' => array(
  4631. array(
  4632. 'id' => 1,
  4633. 'user_id' => 1,
  4634. 'title' => 'First Article',
  4635. 'body' => 'First Article Body',
  4636. 'published' => 'Y',
  4637. 'created' => '2007-03-18 10:39:23',
  4638. 'updated' => '2007-03-18 10:41:31'
  4639. ),
  4640. array(
  4641. 'id' => 3,
  4642. 'user_id' => 1,
  4643. 'title' => 'Third Article',
  4644. 'body' => 'Third Article Body',
  4645. 'published' => 'Y',
  4646. 'created' => '2007-03-18 10:43:23',
  4647. 'updated' => '2007-03-18 10:45:31'
  4648. ))),
  4649. array(
  4650. 'User' => array(
  4651. 'id' => '2',
  4652. 'user' => 'nate'
  4653. ),
  4654. 'Items' => array()
  4655. ),
  4656. array(
  4657. 'User' => array(
  4658. 'id' => '3',
  4659. 'user' => 'larry'
  4660. ),
  4661. 'Items' => array(
  4662. array(
  4663. 'id' => 2,
  4664. 'user_id' => 3,
  4665. 'title' => 'Second Article',
  4666. 'body' => 'Second Article Body',
  4667. 'published' => 'Y',
  4668. 'created' => '2007-03-18 10:41:23',
  4669. 'updated' => '2007-03-18 10:43:31'
  4670. ))),
  4671. array(
  4672. 'User' => array(
  4673. 'id' => '4',
  4674. 'user' => 'garrett'
  4675. ),
  4676. 'Items' => array()
  4677. ));
  4678. $this->assertEquals($expected, $result);
  4679. }
  4680. /**
  4681. * test that multiple reset = true calls to bindModel() result in the original associations.
  4682. *
  4683. * @return void
  4684. */
  4685. public function testBindModelMultipleTimesResetCorrectly() {
  4686. $this->loadFixtures('User', 'Comment', 'Article');
  4687. $TestModel = new User();
  4688. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4689. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4690. $TestModel->resetAssociations();
  4691. $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind');
  4692. }
  4693. /**
  4694. * testBindMultipleTimes method with different reset settings
  4695. *
  4696. * @return void
  4697. */
  4698. public function testBindMultipleTimesWithDifferentResetSettings() {
  4699. $this->loadFixtures('User', 'Comment', 'Article');
  4700. $TestModel = new User();
  4701. $result = $TestModel->hasMany;
  4702. $expected = array();
  4703. $this->assertEquals($expected, $result);
  4704. $result = $TestModel->bindModel(array(
  4705. 'hasMany' => array('Comment')
  4706. ));
  4707. $this->assertTrue($result);
  4708. $result = $TestModel->bindModel(
  4709. array('hasMany' => array('Article')),
  4710. false
  4711. );
  4712. $this->assertTrue($result);
  4713. $result = array_keys($TestModel->hasMany);
  4714. $expected = array('Comment', 'Article');
  4715. $this->assertEquals($expected, $result);
  4716. $TestModel->resetAssociations();
  4717. $result = array_keys($TestModel->hasMany);
  4718. $expected = array('Article');
  4719. $this->assertEquals($expected, $result);
  4720. }
  4721. /**
  4722. * test that bindModel behaves with Custom primary Key associations
  4723. *
  4724. * @return void
  4725. */
  4726. public function testBindWithCustomPrimaryKey() {
  4727. $this->loadFixtures('Story', 'StoriesTag', 'Tag');
  4728. $Model = ClassRegistry::init('StoriesTag');
  4729. $Model->bindModel(array(
  4730. 'belongsTo' => array(
  4731. 'Tag' => array(
  4732. 'className' => 'Tag',
  4733. 'foreignKey' => 'story'
  4734. ))));
  4735. $result = $Model->find('all');
  4736. $this->assertFalse(empty($result));
  4737. }
  4738. /**
  4739. * test that calling unbindModel() with reset == true multiple times
  4740. * leaves associations in the correct state.
  4741. *
  4742. * @return void
  4743. */
  4744. public function testUnbindMultipleTimesResetCorrectly() {
  4745. $this->loadFixtures('User', 'Comment', 'Article');
  4746. $TestModel = new Article10();
  4747. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4748. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4749. $TestModel->resetAssociations();
  4750. $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed');
  4751. }
  4752. /**
  4753. * testBindMultipleTimes method with different reset settings
  4754. *
  4755. * @return void
  4756. */
  4757. public function testUnBindMultipleTimesWithDifferentResetSettings() {
  4758. $this->loadFixtures('User', 'Comment', 'Article');
  4759. $TestModel = new Comment();
  4760. $result = array_keys($TestModel->belongsTo);
  4761. $expected = array('Article', 'User');
  4762. $this->assertEquals($expected, $result);
  4763. $result = $TestModel->unbindModel(array(
  4764. 'belongsTo' => array('User')
  4765. ));
  4766. $this->assertTrue($result);
  4767. $result = $TestModel->unbindModel(
  4768. array('belongsTo' => array('Article')),
  4769. false
  4770. );
  4771. $this->assertTrue($result);
  4772. $result = array_keys($TestModel->belongsTo);
  4773. $expected = array();
  4774. $this->assertEquals($expected, $result);
  4775. $TestModel->resetAssociations();
  4776. $result = array_keys($TestModel->belongsTo);
  4777. $expected = array('User');
  4778. $this->assertEquals($expected, $result);
  4779. }
  4780. /**
  4781. * testAssociationAfterFind method
  4782. *
  4783. * @return void
  4784. */
  4785. public function testAssociationAfterFind() {
  4786. $this->loadFixtures('Post', 'Author', 'Comment');
  4787. $TestModel = new Post();
  4788. $result = $TestModel->find('all');
  4789. $expected = array(
  4790. array(
  4791. 'Post' => array(
  4792. 'id' => '1',
  4793. 'author_id' => '1',
  4794. 'title' => 'First Post',
  4795. 'body' => 'First Post Body',
  4796. 'published' => 'Y',
  4797. 'created' => '2007-03-18 10:39:23',
  4798. 'updated' => '2007-03-18 10:41:31'
  4799. ),
  4800. 'Author' => array(
  4801. 'id' => '1',
  4802. 'user' => 'mariano',
  4803. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4804. 'created' => '2007-03-17 01:16:23',
  4805. 'updated' => '2007-03-17 01:18:31',
  4806. 'test' => 'working'
  4807. )),
  4808. array(
  4809. 'Post' => array(
  4810. 'id' => '2',
  4811. 'author_id' => '3',
  4812. 'title' => 'Second Post',
  4813. 'body' => 'Second Post Body',
  4814. 'published' => 'Y',
  4815. 'created' => '2007-03-18 10:41:23',
  4816. 'updated' => '2007-03-18 10:43:31'
  4817. ),
  4818. 'Author' => array(
  4819. 'id' => '3',
  4820. 'user' => 'larry',
  4821. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4822. 'created' => '2007-03-17 01:20:23',
  4823. 'updated' => '2007-03-17 01:22:31',
  4824. 'test' => 'working'
  4825. )),
  4826. array(
  4827. 'Post' => array(
  4828. 'id' => '3',
  4829. 'author_id' => '1',
  4830. 'title' => 'Third Post',
  4831. 'body' => 'Third Post Body',
  4832. 'published' => 'Y',
  4833. 'created' => '2007-03-18 10:43:23',
  4834. 'updated' => '2007-03-18 10:45:31'
  4835. ),
  4836. 'Author' => array(
  4837. 'id' => '1',
  4838. 'user' => 'mariano',
  4839. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4840. 'created' => '2007-03-17 01:16:23',
  4841. 'updated' => '2007-03-17 01:18:31',
  4842. 'test' => 'working'
  4843. )));
  4844. $this->assertEquals($expected, $result);
  4845. unset($TestModel);
  4846. $Author = new Author();
  4847. $Author->Post->bindModel(array(
  4848. 'hasMany' => array(
  4849. 'Comment' => array(
  4850. 'className' => 'ModifiedComment',
  4851. 'foreignKey' => 'article_id',
  4852. )
  4853. )));
  4854. $result = $Author->find('all', array(
  4855. 'conditions' => array('Author.id' => 1),
  4856. 'recursive' => 2
  4857. ));
  4858. $expected = array(
  4859. 'id' => 1,
  4860. 'article_id' => 1,
  4861. 'user_id' => 2,
  4862. 'comment' => 'First Comment for First Article',
  4863. 'published' => 'Y',
  4864. 'created' => '2007-03-18 10:45:23',
  4865. 'updated' => '2007-03-18 10:47:31',
  4866. 'callback' => 'Fire'
  4867. );
  4868. $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]);
  4869. }
  4870. /**
  4871. * testDeeperAssociationAfterFind method
  4872. *
  4873. * @return void
  4874. */
  4875. public function testDeeperAssociationAfterFind() {
  4876. $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article');
  4877. $Post = new Post();
  4878. $Post->bindModel(array(
  4879. 'hasMany' => array(
  4880. 'Comment' => array(
  4881. 'className' => 'ModifiedComment',
  4882. 'foreignKey' => 'article_id',
  4883. )
  4884. )));
  4885. $Post->Comment->bindModel(array(
  4886. 'hasOne' => array(
  4887. 'Attachment' => array(
  4888. 'className' => 'ModifiedAttachment',
  4889. )
  4890. )));
  4891. $result = $Post->find('first', array(
  4892. 'conditions' => array('Post.id' => 2),
  4893. 'recursive' => 2
  4894. ));
  4895. $this->assertTrue(isset($result['Comment'][0]['callback']));
  4896. $this->assertEquals('Fire', $result['Comment'][0]['callback']);
  4897. $this->assertTrue(isset($result['Comment'][0]['Attachment']['callback']));
  4898. $this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']);
  4899. }
  4900. /**
  4901. * Tests that callbacks can be properly disabled
  4902. *
  4903. * @return void
  4904. */
  4905. public function testCallbackDisabling() {
  4906. $this->loadFixtures('Author');
  4907. $TestModel = new ModifiedAuthor();
  4908. $result = Hash::extract($TestModel->find('all'), '{n}.Author.user');
  4909. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4910. $this->assertEquals($expected, $result);
  4911. $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user');
  4912. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4913. $this->assertEquals($expected, $result);
  4914. $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user');
  4915. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4916. $this->assertEquals($expected, $result);
  4917. $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user');
  4918. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4919. $this->assertEquals($expected, $result);
  4920. }
  4921. /**
  4922. * testAssociationAfterFindCallbacksDisabled method
  4923. *
  4924. * @return void
  4925. */
  4926. public function testAssociationAfterFindCalbacksDisabled() {
  4927. $this->loadFixtures('Post', 'Author', 'Comment');
  4928. $TestModel = new Post();
  4929. $result = $TestModel->find('all', array('callbacks' => false));
  4930. $expected = array(
  4931. array(
  4932. 'Post' => array(
  4933. 'id' => '1',
  4934. 'author_id' => '1',
  4935. 'title' => 'First Post',
  4936. 'body' => 'First Post Body',
  4937. 'published' => 'Y',
  4938. 'created' => '2007-03-18 10:39:23',
  4939. 'updated' => '2007-03-18 10:41:31'
  4940. ),
  4941. 'Author' => array(
  4942. 'id' => '1',
  4943. 'user' => 'mariano',
  4944. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4945. 'created' => '2007-03-17 01:16:23',
  4946. 'updated' => '2007-03-17 01:18:31'
  4947. )),
  4948. array(
  4949. 'Post' => array(
  4950. 'id' => '2',
  4951. 'author_id' => '3',
  4952. 'title' => 'Second Post',
  4953. 'body' => 'Second Post Body',
  4954. 'published' => 'Y',
  4955. 'created' => '2007-03-18 10:41:23',
  4956. 'updated' => '2007-03-18 10:43:31'
  4957. ),
  4958. 'Author' => array(
  4959. 'id' => '3',
  4960. 'user' => 'larry',
  4961. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4962. 'created' => '2007-03-17 01:20:23',
  4963. 'updated' => '2007-03-17 01:22:31'
  4964. )),
  4965. array(
  4966. 'Post' => array(
  4967. 'id' => '3',
  4968. 'author_id' => '1',
  4969. 'title' => 'Third Post',
  4970. 'body' => 'Third Post Body',
  4971. 'published' => 'Y',
  4972. 'created' => '2007-03-18 10:43:23',
  4973. 'updated' => '2007-03-18 10:45:31'
  4974. ),
  4975. 'Author' => array(
  4976. 'id' => '1',
  4977. 'user' => 'mariano',
  4978. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4979. 'created' => '2007-03-17 01:16:23',
  4980. 'updated' => '2007-03-17 01:18:31'
  4981. )));
  4982. $this->assertEquals($expected, $result);
  4983. unset($TestModel);
  4984. $Author = new Author();
  4985. $Author->Post->bindModel(array(
  4986. 'hasMany' => array(
  4987. 'Comment' => array(
  4988. 'className' => 'ModifiedComment',
  4989. 'foreignKey' => 'article_id',
  4990. )
  4991. )));
  4992. $result = $Author->find('all', array(
  4993. 'conditions' => array('Author.id' => 1),
  4994. 'recursive' => 2,
  4995. 'callbacks' => false
  4996. ));
  4997. $expected = array(
  4998. 'id' => 1,
  4999. 'article_id' => 1,
  5000. 'user_id' => 2,
  5001. 'comment' => 'First Comment for First Article',
  5002. 'published' => 'Y',
  5003. 'created' => '2007-03-18 10:45:23',
  5004. 'updated' => '2007-03-18 10:47:31'
  5005. );
  5006. $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]);
  5007. }
  5008. /**
  5009. * Tests that the database configuration assigned to the model can be changed using
  5010. * (before|after)Find callbacks
  5011. *
  5012. * @return void
  5013. */
  5014. public function testCallbackSourceChange() {
  5015. $this->loadFixtures('Post');
  5016. $TestModel = new Post();
  5017. $this->assertEquals(3, count($TestModel->find('all')));
  5018. }
  5019. /**
  5020. * testCallbackSourceChangeUnknownDatasource method
  5021. *
  5022. * @expectedException MissingDatasourceConfigException
  5023. * @return void
  5024. */
  5025. public function testCallbackSourceChangeUnknownDatasource() {
  5026. $this->loadFixtures('Post', 'Author');
  5027. $TestModel = new Post();
  5028. $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
  5029. }
  5030. /**
  5031. * testMultipleBelongsToWithSameClass method
  5032. *
  5033. * @return void
  5034. */
  5035. public function testMultipleBelongsToWithSameClass() {
  5036. $this->loadFixtures(
  5037. 'DeviceType',
  5038. 'DeviceTypeCategory',
  5039. 'FeatureSet',
  5040. 'ExteriorTypeCategory',
  5041. 'Document',
  5042. 'Device',
  5043. 'DocumentDirectory'
  5044. );
  5045. $DeviceType = new DeviceType();
  5046. $DeviceType->recursive = 2;
  5047. $result = $DeviceType->read(null, 1);
  5048. $expected = array(
  5049. 'DeviceType' => array(
  5050. 'id' => 1,
  5051. 'device_type_category_id' => 1,
  5052. 'feature_set_id' => 1,
  5053. 'exterior_type_category_id' => 1,
  5054. 'image_id' => 1,
  5055. 'extra1_id' => 1,
  5056. 'extra2_id' => 1,
  5057. 'name' => 'DeviceType 1',
  5058. 'order' => 0
  5059. ),
  5060. 'Image' => array(
  5061. 'id' => 1,
  5062. 'document_directory_id' => 1,
  5063. 'name' => 'Document 1',
  5064. 'DocumentDirectory' => array(
  5065. 'id' => 1,
  5066. 'name' => 'DocumentDirectory 1'
  5067. )),
  5068. 'Extra1' => array(
  5069. 'id' => 1,
  5070. 'document_directory_id' => 1,
  5071. 'name' => 'Document 1',
  5072. 'DocumentDirectory' => array(
  5073. 'id' => 1,
  5074. 'name' => 'DocumentDirectory 1'
  5075. )),
  5076. 'Extra2' => array(
  5077. 'id' => 1,
  5078. 'document_directory_id' => 1,
  5079. 'name' => 'Document 1',
  5080. 'DocumentDirectory' => array(
  5081. 'id' => 1,
  5082. 'name' => 'DocumentDirectory 1'
  5083. )),
  5084. 'DeviceTypeCategory' => array(
  5085. 'id' => 1,
  5086. 'name' => 'DeviceTypeCategory 1'
  5087. ),
  5088. 'FeatureSet' => array(
  5089. 'id' => 1,
  5090. 'name' => 'FeatureSet 1'
  5091. ),
  5092. 'ExteriorTypeCategory' => array(
  5093. 'id' => 1,
  5094. 'image_id' => 1,
  5095. 'name' => 'ExteriorTypeCategory 1',
  5096. 'Image' => array(
  5097. 'id' => 1,
  5098. 'device_type_id' => 1,
  5099. 'name' => 'Device 1',
  5100. 'typ' => 1
  5101. )),
  5102. 'Device' => array(
  5103. array(
  5104. 'id' => 1,
  5105. 'device_type_id' => 1,
  5106. 'name' => 'Device 1',
  5107. 'typ' => 1
  5108. ),
  5109. array(
  5110. 'id' => 2,
  5111. 'device_type_id' => 1,
  5112. 'name' => 'Device 2',
  5113. 'typ' => 1
  5114. ),
  5115. array(
  5116. 'id' => 3,
  5117. 'device_type_id' => 1,
  5118. 'name' => 'Device 3',
  5119. 'typ' => 2
  5120. )));
  5121. $this->assertEquals($expected, $result);
  5122. }
  5123. /**
  5124. * testHabtmRecursiveBelongsTo method
  5125. *
  5126. * @return void
  5127. */
  5128. public function testHabtmRecursiveBelongsTo() {
  5129. $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
  5130. $Portfolio = new Portfolio();
  5131. $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3));
  5132. $expected = array(
  5133. 'Portfolio' => array(
  5134. 'id' => 2,
  5135. 'seller_id' => 1,
  5136. 'name' => 'Portfolio 2'
  5137. ),
  5138. 'Item' => array(
  5139. array(
  5140. 'id' => 2,
  5141. 'syfile_id' => 2,
  5142. 'published' => false,
  5143. 'name' => 'Item 2',
  5144. 'ItemsPortfolio' => array(
  5145. 'id' => 2,
  5146. 'item_id' => 2,
  5147. 'portfolio_id' => 2
  5148. ),
  5149. 'Syfile' => array(
  5150. 'id' => 2,
  5151. 'image_id' => 2,
  5152. 'name' => 'Syfile 2',
  5153. 'item_count' => null,
  5154. 'Image' => array(
  5155. 'id' => 2,
  5156. 'name' => 'Image 2'
  5157. )
  5158. )),
  5159. array(
  5160. 'id' => 6,
  5161. 'syfile_id' => 6,
  5162. 'published' => false,
  5163. 'name' => 'Item 6',
  5164. 'ItemsPortfolio' => array(
  5165. 'id' => 6,
  5166. 'item_id' => 6,
  5167. 'portfolio_id' => 2
  5168. ),
  5169. 'Syfile' => array(
  5170. 'id' => 6,
  5171. 'image_id' => null,
  5172. 'name' => 'Syfile 6',
  5173. 'item_count' => null,
  5174. 'Image' => array()
  5175. ))));
  5176. $this->assertEquals($expected, $result);
  5177. }
  5178. /**
  5179. * testNonNumericHabtmJoinKey method
  5180. *
  5181. * @return void
  5182. */
  5183. public function testNonNumericHabtmJoinKey() {
  5184. $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author');
  5185. $Post = new Post();
  5186. $Post->bindModel(array(
  5187. 'hasAndBelongsToMany' => array('Tag')
  5188. ));
  5189. $Post->Tag->primaryKey = 'tag';
  5190. $result = $Post->find('all');
  5191. $expected = array(
  5192. array(
  5193. 'Post' => array(
  5194. 'id' => '1',
  5195. 'author_id' => '1',
  5196. 'title' => 'First Post',
  5197. 'body' => 'First Post Body',
  5198. 'published' => 'Y',
  5199. 'created' => '2007-03-18 10:39:23',
  5200. 'updated' => '2007-03-18 10:41:31'
  5201. ),
  5202. 'Author' => array(
  5203. 'id' => 1,
  5204. 'user' => 'mariano',
  5205. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5206. 'created' => '2007-03-17 01:16:23',
  5207. 'updated' => '2007-03-17 01:18:31',
  5208. 'test' => 'working'
  5209. ),
  5210. 'Tag' => array(
  5211. array(
  5212. 'id' => '1',
  5213. 'tag' => 'tag1',
  5214. 'created' => '2007-03-18 12:22:23',
  5215. 'updated' => '2007-03-18 12:24:31'
  5216. ),
  5217. array(
  5218. 'id' => '2',
  5219. 'tag' => 'tag2',
  5220. 'created' => '2007-03-18 12:24:23',
  5221. 'updated' => '2007-03-18 12:26:31'
  5222. ))),
  5223. array(
  5224. 'Post' => array(
  5225. 'id' => '2',
  5226. 'author_id' => '3',
  5227. 'title' => 'Second Post',
  5228. 'body' => 'Second Post Body',
  5229. 'published' => 'Y',
  5230. 'created' => '2007-03-18 10:41:23',
  5231. 'updated' => '2007-03-18 10:43:31'
  5232. ),
  5233. 'Author' => array(
  5234. 'id' => 3,
  5235. 'user' => 'larry',
  5236. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5237. 'created' => '2007-03-17 01:20:23',
  5238. 'updated' => '2007-03-17 01:22:31',
  5239. 'test' => 'working'
  5240. ),
  5241. 'Tag' => array(
  5242. array(
  5243. 'id' => '1',
  5244. 'tag' => 'tag1',
  5245. 'created' => '2007-03-18 12:22:23',
  5246. 'updated' => '2007-03-18 12:24:31'
  5247. ),
  5248. array(
  5249. 'id' => '3',
  5250. 'tag' => 'tag3',
  5251. 'created' => '2007-03-18 12:26:23',
  5252. 'updated' => '2007-03-18 12:28:31'
  5253. ))),
  5254. array(
  5255. 'Post' => array(
  5256. 'id' => '3',
  5257. 'author_id' => '1',
  5258. 'title' => 'Third Post',
  5259. 'body' => 'Third Post Body',
  5260. 'published' => 'Y',
  5261. 'created' => '2007-03-18 10:43:23',
  5262. 'updated' => '2007-03-18 10:45:31'
  5263. ),
  5264. 'Author' => array(
  5265. 'id' => 1,
  5266. 'user' => 'mariano',
  5267. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5268. 'created' => '2007-03-17 01:16:23',
  5269. 'updated' => '2007-03-17 01:18:31',
  5270. 'test' => 'working'
  5271. ),
  5272. 'Tag' => array()
  5273. ));
  5274. $this->assertEquals($expected, $result);
  5275. }
  5276. /**
  5277. * testHabtmFinderQuery method
  5278. *
  5279. * @return void
  5280. */
  5281. public function testHabtmFinderQuery() {
  5282. $this->loadFixtures('Article', 'Tag', 'ArticlesTag');
  5283. $Article = new Article();
  5284. $sql = $this->db->buildStatement(
  5285. array(
  5286. 'fields' => $this->db->fields($Article->Tag, null, array(
  5287. 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id'
  5288. )),
  5289. 'table' => $this->db->fullTableName('tags'),
  5290. 'alias' => 'Tag',
  5291. 'limit' => null,
  5292. 'offset' => null,
  5293. 'group' => null,
  5294. 'joins' => array(array(
  5295. 'alias' => 'ArticlesTag',
  5296. 'table' => 'articles_tags',
  5297. 'conditions' => array(
  5298. array("ArticlesTag.article_id" => '{$__cakeID__$}'),
  5299. array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
  5300. )
  5301. )),
  5302. 'conditions' => array(),
  5303. 'order' => null
  5304. ),
  5305. $Article
  5306. );
  5307. $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
  5308. $result = $Article->find('first');
  5309. $expected = array(
  5310. array(
  5311. 'id' => '1',
  5312. 'tag' => 'tag1'
  5313. ),
  5314. array(
  5315. 'id' => '2',
  5316. 'tag' => 'tag2'
  5317. ));
  5318. $this->assertEquals($expected, $result['Tag']);
  5319. }
  5320. /**
  5321. * testHabtmLimitOptimization method
  5322. *
  5323. * @return void
  5324. */
  5325. public function testHabtmLimitOptimization() {
  5326. $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag');
  5327. $TestModel = new Article();
  5328. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2;
  5329. $result = $TestModel->read(null, 2);
  5330. $expected = array(
  5331. 'Article' => array(
  5332. 'id' => '2',
  5333. 'user_id' => '3',
  5334. 'title' => 'Second Article',
  5335. 'body' => 'Second Article Body',
  5336. 'published' => 'Y',
  5337. 'created' => '2007-03-18 10:41:23',
  5338. 'updated' => '2007-03-18 10:43:31'
  5339. ),
  5340. 'User' => array(
  5341. 'id' => '3',
  5342. 'user' => 'larry',
  5343. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5344. 'created' => '2007-03-17 01:20:23',
  5345. 'updated' => '2007-03-17 01:22:31'
  5346. ),
  5347. 'Comment' => array(
  5348. array(
  5349. 'id' => '5',
  5350. 'article_id' => '2',
  5351. 'user_id' => '1',
  5352. 'comment' => 'First Comment for Second Article',
  5353. 'published' => 'Y',
  5354. 'created' => '2007-03-18 10:53:23',
  5355. 'updated' => '2007-03-18 10:55:31'
  5356. ),
  5357. array(
  5358. 'id' => '6',
  5359. 'article_id' => '2',
  5360. 'user_id' => '2',
  5361. 'comment' => 'Second Comment for Second Article',
  5362. 'published' => 'Y',
  5363. 'created' => '2007-03-18 10:55:23',
  5364. 'updated' => '2007-03-18 10:57:31'
  5365. )),
  5366. 'Tag' => array(
  5367. array(
  5368. 'id' => '1',
  5369. 'tag' => 'tag1',
  5370. 'created' => '2007-03-18 12:22:23',
  5371. 'updated' => '2007-03-18 12:24:31'
  5372. ),
  5373. array(
  5374. 'id' => '3',
  5375. 'tag' => 'tag3',
  5376. 'created' => '2007-03-18 12:26:23',
  5377. 'updated' => '2007-03-18 12:28:31'
  5378. )));
  5379. $this->assertEquals($expected, $result);
  5380. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1;
  5381. $result = $TestModel->read(null, 2);
  5382. unset($expected['Tag'][1]);
  5383. $this->assertEquals($expected, $result);
  5384. }
  5385. /**
  5386. * testHasManyLimitOptimization method
  5387. *
  5388. * @return void
  5389. */
  5390. public function testHasManyLimitOptimization() {
  5391. $this->loadFixtures('Project', 'Thread', 'Message', 'Bid');
  5392. $Project = new Project();
  5393. $Project->recursive = 3;
  5394. $result = $Project->find('all');
  5395. $expected = array(
  5396. array(
  5397. 'Project' => array(
  5398. 'id' => 1,
  5399. 'name' => 'Project 1'
  5400. ),
  5401. 'Thread' => array(
  5402. array(
  5403. 'id' => 1,
  5404. 'project_id' => 1,
  5405. 'name' => 'Project 1, Thread 1',
  5406. 'Project' => array(
  5407. 'id' => 1,
  5408. 'name' => 'Project 1',
  5409. 'Thread' => array(
  5410. array(
  5411. 'id' => 1,
  5412. 'project_id' => 1,
  5413. 'name' => 'Project 1, Thread 1'
  5414. ),
  5415. array(
  5416. 'id' => 2,
  5417. 'project_id' => 1,
  5418. 'name' => 'Project 1, Thread 2'
  5419. ))),
  5420. 'Message' => array(
  5421. array(
  5422. 'id' => 1,
  5423. 'thread_id' => 1,
  5424. 'name' => 'Thread 1, Message 1',
  5425. 'Bid' => array(
  5426. 'id' => 1,
  5427. 'message_id' => 1,
  5428. 'name' => 'Bid 1.1'
  5429. )))),
  5430. array(
  5431. 'id' => 2,
  5432. 'project_id' => 1,
  5433. 'name' => 'Project 1, Thread 2',
  5434. 'Project' => array(
  5435. 'id' => 1,
  5436. 'name' => 'Project 1',
  5437. 'Thread' => array(
  5438. array(
  5439. 'id' => 1,
  5440. 'project_id' => 1,
  5441. 'name' => 'Project 1, Thread 1'
  5442. ),
  5443. array(
  5444. 'id' => 2,
  5445. 'project_id' => 1,
  5446. 'name' => 'Project 1, Thread 2'
  5447. ))),
  5448. 'Message' => array(
  5449. array(
  5450. 'id' => 2,
  5451. 'thread_id' => 2,
  5452. 'name' => 'Thread 2, Message 1',
  5453. 'Bid' => array(
  5454. 'id' => 4,
  5455. 'message_id' => 2,
  5456. 'name' => 'Bid 2.1'
  5457. )))))),
  5458. array(
  5459. 'Project' => array(
  5460. 'id' => 2,
  5461. 'name' => 'Project 2'
  5462. ),
  5463. 'Thread' => array(
  5464. array(
  5465. 'id' => 3,
  5466. 'project_id' => 2,
  5467. 'name' => 'Project 2, Thread 1',
  5468. 'Project' => array(
  5469. 'id' => 2,
  5470. 'name' => 'Project 2',
  5471. 'Thread' => array(
  5472. array(
  5473. 'id' => 3,
  5474. 'project_id' => 2,
  5475. 'name' => 'Project 2, Thread 1'
  5476. ))),
  5477. 'Message' => array(
  5478. array(
  5479. 'id' => 3,
  5480. 'thread_id' => 3,
  5481. 'name' => 'Thread 3, Message 1',
  5482. 'Bid' => array(
  5483. 'id' => 3,
  5484. 'message_id' => 3,
  5485. 'name' => 'Bid 3.1'
  5486. )))))),
  5487. array(
  5488. 'Project' => array(
  5489. 'id' => 3,
  5490. 'name' => 'Project 3'
  5491. ),
  5492. 'Thread' => array()
  5493. ));
  5494. $this->assertEquals($expected, $result);
  5495. }
  5496. /**
  5497. * testFindAllRecursiveSelfJoin method
  5498. *
  5499. * @return void
  5500. */
  5501. public function testFindAllRecursiveSelfJoin() {
  5502. $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement');
  5503. $TestModel = new Home();
  5504. $TestModel->recursive = 2;
  5505. $result = $TestModel->find('all');
  5506. $expected = array(
  5507. array(
  5508. 'Home' => array(
  5509. 'id' => '1',
  5510. 'another_article_id' => '1',
  5511. 'advertisement_id' => '1',
  5512. 'title' => 'First Home',
  5513. 'created' => '2007-03-18 10:39:23',
  5514. 'updated' => '2007-03-18 10:41:31'
  5515. ),
  5516. 'AnotherArticle' => array(
  5517. 'id' => '1',
  5518. 'title' => 'First Article',
  5519. 'created' => '2007-03-18 10:39:23',
  5520. 'updated' => '2007-03-18 10:41:31',
  5521. 'Home' => array(
  5522. array(
  5523. 'id' => '1',
  5524. 'another_article_id' => '1',
  5525. 'advertisement_id' => '1',
  5526. 'title' => 'First Home',
  5527. 'created' => '2007-03-18 10:39:23',
  5528. 'updated' => '2007-03-18 10:41:31'
  5529. ))),
  5530. 'Advertisement' => array(
  5531. 'id' => '1',
  5532. 'title' => 'First Ad',
  5533. 'created' => '2007-03-18 10:39:23',
  5534. 'updated' => '2007-03-18 10:41:31',
  5535. 'Home' => array(
  5536. array(
  5537. 'id' => '1',
  5538. 'another_article_id' => '1',
  5539. 'advertisement_id' => '1',
  5540. 'title' => 'First Home',
  5541. 'created' => '2007-03-18 10:39:23',
  5542. 'updated' => '2007-03-18 10:41:31'
  5543. ),
  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. array(
  5553. 'Home' => array(
  5554. 'id' => '2',
  5555. 'another_article_id' => '3',
  5556. 'advertisement_id' => '1',
  5557. 'title' => 'Second Home',
  5558. 'created' => '2007-03-18 10:41:23',
  5559. 'updated' => '2007-03-18 10:43:31'
  5560. ),
  5561. 'AnotherArticle' => array(
  5562. 'id' => '3',
  5563. 'title' => 'Third Article',
  5564. 'created' => '2007-03-18 10:43:23',
  5565. 'updated' => '2007-03-18 10:45:31',
  5566. 'Home' => array(
  5567. array(
  5568. 'id' => '2',
  5569. 'another_article_id' => '3',
  5570. 'advertisement_id' => '1',
  5571. 'title' => 'Second Home',
  5572. 'created' => '2007-03-18 10:41:23',
  5573. 'updated' => '2007-03-18 10:43:31'
  5574. ))),
  5575. 'Advertisement' => array(
  5576. 'id' => '1',
  5577. 'title' => 'First Ad',
  5578. 'created' => '2007-03-18 10:39:23',
  5579. 'updated' => '2007-03-18 10:41:31',
  5580. 'Home' => array(
  5581. array(
  5582. 'id' => '1',
  5583. 'another_article_id' => '1',
  5584. 'advertisement_id' => '1',
  5585. 'title' => 'First Home',
  5586. 'created' => '2007-03-18 10:39:23',
  5587. 'updated' => '2007-03-18 10:41:31'
  5588. ),
  5589. array(
  5590. 'id' => '2',
  5591. 'another_article_id' => '3',
  5592. 'advertisement_id' => '1',
  5593. 'title' => 'Second Home',
  5594. 'created' => '2007-03-18 10:41:23',
  5595. 'updated' => '2007-03-18 10:43:31'
  5596. )))));
  5597. $this->assertEquals($expected, $result);
  5598. }
  5599. /**
  5600. * testFindAllRecursiveWithHabtm method
  5601. *
  5602. * @return void
  5603. */
  5604. public function testFindAllRecursiveWithHabtm() {
  5605. $this->loadFixtures(
  5606. 'MyCategoriesMyUsers',
  5607. 'MyCategoriesMyProducts',
  5608. 'MyCategory',
  5609. 'MyUser',
  5610. 'MyProduct'
  5611. );
  5612. $MyUser = new MyUser();
  5613. $MyUser->recursive = 2;
  5614. $result = $MyUser->find('all');
  5615. $expected = array(
  5616. array(
  5617. 'MyUser' => array('id' => '1', 'firstname' => 'userA'),
  5618. 'MyCategory' => array(
  5619. array(
  5620. 'id' => '1',
  5621. 'name' => 'A',
  5622. 'MyProduct' => array(
  5623. array(
  5624. 'id' => '1',
  5625. 'name' => 'book'
  5626. ))),
  5627. array(
  5628. 'id' => '3',
  5629. 'name' => 'C',
  5630. 'MyProduct' => array(
  5631. array(
  5632. 'id' => '2',
  5633. 'name' => 'computer'
  5634. ))))),
  5635. array(
  5636. 'MyUser' => array(
  5637. 'id' => '2',
  5638. 'firstname' => 'userB'
  5639. ),
  5640. 'MyCategory' => array(
  5641. array(
  5642. 'id' => '1',
  5643. 'name' => 'A',
  5644. 'MyProduct' => array(
  5645. array(
  5646. 'id' => '1',
  5647. 'name' => 'book'
  5648. ))),
  5649. array(
  5650. 'id' => '2',
  5651. 'name' => 'B',
  5652. 'MyProduct' => array(
  5653. array(
  5654. 'id' => '1',
  5655. 'name' => 'book'
  5656. ),
  5657. array(
  5658. 'id' => '2',
  5659. 'name' => 'computer'
  5660. ))))));
  5661. $this->assertEquals($expected, $result);
  5662. }
  5663. /**
  5664. * testReadFakeThread method
  5665. *
  5666. * @return void
  5667. */
  5668. public function testReadFakeThread() {
  5669. $this->loadFixtures('CategoryThread');
  5670. $TestModel = new CategoryThread();
  5671. $fullDebug = $this->db->fullDebug;
  5672. $this->db->fullDebug = true;
  5673. $TestModel->recursive = 6;
  5674. $TestModel->id = 7;
  5675. $result = $TestModel->read();
  5676. $expected = array(
  5677. 'CategoryThread' => array(
  5678. 'id' => 7,
  5679. 'parent_id' => 6,
  5680. 'name' => 'Category 2.1',
  5681. 'created' => '2007-03-18 15:30:23',
  5682. 'updated' => '2007-03-18 15:32:31'
  5683. ),
  5684. 'ParentCategory' => array(
  5685. 'id' => 6,
  5686. 'parent_id' => 5,
  5687. 'name' => 'Category 2',
  5688. 'created' => '2007-03-18 15:30:23',
  5689. 'updated' => '2007-03-18 15:32:31',
  5690. 'ParentCategory' => array(
  5691. 'id' => 5,
  5692. 'parent_id' => 4,
  5693. 'name' => 'Category 1.1.1.1',
  5694. 'created' => '2007-03-18 15:30:23',
  5695. 'updated' => '2007-03-18 15:32:31',
  5696. 'ParentCategory' => array(
  5697. 'id' => 4,
  5698. 'parent_id' => 3,
  5699. 'name' => 'Category 1.1.2',
  5700. 'created' => '2007-03-18 15:30:23',
  5701. 'updated' => '2007-03-18 15:32:31',
  5702. 'ParentCategory' => array(
  5703. 'id' => 3,
  5704. 'parent_id' => 2,
  5705. 'name' => 'Category 1.1.1',
  5706. 'created' => '2007-03-18 15:30:23',
  5707. 'updated' => '2007-03-18 15:32:31',
  5708. 'ParentCategory' => array(
  5709. 'id' => 2,
  5710. 'parent_id' => 1,
  5711. 'name' => 'Category 1.1',
  5712. 'created' => '2007-03-18 15:30:23',
  5713. 'updated' => '2007-03-18 15:32:31',
  5714. 'ParentCategory' => array(
  5715. 'id' => 1,
  5716. 'parent_id' => 0,
  5717. 'name' => 'Category 1',
  5718. 'created' => '2007-03-18 15:30:23',
  5719. 'updated' => '2007-03-18 15:32:31'
  5720. )))))));
  5721. $this->db->fullDebug = $fullDebug;
  5722. $this->assertEquals($expected, $result);
  5723. }
  5724. /**
  5725. * testFindFakeThread method
  5726. *
  5727. * @return void
  5728. */
  5729. public function testFindFakeThread() {
  5730. $this->loadFixtures('CategoryThread');
  5731. $TestModel = new CategoryThread();
  5732. $fullDebug = $this->db->fullDebug;
  5733. $this->db->fullDebug = true;
  5734. $TestModel->recursive = 6;
  5735. $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7)));
  5736. $expected = array(
  5737. 'CategoryThread' => array(
  5738. 'id' => 7,
  5739. 'parent_id' => 6,
  5740. 'name' => 'Category 2.1',
  5741. 'created' => '2007-03-18 15:30:23',
  5742. 'updated' => '2007-03-18 15:32:31'
  5743. ),
  5744. 'ParentCategory' => array(
  5745. 'id' => 6,
  5746. 'parent_id' => 5,
  5747. 'name' => 'Category 2',
  5748. 'created' => '2007-03-18 15:30:23',
  5749. 'updated' => '2007-03-18 15:32:31',
  5750. 'ParentCategory' => array(
  5751. 'id' => 5,
  5752. 'parent_id' => 4,
  5753. 'name' => 'Category 1.1.1.1',
  5754. 'created' => '2007-03-18 15:30:23',
  5755. 'updated' => '2007-03-18 15:32:31',
  5756. 'ParentCategory' => array(
  5757. 'id' => 4,
  5758. 'parent_id' => 3,
  5759. 'name' => 'Category 1.1.2',
  5760. 'created' => '2007-03-18 15:30:23',
  5761. 'updated' => '2007-03-18 15:32:31',
  5762. 'ParentCategory' => array(
  5763. 'id' => 3,
  5764. 'parent_id' => 2,
  5765. 'name' => 'Category 1.1.1',
  5766. 'created' => '2007-03-18 15:30:23',
  5767. 'updated' => '2007-03-18 15:32:31',
  5768. 'ParentCategory' => array(
  5769. 'id' => 2,
  5770. 'parent_id' => 1,
  5771. 'name' => 'Category 1.1',
  5772. 'created' => '2007-03-18 15:30:23',
  5773. 'updated' => '2007-03-18 15:32:31',
  5774. 'ParentCategory' => array(
  5775. 'id' => 1,
  5776. 'parent_id' => 0,
  5777. 'name' => 'Category 1',
  5778. 'created' => '2007-03-18 15:30:23',
  5779. 'updated' => '2007-03-18 15:32:31'
  5780. )))))));
  5781. $this->db->fullDebug = $fullDebug;
  5782. $this->assertEquals($expected, $result);
  5783. }
  5784. /**
  5785. * testFindAllFakeThread method
  5786. *
  5787. * @return void
  5788. */
  5789. public function testFindAllFakeThread() {
  5790. $this->loadFixtures('CategoryThread');
  5791. $TestModel = new CategoryThread();
  5792. $fullDebug = $this->db->fullDebug;
  5793. $this->db->fullDebug = true;
  5794. $TestModel->recursive = 6;
  5795. $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC');
  5796. $expected = array(
  5797. array(
  5798. 'CategoryThread' => 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. ),
  5805. 'ParentCategory' => array(
  5806. 'id' => null,
  5807. 'parent_id' => null,
  5808. 'name' => null,
  5809. 'created' => null,
  5810. 'updated' => null,
  5811. 'ParentCategory' => array()
  5812. )),
  5813. array(
  5814. 'CategoryThread' => 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. ),
  5821. 'ParentCategory' => array(
  5822. 'id' => 1,
  5823. 'parent_id' => 0,
  5824. 'name' => 'Category 1',
  5825. 'created' => '2007-03-18 15:30:23',
  5826. 'updated' => '2007-03-18 15:32:31',
  5827. 'ParentCategory' => array()
  5828. )),
  5829. array(
  5830. 'CategoryThread' => array(
  5831. 'id' => 3,
  5832. 'parent_id' => 2,
  5833. 'name' => 'Category 1.1.1',
  5834. 'created' => '2007-03-18 15:30:23',
  5835. 'updated' => '2007-03-18 15:32:31'
  5836. ),
  5837. 'ParentCategory' => array(
  5838. 'id' => 2,
  5839. 'parent_id' => 1,
  5840. 'name' => 'Category 1.1',
  5841. 'created' => '2007-03-18 15:30:23',
  5842. 'updated' => '2007-03-18 15:32:31',
  5843. 'ParentCategory' => array(
  5844. 'id' => 1,
  5845. 'parent_id' => 0,
  5846. 'name' => 'Category 1',
  5847. 'created' => '2007-03-18 15:30:23',
  5848. 'updated' => '2007-03-18 15:32:31',
  5849. 'ParentCategory' => array()
  5850. ))),
  5851. array(
  5852. 'CategoryThread' => array(
  5853. 'id' => 4,
  5854. 'parent_id' => 3,
  5855. 'name' => 'Category 1.1.2',
  5856. 'created' => '2007-03-18 15:30:23',
  5857. 'updated' => '2007-03-18 15:32:31'
  5858. ),
  5859. 'ParentCategory' => array(
  5860. 'id' => 3,
  5861. 'parent_id' => 2,
  5862. 'name' => 'Category 1.1.1',
  5863. 'created' => '2007-03-18 15:30:23',
  5864. 'updated' => '2007-03-18 15:32:31',
  5865. 'ParentCategory' => array(
  5866. 'id' => 2,
  5867. 'parent_id' => 1,
  5868. 'name' => 'Category 1.1',
  5869. 'created' => '2007-03-18 15:30:23',
  5870. 'updated' => '2007-03-18 15:32:31',
  5871. 'ParentCategory' => array(
  5872. 'id' => 1,
  5873. 'parent_id' => 0,
  5874. 'name' => 'Category 1',
  5875. 'created' => '2007-03-18 15:30:23',
  5876. 'updated' => '2007-03-18 15:32:31',
  5877. 'ParentCategory' => array()
  5878. )))),
  5879. array(
  5880. 'CategoryThread' => array(
  5881. 'id' => 5,
  5882. 'parent_id' => 4,
  5883. 'name' => 'Category 1.1.1.1',
  5884. 'created' => '2007-03-18 15:30:23',
  5885. 'updated' => '2007-03-18 15:32:31'
  5886. ),
  5887. 'ParentCategory' => array(
  5888. 'id' => 4,
  5889. 'parent_id' => 3,
  5890. 'name' => 'Category 1.1.2',
  5891. 'created' => '2007-03-18 15:30:23',
  5892. 'updated' => '2007-03-18 15:32:31',
  5893. 'ParentCategory' => array(
  5894. 'id' => 3,
  5895. 'parent_id' => 2,
  5896. 'name' => 'Category 1.1.1',
  5897. 'created' => '2007-03-18 15:30:23',
  5898. 'updated' => '2007-03-18 15:32:31',
  5899. 'ParentCategory' => array(
  5900. 'id' => 2,
  5901. 'parent_id' => 1,
  5902. 'name' => 'Category 1.1',
  5903. 'created' => '2007-03-18 15:30:23',
  5904. 'updated' => '2007-03-18 15:32:31',
  5905. 'ParentCategory' => array(
  5906. 'id' => 1,
  5907. 'parent_id' => 0,
  5908. 'name' => 'Category 1',
  5909. 'created' => '2007-03-18 15:30:23',
  5910. 'updated' => '2007-03-18 15:32:31',
  5911. 'ParentCategory' => array()
  5912. ))))),
  5913. array(
  5914. 'CategoryThread' => array(
  5915. 'id' => 6,
  5916. 'parent_id' => 5,
  5917. 'name' => 'Category 2',
  5918. 'created' => '2007-03-18 15:30:23',
  5919. 'updated' => '2007-03-18 15:32:31'
  5920. ),
  5921. 'ParentCategory' => array(
  5922. 'id' => 5,
  5923. 'parent_id' => 4,
  5924. 'name' => 'Category 1.1.1.1',
  5925. 'created' => '2007-03-18 15:30:23',
  5926. 'updated' => '2007-03-18 15:32:31',
  5927. 'ParentCategory' => array(
  5928. 'id' => 4,
  5929. 'parent_id' => 3,
  5930. 'name' => 'Category 1.1.2',
  5931. 'created' => '2007-03-18 15:30:23',
  5932. 'updated' => '2007-03-18 15:32:31',
  5933. 'ParentCategory' => array(
  5934. 'id' => 3,
  5935. 'parent_id' => 2,
  5936. 'name' => 'Category 1.1.1',
  5937. 'created' => '2007-03-18 15:30:23',
  5938. 'updated' => '2007-03-18 15:32:31',
  5939. 'ParentCategory' => array(
  5940. 'id' => 2,
  5941. 'parent_id' => 1,
  5942. 'name' => 'Category 1.1',
  5943. 'created' => '2007-03-18 15:30:23',
  5944. 'updated' => '2007-03-18 15:32:31',
  5945. 'ParentCategory' => array(
  5946. 'id' => 1,
  5947. 'parent_id' => 0,
  5948. 'name' => 'Category 1',
  5949. 'created' => '2007-03-18 15:30:23',
  5950. 'updated' => '2007-03-18 15:32:31',
  5951. 'ParentCategory' => array()
  5952. )))))),
  5953. array(
  5954. 'CategoryThread' => array(
  5955. 'id' => 7,
  5956. 'parent_id' => 6,
  5957. 'name' => 'Category 2.1',
  5958. 'created' => '2007-03-18 15:30:23',
  5959. 'updated' => '2007-03-18 15:32:31'
  5960. ),
  5961. 'ParentCategory' => array(
  5962. 'id' => 6,
  5963. 'parent_id' => 5,
  5964. 'name' => 'Category 2',
  5965. 'created' => '2007-03-18 15:30:23',
  5966. 'updated' => '2007-03-18 15:32:31',
  5967. 'ParentCategory' => array(
  5968. 'id' => 5,
  5969. 'parent_id' => 4,
  5970. 'name' => 'Category 1.1.1.1',
  5971. 'created' => '2007-03-18 15:30:23',
  5972. 'updated' => '2007-03-18 15:32:31',
  5973. 'ParentCategory' => array(
  5974. 'id' => 4,
  5975. 'parent_id' => 3,
  5976. 'name' => 'Category 1.1.2',
  5977. 'created' => '2007-03-18 15:30:23',
  5978. 'updated' => '2007-03-18 15:32:31',
  5979. 'ParentCategory' => array(
  5980. 'id' => 3,
  5981. 'parent_id' => 2,
  5982. 'name' => 'Category 1.1.1',
  5983. 'created' => '2007-03-18 15:30:23',
  5984. 'updated' => '2007-03-18 15:32:31',
  5985. 'ParentCategory' => array(
  5986. 'id' => 2,
  5987. 'parent_id' => 1,
  5988. 'name' => 'Category 1.1',
  5989. 'created' => '2007-03-18 15:30:23',
  5990. 'updated' => '2007-03-18 15:32:31',
  5991. 'ParentCategory' => array(
  5992. 'id' => 1,
  5993. 'parent_id' => 0,
  5994. 'name' => 'Category 1',
  5995. 'created' => '2007-03-18 15:30:23',
  5996. 'updated' => '2007-03-18 15:32:31'
  5997. ))))))));
  5998. $this->db->fullDebug = $fullDebug;
  5999. $this->assertEquals($expected, $result);
  6000. }
  6001. /**
  6002. * testConditionalNumerics method
  6003. *
  6004. * @return void
  6005. */
  6006. public function testConditionalNumerics() {
  6007. $this->loadFixtures('NumericArticle');
  6008. $NumericArticle = new NumericArticle();
  6009. $data = array('conditions' => array('title' => '12345abcde'));
  6010. $result = $NumericArticle->find('first', $data);
  6011. $this->assertTrue(!empty($result));
  6012. $data = array('conditions' => array('title' => '12345'));
  6013. $result = $NumericArticle->find('first', $data);
  6014. $this->assertTrue(empty($result));
  6015. }
  6016. /**
  6017. * test buildQuery()
  6018. *
  6019. * @return void
  6020. */
  6021. public function testBuildQuery() {
  6022. $this->loadFixtures('User');
  6023. $TestModel = new User();
  6024. $TestModel->cacheQueries = false;
  6025. $expected = array(
  6026. 'conditions' => array(
  6027. 'user' => 'larry'
  6028. ),
  6029. 'fields' => null,
  6030. 'joins' => array(),
  6031. 'limit' => null,
  6032. 'offset' => null,
  6033. 'order' => array(
  6034. 0 => null
  6035. ),
  6036. 'page' => 1,
  6037. 'group' => null,
  6038. 'callbacks' => true,
  6039. 'returnQuery' => true
  6040. );
  6041. $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry')));
  6042. $this->assertEquals($expected, $result);
  6043. }
  6044. /**
  6045. * test find('all') method
  6046. *
  6047. * @return void
  6048. */
  6049. public function testFindAll() {
  6050. $this->loadFixtures('User');
  6051. $TestModel = new User();
  6052. $TestModel->cacheQueries = false;
  6053. $result = $TestModel->find('all');
  6054. $expected = array(
  6055. array(
  6056. 'User' => array(
  6057. 'id' => '1',
  6058. 'user' => 'mariano',
  6059. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6060. 'created' => '2007-03-17 01:16:23',
  6061. 'updated' => '2007-03-17 01:18:31'
  6062. )),
  6063. array(
  6064. 'User' => array(
  6065. 'id' => '2',
  6066. 'user' => 'nate',
  6067. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6068. 'created' => '2007-03-17 01:18:23',
  6069. 'updated' => '2007-03-17 01:20:31'
  6070. )),
  6071. array(
  6072. 'User' => array(
  6073. 'id' => '3',
  6074. 'user' => 'larry',
  6075. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6076. 'created' => '2007-03-17 01:20:23',
  6077. 'updated' => '2007-03-17 01:22:31'
  6078. )),
  6079. array(
  6080. 'User' => array(
  6081. 'id' => '4',
  6082. 'user' => 'garrett',
  6083. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6084. 'created' => '2007-03-17 01:22:23',
  6085. 'updated' => '2007-03-17 01:24:31'
  6086. )));
  6087. $this->assertEquals($expected, $result);
  6088. $result = $TestModel->find('all', array('conditions' => 'User.id > 2'));
  6089. $expected = array(
  6090. array(
  6091. 'User' => array(
  6092. 'id' => '3',
  6093. 'user' => 'larry',
  6094. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6095. 'created' => '2007-03-17 01:20:23',
  6096. 'updated' => '2007-03-17 01:22:31'
  6097. )),
  6098. array(
  6099. 'User' => array(
  6100. 'id' => '4',
  6101. 'user' => 'garrett',
  6102. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6103. 'created' => '2007-03-17 01:22:23',
  6104. 'updated' => '2007-03-17 01:24:31'
  6105. )));
  6106. $this->assertEquals($expected, $result);
  6107. $result = $TestModel->find('all', array(
  6108. 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%')
  6109. ));
  6110. $expected = array(
  6111. array(
  6112. 'User' => array(
  6113. 'id' => '3',
  6114. 'user' => 'larry',
  6115. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6116. 'created' => '2007-03-17 01:20:23',
  6117. 'updated' => '2007-03-17 01:22:31'
  6118. )),
  6119. array(
  6120. 'User' => array(
  6121. 'id' => '4',
  6122. 'user' => 'garrett',
  6123. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6124. 'created' => '2007-03-17 01:22:23',
  6125. 'updated' => '2007-03-17 01:24:31'
  6126. )));
  6127. $this->assertEquals($expected, $result);
  6128. $result = $TestModel->find('all', array('conditions' => array('User.id' => '0')));
  6129. $expected = array();
  6130. $this->assertEquals($expected, $result);
  6131. $result = $TestModel->find('all', array(
  6132. 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%')
  6133. )));
  6134. $expected = array(
  6135. array(
  6136. 'User' => array(
  6137. 'id' => '1',
  6138. 'user' => 'mariano',
  6139. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6140. 'created' => '2007-03-17 01:16:23',
  6141. 'updated' => '2007-03-17 01:18:31'
  6142. )),
  6143. array(
  6144. 'User' => array(
  6145. 'id' => '2',
  6146. 'user' => 'nate',
  6147. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6148. 'created' => '2007-03-17 01:18:23',
  6149. 'updated' => '2007-03-17 01:20:31'
  6150. )),
  6151. array(
  6152. 'User' => array(
  6153. 'id' => '3',
  6154. 'user' => 'larry',
  6155. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6156. 'created' => '2007-03-17 01:20:23',
  6157. 'updated' => '2007-03-17 01:22:31'
  6158. )),
  6159. array(
  6160. 'User' => array(
  6161. 'id' => '4',
  6162. 'user' => 'garrett',
  6163. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6164. 'created' => '2007-03-17 01:22:23',
  6165. 'updated' => '2007-03-17 01:24:31'
  6166. )));
  6167. $this->assertEquals($expected, $result);
  6168. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  6169. $expected = array(
  6170. array('User' => array('id' => '1', 'user' => 'mariano')),
  6171. array('User' => array('id' => '2', 'user' => 'nate')),
  6172. array('User' => array('id' => '3', 'user' => 'larry')),
  6173. array('User' => array('id' => '4', 'user' => 'garrett')));
  6174. $this->assertEquals($expected, $result);
  6175. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC'));
  6176. $expected = array(
  6177. array('User' => array('user' => 'garrett')),
  6178. array('User' => array('user' => 'larry')),
  6179. array('User' => array('user' => 'mariano')),
  6180. array('User' => array('user' => 'nate')));
  6181. $this->assertEquals($expected, $result);
  6182. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC'));
  6183. $expected = array(
  6184. array('User' => array('user' => 'nate')),
  6185. array('User' => array('user' => 'mariano')),
  6186. array('User' => array('user' => 'larry')),
  6187. array('User' => array('user' => 'garrett')));
  6188. $this->assertEquals($expected, $result);
  6189. $result = $TestModel->find('all', array('limit' => 3, 'page' => 1));
  6190. $expected = array(
  6191. array(
  6192. 'User' => array(
  6193. 'id' => '1',
  6194. 'user' => 'mariano',
  6195. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6196. 'created' => '2007-03-17 01:16:23',
  6197. 'updated' => '2007-03-17 01:18:31'
  6198. )),
  6199. array(
  6200. 'User' => array(
  6201. 'id' => '2',
  6202. 'user' => 'nate',
  6203. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6204. 'created' => '2007-03-17 01:18:23',
  6205. 'updated' => '2007-03-17 01:20: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. $ids = array(4 => 1, 5 => 3);
  6217. $result = $TestModel->find('all', array(
  6218. 'conditions' => array('User.id' => $ids),
  6219. 'order' => 'User.id'
  6220. ));
  6221. $expected = array(
  6222. array(
  6223. 'User' => array(
  6224. 'id' => '1',
  6225. 'user' => 'mariano',
  6226. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6227. 'created' => '2007-03-17 01:16:23',
  6228. 'updated' => '2007-03-17 01:18:31'
  6229. )),
  6230. array(
  6231. 'User' => array(
  6232. 'id' => '3',
  6233. 'user' => 'larry',
  6234. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6235. 'created' => '2007-03-17 01:20:23',
  6236. 'updated' => '2007-03-17 01:22:31'
  6237. )));
  6238. $this->assertEquals($expected, $result);
  6239. // These tests are expected to fail on SQL Server since the LIMIT/OFFSET
  6240. // hack can't handle small record counts.
  6241. if (!($this->db instanceof Sqlserver)) {
  6242. $result = $TestModel->find('all', array('limit' => 3, 'page' => 2));
  6243. $expected = array(
  6244. array(
  6245. 'User' => array(
  6246. 'id' => '4',
  6247. 'user' => 'garrett',
  6248. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6249. 'created' => '2007-03-17 01:22:23',
  6250. 'updated' => '2007-03-17 01:24:31'
  6251. )));
  6252. $this->assertEquals($expected, $result);
  6253. $result = $TestModel->find('all', array('limit' => 3, 'page' => 3));
  6254. $expected = array();
  6255. $this->assertEquals($expected, $result);
  6256. }
  6257. }
  6258. /**
  6259. * test find('list') method
  6260. *
  6261. * @return void
  6262. */
  6263. public function testGenerateFindList() {
  6264. $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment');
  6265. $TestModel = new Article();
  6266. $TestModel->displayField = 'title';
  6267. $result = $TestModel->find('list', array(
  6268. 'order' => 'Article.title ASC'
  6269. ));
  6270. $expected = array(
  6271. 1 => 'First Article',
  6272. 2 => 'Second Article',
  6273. 3 => 'Third Article'
  6274. );
  6275. $this->assertEquals($expected, $result);
  6276. $db = ConnectionManager::getDataSource('test');
  6277. if ($db instanceof Mysql) {
  6278. $result = $TestModel->find('list', array(
  6279. 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC')
  6280. ));
  6281. $expected = array(
  6282. 1 => 'First Article',
  6283. 3 => 'Third Article',
  6284. 2 => 'Second Article'
  6285. );
  6286. $this->assertEquals($expected, $result);
  6287. }
  6288. $result = Hash::combine(
  6289. $TestModel->find('all', array(
  6290. 'order' => 'Article.title ASC',
  6291. 'fields' => array('id', 'title')
  6292. )),
  6293. '{n}.Article.id', '{n}.Article.title'
  6294. );
  6295. $expected = array(
  6296. 1 => 'First Article',
  6297. 2 => 'Second Article',
  6298. 3 => 'Third Article'
  6299. );
  6300. $this->assertEquals($expected, $result);
  6301. $result = Hash::combine(
  6302. $TestModel->find('all', array(
  6303. 'order' => 'Article.title ASC'
  6304. )),
  6305. '{n}.Article.id', '{n}.Article'
  6306. );
  6307. $expected = array(
  6308. 1 => array(
  6309. 'id' => 1,
  6310. 'user_id' => 1,
  6311. 'title' => 'First Article',
  6312. 'body' => 'First Article Body',
  6313. 'published' => 'Y',
  6314. 'created' => '2007-03-18 10:39:23',
  6315. 'updated' => '2007-03-18 10:41:31'
  6316. ),
  6317. 2 => array(
  6318. 'id' => 2,
  6319. 'user_id' => 3,
  6320. 'title' => 'Second Article',
  6321. 'body' => 'Second Article Body',
  6322. 'published' => 'Y',
  6323. 'created' => '2007-03-18 10:41:23',
  6324. 'updated' => '2007-03-18 10:43:31'
  6325. ),
  6326. 3 => array(
  6327. 'id' => 3,
  6328. 'user_id' => 1,
  6329. 'title' => 'Third Article',
  6330. 'body' => 'Third Article Body',
  6331. 'published' => 'Y',
  6332. 'created' => '2007-03-18 10:43:23',
  6333. 'updated' => '2007-03-18 10:45:31'
  6334. ));
  6335. $this->assertEquals($expected, $result);
  6336. $result = Hash::combine(
  6337. $TestModel->find('all', array(
  6338. 'order' => 'Article.title ASC'
  6339. )),
  6340. '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
  6341. );
  6342. $expected = array(
  6343. 1 => array(
  6344. 1 => array(
  6345. 'id' => 1,
  6346. 'user_id' => 1,
  6347. 'title' => 'First Article',
  6348. 'body' => 'First Article Body',
  6349. 'published' => 'Y',
  6350. 'created' => '2007-03-18 10:39:23',
  6351. 'updated' => '2007-03-18 10:41:31'
  6352. ),
  6353. 3 => array(
  6354. 'id' => 3,
  6355. 'user_id' => 1,
  6356. 'title' => 'Third Article',
  6357. 'body' => 'Third Article Body',
  6358. 'published' => 'Y',
  6359. 'created' => '2007-03-18 10:43:23',
  6360. 'updated' => '2007-03-18 10:45:31'
  6361. )),
  6362. 3 => array(
  6363. 2 => array(
  6364. 'id' => 2,
  6365. 'user_id' => 3,
  6366. 'title' => 'Second Article',
  6367. 'body' => 'Second Article Body',
  6368. 'published' => 'Y',
  6369. 'created' => '2007-03-18 10:41:23',
  6370. 'updated' => '2007-03-18 10:43:31'
  6371. )));
  6372. $this->assertEquals($expected, $result);
  6373. $result = Hash::combine(
  6374. $TestModel->find('all', array(
  6375. 'order' => 'Article.title ASC',
  6376. 'fields' => array('id', 'title', 'user_id')
  6377. )),
  6378. '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
  6379. );
  6380. $expected = array(
  6381. 1 => array(
  6382. 1 => 'First Article',
  6383. 3 => 'Third Article'
  6384. ),
  6385. 3 => array(
  6386. 2 => 'Second Article'
  6387. ));
  6388. $this->assertEquals($expected, $result);
  6389. $TestModel = new Apple();
  6390. $expected = array(
  6391. 1 => 'Red Apple 1',
  6392. 2 => 'Bright Red Apple',
  6393. 3 => 'green blue',
  6394. 4 => 'Test Name',
  6395. 5 => 'Blue Green',
  6396. 6 => 'My new apple',
  6397. 7 => 'Some odd color'
  6398. );
  6399. $this->assertEquals($expected, $TestModel->find('list'));
  6400. $this->assertEquals($expected, $TestModel->Parent->find('list'));
  6401. $TestModel = new Post();
  6402. $result = $TestModel->find('list', array(
  6403. 'fields' => 'Post.title'
  6404. ));
  6405. $expected = array(
  6406. 1 => 'First Post',
  6407. 2 => 'Second Post',
  6408. 3 => 'Third Post'
  6409. );
  6410. $this->assertEquals($expected, $result);
  6411. $result = $TestModel->find('list', array(
  6412. 'fields' => 'title'
  6413. ));
  6414. $expected = array(
  6415. 1 => 'First Post',
  6416. 2 => 'Second Post',
  6417. 3 => 'Third Post'
  6418. );
  6419. $this->assertEquals($expected, $result);
  6420. $result = $TestModel->find('list', array(
  6421. 'fields' => array('title', 'id')
  6422. ));
  6423. $expected = array(
  6424. 'First Post' => '1',
  6425. 'Second Post' => '2',
  6426. 'Third Post' => '3'
  6427. );
  6428. $this->assertEquals($expected, $result);
  6429. $result = $TestModel->find('list', array(
  6430. 'fields' => array('title', 'id', 'created')
  6431. ));
  6432. $expected = array(
  6433. '2007-03-18 10:39:23' => array(
  6434. 'First Post' => '1'
  6435. ),
  6436. '2007-03-18 10:41:23' => array(
  6437. 'Second Post' => '2'
  6438. ),
  6439. '2007-03-18 10:43:23' => array(
  6440. 'Third Post' => '3'
  6441. ),
  6442. );
  6443. $this->assertEquals($expected, $result);
  6444. $result = $TestModel->find('list', array(
  6445. 'fields' => array('Post.body')
  6446. ));
  6447. $expected = array(
  6448. 1 => 'First Post Body',
  6449. 2 => 'Second Post Body',
  6450. 3 => 'Third Post Body'
  6451. );
  6452. $this->assertEquals($expected, $result);
  6453. $result = $TestModel->find('list', array(
  6454. 'fields' => array('Post.title', 'Post.body')
  6455. ));
  6456. $expected = array(
  6457. 'First Post' => 'First Post Body',
  6458. 'Second Post' => 'Second Post Body',
  6459. 'Third Post' => 'Third Post Body'
  6460. );
  6461. $this->assertEquals($expected, $result);
  6462. $result = $TestModel->find('list', array(
  6463. 'fields' => array('Post.id', 'Post.title', 'Author.user'),
  6464. 'recursive' => 1
  6465. ));
  6466. $expected = array(
  6467. 'mariano' => array(
  6468. 1 => 'First Post',
  6469. 3 => 'Third Post'
  6470. ),
  6471. 'larry' => array(
  6472. 2 => 'Second Post'
  6473. ));
  6474. $this->assertEquals($expected, $result);
  6475. $TestModel = new User();
  6476. $result = $TestModel->find('list', array(
  6477. 'fields' => array('User.user', 'User.password')
  6478. ));
  6479. $expected = array(
  6480. 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6481. 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6482. 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6483. 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6484. );
  6485. $this->assertEquals($expected, $result);
  6486. $TestModel = new ModifiedAuthor();
  6487. $result = $TestModel->find('list', array(
  6488. 'fields' => array('Author.id', 'Author.user')
  6489. ));
  6490. $expected = array(
  6491. 1 => 'mariano (CakePHP)',
  6492. 2 => 'nate (CakePHP)',
  6493. 3 => 'larry (CakePHP)',
  6494. 4 => 'garrett (CakePHP)'
  6495. );
  6496. $this->assertEquals($expected, $result);
  6497. $TestModel = new Article();
  6498. $TestModel->displayField = 'title';
  6499. $result = $TestModel->find('list', array(
  6500. 'conditions' => array('User.user' => 'mariano'),
  6501. 'recursive' => 0
  6502. ));
  6503. $expected = array(
  6504. 1 => 'First Article',
  6505. 3 => 'Third Article'
  6506. );
  6507. $this->assertEquals($expected, $result);
  6508. }
  6509. /**
  6510. * testFindField method
  6511. *
  6512. * @return void
  6513. */
  6514. public function testFindField() {
  6515. $this->loadFixtures('User');
  6516. $TestModel = new User();
  6517. $TestModel->id = 1;
  6518. $result = $TestModel->field('user');
  6519. $this->assertEquals('mariano', $result);
  6520. $result = $TestModel->field('User.user');
  6521. $this->assertEquals('mariano', $result);
  6522. $TestModel->id = false;
  6523. $result = $TestModel->field('user', array(
  6524. 'user' => 'mariano'
  6525. ));
  6526. $this->assertEquals('mariano', $result);
  6527. $result = $TestModel->field('COUNT(*) AS count', true);
  6528. $this->assertEquals(4, $result);
  6529. $result = $TestModel->field('COUNT(*)', true);
  6530. $this->assertEquals(4, $result);
  6531. }
  6532. /**
  6533. * testFindUnique method
  6534. *
  6535. * @return void
  6536. */
  6537. public function testFindUnique() {
  6538. $this->loadFixtures('User');
  6539. $TestModel = new User();
  6540. $this->assertFalse($TestModel->isUnique(array(
  6541. 'user' => 'nate'
  6542. )));
  6543. $TestModel->id = 2;
  6544. $this->assertTrue($TestModel->isUnique(array(
  6545. 'user' => 'nate'
  6546. )));
  6547. $this->assertFalse($TestModel->isUnique(array(
  6548. 'user' => 'nate',
  6549. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6550. )));
  6551. }
  6552. /**
  6553. * test find('count') method
  6554. *
  6555. * @return void
  6556. */
  6557. public function testFindCount() {
  6558. $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag');
  6559. $TestModel = new User();
  6560. $this->db->getLog(false, true);
  6561. $result = $TestModel->find('count');
  6562. $this->assertEquals(4, $result);
  6563. $this->db->getLog(false, true);
  6564. $fullDebug = $this->db->fullDebug;
  6565. $this->db->fullDebug = true;
  6566. $TestModel->order = 'User.id';
  6567. $result = $TestModel->find('count');
  6568. $this->db->fullDebug = $fullDebug;
  6569. $this->assertEquals(4, $result);
  6570. $log = $this->db->getLog();
  6571. $this->assertTrue(isset($log['log'][0]['query']));
  6572. $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']);
  6573. $Article = new Article();
  6574. $Article->recursive = -1;
  6575. $expected = count($Article->find('all', array(
  6576. 'fields' => array('Article.user_id'),
  6577. 'group' => 'Article.user_id')
  6578. ));
  6579. $result = $Article->find('count', array('group' => array('Article.user_id')));
  6580. $this->assertEquals($expected, $result);
  6581. }
  6582. /**
  6583. * Test that find('first') does not use the id set to the object.
  6584. *
  6585. * @return void
  6586. */
  6587. public function testFindFirstNoIdUsed() {
  6588. $this->loadFixtures('Project');
  6589. $Project = new Project();
  6590. $Project->id = 3;
  6591. $result = $Project->find('first');
  6592. $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved');
  6593. }
  6594. /**
  6595. * test find with COUNT(DISTINCT field)
  6596. *
  6597. * @return void
  6598. */
  6599. public function testFindCountDistinct() {
  6600. $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
  6601. $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
  6602. $this->loadFixtures('Project');
  6603. $TestModel = new Project();
  6604. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6605. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6606. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6607. $result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
  6608. $this->assertEquals(4, $result);
  6609. }
  6610. /**
  6611. * Test find(count) with Db::expression
  6612. *
  6613. * @return void
  6614. */
  6615. public function testFindCountWithDbExpressions() {
  6616. $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');
  6617. $this->loadFixtures('Project', 'Thread');
  6618. $db = ConnectionManager::getDataSource('test');
  6619. $TestModel = new Project();
  6620. $result = $TestModel->find('count', array('conditions' => array(
  6621. $db->expression('Project.name = \'Project 3\'')
  6622. )));
  6623. $this->assertEquals(1, $result);
  6624. $result = $TestModel->find('count', array('conditions' => array(
  6625. 'Project.name' => $db->expression('\'Project 3\'')
  6626. )));
  6627. $this->assertEquals(1, $result);
  6628. }
  6629. /**
  6630. * testFindMagic method
  6631. *
  6632. * @return void
  6633. */
  6634. public function testFindMagic() {
  6635. $this->loadFixtures('User');
  6636. $TestModel = new User();
  6637. $result = $TestModel->findByUser('mariano');
  6638. $expected = array(
  6639. 'User' => array(
  6640. 'id' => '1',
  6641. 'user' => 'mariano',
  6642. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6643. 'created' => '2007-03-17 01:16:23',
  6644. 'updated' => '2007-03-17 01:18:31'
  6645. ));
  6646. $this->assertEquals($expected, $result);
  6647. $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99');
  6648. $expected = array('User' => array(
  6649. 'id' => '1',
  6650. 'user' => 'mariano',
  6651. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6652. 'created' => '2007-03-17 01:16:23',
  6653. 'updated' => '2007-03-17 01:18:31'
  6654. ));
  6655. $this->assertEquals($expected, $result);
  6656. }
  6657. /**
  6658. * testRead method
  6659. *
  6660. * @return void
  6661. */
  6662. public function testRead() {
  6663. $this->loadFixtures('User', 'Article');
  6664. $TestModel = new User();
  6665. $result = $TestModel->read();
  6666. $this->assertFalse($result);
  6667. $TestModel->id = 2;
  6668. $result = $TestModel->read();
  6669. $expected = array(
  6670. 'User' => array(
  6671. 'id' => '2',
  6672. 'user' => 'nate',
  6673. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6674. 'created' => '2007-03-17 01:18:23',
  6675. 'updated' => '2007-03-17 01:20:31'
  6676. ));
  6677. $this->assertEquals($expected, $result);
  6678. $result = $TestModel->read(null, 2);
  6679. $expected = array(
  6680. 'User' => array(
  6681. 'id' => '2',
  6682. 'user' => 'nate',
  6683. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6684. 'created' => '2007-03-17 01:18:23',
  6685. 'updated' => '2007-03-17 01:20:31'
  6686. ));
  6687. $this->assertEquals($expected, $result);
  6688. $TestModel->id = 2;
  6689. $result = $TestModel->read(array('id', 'user'));
  6690. $expected = array('User' => array('id' => '2', 'user' => 'nate'));
  6691. $this->assertEquals($expected, $result);
  6692. $result = $TestModel->read('id, user', 2);
  6693. $expected = array(
  6694. 'User' => array(
  6695. 'id' => '2',
  6696. 'user' => 'nate'
  6697. ));
  6698. $this->assertEquals($expected, $result);
  6699. $result = $TestModel->bindModel(array('hasMany' => array('Article')));
  6700. $this->assertTrue($result);
  6701. $TestModel->id = 1;
  6702. $result = $TestModel->read('id, user');
  6703. $expected = array(
  6704. 'User' => array(
  6705. 'id' => '1',
  6706. 'user' => 'mariano'
  6707. ),
  6708. 'Article' => array(
  6709. array(
  6710. 'id' => '1',
  6711. 'user_id' => '1',
  6712. 'title' => 'First Article',
  6713. 'body' => 'First Article Body',
  6714. 'published' => 'Y',
  6715. 'created' => '2007-03-18 10:39:23',
  6716. 'updated' => '2007-03-18 10:41:31'
  6717. ),
  6718. array(
  6719. 'id' => '3',
  6720. 'user_id' => '1',
  6721. 'title' => 'Third Article',
  6722. 'body' => 'Third Article Body',
  6723. 'published' => 'Y',
  6724. 'created' => '2007-03-18 10:43:23',
  6725. 'updated' => '2007-03-18 10:45:31'
  6726. )));
  6727. $this->assertEquals($expected, $result);
  6728. }
  6729. /**
  6730. * testRecursiveRead method
  6731. *
  6732. * @return void
  6733. */
  6734. public function testRecursiveRead() {
  6735. $this->loadFixtures(
  6736. 'User',
  6737. 'Article',
  6738. 'Comment',
  6739. 'Tag',
  6740. 'ArticlesTag',
  6741. 'Featured',
  6742. 'ArticleFeatured'
  6743. );
  6744. $TestModel = new User();
  6745. $result = $TestModel->bindModel(array('hasMany' => array('Article')), false);
  6746. $this->assertTrue($result);
  6747. $TestModel->recursive = 0;
  6748. $result = $TestModel->read('id, user', 1);
  6749. $expected = array(
  6750. 'User' => array('id' => '1', 'user' => 'mariano'),
  6751. );
  6752. $this->assertEquals($expected, $result);
  6753. $TestModel->recursive = 1;
  6754. $result = $TestModel->read('id, user', 1);
  6755. $expected = array(
  6756. 'User' => array(
  6757. 'id' => '1',
  6758. 'user' => 'mariano'
  6759. ),
  6760. 'Article' => array(
  6761. array(
  6762. 'id' => '1',
  6763. 'user_id' => '1',
  6764. 'title' => 'First Article',
  6765. 'body' => 'First Article Body',
  6766. 'published' => 'Y',
  6767. 'created' => '2007-03-18 10:39:23',
  6768. 'updated' => '2007-03-18 10:41:31'
  6769. ),
  6770. array(
  6771. 'id' => '3',
  6772. 'user_id' => '1',
  6773. 'title' => 'Third Article',
  6774. 'body' => 'Third Article Body',
  6775. 'published' => 'Y',
  6776. 'created' => '2007-03-18 10:43:23',
  6777. 'updated' => '2007-03-18 10:45:31'
  6778. )));
  6779. $this->assertEquals($expected, $result);
  6780. $TestModel->recursive = 2;
  6781. $result = $TestModel->read('id, user', 3);
  6782. $expected = array(
  6783. 'User' => array(
  6784. 'id' => '3',
  6785. 'user' => 'larry'
  6786. ),
  6787. 'Article' => array(
  6788. array(
  6789. 'id' => '2',
  6790. 'user_id' => '3',
  6791. 'title' => 'Second Article',
  6792. 'body' => 'Second Article Body',
  6793. 'published' => 'Y',
  6794. 'created' => '2007-03-18 10:41:23',
  6795. 'updated' => '2007-03-18 10:43:31',
  6796. 'User' => array(
  6797. 'id' => '3',
  6798. 'user' => 'larry',
  6799. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6800. 'created' => '2007-03-17 01:20:23',
  6801. 'updated' => '2007-03-17 01:22:31'
  6802. ),
  6803. 'Comment' => array(
  6804. array(
  6805. 'id' => '5',
  6806. 'article_id' => '2',
  6807. 'user_id' => '1',
  6808. 'comment' => 'First Comment for Second Article',
  6809. 'published' => 'Y',
  6810. 'created' => '2007-03-18 10:53:23',
  6811. 'updated' => '2007-03-18 10:55:31'
  6812. ),
  6813. array(
  6814. 'id' => '6',
  6815. 'article_id' => '2',
  6816. 'user_id' => '2',
  6817. 'comment' => 'Second Comment for Second Article',
  6818. 'published' => 'Y',
  6819. 'created' => '2007-03-18 10:55:23',
  6820. 'updated' => '2007-03-18 10:57:31'
  6821. )),
  6822. 'Tag' => array(
  6823. array(
  6824. 'id' => '1',
  6825. 'tag' => 'tag1',
  6826. 'created' => '2007-03-18 12:22:23',
  6827. 'updated' => '2007-03-18 12:24:31'
  6828. ),
  6829. array(
  6830. 'id' => '3',
  6831. 'tag' => 'tag3',
  6832. 'created' => '2007-03-18 12:26:23',
  6833. 'updated' => '2007-03-18 12:28:31'
  6834. )))));
  6835. $this->assertEquals($expected, $result);
  6836. }
  6837. public function testRecursiveFindAll() {
  6838. $this->loadFixtures(
  6839. 'User',
  6840. 'Article',
  6841. 'Comment',
  6842. 'Tag',
  6843. 'ArticlesTag',
  6844. 'Attachment',
  6845. 'ArticleFeatured',
  6846. 'ArticleFeaturedsTags',
  6847. 'Featured',
  6848. 'Category'
  6849. );
  6850. $TestModel = new Article();
  6851. $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1)));
  6852. $expected = array(
  6853. array(
  6854. 'Article' => array(
  6855. 'id' => '1',
  6856. 'user_id' => '1',
  6857. 'title' => 'First Article',
  6858. 'body' => 'First Article Body',
  6859. 'published' => 'Y',
  6860. 'created' => '2007-03-18 10:39:23',
  6861. 'updated' => '2007-03-18 10:41:31'
  6862. ),
  6863. 'User' => array(
  6864. 'id' => '1',
  6865. 'user' => 'mariano',
  6866. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6867. 'created' => '2007-03-17 01:16:23',
  6868. 'updated' => '2007-03-17 01:18:31'
  6869. ),
  6870. 'Comment' => array(
  6871. array(
  6872. 'id' => '1',
  6873. 'article_id' => '1',
  6874. 'user_id' => '2',
  6875. 'comment' => 'First Comment for First Article',
  6876. 'published' => 'Y',
  6877. 'created' => '2007-03-18 10:45:23',
  6878. 'updated' => '2007-03-18 10:47:31'
  6879. ),
  6880. array(
  6881. 'id' => '2',
  6882. 'article_id' => '1',
  6883. 'user_id' => '4',
  6884. 'comment' => 'Second Comment for First Article',
  6885. 'published' => 'Y',
  6886. 'created' => '2007-03-18 10:47:23',
  6887. 'updated' => '2007-03-18 10:49:31'
  6888. ),
  6889. array(
  6890. 'id' => '3',
  6891. 'article_id' => '1',
  6892. 'user_id' => '1',
  6893. 'comment' => 'Third Comment for First Article',
  6894. 'published' => 'Y',
  6895. 'created' => '2007-03-18 10:49:23',
  6896. 'updated' => '2007-03-18 10:51:31'
  6897. ),
  6898. array(
  6899. 'id' => '4',
  6900. 'article_id' => '1',
  6901. 'user_id' => '1',
  6902. 'comment' => 'Fourth Comment for First Article',
  6903. 'published' => 'N',
  6904. 'created' => '2007-03-18 10:51:23',
  6905. 'updated' => '2007-03-18 10:53:31'
  6906. )
  6907. ),
  6908. 'Tag' => array(
  6909. array(
  6910. 'id' => '1',
  6911. 'tag' => 'tag1',
  6912. 'created' => '2007-03-18 12:22:23',
  6913. 'updated' => '2007-03-18 12:24:31'
  6914. ),
  6915. array(
  6916. 'id' => '2',
  6917. 'tag' => 'tag2',
  6918. 'created' => '2007-03-18 12:24:23',
  6919. 'updated' => '2007-03-18 12:26:31'
  6920. ))),
  6921. array(
  6922. 'Article' => array(
  6923. 'id' => '3',
  6924. 'user_id' => '1',
  6925. 'title' => 'Third Article',
  6926. 'body' => 'Third Article Body',
  6927. 'published' => 'Y',
  6928. 'created' => '2007-03-18 10:43:23',
  6929. 'updated' => '2007-03-18 10:45:31'
  6930. ),
  6931. 'User' => array(
  6932. 'id' => '1',
  6933. 'user' => 'mariano',
  6934. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6935. 'created' => '2007-03-17 01:16:23',
  6936. 'updated' => '2007-03-17 01:18:31'
  6937. ),
  6938. 'Comment' => array(),
  6939. 'Tag' => array()
  6940. )
  6941. );
  6942. $this->assertEquals($expected, $result);
  6943. $result = $TestModel->find('all', array(
  6944. 'conditions' => array('Article.user_id' => 3),
  6945. 'limit' => 1,
  6946. 'recursive' => 2
  6947. ));
  6948. $expected = array(
  6949. array(
  6950. 'Article' => array(
  6951. 'id' => '2',
  6952. 'user_id' => '3',
  6953. 'title' => 'Second Article',
  6954. 'body' => 'Second Article Body',
  6955. 'published' => 'Y',
  6956. 'created' => '2007-03-18 10:41:23',
  6957. 'updated' => '2007-03-18 10:43:31'
  6958. ),
  6959. 'User' => array(
  6960. 'id' => '3',
  6961. 'user' => 'larry',
  6962. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6963. 'created' => '2007-03-17 01:20:23',
  6964. 'updated' => '2007-03-17 01:22:31'
  6965. ),
  6966. 'Comment' => array(
  6967. array(
  6968. 'id' => '5',
  6969. 'article_id' => '2',
  6970. 'user_id' => '1',
  6971. 'comment' => 'First Comment for Second Article',
  6972. 'published' => 'Y',
  6973. 'created' => '2007-03-18 10:53:23',
  6974. 'updated' => '2007-03-18 10:55:31',
  6975. 'Article' => array(
  6976. 'id' => '2',
  6977. 'user_id' => '3',
  6978. 'title' => 'Second Article',
  6979. 'body' => 'Second Article Body',
  6980. 'published' => 'Y',
  6981. 'created' => '2007-03-18 10:41:23',
  6982. 'updated' => '2007-03-18 10:43:31'
  6983. ),
  6984. 'User' => array(
  6985. 'id' => '1',
  6986. 'user' => 'mariano',
  6987. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6988. 'created' => '2007-03-17 01:16:23',
  6989. 'updated' => '2007-03-17 01:18:31'
  6990. ),
  6991. 'Attachment' => array(
  6992. 'id' => '1',
  6993. 'comment_id' => 5,
  6994. 'attachment' => 'attachment.zip',
  6995. 'created' => '2007-03-18 10:51:23',
  6996. 'updated' => '2007-03-18 10:53:31'
  6997. )
  6998. ),
  6999. array(
  7000. 'id' => '6',
  7001. 'article_id' => '2',
  7002. 'user_id' => '2',
  7003. 'comment' => 'Second Comment for Second Article',
  7004. 'published' => 'Y',
  7005. 'created' => '2007-03-18 10:55:23',
  7006. 'updated' => '2007-03-18 10:57:31',
  7007. 'Article' => array(
  7008. 'id' => '2',
  7009. 'user_id' => '3',
  7010. 'title' => 'Second Article',
  7011. 'body' => 'Second Article Body',
  7012. 'published' => 'Y',
  7013. 'created' => '2007-03-18 10:41:23',
  7014. 'updated' => '2007-03-18 10:43:31'
  7015. ),
  7016. 'User' => array(
  7017. 'id' => '2',
  7018. 'user' => 'nate',
  7019. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7020. 'created' => '2007-03-17 01:18:23',
  7021. 'updated' => '2007-03-17 01:20:31'
  7022. ),
  7023. 'Attachment' => array()
  7024. )
  7025. ),
  7026. 'Tag' => array(
  7027. array(
  7028. 'id' => '1',
  7029. 'tag' => 'tag1',
  7030. 'created' => '2007-03-18 12:22:23',
  7031. 'updated' => '2007-03-18 12:24:31'
  7032. ),
  7033. array(
  7034. 'id' => '3',
  7035. 'tag' => 'tag3',
  7036. 'created' => '2007-03-18 12:26:23',
  7037. 'updated' => '2007-03-18 12:28:31'
  7038. ))));
  7039. $this->assertEquals($expected, $result);
  7040. $Featured = new Featured();
  7041. $Featured->recursive = 2;
  7042. $Featured->bindModel(array(
  7043. 'belongsTo' => array(
  7044. 'ArticleFeatured' => array(
  7045. 'conditions' => "ArticleFeatured.published = 'Y'",
  7046. 'fields' => 'id, title, user_id, published'
  7047. )
  7048. )
  7049. ));
  7050. $Featured->ArticleFeatured->unbindModel(array(
  7051. 'hasMany' => array('Attachment', 'Comment'),
  7052. 'hasAndBelongsToMany' => array('Tag'))
  7053. );
  7054. $orderBy = 'ArticleFeatured.id ASC';
  7055. $result = $Featured->find('all', array(
  7056. 'order' => $orderBy, 'limit' => 3
  7057. ));
  7058. $expected = array(
  7059. array(
  7060. 'Featured' => array(
  7061. 'id' => '1',
  7062. 'article_featured_id' => '1',
  7063. 'category_id' => '1',
  7064. 'published_date' => '2007-03-31 10:39:23',
  7065. 'end_date' => '2007-05-15 10:39:23',
  7066. 'created' => '2007-03-18 10:39:23',
  7067. 'updated' => '2007-03-18 10:41:31'
  7068. ),
  7069. 'ArticleFeatured' => array(
  7070. 'id' => '1',
  7071. 'title' => 'First Article',
  7072. 'user_id' => '1',
  7073. 'published' => 'Y',
  7074. 'User' => array(
  7075. 'id' => '1',
  7076. 'user' => 'mariano',
  7077. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7078. 'created' => '2007-03-17 01:16:23',
  7079. 'updated' => '2007-03-17 01:18:31'
  7080. ),
  7081. 'Category' => array(),
  7082. 'Featured' => array(
  7083. 'id' => '1',
  7084. 'article_featured_id' => '1',
  7085. 'category_id' => '1',
  7086. 'published_date' => '2007-03-31 10:39:23',
  7087. 'end_date' => '2007-05-15 10:39:23',
  7088. 'created' => '2007-03-18 10:39:23',
  7089. 'updated' => '2007-03-18 10:41:31'
  7090. )),
  7091. 'Category' => array(
  7092. 'id' => '1',
  7093. 'parent_id' => '0',
  7094. 'name' => 'Category 1',
  7095. 'created' => '2007-03-18 15:30:23',
  7096. 'updated' => '2007-03-18 15:32:31'
  7097. )),
  7098. array(
  7099. 'Featured' => array(
  7100. 'id' => '2',
  7101. 'article_featured_id' => '2',
  7102. 'category_id' => '1',
  7103. 'published_date' => '2007-03-31 10:39:23',
  7104. 'end_date' => '2007-05-15 10:39:23',
  7105. 'created' => '2007-03-18 10:39:23',
  7106. 'updated' => '2007-03-18 10:41:31'
  7107. ),
  7108. 'ArticleFeatured' => array(
  7109. 'id' => '2',
  7110. 'title' => 'Second Article',
  7111. 'user_id' => '3',
  7112. 'published' => 'Y',
  7113. 'User' => array(
  7114. 'id' => '3',
  7115. 'user' => 'larry',
  7116. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7117. 'created' => '2007-03-17 01:20:23',
  7118. 'updated' => '2007-03-17 01:22:31'
  7119. ),
  7120. 'Category' => array(),
  7121. 'Featured' => array(
  7122. 'id' => '2',
  7123. 'article_featured_id' => '2',
  7124. 'category_id' => '1',
  7125. 'published_date' => '2007-03-31 10:39:23',
  7126. 'end_date' => '2007-05-15 10:39:23',
  7127. 'created' => '2007-03-18 10:39:23',
  7128. 'updated' => '2007-03-18 10:41:31'
  7129. )),
  7130. 'Category' => array(
  7131. 'id' => '1',
  7132. 'parent_id' => '0',
  7133. 'name' => 'Category 1',
  7134. 'created' => '2007-03-18 15:30:23',
  7135. 'updated' => '2007-03-18 15:32:31'
  7136. )));
  7137. $this->assertEquals($expected, $result);
  7138. }
  7139. /**
  7140. * testRecursiveFindAllWithLimit method
  7141. *
  7142. * @return void
  7143. */
  7144. public function testRecursiveFindAllWithLimit() {
  7145. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
  7146. $TestModel = new Article();
  7147. $TestModel->hasMany['Comment']['limit'] = 2;
  7148. $result = $TestModel->find('all', array(
  7149. 'conditions' => array('Article.user_id' => 1)
  7150. ));
  7151. $expected = array(
  7152. array(
  7153. 'Article' => array(
  7154. 'id' => '1',
  7155. 'user_id' => '1',
  7156. 'title' => 'First Article',
  7157. 'body' => 'First Article Body',
  7158. 'published' => 'Y',
  7159. 'created' => '2007-03-18 10:39:23',
  7160. 'updated' => '2007-03-18 10:41:31'
  7161. ),
  7162. 'User' => array(
  7163. 'id' => '1',
  7164. 'user' => 'mariano',
  7165. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7166. 'created' => '2007-03-17 01:16:23',
  7167. 'updated' => '2007-03-17 01:18:31'
  7168. ),
  7169. 'Comment' => array(
  7170. array(
  7171. 'id' => '1',
  7172. 'article_id' => '1',
  7173. 'user_id' => '2',
  7174. 'comment' => 'First Comment for First Article',
  7175. 'published' => 'Y',
  7176. 'created' => '2007-03-18 10:45:23',
  7177. 'updated' => '2007-03-18 10:47:31'
  7178. ),
  7179. array(
  7180. 'id' => '2',
  7181. 'article_id' => '1',
  7182. 'user_id' => '4',
  7183. 'comment' => 'Second Comment for First Article',
  7184. 'published' => 'Y',
  7185. 'created' => '2007-03-18 10:47:23',
  7186. 'updated' => '2007-03-18 10:49:31'
  7187. ),
  7188. ),
  7189. 'Tag' => array(
  7190. array(
  7191. 'id' => '1',
  7192. 'tag' => 'tag1',
  7193. 'created' => '2007-03-18 12:22:23',
  7194. 'updated' => '2007-03-18 12:24:31'
  7195. ),
  7196. array(
  7197. 'id' => '2',
  7198. 'tag' => 'tag2',
  7199. 'created' => '2007-03-18 12:24:23',
  7200. 'updated' => '2007-03-18 12:26:31'
  7201. ))),
  7202. array(
  7203. 'Article' => array(
  7204. 'id' => '3',
  7205. 'user_id' => '1',
  7206. 'title' => 'Third Article',
  7207. 'body' => 'Third Article Body',
  7208. 'published' => 'Y',
  7209. 'created' => '2007-03-18 10:43:23',
  7210. 'updated' => '2007-03-18 10:45:31'
  7211. ),
  7212. 'User' => array(
  7213. 'id' => '1',
  7214. 'user' => 'mariano',
  7215. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7216. 'created' => '2007-03-17 01:16:23',
  7217. 'updated' => '2007-03-17 01:18:31'
  7218. ),
  7219. 'Comment' => array(),
  7220. 'Tag' => array()
  7221. )
  7222. );
  7223. $this->assertEquals($expected, $result);
  7224. $TestModel->hasMany['Comment']['limit'] = 1;
  7225. $result = $TestModel->find('all', array(
  7226. 'conditions' => array('Article.user_id' => 3),
  7227. 'limit' => 1,
  7228. 'recursive' => 2
  7229. ));
  7230. $expected = array(
  7231. array(
  7232. 'Article' => array(
  7233. 'id' => '2',
  7234. 'user_id' => '3',
  7235. 'title' => 'Second Article',
  7236. 'body' => 'Second Article Body',
  7237. 'published' => 'Y',
  7238. 'created' => '2007-03-18 10:41:23',
  7239. 'updated' => '2007-03-18 10:43:31'
  7240. ),
  7241. 'User' => array(
  7242. 'id' => '3',
  7243. 'user' => 'larry',
  7244. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7245. 'created' => '2007-03-17 01:20:23',
  7246. 'updated' => '2007-03-17 01:22:31'
  7247. ),
  7248. 'Comment' => array(
  7249. array(
  7250. 'id' => '5',
  7251. 'article_id' => '2',
  7252. 'user_id' => '1',
  7253. 'comment' => 'First Comment for Second Article',
  7254. 'published' => 'Y',
  7255. 'created' => '2007-03-18 10:53:23',
  7256. 'updated' => '2007-03-18 10:55:31',
  7257. 'Article' => array(
  7258. 'id' => '2',
  7259. 'user_id' => '3',
  7260. 'title' => 'Second Article',
  7261. 'body' => 'Second Article Body',
  7262. 'published' => 'Y',
  7263. 'created' => '2007-03-18 10:41:23',
  7264. 'updated' => '2007-03-18 10:43:31'
  7265. ),
  7266. 'User' => array(
  7267. 'id' => '1',
  7268. 'user' => 'mariano',
  7269. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7270. 'created' => '2007-03-17 01:16:23',
  7271. 'updated' => '2007-03-17 01:18:31'
  7272. ),
  7273. 'Attachment' => array(
  7274. 'id' => '1',
  7275. 'comment_id' => 5,
  7276. 'attachment' => 'attachment.zip',
  7277. 'created' => '2007-03-18 10:51:23',
  7278. 'updated' => '2007-03-18 10:53:31'
  7279. )
  7280. )
  7281. ),
  7282. 'Tag' => array(
  7283. array(
  7284. 'id' => '1',
  7285. 'tag' => 'tag1',
  7286. 'created' => '2007-03-18 12:22:23',
  7287. 'updated' => '2007-03-18 12:24:31'
  7288. ),
  7289. array(
  7290. 'id' => '3',
  7291. 'tag' => 'tag3',
  7292. 'created' => '2007-03-18 12:26:23',
  7293. 'updated' => '2007-03-18 12:28:31'
  7294. )
  7295. )
  7296. )
  7297. );
  7298. $this->assertEquals($expected, $result);
  7299. }
  7300. /**
  7301. * Testing availability of $this->findQueryType in Model callbacks
  7302. *
  7303. * @return void
  7304. */
  7305. public function testFindQueryTypeInCallbacks() {
  7306. $this->loadFixtures('Comment');
  7307. $Comment = new AgainModifiedComment();
  7308. $comments = $Comment->find('all');
  7309. $this->assertEquals('all', $comments[0]['Comment']['querytype']);
  7310. $comments = $Comment->find('first');
  7311. $this->assertEquals('first', $comments['Comment']['querytype']);
  7312. }
  7313. /**
  7314. * testVirtualFields()
  7315. *
  7316. * Test correct fetching of virtual fields
  7317. * currently is not possible to do Relation.virtualField
  7318. *
  7319. * @return void
  7320. */
  7321. public function testVirtualFields() {
  7322. $this->loadFixtures('Post', 'Author');
  7323. $Post = ClassRegistry::init('Post');
  7324. $Post->virtualFields = array('two' => "1 + 1");
  7325. $result = $Post->find('first');
  7326. $this->assertEquals(2, $result['Post']['two']);
  7327. // SQL Server does not support operators in expressions
  7328. if (!($this->db instanceof Sqlserver)) {
  7329. $Post->Author->virtualFields = array('false' => '1 = 2');
  7330. $result = $Post->find('first');
  7331. $this->assertEquals(2, $result['Post']['two']);
  7332. $this->assertFalse((bool)$result['Author']['false']);
  7333. }
  7334. $result = $Post->find('first',array('fields' => array('author_id')));
  7335. $this->assertFalse(isset($result['Post']['two']));
  7336. $this->assertFalse(isset($result['Author']['false']));
  7337. $result = $Post->find('first',array('fields' => array('author_id', 'two')));
  7338. $this->assertEquals(2, $result['Post']['two']);
  7339. $this->assertFalse(isset($result['Author']['false']));
  7340. $result = $Post->find('first',array('fields' => array('two')));
  7341. $this->assertEquals(2, $result['Post']['two']);
  7342. $Post->id = 1;
  7343. $result = $Post->field('two');
  7344. $this->assertEquals(2, $result);
  7345. $result = $Post->find('first',array(
  7346. 'conditions' => array('two' => 2),
  7347. 'limit' => 1
  7348. ));
  7349. $this->assertEquals(2, $result['Post']['two']);
  7350. $result = $Post->find('first',array(
  7351. 'conditions' => array('two <' => 3),
  7352. 'limit' => 1
  7353. ));
  7354. $this->assertEquals(2, $result['Post']['two']);
  7355. $result = $Post->find('first',array(
  7356. 'conditions' => array('NOT' => array('two >' => 3)),
  7357. 'limit' => 1
  7358. ));
  7359. $this->assertEquals(2, $result['Post']['two']);
  7360. $dbo = $Post->getDataSource();
  7361. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7362. $result = $Post->find('first', array(
  7363. 'conditions' => array('other_field' => 3),
  7364. 'limit' => 1
  7365. ));
  7366. $this->assertEquals(2, $result['Post']['id']);
  7367. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7368. $result = $Post->find('all', array(
  7369. 'fields' => array($dbo->calculate($Post, 'max', array('other_field')))
  7370. ));
  7371. $this->assertEquals(4, $result[0][0]['other_field']);
  7372. ClassRegistry::flush();
  7373. $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
  7374. $Writing->virtualFields = array('two' => "1 + 1");
  7375. $result = $Writing->find('first');
  7376. $this->assertEquals(2, $result['Writing']['two']);
  7377. $Post->create();
  7378. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7379. $result = $Post->field('other_field');
  7380. $this->assertEquals(4, $result);
  7381. }
  7382. /**
  7383. * testVirtualFieldsOrder()
  7384. *
  7385. * Test correct order on virtual fields
  7386. *
  7387. * @return void
  7388. */
  7389. public function testVirtualFieldsOrder() {
  7390. $this->loadFixtures('Post', 'Author');
  7391. $Post = ClassRegistry::init('Post');
  7392. $Post->virtualFields = array('other_field' => '10 - Post.id');
  7393. $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC')));
  7394. $expected = array(
  7395. '3' => 'Third Post',
  7396. '2' => 'Second Post',
  7397. '1' => 'First Post'
  7398. );
  7399. $this->assertEquals($expected, $result);
  7400. $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC')));
  7401. $expected = array(
  7402. '1' => 'First Post',
  7403. '2' => 'Second Post',
  7404. '3' => 'Third Post'
  7405. );
  7406. $this->assertEquals($expected, $result);
  7407. $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id');
  7408. $result = $Post->find('all');
  7409. $result = Hash::extract($result, '{n}.Author.joined');
  7410. $expected = array(1, 6, 3);
  7411. $this->assertEquals($expected, $result);
  7412. $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC')));
  7413. $result = Hash::extract($result, '{n}.Author.joined');
  7414. $expected = array(1, 3, 6);
  7415. $this->assertEquals($expected, $result);
  7416. $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC')));
  7417. $result = Hash::extract($result, '{n}.Author.joined');
  7418. $expected = array(6, 3, 1);
  7419. $this->assertEquals($expected, $result);
  7420. }
  7421. /**
  7422. * testVirtualFieldsMysql()
  7423. *
  7424. * Test correct fetching of virtual fields
  7425. * currently is not possible to do Relation.virtualField
  7426. *
  7427. */
  7428. public function testVirtualFieldsMysql() {
  7429. $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.');
  7430. $this->loadFixtures('Post', 'Author');
  7431. $Post = ClassRegistry::init('Post');
  7432. $Post->create();
  7433. $Post->virtualFields = array(
  7434. 'low_title' => 'lower(Post.title)',
  7435. 'unique_test_field' => 'COUNT(Post.id)'
  7436. );
  7437. $expectation = array(
  7438. 'Post' => array(
  7439. 'low_title' => 'first post',
  7440. 'unique_test_field' => 1
  7441. )
  7442. );
  7443. $result = $Post->find('first', array(
  7444. 'fields' => array_keys($Post->virtualFields),
  7445. 'group' => array('low_title')
  7446. ));
  7447. $this->assertEquals($expectation, $result);
  7448. $Author = ClassRegistry::init('Author');
  7449. $Author->virtualFields = array(
  7450. 'full_name' => 'CONCAT(Author.user, " ", Author.id)'
  7451. );
  7452. $result = $Author->find('first', array(
  7453. 'conditions' => array('Author.user' => 'mariano'),
  7454. 'fields' => array('Author.password', 'Author.full_name'),
  7455. 'recursive' => -1
  7456. ));
  7457. $this->assertTrue(isset($result['Author']['full_name']));
  7458. $result = $Author->find('first', array(
  7459. 'conditions' => array('Author.user' => 'mariano'),
  7460. 'fields' => array('Author.full_name', 'Author.password'),
  7461. 'recursive' => -1
  7462. ));
  7463. $this->assertTrue(isset($result['Author']['full_name']));
  7464. }
  7465. /**
  7466. * test that virtual fields work when they don't contain functions.
  7467. *
  7468. * @return void
  7469. */
  7470. public function testVirtualFieldAsAString() {
  7471. $this->loadFixtures('Post', 'Author');
  7472. $Post = new Post();
  7473. $Post->virtualFields = array(
  7474. 'writer' => 'Author.user'
  7475. );
  7476. $result = $Post->find('first');
  7477. $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
  7478. }
  7479. /**
  7480. * test that isVirtualField will accept both aliased and non aliased fieldnames
  7481. *
  7482. * @return void
  7483. */
  7484. public function testIsVirtualField() {
  7485. $this->loadFixtures('Post');
  7486. $Post = ClassRegistry::init('Post');
  7487. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7488. $this->assertTrue($Post->isVirtualField('other_field'));
  7489. $this->assertTrue($Post->isVirtualField('Post.other_field'));
  7490. $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.');
  7491. $this->assertFalse($Post->isVirtualField('id'));
  7492. $this->assertFalse($Post->isVirtualField('Post.id'));
  7493. $this->assertFalse($Post->isVirtualField(array()));
  7494. }
  7495. /**
  7496. * test that getting virtual fields works with and without model alias attached
  7497. *
  7498. * @return void
  7499. */
  7500. public function testGetVirtualField() {
  7501. $this->loadFixtures('Post');
  7502. $Post = ClassRegistry::init('Post');
  7503. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7504. $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']);
  7505. $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
  7506. }
  7507. /**
  7508. * test that checks for error when NOT condition passed in key and a 1 element array value
  7509. *
  7510. * @return void
  7511. */
  7512. public function testNotInArrayWithOneValue() {
  7513. $this->loadFixtures('Article');
  7514. $Article = new Article();
  7515. $Article->recursive = -1;
  7516. $result = $Article->find(
  7517. 'all',
  7518. array(
  7519. 'conditions' => array(
  7520. 'Article.id NOT' => array(1)
  7521. )
  7522. )
  7523. );
  7524. $this->assertTrue(is_array($result) && !empty($result));
  7525. }
  7526. /**
  7527. * test custom find method
  7528. *
  7529. * @return void
  7530. */
  7531. public function testfindCustom() {
  7532. $this->loadFixtures('Article');
  7533. $Article = new CustomArticle();
  7534. $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  7535. $Article->create($data);
  7536. $Article->save(null, false);
  7537. $this->assertEquals(4, $Article->id);
  7538. $result = $Article->find('published');
  7539. $this->assertEquals(3, count($result));
  7540. $result = $Article->find('unPublished');
  7541. $this->assertEquals(1, count($result));
  7542. }
  7543. }