ModelReadTest.php 195 KB

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