ModelReadTest.php 204 KB

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