ModelReadTest.php 204 KB

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