ModelReadTest.php 212 KB

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