ModelReadTest.php 194 KB

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