ModelReadTest.php 205 KB

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