ModelReadTest.php 212 KB

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