ModelReadTest.php 202 KB

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