ModelReadTest.php 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931
  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('callbacks' => false));
  4943. $expected = array(
  4944. array(
  4945. 'Post' => array(
  4946. 'id' => '1',
  4947. 'author_id' => '1',
  4948. 'title' => 'First Post',
  4949. 'body' => 'First Post Body',
  4950. 'published' => 'Y',
  4951. 'created' => '2007-03-18 10:39:23',
  4952. 'updated' => '2007-03-18 10:41:31'
  4953. ),
  4954. 'Author' => array(
  4955. 'id' => '1',
  4956. 'user' => 'mariano',
  4957. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4958. 'created' => '2007-03-17 01:16:23',
  4959. 'updated' => '2007-03-17 01:18:31'
  4960. )),
  4961. array(
  4962. 'Post' => array(
  4963. 'id' => '2',
  4964. 'author_id' => '3',
  4965. 'title' => 'Second Post',
  4966. 'body' => 'Second Post Body',
  4967. 'published' => 'Y',
  4968. 'created' => '2007-03-18 10:41:23',
  4969. 'updated' => '2007-03-18 10:43:31'
  4970. ),
  4971. 'Author' => array(
  4972. 'id' => '3',
  4973. 'user' => 'larry',
  4974. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4975. 'created' => '2007-03-17 01:20:23',
  4976. 'updated' => '2007-03-17 01:22:31'
  4977. )),
  4978. array(
  4979. 'Post' => array(
  4980. 'id' => '3',
  4981. 'author_id' => '1',
  4982. 'title' => 'Third Post',
  4983. 'body' => 'Third Post Body',
  4984. 'published' => 'Y',
  4985. 'created' => '2007-03-18 10:43:23',
  4986. 'updated' => '2007-03-18 10:45:31'
  4987. ),
  4988. 'Author' => array(
  4989. 'id' => '1',
  4990. 'user' => 'mariano',
  4991. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4992. 'created' => '2007-03-17 01:16:23',
  4993. 'updated' => '2007-03-17 01:18:31'
  4994. )));
  4995. $this->assertEquals($expected, $result);
  4996. unset($TestModel);
  4997. $Author = new Author();
  4998. $Author->Post->bindModel(array(
  4999. 'hasMany' => array(
  5000. 'Comment' => array(
  5001. 'className' => 'ModifiedComment',
  5002. 'foreignKey' => 'article_id',
  5003. )
  5004. )));
  5005. $result = $Author->find('all', array(
  5006. 'conditions' => array('Author.id' => 1),
  5007. 'recursive' => 2,
  5008. 'callbacks' => false
  5009. ));
  5010. $expected = array(
  5011. 'id' => 1,
  5012. 'article_id' => 1,
  5013. 'user_id' => 2,
  5014. 'comment' => 'First Comment for First Article',
  5015. 'published' => 'Y',
  5016. 'created' => '2007-03-18 10:45:23',
  5017. 'updated' => '2007-03-18 10:47:31'
  5018. );
  5019. $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]);
  5020. }
  5021. /**
  5022. * Tests that the database configuration assigned to the model can be changed using
  5023. * (before|after)Find callbacks
  5024. *
  5025. * @return void
  5026. */
  5027. public function testCallbackSourceChange() {
  5028. $this->loadFixtures('Post');
  5029. $TestModel = new Post();
  5030. $this->assertEquals(3, count($TestModel->find('all')));
  5031. }
  5032. /**
  5033. * testCallbackSourceChangeUnknownDatasource method
  5034. *
  5035. * @expectedException MissingDatasourceConfigException
  5036. * @return void
  5037. */
  5038. public function testCallbackSourceChangeUnknownDatasource() {
  5039. $this->loadFixtures('Post', 'Author');
  5040. $TestModel = new Post();
  5041. $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
  5042. }
  5043. /**
  5044. * testMultipleBelongsToWithSameClass method
  5045. *
  5046. * @return void
  5047. */
  5048. public function testMultipleBelongsToWithSameClass() {
  5049. $this->loadFixtures(
  5050. 'DeviceType',
  5051. 'DeviceTypeCategory',
  5052. 'FeatureSet',
  5053. 'ExteriorTypeCategory',
  5054. 'Document',
  5055. 'Device',
  5056. 'DocumentDirectory'
  5057. );
  5058. $DeviceType = new DeviceType();
  5059. $DeviceType->recursive = 2;
  5060. $result = $DeviceType->read(null, 1);
  5061. $expected = array(
  5062. 'DeviceType' => array(
  5063. 'id' => 1,
  5064. 'device_type_category_id' => 1,
  5065. 'feature_set_id' => 1,
  5066. 'exterior_type_category_id' => 1,
  5067. 'image_id' => 1,
  5068. 'extra1_id' => 1,
  5069. 'extra2_id' => 1,
  5070. 'name' => 'DeviceType 1',
  5071. 'order' => 0
  5072. ),
  5073. 'Image' => array(
  5074. 'id' => 1,
  5075. 'document_directory_id' => 1,
  5076. 'name' => 'Document 1',
  5077. 'DocumentDirectory' => array(
  5078. 'id' => 1,
  5079. 'name' => 'DocumentDirectory 1'
  5080. )),
  5081. 'Extra1' => array(
  5082. 'id' => 1,
  5083. 'document_directory_id' => 1,
  5084. 'name' => 'Document 1',
  5085. 'DocumentDirectory' => array(
  5086. 'id' => 1,
  5087. 'name' => 'DocumentDirectory 1'
  5088. )),
  5089. 'Extra2' => array(
  5090. 'id' => 1,
  5091. 'document_directory_id' => 1,
  5092. 'name' => 'Document 1',
  5093. 'DocumentDirectory' => array(
  5094. 'id' => 1,
  5095. 'name' => 'DocumentDirectory 1'
  5096. )),
  5097. 'DeviceTypeCategory' => array(
  5098. 'id' => 1,
  5099. 'name' => 'DeviceTypeCategory 1'
  5100. ),
  5101. 'FeatureSet' => array(
  5102. 'id' => 1,
  5103. 'name' => 'FeatureSet 1'
  5104. ),
  5105. 'ExteriorTypeCategory' => array(
  5106. 'id' => 1,
  5107. 'image_id' => 1,
  5108. 'name' => 'ExteriorTypeCategory 1',
  5109. 'Image' => array(
  5110. 'id' => 1,
  5111. 'device_type_id' => 1,
  5112. 'name' => 'Device 1',
  5113. 'typ' => 1
  5114. )),
  5115. 'Device' => array(
  5116. array(
  5117. 'id' => 1,
  5118. 'device_type_id' => 1,
  5119. 'name' => 'Device 1',
  5120. 'typ' => 1
  5121. ),
  5122. array(
  5123. 'id' => 2,
  5124. 'device_type_id' => 1,
  5125. 'name' => 'Device 2',
  5126. 'typ' => 1
  5127. ),
  5128. array(
  5129. 'id' => 3,
  5130. 'device_type_id' => 1,
  5131. 'name' => 'Device 3',
  5132. 'typ' => 2
  5133. )));
  5134. $this->assertEquals($expected, $result);
  5135. }
  5136. /**
  5137. * testHabtmRecursiveBelongsTo method
  5138. *
  5139. * @return void
  5140. */
  5141. public function testHabtmRecursiveBelongsTo() {
  5142. $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
  5143. $Portfolio = new Portfolio();
  5144. $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3));
  5145. $expected = array(
  5146. 'Portfolio' => array(
  5147. 'id' => 2,
  5148. 'seller_id' => 1,
  5149. 'name' => 'Portfolio 2'
  5150. ),
  5151. 'Item' => array(
  5152. array(
  5153. 'id' => 2,
  5154. 'syfile_id' => 2,
  5155. 'published' => false,
  5156. 'name' => 'Item 2',
  5157. 'ItemsPortfolio' => array(
  5158. 'id' => 2,
  5159. 'item_id' => 2,
  5160. 'portfolio_id' => 2
  5161. ),
  5162. 'Syfile' => array(
  5163. 'id' => 2,
  5164. 'image_id' => 2,
  5165. 'name' => 'Syfile 2',
  5166. 'item_count' => null,
  5167. 'Image' => array(
  5168. 'id' => 2,
  5169. 'name' => 'Image 2'
  5170. )
  5171. )),
  5172. array(
  5173. 'id' => 6,
  5174. 'syfile_id' => 6,
  5175. 'published' => false,
  5176. 'name' => 'Item 6',
  5177. 'ItemsPortfolio' => array(
  5178. 'id' => 6,
  5179. 'item_id' => 6,
  5180. 'portfolio_id' => 2
  5181. ),
  5182. 'Syfile' => array(
  5183. 'id' => 6,
  5184. 'image_id' => null,
  5185. 'name' => 'Syfile 6',
  5186. 'item_count' => null,
  5187. 'Image' => array()
  5188. ))));
  5189. $this->assertEquals($expected, $result);
  5190. }
  5191. /**
  5192. * testNonNumericHabtmJoinKey method
  5193. *
  5194. * @return void
  5195. */
  5196. public function testNonNumericHabtmJoinKey() {
  5197. $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author');
  5198. $Post = new Post();
  5199. $Post->bindModel(array(
  5200. 'hasAndBelongsToMany' => array('Tag')
  5201. ));
  5202. $Post->Tag->primaryKey = 'tag';
  5203. $result = $Post->find('all');
  5204. $expected = array(
  5205. array(
  5206. 'Post' => array(
  5207. 'id' => '1',
  5208. 'author_id' => '1',
  5209. 'title' => 'First Post',
  5210. 'body' => 'First Post Body',
  5211. 'published' => 'Y',
  5212. 'created' => '2007-03-18 10:39:23',
  5213. 'updated' => '2007-03-18 10:41:31'
  5214. ),
  5215. 'Author' => array(
  5216. 'id' => 1,
  5217. 'user' => 'mariano',
  5218. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5219. 'created' => '2007-03-17 01:16:23',
  5220. 'updated' => '2007-03-17 01:18:31',
  5221. 'test' => 'working'
  5222. ),
  5223. 'Tag' => array(
  5224. array(
  5225. 'id' => '1',
  5226. 'tag' => 'tag1',
  5227. 'created' => '2007-03-18 12:22:23',
  5228. 'updated' => '2007-03-18 12:24:31'
  5229. ),
  5230. array(
  5231. 'id' => '2',
  5232. 'tag' => 'tag2',
  5233. 'created' => '2007-03-18 12:24:23',
  5234. 'updated' => '2007-03-18 12:26:31'
  5235. ))),
  5236. array(
  5237. 'Post' => array(
  5238. 'id' => '2',
  5239. 'author_id' => '3',
  5240. 'title' => 'Second Post',
  5241. 'body' => 'Second Post Body',
  5242. 'published' => 'Y',
  5243. 'created' => '2007-03-18 10:41:23',
  5244. 'updated' => '2007-03-18 10:43:31'
  5245. ),
  5246. 'Author' => array(
  5247. 'id' => 3,
  5248. 'user' => 'larry',
  5249. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5250. 'created' => '2007-03-17 01:20:23',
  5251. 'updated' => '2007-03-17 01:22:31',
  5252. 'test' => 'working'
  5253. ),
  5254. 'Tag' => array(
  5255. array(
  5256. 'id' => '1',
  5257. 'tag' => 'tag1',
  5258. 'created' => '2007-03-18 12:22:23',
  5259. 'updated' => '2007-03-18 12:24:31'
  5260. ),
  5261. array(
  5262. 'id' => '3',
  5263. 'tag' => 'tag3',
  5264. 'created' => '2007-03-18 12:26:23',
  5265. 'updated' => '2007-03-18 12:28:31'
  5266. ))),
  5267. array(
  5268. 'Post' => array(
  5269. 'id' => '3',
  5270. 'author_id' => '1',
  5271. 'title' => 'Third Post',
  5272. 'body' => 'Third Post Body',
  5273. 'published' => 'Y',
  5274. 'created' => '2007-03-18 10:43:23',
  5275. 'updated' => '2007-03-18 10:45:31'
  5276. ),
  5277. 'Author' => array(
  5278. 'id' => 1,
  5279. 'user' => 'mariano',
  5280. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5281. 'created' => '2007-03-17 01:16:23',
  5282. 'updated' => '2007-03-17 01:18:31',
  5283. 'test' => 'working'
  5284. ),
  5285. 'Tag' => array()
  5286. ));
  5287. $this->assertEquals($expected, $result);
  5288. }
  5289. /**
  5290. * testHabtmFinderQuery method
  5291. *
  5292. * @return void
  5293. */
  5294. public function testHabtmFinderQuery() {
  5295. $this->loadFixtures('Article', 'Tag', 'ArticlesTag');
  5296. $Article = new Article();
  5297. $sql = $this->db->buildStatement(
  5298. array(
  5299. 'fields' => $this->db->fields($Article->Tag, null, array(
  5300. 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id'
  5301. )),
  5302. 'table' => $this->db->fullTableName('tags'),
  5303. 'alias' => 'Tag',
  5304. 'limit' => null,
  5305. 'offset' => null,
  5306. 'group' => null,
  5307. 'joins' => array(array(
  5308. 'alias' => 'ArticlesTag',
  5309. 'table' => 'articles_tags',
  5310. 'conditions' => array(
  5311. array("ArticlesTag.article_id" => '{$__cakeID__$}'),
  5312. array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
  5313. )
  5314. )),
  5315. 'conditions' => array(),
  5316. 'order' => null
  5317. ),
  5318. $Article
  5319. );
  5320. $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
  5321. $result = $Article->find('first');
  5322. $expected = array(
  5323. array(
  5324. 'id' => '1',
  5325. 'tag' => 'tag1'
  5326. ),
  5327. array(
  5328. 'id' => '2',
  5329. 'tag' => 'tag2'
  5330. ));
  5331. $this->assertEquals($expected, $result['Tag']);
  5332. }
  5333. /**
  5334. * testHabtmLimitOptimization method
  5335. *
  5336. * @return void
  5337. */
  5338. public function testHabtmLimitOptimization() {
  5339. $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag');
  5340. $TestModel = new Article();
  5341. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2;
  5342. $result = $TestModel->read(null, 2);
  5343. $expected = array(
  5344. 'Article' => array(
  5345. 'id' => '2',
  5346. 'user_id' => '3',
  5347. 'title' => 'Second Article',
  5348. 'body' => 'Second Article Body',
  5349. 'published' => 'Y',
  5350. 'created' => '2007-03-18 10:41:23',
  5351. 'updated' => '2007-03-18 10:43:31'
  5352. ),
  5353. 'User' => array(
  5354. 'id' => '3',
  5355. 'user' => 'larry',
  5356. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5357. 'created' => '2007-03-17 01:20:23',
  5358. 'updated' => '2007-03-17 01:22:31'
  5359. ),
  5360. 'Comment' => array(
  5361. array(
  5362. 'id' => '5',
  5363. 'article_id' => '2',
  5364. 'user_id' => '1',
  5365. 'comment' => 'First Comment for Second Article',
  5366. 'published' => 'Y',
  5367. 'created' => '2007-03-18 10:53:23',
  5368. 'updated' => '2007-03-18 10:55:31'
  5369. ),
  5370. array(
  5371. 'id' => '6',
  5372. 'article_id' => '2',
  5373. 'user_id' => '2',
  5374. 'comment' => 'Second Comment for Second Article',
  5375. 'published' => 'Y',
  5376. 'created' => '2007-03-18 10:55:23',
  5377. 'updated' => '2007-03-18 10:57:31'
  5378. )),
  5379. 'Tag' => array(
  5380. array(
  5381. 'id' => '1',
  5382. 'tag' => 'tag1',
  5383. 'created' => '2007-03-18 12:22:23',
  5384. 'updated' => '2007-03-18 12:24:31'
  5385. ),
  5386. array(
  5387. 'id' => '3',
  5388. 'tag' => 'tag3',
  5389. 'created' => '2007-03-18 12:26:23',
  5390. 'updated' => '2007-03-18 12:28:31'
  5391. )));
  5392. $this->assertEquals($expected, $result);
  5393. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1;
  5394. $result = $TestModel->read(null, 2);
  5395. unset($expected['Tag'][1]);
  5396. $this->assertEquals($expected, $result);
  5397. }
  5398. /**
  5399. * testHasManyLimitOptimization method
  5400. *
  5401. * @return void
  5402. */
  5403. public function testHasManyLimitOptimization() {
  5404. $this->loadFixtures('Project', 'Thread', 'Message', 'Bid');
  5405. $Project = new Project();
  5406. $Project->recursive = 3;
  5407. $result = $Project->find('all');
  5408. $expected = array(
  5409. array(
  5410. 'Project' => array(
  5411. 'id' => 1,
  5412. 'name' => 'Project 1'
  5413. ),
  5414. 'Thread' => array(
  5415. array(
  5416. 'id' => 1,
  5417. 'project_id' => 1,
  5418. 'name' => 'Project 1, Thread 1',
  5419. 'Project' => array(
  5420. 'id' => 1,
  5421. 'name' => 'Project 1',
  5422. 'Thread' => array(
  5423. array(
  5424. 'id' => 1,
  5425. 'project_id' => 1,
  5426. 'name' => 'Project 1, Thread 1'
  5427. ),
  5428. array(
  5429. 'id' => 2,
  5430. 'project_id' => 1,
  5431. 'name' => 'Project 1, Thread 2'
  5432. ))),
  5433. 'Message' => array(
  5434. array(
  5435. 'id' => 1,
  5436. 'thread_id' => 1,
  5437. 'name' => 'Thread 1, Message 1',
  5438. 'Bid' => array(
  5439. 'id' => 1,
  5440. 'message_id' => 1,
  5441. 'name' => 'Bid 1.1'
  5442. )))),
  5443. array(
  5444. 'id' => 2,
  5445. 'project_id' => 1,
  5446. 'name' => 'Project 1, Thread 2',
  5447. 'Project' => array(
  5448. 'id' => 1,
  5449. 'name' => 'Project 1',
  5450. 'Thread' => array(
  5451. array(
  5452. 'id' => 1,
  5453. 'project_id' => 1,
  5454. 'name' => 'Project 1, Thread 1'
  5455. ),
  5456. array(
  5457. 'id' => 2,
  5458. 'project_id' => 1,
  5459. 'name' => 'Project 1, Thread 2'
  5460. ))),
  5461. 'Message' => array(
  5462. array(
  5463. 'id' => 2,
  5464. 'thread_id' => 2,
  5465. 'name' => 'Thread 2, Message 1',
  5466. 'Bid' => array(
  5467. 'id' => 4,
  5468. 'message_id' => 2,
  5469. 'name' => 'Bid 2.1'
  5470. )))))),
  5471. array(
  5472. 'Project' => array(
  5473. 'id' => 2,
  5474. 'name' => 'Project 2'
  5475. ),
  5476. 'Thread' => array(
  5477. array(
  5478. 'id' => 3,
  5479. 'project_id' => 2,
  5480. 'name' => 'Project 2, Thread 1',
  5481. 'Project' => array(
  5482. 'id' => 2,
  5483. 'name' => 'Project 2',
  5484. 'Thread' => array(
  5485. array(
  5486. 'id' => 3,
  5487. 'project_id' => 2,
  5488. 'name' => 'Project 2, Thread 1'
  5489. ))),
  5490. 'Message' => array(
  5491. array(
  5492. 'id' => 3,
  5493. 'thread_id' => 3,
  5494. 'name' => 'Thread 3, Message 1',
  5495. 'Bid' => array(
  5496. 'id' => 3,
  5497. 'message_id' => 3,
  5498. 'name' => 'Bid 3.1'
  5499. )))))),
  5500. array(
  5501. 'Project' => array(
  5502. 'id' => 3,
  5503. 'name' => 'Project 3'
  5504. ),
  5505. 'Thread' => array()
  5506. ));
  5507. $this->assertEquals($expected, $result);
  5508. }
  5509. /**
  5510. * testFindAllRecursiveSelfJoin method
  5511. *
  5512. * @return void
  5513. */
  5514. public function testFindAllRecursiveSelfJoin() {
  5515. $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement');
  5516. $TestModel = new Home();
  5517. $TestModel->recursive = 2;
  5518. $result = $TestModel->find('all');
  5519. $expected = array(
  5520. array(
  5521. 'Home' => array(
  5522. 'id' => '1',
  5523. 'another_article_id' => '1',
  5524. 'advertisement_id' => '1',
  5525. 'title' => 'First Home',
  5526. 'created' => '2007-03-18 10:39:23',
  5527. 'updated' => '2007-03-18 10:41:31'
  5528. ),
  5529. 'AnotherArticle' => array(
  5530. 'id' => '1',
  5531. 'title' => 'First Article',
  5532. 'created' => '2007-03-18 10:39:23',
  5533. 'updated' => '2007-03-18 10:41:31',
  5534. 'Home' => array(
  5535. array(
  5536. 'id' => '1',
  5537. 'another_article_id' => '1',
  5538. 'advertisement_id' => '1',
  5539. 'title' => 'First Home',
  5540. 'created' => '2007-03-18 10:39:23',
  5541. 'updated' => '2007-03-18 10:41:31'
  5542. ))),
  5543. 'Advertisement' => array(
  5544. 'id' => '1',
  5545. 'title' => 'First Ad',
  5546. 'created' => '2007-03-18 10:39:23',
  5547. 'updated' => '2007-03-18 10:41:31',
  5548. 'Home' => array(
  5549. array(
  5550. 'id' => '1',
  5551. 'another_article_id' => '1',
  5552. 'advertisement_id' => '1',
  5553. 'title' => 'First Home',
  5554. 'created' => '2007-03-18 10:39:23',
  5555. 'updated' => '2007-03-18 10:41:31'
  5556. ),
  5557. array(
  5558. 'id' => '2',
  5559. 'another_article_id' => '3',
  5560. 'advertisement_id' => '1',
  5561. 'title' => 'Second Home',
  5562. 'created' => '2007-03-18 10:41:23',
  5563. 'updated' => '2007-03-18 10:43:31'
  5564. )))),
  5565. array(
  5566. 'Home' => array(
  5567. 'id' => '2',
  5568. 'another_article_id' => '3',
  5569. 'advertisement_id' => '1',
  5570. 'title' => 'Second Home',
  5571. 'created' => '2007-03-18 10:41:23',
  5572. 'updated' => '2007-03-18 10:43:31'
  5573. ),
  5574. 'AnotherArticle' => array(
  5575. 'id' => '3',
  5576. 'title' => 'Third Article',
  5577. 'created' => '2007-03-18 10:43:23',
  5578. 'updated' => '2007-03-18 10:45:31',
  5579. 'Home' => array(
  5580. array(
  5581. 'id' => '2',
  5582. 'another_article_id' => '3',
  5583. 'advertisement_id' => '1',
  5584. 'title' => 'Second Home',
  5585. 'created' => '2007-03-18 10:41:23',
  5586. 'updated' => '2007-03-18 10:43:31'
  5587. ))),
  5588. 'Advertisement' => array(
  5589. 'id' => '1',
  5590. 'title' => 'First Ad',
  5591. 'created' => '2007-03-18 10:39:23',
  5592. 'updated' => '2007-03-18 10:41:31',
  5593. 'Home' => array(
  5594. array(
  5595. 'id' => '1',
  5596. 'another_article_id' => '1',
  5597. 'advertisement_id' => '1',
  5598. 'title' => 'First Home',
  5599. 'created' => '2007-03-18 10:39:23',
  5600. 'updated' => '2007-03-18 10:41:31'
  5601. ),
  5602. array(
  5603. 'id' => '2',
  5604. 'another_article_id' => '3',
  5605. 'advertisement_id' => '1',
  5606. 'title' => 'Second Home',
  5607. 'created' => '2007-03-18 10:41:23',
  5608. 'updated' => '2007-03-18 10:43:31'
  5609. )))));
  5610. $this->assertEquals($expected, $result);
  5611. }
  5612. /**
  5613. * testFindAllRecursiveWithHabtm method
  5614. *
  5615. * @return void
  5616. */
  5617. public function testFindAllRecursiveWithHabtm() {
  5618. $this->loadFixtures(
  5619. 'MyCategoriesMyUsers',
  5620. 'MyCategoriesMyProducts',
  5621. 'MyCategory',
  5622. 'MyUser',
  5623. 'MyProduct'
  5624. );
  5625. $MyUser = new MyUser();
  5626. $MyUser->recursive = 2;
  5627. $result = $MyUser->find('all');
  5628. $expected = array(
  5629. array(
  5630. 'MyUser' => array('id' => '1', 'firstname' => 'userA'),
  5631. 'MyCategory' => array(
  5632. array(
  5633. 'id' => '1',
  5634. 'name' => 'A',
  5635. 'MyProduct' => array(
  5636. array(
  5637. 'id' => '1',
  5638. 'name' => 'book'
  5639. ))),
  5640. array(
  5641. 'id' => '3',
  5642. 'name' => 'C',
  5643. 'MyProduct' => array(
  5644. array(
  5645. 'id' => '2',
  5646. 'name' => 'computer'
  5647. ))))),
  5648. array(
  5649. 'MyUser' => array(
  5650. 'id' => '2',
  5651. 'firstname' => 'userB'
  5652. ),
  5653. 'MyCategory' => array(
  5654. array(
  5655. 'id' => '1',
  5656. 'name' => 'A',
  5657. 'MyProduct' => array(
  5658. array(
  5659. 'id' => '1',
  5660. 'name' => 'book'
  5661. ))),
  5662. array(
  5663. 'id' => '2',
  5664. 'name' => 'B',
  5665. 'MyProduct' => array(
  5666. array(
  5667. 'id' => '1',
  5668. 'name' => 'book'
  5669. ),
  5670. array(
  5671. 'id' => '2',
  5672. 'name' => 'computer'
  5673. ))))));
  5674. $this->assertEquals($expected, $result);
  5675. }
  5676. /**
  5677. * testReadFakeThread method
  5678. *
  5679. * @return void
  5680. */
  5681. public function testReadFakeThread() {
  5682. $this->loadFixtures('CategoryThread');
  5683. $TestModel = new CategoryThread();
  5684. $fullDebug = $this->db->fullDebug;
  5685. $this->db->fullDebug = true;
  5686. $TestModel->recursive = 6;
  5687. $TestModel->id = 7;
  5688. $result = $TestModel->read();
  5689. $expected = array(
  5690. 'CategoryThread' => array(
  5691. 'id' => 7,
  5692. 'parent_id' => 6,
  5693. 'name' => 'Category 2.1',
  5694. 'created' => '2007-03-18 15:30:23',
  5695. 'updated' => '2007-03-18 15:32:31'
  5696. ),
  5697. 'ParentCategory' => array(
  5698. 'id' => 6,
  5699. 'parent_id' => 5,
  5700. 'name' => 'Category 2',
  5701. 'created' => '2007-03-18 15:30:23',
  5702. 'updated' => '2007-03-18 15:32:31',
  5703. 'ParentCategory' => array(
  5704. 'id' => 5,
  5705. 'parent_id' => 4,
  5706. 'name' => 'Category 1.1.1.1',
  5707. 'created' => '2007-03-18 15:30:23',
  5708. 'updated' => '2007-03-18 15:32:31',
  5709. 'ParentCategory' => array(
  5710. 'id' => 4,
  5711. 'parent_id' => 3,
  5712. 'name' => 'Category 1.1.2',
  5713. 'created' => '2007-03-18 15:30:23',
  5714. 'updated' => '2007-03-18 15:32:31',
  5715. 'ParentCategory' => array(
  5716. 'id' => 3,
  5717. 'parent_id' => 2,
  5718. 'name' => 'Category 1.1.1',
  5719. 'created' => '2007-03-18 15:30:23',
  5720. 'updated' => '2007-03-18 15:32:31',
  5721. 'ParentCategory' => array(
  5722. 'id' => 2,
  5723. 'parent_id' => 1,
  5724. 'name' => 'Category 1.1',
  5725. 'created' => '2007-03-18 15:30:23',
  5726. 'updated' => '2007-03-18 15:32:31',
  5727. 'ParentCategory' => array(
  5728. 'id' => 1,
  5729. 'parent_id' => 0,
  5730. 'name' => 'Category 1',
  5731. 'created' => '2007-03-18 15:30:23',
  5732. 'updated' => '2007-03-18 15:32:31'
  5733. )))))));
  5734. $this->db->fullDebug = $fullDebug;
  5735. $this->assertEquals($expected, $result);
  5736. }
  5737. /**
  5738. * testFindFakeThread method
  5739. *
  5740. * @return void
  5741. */
  5742. public function testFindFakeThread() {
  5743. $this->loadFixtures('CategoryThread');
  5744. $TestModel = new CategoryThread();
  5745. $fullDebug = $this->db->fullDebug;
  5746. $this->db->fullDebug = true;
  5747. $TestModel->recursive = 6;
  5748. $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7)));
  5749. $expected = array(
  5750. 'CategoryThread' => array(
  5751. 'id' => 7,
  5752. 'parent_id' => 6,
  5753. 'name' => 'Category 2.1',
  5754. 'created' => '2007-03-18 15:30:23',
  5755. 'updated' => '2007-03-18 15:32:31'
  5756. ),
  5757. 'ParentCategory' => array(
  5758. 'id' => 6,
  5759. 'parent_id' => 5,
  5760. 'name' => 'Category 2',
  5761. 'created' => '2007-03-18 15:30:23',
  5762. 'updated' => '2007-03-18 15:32:31',
  5763. 'ParentCategory' => array(
  5764. 'id' => 5,
  5765. 'parent_id' => 4,
  5766. 'name' => 'Category 1.1.1.1',
  5767. 'created' => '2007-03-18 15:30:23',
  5768. 'updated' => '2007-03-18 15:32:31',
  5769. 'ParentCategory' => array(
  5770. 'id' => 4,
  5771. 'parent_id' => 3,
  5772. 'name' => 'Category 1.1.2',
  5773. 'created' => '2007-03-18 15:30:23',
  5774. 'updated' => '2007-03-18 15:32:31',
  5775. 'ParentCategory' => array(
  5776. 'id' => 3,
  5777. 'parent_id' => 2,
  5778. 'name' => 'Category 1.1.1',
  5779. 'created' => '2007-03-18 15:30:23',
  5780. 'updated' => '2007-03-18 15:32:31',
  5781. 'ParentCategory' => array(
  5782. 'id' => 2,
  5783. 'parent_id' => 1,
  5784. 'name' => 'Category 1.1',
  5785. 'created' => '2007-03-18 15:30:23',
  5786. 'updated' => '2007-03-18 15:32:31',
  5787. 'ParentCategory' => array(
  5788. 'id' => 1,
  5789. 'parent_id' => 0,
  5790. 'name' => 'Category 1',
  5791. 'created' => '2007-03-18 15:30:23',
  5792. 'updated' => '2007-03-18 15:32:31'
  5793. )))))));
  5794. $this->db->fullDebug = $fullDebug;
  5795. $this->assertEquals($expected, $result);
  5796. }
  5797. /**
  5798. * testFindAllFakeThread method
  5799. *
  5800. * @return void
  5801. */
  5802. public function testFindAllFakeThread() {
  5803. $this->loadFixtures('CategoryThread');
  5804. $TestModel = new CategoryThread();
  5805. $fullDebug = $this->db->fullDebug;
  5806. $this->db->fullDebug = true;
  5807. $TestModel->recursive = 6;
  5808. $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC');
  5809. $expected = array(
  5810. array(
  5811. 'CategoryThread' => array(
  5812. 'id' => 1,
  5813. 'parent_id' => 0,
  5814. 'name' => 'Category 1',
  5815. 'created' => '2007-03-18 15:30:23',
  5816. 'updated' => '2007-03-18 15:32:31'
  5817. ),
  5818. 'ParentCategory' => array(
  5819. 'id' => null,
  5820. 'parent_id' => null,
  5821. 'name' => null,
  5822. 'created' => null,
  5823. 'updated' => null,
  5824. 'ParentCategory' => array()
  5825. )),
  5826. array(
  5827. 'CategoryThread' => array(
  5828. 'id' => 2,
  5829. 'parent_id' => 1,
  5830. 'name' => 'Category 1.1',
  5831. 'created' => '2007-03-18 15:30:23',
  5832. 'updated' => '2007-03-18 15:32:31'
  5833. ),
  5834. 'ParentCategory' => array(
  5835. 'id' => 1,
  5836. 'parent_id' => 0,
  5837. 'name' => 'Category 1',
  5838. 'created' => '2007-03-18 15:30:23',
  5839. 'updated' => '2007-03-18 15:32:31',
  5840. 'ParentCategory' => array()
  5841. )),
  5842. array(
  5843. 'CategoryThread' => array(
  5844. 'id' => 3,
  5845. 'parent_id' => 2,
  5846. 'name' => 'Category 1.1.1',
  5847. 'created' => '2007-03-18 15:30:23',
  5848. 'updated' => '2007-03-18 15:32:31'
  5849. ),
  5850. 'ParentCategory' => array(
  5851. 'id' => 2,
  5852. 'parent_id' => 1,
  5853. 'name' => 'Category 1.1',
  5854. 'created' => '2007-03-18 15:30:23',
  5855. 'updated' => '2007-03-18 15:32:31',
  5856. 'ParentCategory' => array(
  5857. 'id' => 1,
  5858. 'parent_id' => 0,
  5859. 'name' => 'Category 1',
  5860. 'created' => '2007-03-18 15:30:23',
  5861. 'updated' => '2007-03-18 15:32:31',
  5862. 'ParentCategory' => array()
  5863. ))),
  5864. array(
  5865. 'CategoryThread' => array(
  5866. 'id' => 4,
  5867. 'parent_id' => 3,
  5868. 'name' => 'Category 1.1.2',
  5869. 'created' => '2007-03-18 15:30:23',
  5870. 'updated' => '2007-03-18 15:32:31'
  5871. ),
  5872. 'ParentCategory' => array(
  5873. 'id' => 3,
  5874. 'parent_id' => 2,
  5875. 'name' => 'Category 1.1.1',
  5876. 'created' => '2007-03-18 15:30:23',
  5877. 'updated' => '2007-03-18 15:32:31',
  5878. 'ParentCategory' => array(
  5879. 'id' => 2,
  5880. 'parent_id' => 1,
  5881. 'name' => 'Category 1.1',
  5882. 'created' => '2007-03-18 15:30:23',
  5883. 'updated' => '2007-03-18 15:32:31',
  5884. 'ParentCategory' => array(
  5885. 'id' => 1,
  5886. 'parent_id' => 0,
  5887. 'name' => 'Category 1',
  5888. 'created' => '2007-03-18 15:30:23',
  5889. 'updated' => '2007-03-18 15:32:31',
  5890. 'ParentCategory' => array()
  5891. )))),
  5892. array(
  5893. 'CategoryThread' => array(
  5894. 'id' => 5,
  5895. 'parent_id' => 4,
  5896. 'name' => 'Category 1.1.1.1',
  5897. 'created' => '2007-03-18 15:30:23',
  5898. 'updated' => '2007-03-18 15:32:31'
  5899. ),
  5900. 'ParentCategory' => array(
  5901. 'id' => 4,
  5902. 'parent_id' => 3,
  5903. 'name' => 'Category 1.1.2',
  5904. 'created' => '2007-03-18 15:30:23',
  5905. 'updated' => '2007-03-18 15:32:31',
  5906. 'ParentCategory' => array(
  5907. 'id' => 3,
  5908. 'parent_id' => 2,
  5909. 'name' => 'Category 1.1.1',
  5910. 'created' => '2007-03-18 15:30:23',
  5911. 'updated' => '2007-03-18 15:32:31',
  5912. 'ParentCategory' => array(
  5913. 'id' => 2,
  5914. 'parent_id' => 1,
  5915. 'name' => 'Category 1.1',
  5916. 'created' => '2007-03-18 15:30:23',
  5917. 'updated' => '2007-03-18 15:32:31',
  5918. 'ParentCategory' => array(
  5919. 'id' => 1,
  5920. 'parent_id' => 0,
  5921. 'name' => 'Category 1',
  5922. 'created' => '2007-03-18 15:30:23',
  5923. 'updated' => '2007-03-18 15:32:31',
  5924. 'ParentCategory' => array()
  5925. ))))),
  5926. array(
  5927. 'CategoryThread' => array(
  5928. 'id' => 6,
  5929. 'parent_id' => 5,
  5930. 'name' => 'Category 2',
  5931. 'created' => '2007-03-18 15:30:23',
  5932. 'updated' => '2007-03-18 15:32:31'
  5933. ),
  5934. 'ParentCategory' => array(
  5935. 'id' => 5,
  5936. 'parent_id' => 4,
  5937. 'name' => 'Category 1.1.1.1',
  5938. 'created' => '2007-03-18 15:30:23',
  5939. 'updated' => '2007-03-18 15:32:31',
  5940. 'ParentCategory' => array(
  5941. 'id' => 4,
  5942. 'parent_id' => 3,
  5943. 'name' => 'Category 1.1.2',
  5944. 'created' => '2007-03-18 15:30:23',
  5945. 'updated' => '2007-03-18 15:32:31',
  5946. 'ParentCategory' => array(
  5947. 'id' => 3,
  5948. 'parent_id' => 2,
  5949. 'name' => 'Category 1.1.1',
  5950. 'created' => '2007-03-18 15:30:23',
  5951. 'updated' => '2007-03-18 15:32:31',
  5952. 'ParentCategory' => array(
  5953. 'id' => 2,
  5954. 'parent_id' => 1,
  5955. 'name' => 'Category 1.1',
  5956. 'created' => '2007-03-18 15:30:23',
  5957. 'updated' => '2007-03-18 15:32:31',
  5958. 'ParentCategory' => array(
  5959. 'id' => 1,
  5960. 'parent_id' => 0,
  5961. 'name' => 'Category 1',
  5962. 'created' => '2007-03-18 15:30:23',
  5963. 'updated' => '2007-03-18 15:32:31',
  5964. 'ParentCategory' => array()
  5965. )))))),
  5966. array(
  5967. 'CategoryThread' => array(
  5968. 'id' => 7,
  5969. 'parent_id' => 6,
  5970. 'name' => 'Category 2.1',
  5971. 'created' => '2007-03-18 15:30:23',
  5972. 'updated' => '2007-03-18 15:32:31'
  5973. ),
  5974. 'ParentCategory' => array(
  5975. 'id' => 6,
  5976. 'parent_id' => 5,
  5977. 'name' => 'Category 2',
  5978. 'created' => '2007-03-18 15:30:23',
  5979. 'updated' => '2007-03-18 15:32:31',
  5980. 'ParentCategory' => array(
  5981. 'id' => 5,
  5982. 'parent_id' => 4,
  5983. 'name' => 'Category 1.1.1.1',
  5984. 'created' => '2007-03-18 15:30:23',
  5985. 'updated' => '2007-03-18 15:32:31',
  5986. 'ParentCategory' => array(
  5987. 'id' => 4,
  5988. 'parent_id' => 3,
  5989. 'name' => 'Category 1.1.2',
  5990. 'created' => '2007-03-18 15:30:23',
  5991. 'updated' => '2007-03-18 15:32:31',
  5992. 'ParentCategory' => array(
  5993. 'id' => 3,
  5994. 'parent_id' => 2,
  5995. 'name' => 'Category 1.1.1',
  5996. 'created' => '2007-03-18 15:30:23',
  5997. 'updated' => '2007-03-18 15:32:31',
  5998. 'ParentCategory' => array(
  5999. 'id' => 2,
  6000. 'parent_id' => 1,
  6001. 'name' => 'Category 1.1',
  6002. 'created' => '2007-03-18 15:30:23',
  6003. 'updated' => '2007-03-18 15:32:31',
  6004. 'ParentCategory' => array(
  6005. 'id' => 1,
  6006. 'parent_id' => 0,
  6007. 'name' => 'Category 1',
  6008. 'created' => '2007-03-18 15:30:23',
  6009. 'updated' => '2007-03-18 15:32:31'
  6010. ))))))));
  6011. $this->db->fullDebug = $fullDebug;
  6012. $this->assertEquals($expected, $result);
  6013. }
  6014. /**
  6015. * testConditionalNumerics method
  6016. *
  6017. * @return void
  6018. */
  6019. public function testConditionalNumerics() {
  6020. $this->loadFixtures('NumericArticle');
  6021. $NumericArticle = new NumericArticle();
  6022. $data = array('conditions' => array('title' => '12345abcde'));
  6023. $result = $NumericArticle->find('first', $data);
  6024. $this->assertTrue(!empty($result));
  6025. $data = array('conditions' => array('title' => '12345'));
  6026. $result = $NumericArticle->find('first', $data);
  6027. $this->assertTrue(empty($result));
  6028. }
  6029. /**
  6030. * test buildQuery()
  6031. *
  6032. * @return void
  6033. */
  6034. public function testBuildQuery() {
  6035. $this->loadFixtures('User');
  6036. $TestModel = new User();
  6037. $TestModel->cacheQueries = false;
  6038. $expected = array(
  6039. 'conditions' => array(
  6040. 'user' => 'larry'
  6041. ),
  6042. 'fields' => null,
  6043. 'joins' => array(),
  6044. 'limit' => null,
  6045. 'offset' => null,
  6046. 'order' => array(
  6047. 0 => null
  6048. ),
  6049. 'page' => 1,
  6050. 'group' => null,
  6051. 'callbacks' => true,
  6052. 'returnQuery' => true
  6053. );
  6054. $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry')));
  6055. $this->assertEquals($expected, $result);
  6056. }
  6057. /**
  6058. * test find('all') method
  6059. *
  6060. * @return void
  6061. */
  6062. public function testFindAll() {
  6063. $this->loadFixtures('User');
  6064. $TestModel = new User();
  6065. $TestModel->cacheQueries = false;
  6066. $result = $TestModel->find('all');
  6067. $expected = array(
  6068. array(
  6069. 'User' => array(
  6070. 'id' => '1',
  6071. 'user' => 'mariano',
  6072. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6073. 'created' => '2007-03-17 01:16:23',
  6074. 'updated' => '2007-03-17 01:18:31'
  6075. )),
  6076. array(
  6077. 'User' => array(
  6078. 'id' => '2',
  6079. 'user' => 'nate',
  6080. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6081. 'created' => '2007-03-17 01:18:23',
  6082. 'updated' => '2007-03-17 01:20:31'
  6083. )),
  6084. array(
  6085. 'User' => array(
  6086. 'id' => '3',
  6087. 'user' => 'larry',
  6088. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6089. 'created' => '2007-03-17 01:20:23',
  6090. 'updated' => '2007-03-17 01:22:31'
  6091. )),
  6092. array(
  6093. 'User' => array(
  6094. 'id' => '4',
  6095. 'user' => 'garrett',
  6096. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6097. 'created' => '2007-03-17 01:22:23',
  6098. 'updated' => '2007-03-17 01:24:31'
  6099. )));
  6100. $this->assertEquals($expected, $result);
  6101. $result = $TestModel->find('all', array('conditions' => 'User.id > 2'));
  6102. $expected = array(
  6103. array(
  6104. 'User' => array(
  6105. 'id' => '3',
  6106. 'user' => 'larry',
  6107. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6108. 'created' => '2007-03-17 01:20:23',
  6109. 'updated' => '2007-03-17 01:22:31'
  6110. )),
  6111. array(
  6112. 'User' => array(
  6113. 'id' => '4',
  6114. 'user' => 'garrett',
  6115. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6116. 'created' => '2007-03-17 01:22:23',
  6117. 'updated' => '2007-03-17 01:24:31'
  6118. )));
  6119. $this->assertEquals($expected, $result);
  6120. $result = $TestModel->find('all', array(
  6121. 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%')
  6122. ));
  6123. $expected = array(
  6124. array(
  6125. 'User' => array(
  6126. 'id' => '3',
  6127. 'user' => 'larry',
  6128. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6129. 'created' => '2007-03-17 01:20:23',
  6130. 'updated' => '2007-03-17 01:22:31'
  6131. )),
  6132. array(
  6133. 'User' => array(
  6134. 'id' => '4',
  6135. 'user' => 'garrett',
  6136. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6137. 'created' => '2007-03-17 01:22:23',
  6138. 'updated' => '2007-03-17 01:24:31'
  6139. )));
  6140. $this->assertEquals($expected, $result);
  6141. $result = $TestModel->find('all', array('conditions' => array('User.id' => '0')));
  6142. $expected = array();
  6143. $this->assertEquals($expected, $result);
  6144. $result = $TestModel->find('all', array(
  6145. 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%')
  6146. )));
  6147. $expected = array(
  6148. array(
  6149. 'User' => array(
  6150. 'id' => '1',
  6151. 'user' => 'mariano',
  6152. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6153. 'created' => '2007-03-17 01:16:23',
  6154. 'updated' => '2007-03-17 01:18:31'
  6155. )),
  6156. array(
  6157. 'User' => array(
  6158. 'id' => '2',
  6159. 'user' => 'nate',
  6160. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6161. 'created' => '2007-03-17 01:18:23',
  6162. 'updated' => '2007-03-17 01:20:31'
  6163. )),
  6164. array(
  6165. 'User' => array(
  6166. 'id' => '3',
  6167. 'user' => 'larry',
  6168. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6169. 'created' => '2007-03-17 01:20:23',
  6170. 'updated' => '2007-03-17 01:22:31'
  6171. )),
  6172. array(
  6173. 'User' => array(
  6174. 'id' => '4',
  6175. 'user' => 'garrett',
  6176. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6177. 'created' => '2007-03-17 01:22:23',
  6178. 'updated' => '2007-03-17 01:24:31'
  6179. )));
  6180. $this->assertEquals($expected, $result);
  6181. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  6182. $expected = array(
  6183. array('User' => array('id' => '1', 'user' => 'mariano')),
  6184. array('User' => array('id' => '2', 'user' => 'nate')),
  6185. array('User' => array('id' => '3', 'user' => 'larry')),
  6186. array('User' => array('id' => '4', 'user' => 'garrett')));
  6187. $this->assertEquals($expected, $result);
  6188. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC'));
  6189. $expected = array(
  6190. array('User' => array('user' => 'garrett')),
  6191. array('User' => array('user' => 'larry')),
  6192. array('User' => array('user' => 'mariano')),
  6193. array('User' => array('user' => 'nate')));
  6194. $this->assertEquals($expected, $result);
  6195. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC'));
  6196. $expected = array(
  6197. array('User' => array('user' => 'nate')),
  6198. array('User' => array('user' => 'mariano')),
  6199. array('User' => array('user' => 'larry')),
  6200. array('User' => array('user' => 'garrett')));
  6201. $this->assertEquals($expected, $result);
  6202. $result = $TestModel->find('all', array('limit' => 3, 'page' => 1));
  6203. $expected = array(
  6204. array(
  6205. 'User' => array(
  6206. 'id' => '1',
  6207. 'user' => 'mariano',
  6208. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6209. 'created' => '2007-03-17 01:16:23',
  6210. 'updated' => '2007-03-17 01:18:31'
  6211. )),
  6212. array(
  6213. 'User' => array(
  6214. 'id' => '2',
  6215. 'user' => 'nate',
  6216. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6217. 'created' => '2007-03-17 01:18:23',
  6218. 'updated' => '2007-03-17 01:20:31'
  6219. )),
  6220. array(
  6221. 'User' => array(
  6222. 'id' => '3',
  6223. 'user' => 'larry',
  6224. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6225. 'created' => '2007-03-17 01:20:23',
  6226. 'updated' => '2007-03-17 01:22:31'
  6227. )));
  6228. $this->assertEquals($expected, $result);
  6229. $ids = array(4 => 1, 5 => 3);
  6230. $result = $TestModel->find('all', array(
  6231. 'conditions' => array('User.id' => $ids),
  6232. 'order' => 'User.id'
  6233. ));
  6234. $expected = array(
  6235. array(
  6236. 'User' => array(
  6237. 'id' => '1',
  6238. 'user' => 'mariano',
  6239. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6240. 'created' => '2007-03-17 01:16:23',
  6241. 'updated' => '2007-03-17 01:18:31'
  6242. )),
  6243. array(
  6244. 'User' => array(
  6245. 'id' => '3',
  6246. 'user' => 'larry',
  6247. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6248. 'created' => '2007-03-17 01:20:23',
  6249. 'updated' => '2007-03-17 01:22:31'
  6250. )));
  6251. $this->assertEquals($expected, $result);
  6252. // These tests are expected to fail on SQL Server since the LIMIT/OFFSET
  6253. // hack can't handle small record counts.
  6254. if (!($this->db instanceof Sqlserver)) {
  6255. $result = $TestModel->find('all', array('limit' => 3, 'page' => 2));
  6256. $expected = array(
  6257. array(
  6258. 'User' => array(
  6259. 'id' => '4',
  6260. 'user' => 'garrett',
  6261. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6262. 'created' => '2007-03-17 01:22:23',
  6263. 'updated' => '2007-03-17 01:24:31'
  6264. )));
  6265. $this->assertEquals($expected, $result);
  6266. $result = $TestModel->find('all', array('limit' => 3, 'page' => 3));
  6267. $expected = array();
  6268. $this->assertEquals($expected, $result);
  6269. }
  6270. }
  6271. /**
  6272. * test find('list') method
  6273. *
  6274. * @return void
  6275. */
  6276. public function testGenerateFindList() {
  6277. $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment');
  6278. $TestModel = new Article();
  6279. $TestModel->displayField = 'title';
  6280. $result = $TestModel->find('list', array(
  6281. 'order' => 'Article.title ASC'
  6282. ));
  6283. $expected = array(
  6284. 1 => 'First Article',
  6285. 2 => 'Second Article',
  6286. 3 => 'Third Article'
  6287. );
  6288. $this->assertEquals($expected, $result);
  6289. $db = ConnectionManager::getDataSource('test');
  6290. if ($db instanceof Mysql) {
  6291. $result = $TestModel->find('list', array(
  6292. 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC')
  6293. ));
  6294. $expected = array(
  6295. 1 => 'First Article',
  6296. 3 => 'Third Article',
  6297. 2 => 'Second Article'
  6298. );
  6299. $this->assertEquals($expected, $result);
  6300. }
  6301. $result = Hash::combine(
  6302. $TestModel->find('all', array(
  6303. 'order' => 'Article.title ASC',
  6304. 'fields' => array('id', 'title')
  6305. )),
  6306. '{n}.Article.id', '{n}.Article.title'
  6307. );
  6308. $expected = array(
  6309. 1 => 'First Article',
  6310. 2 => 'Second Article',
  6311. 3 => 'Third Article'
  6312. );
  6313. $this->assertEquals($expected, $result);
  6314. $result = Hash::combine(
  6315. $TestModel->find('all', array(
  6316. 'order' => 'Article.title ASC'
  6317. )),
  6318. '{n}.Article.id', '{n}.Article'
  6319. );
  6320. $expected = array(
  6321. 1 => array(
  6322. 'id' => 1,
  6323. 'user_id' => 1,
  6324. 'title' => 'First Article',
  6325. 'body' => 'First Article Body',
  6326. 'published' => 'Y',
  6327. 'created' => '2007-03-18 10:39:23',
  6328. 'updated' => '2007-03-18 10:41:31'
  6329. ),
  6330. 2 => array(
  6331. 'id' => 2,
  6332. 'user_id' => 3,
  6333. 'title' => 'Second Article',
  6334. 'body' => 'Second Article Body',
  6335. 'published' => 'Y',
  6336. 'created' => '2007-03-18 10:41:23',
  6337. 'updated' => '2007-03-18 10:43:31'
  6338. ),
  6339. 3 => array(
  6340. 'id' => 3,
  6341. 'user_id' => 1,
  6342. 'title' => 'Third Article',
  6343. 'body' => 'Third Article Body',
  6344. 'published' => 'Y',
  6345. 'created' => '2007-03-18 10:43:23',
  6346. 'updated' => '2007-03-18 10:45:31'
  6347. ));
  6348. $this->assertEquals($expected, $result);
  6349. $result = Hash::combine(
  6350. $TestModel->find('all', array(
  6351. 'order' => 'Article.title ASC'
  6352. )),
  6353. '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
  6354. );
  6355. $expected = array(
  6356. 1 => array(
  6357. 1 => array(
  6358. 'id' => 1,
  6359. 'user_id' => 1,
  6360. 'title' => 'First Article',
  6361. 'body' => 'First Article Body',
  6362. 'published' => 'Y',
  6363. 'created' => '2007-03-18 10:39:23',
  6364. 'updated' => '2007-03-18 10:41:31'
  6365. ),
  6366. 3 => array(
  6367. 'id' => 3,
  6368. 'user_id' => 1,
  6369. 'title' => 'Third Article',
  6370. 'body' => 'Third Article Body',
  6371. 'published' => 'Y',
  6372. 'created' => '2007-03-18 10:43:23',
  6373. 'updated' => '2007-03-18 10:45:31'
  6374. )),
  6375. 3 => array(
  6376. 2 => array(
  6377. 'id' => 2,
  6378. 'user_id' => 3,
  6379. 'title' => 'Second Article',
  6380. 'body' => 'Second Article Body',
  6381. 'published' => 'Y',
  6382. 'created' => '2007-03-18 10:41:23',
  6383. 'updated' => '2007-03-18 10:43:31'
  6384. )));
  6385. $this->assertEquals($expected, $result);
  6386. $result = Hash::combine(
  6387. $TestModel->find('all', array(
  6388. 'order' => 'Article.title ASC',
  6389. 'fields' => array('id', 'title', 'user_id')
  6390. )),
  6391. '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
  6392. );
  6393. $expected = array(
  6394. 1 => array(
  6395. 1 => 'First Article',
  6396. 3 => 'Third Article'
  6397. ),
  6398. 3 => array(
  6399. 2 => 'Second Article'
  6400. ));
  6401. $this->assertEquals($expected, $result);
  6402. $TestModel = new Apple();
  6403. $expected = array(
  6404. 1 => 'Red Apple 1',
  6405. 2 => 'Bright Red Apple',
  6406. 3 => 'green blue',
  6407. 4 => 'Test Name',
  6408. 5 => 'Blue Green',
  6409. 6 => 'My new apple',
  6410. 7 => 'Some odd color'
  6411. );
  6412. $this->assertEquals($expected, $TestModel->find('list'));
  6413. $this->assertEquals($expected, $TestModel->Parent->find('list'));
  6414. $TestModel = new Post();
  6415. $result = $TestModel->find('list', array(
  6416. 'fields' => 'Post.title'
  6417. ));
  6418. $expected = array(
  6419. 1 => 'First Post',
  6420. 2 => 'Second Post',
  6421. 3 => 'Third Post'
  6422. );
  6423. $this->assertEquals($expected, $result);
  6424. $result = $TestModel->find('list', array(
  6425. 'fields' => 'title'
  6426. ));
  6427. $expected = array(
  6428. 1 => 'First Post',
  6429. 2 => 'Second Post',
  6430. 3 => 'Third Post'
  6431. );
  6432. $this->assertEquals($expected, $result);
  6433. $result = $TestModel->find('list', array(
  6434. 'fields' => array('title', 'id')
  6435. ));
  6436. $expected = array(
  6437. 'First Post' => '1',
  6438. 'Second Post' => '2',
  6439. 'Third Post' => '3'
  6440. );
  6441. $this->assertEquals($expected, $result);
  6442. $result = $TestModel->find('list', array(
  6443. 'fields' => array('title', 'id', 'created')
  6444. ));
  6445. $expected = array(
  6446. '2007-03-18 10:39:23' => array(
  6447. 'First Post' => '1'
  6448. ),
  6449. '2007-03-18 10:41:23' => array(
  6450. 'Second Post' => '2'
  6451. ),
  6452. '2007-03-18 10:43:23' => array(
  6453. 'Third Post' => '3'
  6454. ),
  6455. );
  6456. $this->assertEquals($expected, $result);
  6457. $result = $TestModel->find('list', array(
  6458. 'fields' => array('Post.body')
  6459. ));
  6460. $expected = array(
  6461. 1 => 'First Post Body',
  6462. 2 => 'Second Post Body',
  6463. 3 => 'Third Post Body'
  6464. );
  6465. $this->assertEquals($expected, $result);
  6466. $result = $TestModel->find('list', array(
  6467. 'fields' => array('Post.title', 'Post.body')
  6468. ));
  6469. $expected = array(
  6470. 'First Post' => 'First Post Body',
  6471. 'Second Post' => 'Second Post Body',
  6472. 'Third Post' => 'Third Post Body'
  6473. );
  6474. $this->assertEquals($expected, $result);
  6475. $result = $TestModel->find('list', array(
  6476. 'fields' => array('Post.id', 'Post.title', 'Author.user'),
  6477. 'recursive' => 1
  6478. ));
  6479. $expected = array(
  6480. 'mariano' => array(
  6481. 1 => 'First Post',
  6482. 3 => 'Third Post'
  6483. ),
  6484. 'larry' => array(
  6485. 2 => 'Second Post'
  6486. ));
  6487. $this->assertEquals($expected, $result);
  6488. $TestModel = new User();
  6489. $result = $TestModel->find('list', array(
  6490. 'fields' => array('User.user', 'User.password')
  6491. ));
  6492. $expected = array(
  6493. 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6494. 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6495. 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6496. 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6497. );
  6498. $this->assertEquals($expected, $result);
  6499. $TestModel = new ModifiedAuthor();
  6500. $result = $TestModel->find('list', array(
  6501. 'fields' => array('Author.id', 'Author.user')
  6502. ));
  6503. $expected = array(
  6504. 1 => 'mariano (CakePHP)',
  6505. 2 => 'nate (CakePHP)',
  6506. 3 => 'larry (CakePHP)',
  6507. 4 => 'garrett (CakePHP)'
  6508. );
  6509. $this->assertEquals($expected, $result);
  6510. $TestModel = new Article();
  6511. $TestModel->displayField = 'title';
  6512. $result = $TestModel->find('list', array(
  6513. 'conditions' => array('User.user' => 'mariano'),
  6514. 'recursive' => 0
  6515. ));
  6516. $expected = array(
  6517. 1 => 'First Article',
  6518. 3 => 'Third Article'
  6519. );
  6520. $this->assertEquals($expected, $result);
  6521. }
  6522. /**
  6523. * testFindField method
  6524. *
  6525. * @return void
  6526. */
  6527. public function testFindField() {
  6528. $this->loadFixtures('User');
  6529. $TestModel = new User();
  6530. $TestModel->id = 1;
  6531. $result = $TestModel->field('user');
  6532. $this->assertEquals('mariano', $result);
  6533. $result = $TestModel->field('User.user');
  6534. $this->assertEquals('mariano', $result);
  6535. $TestModel->id = false;
  6536. $result = $TestModel->field('user', array(
  6537. 'user' => 'mariano'
  6538. ));
  6539. $this->assertEquals('mariano', $result);
  6540. $result = $TestModel->field('COUNT(*) AS count', true);
  6541. $this->assertEquals(4, $result);
  6542. $result = $TestModel->field('COUNT(*)', true);
  6543. $this->assertEquals(4, $result);
  6544. }
  6545. /**
  6546. * testFindUnique method
  6547. *
  6548. * @return void
  6549. */
  6550. public function testFindUnique() {
  6551. $this->loadFixtures('User');
  6552. $TestModel = new User();
  6553. $this->assertFalse($TestModel->isUnique(array(
  6554. 'user' => 'nate'
  6555. )));
  6556. $TestModel->id = 2;
  6557. $this->assertTrue($TestModel->isUnique(array(
  6558. 'user' => 'nate'
  6559. )));
  6560. $this->assertFalse($TestModel->isUnique(array(
  6561. 'user' => 'nate',
  6562. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6563. )));
  6564. }
  6565. /**
  6566. * test find('count') method
  6567. *
  6568. * @return void
  6569. */
  6570. public function testFindCount() {
  6571. $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag');
  6572. $TestModel = new User();
  6573. $this->db->getLog(false, true);
  6574. $result = $TestModel->find('count');
  6575. $this->assertEquals(4, $result);
  6576. $this->db->getLog(false, true);
  6577. $fullDebug = $this->db->fullDebug;
  6578. $this->db->fullDebug = true;
  6579. $TestModel->order = 'User.id';
  6580. $result = $TestModel->find('count');
  6581. $this->db->fullDebug = $fullDebug;
  6582. $this->assertEquals(4, $result);
  6583. $log = $this->db->getLog();
  6584. $this->assertTrue(isset($log['log'][0]['query']));
  6585. $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']);
  6586. $Article = new Article();
  6587. $Article->recursive = -1;
  6588. $expected = count($Article->find('all', array(
  6589. 'fields' => array('Article.user_id'),
  6590. 'group' => 'Article.user_id')
  6591. ));
  6592. $result = $Article->find('count', array('group' => array('Article.user_id')));
  6593. $this->assertEquals($expected, $result);
  6594. $expected = count($Article->find('all', array(
  6595. 'fields' => array('Article.user_id'),
  6596. 'conditions' => array('Article.user_id' => 1),
  6597. 'group' => 'Article.user_id')
  6598. ));
  6599. $result = $Article->find('count', array(
  6600. 'conditions' => array('Article.user_id' => 1),
  6601. 'group' => array('Article.user_id'),
  6602. ));
  6603. $this->assertEquals($expected, $result);
  6604. }
  6605. /**
  6606. * Test that find('first') does not use the id set to the object.
  6607. *
  6608. * @return void
  6609. */
  6610. public function testFindFirstNoIdUsed() {
  6611. $this->loadFixtures('Project');
  6612. $Project = new Project();
  6613. $Project->id = 3;
  6614. $result = $Project->find('first');
  6615. $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved');
  6616. }
  6617. /**
  6618. * test find with COUNT(DISTINCT field)
  6619. *
  6620. * @return void
  6621. */
  6622. public function testFindCountDistinct() {
  6623. $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
  6624. $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
  6625. $this->loadFixtures('Project', 'Thread');
  6626. $TestModel = new Project();
  6627. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6628. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6629. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6630. $result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
  6631. $this->assertEquals(4, $result);
  6632. }
  6633. /**
  6634. * Test find(count) with Db::expression
  6635. *
  6636. * @return void
  6637. */
  6638. public function testFindCountWithDbExpressions() {
  6639. $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');
  6640. $this->loadFixtures('Project', 'Thread');
  6641. $db = ConnectionManager::getDataSource('test');
  6642. $TestModel = new Project();
  6643. $result = $TestModel->find('count', array('conditions' => array(
  6644. $db->expression('Project.name = \'Project 3\'')
  6645. )));
  6646. $this->assertEquals(1, $result);
  6647. $result = $TestModel->find('count', array('conditions' => array(
  6648. 'Project.name' => $db->expression('\'Project 3\'')
  6649. )));
  6650. $this->assertEquals(1, $result);
  6651. }
  6652. /**
  6653. * testFindMagic method
  6654. *
  6655. * @return void
  6656. */
  6657. public function testFindMagic() {
  6658. $this->loadFixtures('User');
  6659. $TestModel = new User();
  6660. $result = $TestModel->findByUser('mariano');
  6661. $expected = array(
  6662. 'User' => array(
  6663. 'id' => '1',
  6664. 'user' => 'mariano',
  6665. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6666. 'created' => '2007-03-17 01:16:23',
  6667. 'updated' => '2007-03-17 01:18:31'
  6668. ));
  6669. $this->assertEquals($expected, $result);
  6670. $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99');
  6671. $expected = array('User' => array(
  6672. 'id' => '1',
  6673. 'user' => 'mariano',
  6674. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6675. 'created' => '2007-03-17 01:16:23',
  6676. 'updated' => '2007-03-17 01:18:31'
  6677. ));
  6678. $this->assertEquals($expected, $result);
  6679. }
  6680. /**
  6681. * testRead method
  6682. *
  6683. * @return void
  6684. */
  6685. public function testRead() {
  6686. $this->loadFixtures('User', 'Article');
  6687. $TestModel = new User();
  6688. $result = $TestModel->read();
  6689. $this->assertFalse($result);
  6690. $TestModel->id = 2;
  6691. $result = $TestModel->read();
  6692. $expected = array(
  6693. 'User' => array(
  6694. 'id' => '2',
  6695. 'user' => 'nate',
  6696. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6697. 'created' => '2007-03-17 01:18:23',
  6698. 'updated' => '2007-03-17 01:20:31'
  6699. ));
  6700. $this->assertEquals($expected, $result);
  6701. $result = $TestModel->read(null, 2);
  6702. $expected = array(
  6703. 'User' => array(
  6704. 'id' => '2',
  6705. 'user' => 'nate',
  6706. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6707. 'created' => '2007-03-17 01:18:23',
  6708. 'updated' => '2007-03-17 01:20:31'
  6709. ));
  6710. $this->assertEquals($expected, $result);
  6711. $TestModel->id = 2;
  6712. $result = $TestModel->read(array('id', 'user'));
  6713. $expected = array('User' => array('id' => '2', 'user' => 'nate'));
  6714. $this->assertEquals($expected, $result);
  6715. $result = $TestModel->read('id, user', 2);
  6716. $expected = array(
  6717. 'User' => array(
  6718. 'id' => '2',
  6719. 'user' => 'nate'
  6720. ));
  6721. $this->assertEquals($expected, $result);
  6722. $result = $TestModel->bindModel(array('hasMany' => array('Article')));
  6723. $this->assertTrue($result);
  6724. $TestModel->id = 1;
  6725. $result = $TestModel->read('id, user');
  6726. $expected = array(
  6727. 'User' => array(
  6728. 'id' => '1',
  6729. 'user' => 'mariano'
  6730. ),
  6731. 'Article' => array(
  6732. array(
  6733. 'id' => '1',
  6734. 'user_id' => '1',
  6735. 'title' => 'First Article',
  6736. 'body' => 'First Article Body',
  6737. 'published' => 'Y',
  6738. 'created' => '2007-03-18 10:39:23',
  6739. 'updated' => '2007-03-18 10:41:31'
  6740. ),
  6741. array(
  6742. 'id' => '3',
  6743. 'user_id' => '1',
  6744. 'title' => 'Third Article',
  6745. 'body' => 'Third Article Body',
  6746. 'published' => 'Y',
  6747. 'created' => '2007-03-18 10:43:23',
  6748. 'updated' => '2007-03-18 10:45:31'
  6749. )));
  6750. $this->assertEquals($expected, $result);
  6751. }
  6752. /**
  6753. * testRecursiveRead method
  6754. *
  6755. * @return void
  6756. */
  6757. public function testRecursiveRead() {
  6758. $this->loadFixtures(
  6759. 'User',
  6760. 'Article',
  6761. 'Comment',
  6762. 'Tag',
  6763. 'ArticlesTag',
  6764. 'Featured',
  6765. 'ArticleFeatured'
  6766. );
  6767. $TestModel = new User();
  6768. $result = $TestModel->bindModel(array('hasMany' => array('Article')), false);
  6769. $this->assertTrue($result);
  6770. $TestModel->recursive = 0;
  6771. $result = $TestModel->read('id, user', 1);
  6772. $expected = array(
  6773. 'User' => array('id' => '1', 'user' => 'mariano'),
  6774. );
  6775. $this->assertEquals($expected, $result);
  6776. $TestModel->recursive = 1;
  6777. $result = $TestModel->read('id, user', 1);
  6778. $expected = array(
  6779. 'User' => array(
  6780. 'id' => '1',
  6781. 'user' => 'mariano'
  6782. ),
  6783. 'Article' => array(
  6784. array(
  6785. 'id' => '1',
  6786. 'user_id' => '1',
  6787. 'title' => 'First Article',
  6788. 'body' => 'First Article Body',
  6789. 'published' => 'Y',
  6790. 'created' => '2007-03-18 10:39:23',
  6791. 'updated' => '2007-03-18 10:41:31'
  6792. ),
  6793. array(
  6794. 'id' => '3',
  6795. 'user_id' => '1',
  6796. 'title' => 'Third Article',
  6797. 'body' => 'Third Article Body',
  6798. 'published' => 'Y',
  6799. 'created' => '2007-03-18 10:43:23',
  6800. 'updated' => '2007-03-18 10:45:31'
  6801. )));
  6802. $this->assertEquals($expected, $result);
  6803. $TestModel->recursive = 2;
  6804. $result = $TestModel->read('id, user', 3);
  6805. $expected = array(
  6806. 'User' => array(
  6807. 'id' => '3',
  6808. 'user' => 'larry'
  6809. ),
  6810. 'Article' => array(
  6811. array(
  6812. 'id' => '2',
  6813. 'user_id' => '3',
  6814. 'title' => 'Second Article',
  6815. 'body' => 'Second Article Body',
  6816. 'published' => 'Y',
  6817. 'created' => '2007-03-18 10:41:23',
  6818. 'updated' => '2007-03-18 10:43:31',
  6819. 'User' => array(
  6820. 'id' => '3',
  6821. 'user' => 'larry',
  6822. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6823. 'created' => '2007-03-17 01:20:23',
  6824. 'updated' => '2007-03-17 01:22:31'
  6825. ),
  6826. 'Comment' => array(
  6827. array(
  6828. 'id' => '5',
  6829. 'article_id' => '2',
  6830. 'user_id' => '1',
  6831. 'comment' => 'First Comment for Second Article',
  6832. 'published' => 'Y',
  6833. 'created' => '2007-03-18 10:53:23',
  6834. 'updated' => '2007-03-18 10:55:31'
  6835. ),
  6836. array(
  6837. 'id' => '6',
  6838. 'article_id' => '2',
  6839. 'user_id' => '2',
  6840. 'comment' => 'Second Comment for Second Article',
  6841. 'published' => 'Y',
  6842. 'created' => '2007-03-18 10:55:23',
  6843. 'updated' => '2007-03-18 10:57:31'
  6844. )),
  6845. 'Tag' => array(
  6846. array(
  6847. 'id' => '1',
  6848. 'tag' => 'tag1',
  6849. 'created' => '2007-03-18 12:22:23',
  6850. 'updated' => '2007-03-18 12:24:31'
  6851. ),
  6852. array(
  6853. 'id' => '3',
  6854. 'tag' => 'tag3',
  6855. 'created' => '2007-03-18 12:26:23',
  6856. 'updated' => '2007-03-18 12:28:31'
  6857. )))));
  6858. $this->assertEquals($expected, $result);
  6859. }
  6860. public function testRecursiveFindAll() {
  6861. $this->loadFixtures(
  6862. 'User',
  6863. 'Article',
  6864. 'Comment',
  6865. 'Tag',
  6866. 'ArticlesTag',
  6867. 'Attachment',
  6868. 'ArticleFeatured',
  6869. 'ArticleFeaturedsTags',
  6870. 'Featured',
  6871. 'Category'
  6872. );
  6873. $TestModel = new Article();
  6874. $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1)));
  6875. $expected = array(
  6876. array(
  6877. 'Article' => array(
  6878. 'id' => '1',
  6879. 'user_id' => '1',
  6880. 'title' => 'First Article',
  6881. 'body' => 'First Article Body',
  6882. 'published' => 'Y',
  6883. 'created' => '2007-03-18 10:39:23',
  6884. 'updated' => '2007-03-18 10:41:31'
  6885. ),
  6886. 'User' => array(
  6887. 'id' => '1',
  6888. 'user' => 'mariano',
  6889. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6890. 'created' => '2007-03-17 01:16:23',
  6891. 'updated' => '2007-03-17 01:18:31'
  6892. ),
  6893. 'Comment' => array(
  6894. array(
  6895. 'id' => '1',
  6896. 'article_id' => '1',
  6897. 'user_id' => '2',
  6898. 'comment' => 'First Comment for First Article',
  6899. 'published' => 'Y',
  6900. 'created' => '2007-03-18 10:45:23',
  6901. 'updated' => '2007-03-18 10:47:31'
  6902. ),
  6903. array(
  6904. 'id' => '2',
  6905. 'article_id' => '1',
  6906. 'user_id' => '4',
  6907. 'comment' => 'Second Comment for First Article',
  6908. 'published' => 'Y',
  6909. 'created' => '2007-03-18 10:47:23',
  6910. 'updated' => '2007-03-18 10:49:31'
  6911. ),
  6912. array(
  6913. 'id' => '3',
  6914. 'article_id' => '1',
  6915. 'user_id' => '1',
  6916. 'comment' => 'Third Comment for First Article',
  6917. 'published' => 'Y',
  6918. 'created' => '2007-03-18 10:49:23',
  6919. 'updated' => '2007-03-18 10:51:31'
  6920. ),
  6921. array(
  6922. 'id' => '4',
  6923. 'article_id' => '1',
  6924. 'user_id' => '1',
  6925. 'comment' => 'Fourth Comment for First Article',
  6926. 'published' => 'N',
  6927. 'created' => '2007-03-18 10:51:23',
  6928. 'updated' => '2007-03-18 10:53:31'
  6929. )
  6930. ),
  6931. 'Tag' => array(
  6932. array(
  6933. 'id' => '1',
  6934. 'tag' => 'tag1',
  6935. 'created' => '2007-03-18 12:22:23',
  6936. 'updated' => '2007-03-18 12:24:31'
  6937. ),
  6938. array(
  6939. 'id' => '2',
  6940. 'tag' => 'tag2',
  6941. 'created' => '2007-03-18 12:24:23',
  6942. 'updated' => '2007-03-18 12:26:31'
  6943. ))),
  6944. array(
  6945. 'Article' => array(
  6946. 'id' => '3',
  6947. 'user_id' => '1',
  6948. 'title' => 'Third Article',
  6949. 'body' => 'Third Article Body',
  6950. 'published' => 'Y',
  6951. 'created' => '2007-03-18 10:43:23',
  6952. 'updated' => '2007-03-18 10:45:31'
  6953. ),
  6954. 'User' => array(
  6955. 'id' => '1',
  6956. 'user' => 'mariano',
  6957. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6958. 'created' => '2007-03-17 01:16:23',
  6959. 'updated' => '2007-03-17 01:18:31'
  6960. ),
  6961. 'Comment' => array(),
  6962. 'Tag' => array()
  6963. )
  6964. );
  6965. $this->assertEquals($expected, $result);
  6966. $result = $TestModel->find('all', array(
  6967. 'conditions' => array('Article.user_id' => 3),
  6968. 'limit' => 1,
  6969. 'recursive' => 2
  6970. ));
  6971. $expected = array(
  6972. array(
  6973. 'Article' => array(
  6974. 'id' => '2',
  6975. 'user_id' => '3',
  6976. 'title' => 'Second Article',
  6977. 'body' => 'Second Article Body',
  6978. 'published' => 'Y',
  6979. 'created' => '2007-03-18 10:41:23',
  6980. 'updated' => '2007-03-18 10:43:31'
  6981. ),
  6982. 'User' => array(
  6983. 'id' => '3',
  6984. 'user' => 'larry',
  6985. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6986. 'created' => '2007-03-17 01:20:23',
  6987. 'updated' => '2007-03-17 01:22:31'
  6988. ),
  6989. 'Comment' => array(
  6990. array(
  6991. 'id' => '5',
  6992. 'article_id' => '2',
  6993. 'user_id' => '1',
  6994. 'comment' => 'First Comment for Second Article',
  6995. 'published' => 'Y',
  6996. 'created' => '2007-03-18 10:53:23',
  6997. 'updated' => '2007-03-18 10:55:31',
  6998. 'Article' => array(
  6999. 'id' => '2',
  7000. 'user_id' => '3',
  7001. 'title' => 'Second Article',
  7002. 'body' => 'Second Article Body',
  7003. 'published' => 'Y',
  7004. 'created' => '2007-03-18 10:41:23',
  7005. 'updated' => '2007-03-18 10:43:31'
  7006. ),
  7007. 'User' => array(
  7008. 'id' => '1',
  7009. 'user' => 'mariano',
  7010. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7011. 'created' => '2007-03-17 01:16:23',
  7012. 'updated' => '2007-03-17 01:18:31'
  7013. ),
  7014. 'Attachment' => array(
  7015. 'id' => '1',
  7016. 'comment_id' => 5,
  7017. 'attachment' => 'attachment.zip',
  7018. 'created' => '2007-03-18 10:51:23',
  7019. 'updated' => '2007-03-18 10:53:31'
  7020. )
  7021. ),
  7022. array(
  7023. 'id' => '6',
  7024. 'article_id' => '2',
  7025. 'user_id' => '2',
  7026. 'comment' => 'Second Comment for Second Article',
  7027. 'published' => 'Y',
  7028. 'created' => '2007-03-18 10:55:23',
  7029. 'updated' => '2007-03-18 10:57:31',
  7030. 'Article' => array(
  7031. 'id' => '2',
  7032. 'user_id' => '3',
  7033. 'title' => 'Second Article',
  7034. 'body' => 'Second Article Body',
  7035. 'published' => 'Y',
  7036. 'created' => '2007-03-18 10:41:23',
  7037. 'updated' => '2007-03-18 10:43:31'
  7038. ),
  7039. 'User' => array(
  7040. 'id' => '2',
  7041. 'user' => 'nate',
  7042. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7043. 'created' => '2007-03-17 01:18:23',
  7044. 'updated' => '2007-03-17 01:20:31'
  7045. ),
  7046. 'Attachment' => array()
  7047. )
  7048. ),
  7049. 'Tag' => array(
  7050. array(
  7051. 'id' => '1',
  7052. 'tag' => 'tag1',
  7053. 'created' => '2007-03-18 12:22:23',
  7054. 'updated' => '2007-03-18 12:24:31'
  7055. ),
  7056. array(
  7057. 'id' => '3',
  7058. 'tag' => 'tag3',
  7059. 'created' => '2007-03-18 12:26:23',
  7060. 'updated' => '2007-03-18 12:28:31'
  7061. ))));
  7062. $this->assertEquals($expected, $result);
  7063. $Featured = new Featured();
  7064. $Featured->recursive = 2;
  7065. $Featured->bindModel(array(
  7066. 'belongsTo' => array(
  7067. 'ArticleFeatured' => array(
  7068. 'conditions' => "ArticleFeatured.published = 'Y'",
  7069. 'fields' => 'id, title, user_id, published'
  7070. )
  7071. )
  7072. ));
  7073. $Featured->ArticleFeatured->unbindModel(array(
  7074. 'hasMany' => array('Attachment', 'Comment'),
  7075. 'hasAndBelongsToMany' => array('Tag'))
  7076. );
  7077. $orderBy = 'ArticleFeatured.id ASC';
  7078. $result = $Featured->find('all', array(
  7079. 'order' => $orderBy, 'limit' => 3
  7080. ));
  7081. $expected = array(
  7082. array(
  7083. 'Featured' => array(
  7084. 'id' => '1',
  7085. 'article_featured_id' => '1',
  7086. 'category_id' => '1',
  7087. 'published_date' => '2007-03-31 10:39:23',
  7088. 'end_date' => '2007-05-15 10:39:23',
  7089. 'created' => '2007-03-18 10:39:23',
  7090. 'updated' => '2007-03-18 10:41:31'
  7091. ),
  7092. 'ArticleFeatured' => array(
  7093. 'id' => '1',
  7094. 'title' => 'First Article',
  7095. 'user_id' => '1',
  7096. 'published' => 'Y',
  7097. 'User' => array(
  7098. 'id' => '1',
  7099. 'user' => 'mariano',
  7100. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7101. 'created' => '2007-03-17 01:16:23',
  7102. 'updated' => '2007-03-17 01:18:31'
  7103. ),
  7104. 'Category' => array(),
  7105. 'Featured' => array(
  7106. 'id' => '1',
  7107. 'article_featured_id' => '1',
  7108. 'category_id' => '1',
  7109. 'published_date' => '2007-03-31 10:39:23',
  7110. 'end_date' => '2007-05-15 10:39:23',
  7111. 'created' => '2007-03-18 10:39:23',
  7112. 'updated' => '2007-03-18 10:41:31'
  7113. )),
  7114. 'Category' => array(
  7115. 'id' => '1',
  7116. 'parent_id' => '0',
  7117. 'name' => 'Category 1',
  7118. 'created' => '2007-03-18 15:30:23',
  7119. 'updated' => '2007-03-18 15:32:31'
  7120. )),
  7121. array(
  7122. 'Featured' => array(
  7123. 'id' => '2',
  7124. 'article_featured_id' => '2',
  7125. 'category_id' => '1',
  7126. 'published_date' => '2007-03-31 10:39:23',
  7127. 'end_date' => '2007-05-15 10:39:23',
  7128. 'created' => '2007-03-18 10:39:23',
  7129. 'updated' => '2007-03-18 10:41:31'
  7130. ),
  7131. 'ArticleFeatured' => array(
  7132. 'id' => '2',
  7133. 'title' => 'Second Article',
  7134. 'user_id' => '3',
  7135. 'published' => 'Y',
  7136. 'User' => array(
  7137. 'id' => '3',
  7138. 'user' => 'larry',
  7139. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7140. 'created' => '2007-03-17 01:20:23',
  7141. 'updated' => '2007-03-17 01:22:31'
  7142. ),
  7143. 'Category' => array(),
  7144. 'Featured' => array(
  7145. 'id' => '2',
  7146. 'article_featured_id' => '2',
  7147. 'category_id' => '1',
  7148. 'published_date' => '2007-03-31 10:39:23',
  7149. 'end_date' => '2007-05-15 10:39:23',
  7150. 'created' => '2007-03-18 10:39:23',
  7151. 'updated' => '2007-03-18 10:41:31'
  7152. )),
  7153. 'Category' => array(
  7154. 'id' => '1',
  7155. 'parent_id' => '0',
  7156. 'name' => 'Category 1',
  7157. 'created' => '2007-03-18 15:30:23',
  7158. 'updated' => '2007-03-18 15:32:31'
  7159. )));
  7160. $this->assertEquals($expected, $result);
  7161. }
  7162. /**
  7163. * testRecursiveFindAllWithLimit method
  7164. *
  7165. * @return void
  7166. */
  7167. public function testRecursiveFindAllWithLimit() {
  7168. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
  7169. $TestModel = new Article();
  7170. $TestModel->hasMany['Comment']['limit'] = 2;
  7171. $result = $TestModel->find('all', array(
  7172. 'conditions' => array('Article.user_id' => 1)
  7173. ));
  7174. $expected = array(
  7175. array(
  7176. 'Article' => array(
  7177. 'id' => '1',
  7178. 'user_id' => '1',
  7179. 'title' => 'First Article',
  7180. 'body' => 'First Article Body',
  7181. 'published' => 'Y',
  7182. 'created' => '2007-03-18 10:39:23',
  7183. 'updated' => '2007-03-18 10:41:31'
  7184. ),
  7185. 'User' => array(
  7186. 'id' => '1',
  7187. 'user' => 'mariano',
  7188. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7189. 'created' => '2007-03-17 01:16:23',
  7190. 'updated' => '2007-03-17 01:18:31'
  7191. ),
  7192. 'Comment' => array(
  7193. array(
  7194. 'id' => '1',
  7195. 'article_id' => '1',
  7196. 'user_id' => '2',
  7197. 'comment' => 'First Comment for First Article',
  7198. 'published' => 'Y',
  7199. 'created' => '2007-03-18 10:45:23',
  7200. 'updated' => '2007-03-18 10:47:31'
  7201. ),
  7202. array(
  7203. 'id' => '2',
  7204. 'article_id' => '1',
  7205. 'user_id' => '4',
  7206. 'comment' => 'Second Comment for First Article',
  7207. 'published' => 'Y',
  7208. 'created' => '2007-03-18 10:47:23',
  7209. 'updated' => '2007-03-18 10:49:31'
  7210. ),
  7211. ),
  7212. 'Tag' => array(
  7213. array(
  7214. 'id' => '1',
  7215. 'tag' => 'tag1',
  7216. 'created' => '2007-03-18 12:22:23',
  7217. 'updated' => '2007-03-18 12:24:31'
  7218. ),
  7219. array(
  7220. 'id' => '2',
  7221. 'tag' => 'tag2',
  7222. 'created' => '2007-03-18 12:24:23',
  7223. 'updated' => '2007-03-18 12:26:31'
  7224. ))),
  7225. array(
  7226. 'Article' => array(
  7227. 'id' => '3',
  7228. 'user_id' => '1',
  7229. 'title' => 'Third Article',
  7230. 'body' => 'Third Article Body',
  7231. 'published' => 'Y',
  7232. 'created' => '2007-03-18 10:43:23',
  7233. 'updated' => '2007-03-18 10:45:31'
  7234. ),
  7235. 'User' => array(
  7236. 'id' => '1',
  7237. 'user' => 'mariano',
  7238. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7239. 'created' => '2007-03-17 01:16:23',
  7240. 'updated' => '2007-03-17 01:18:31'
  7241. ),
  7242. 'Comment' => array(),
  7243. 'Tag' => array()
  7244. )
  7245. );
  7246. $this->assertEquals($expected, $result);
  7247. $TestModel->hasMany['Comment']['limit'] = 1;
  7248. $result = $TestModel->find('all', array(
  7249. 'conditions' => array('Article.user_id' => 3),
  7250. 'limit' => 1,
  7251. 'recursive' => 2
  7252. ));
  7253. $expected = array(
  7254. array(
  7255. 'Article' => array(
  7256. 'id' => '2',
  7257. 'user_id' => '3',
  7258. 'title' => 'Second Article',
  7259. 'body' => 'Second Article Body',
  7260. 'published' => 'Y',
  7261. 'created' => '2007-03-18 10:41:23',
  7262. 'updated' => '2007-03-18 10:43:31'
  7263. ),
  7264. 'User' => array(
  7265. 'id' => '3',
  7266. 'user' => 'larry',
  7267. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7268. 'created' => '2007-03-17 01:20:23',
  7269. 'updated' => '2007-03-17 01:22:31'
  7270. ),
  7271. 'Comment' => array(
  7272. array(
  7273. 'id' => '5',
  7274. 'article_id' => '2',
  7275. 'user_id' => '1',
  7276. 'comment' => 'First Comment for Second Article',
  7277. 'published' => 'Y',
  7278. 'created' => '2007-03-18 10:53:23',
  7279. 'updated' => '2007-03-18 10:55:31',
  7280. 'Article' => array(
  7281. 'id' => '2',
  7282. 'user_id' => '3',
  7283. 'title' => 'Second Article',
  7284. 'body' => 'Second Article Body',
  7285. 'published' => 'Y',
  7286. 'created' => '2007-03-18 10:41:23',
  7287. 'updated' => '2007-03-18 10:43:31'
  7288. ),
  7289. 'User' => array(
  7290. 'id' => '1',
  7291. 'user' => 'mariano',
  7292. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  7293. 'created' => '2007-03-17 01:16:23',
  7294. 'updated' => '2007-03-17 01:18:31'
  7295. ),
  7296. 'Attachment' => array(
  7297. 'id' => '1',
  7298. 'comment_id' => 5,
  7299. 'attachment' => 'attachment.zip',
  7300. 'created' => '2007-03-18 10:51:23',
  7301. 'updated' => '2007-03-18 10:53:31'
  7302. )
  7303. )
  7304. ),
  7305. 'Tag' => array(
  7306. array(
  7307. 'id' => '1',
  7308. 'tag' => 'tag1',
  7309. 'created' => '2007-03-18 12:22:23',
  7310. 'updated' => '2007-03-18 12:24:31'
  7311. ),
  7312. array(
  7313. 'id' => '3',
  7314. 'tag' => 'tag3',
  7315. 'created' => '2007-03-18 12:26:23',
  7316. 'updated' => '2007-03-18 12:28:31'
  7317. )
  7318. )
  7319. )
  7320. );
  7321. $this->assertEquals($expected, $result);
  7322. }
  7323. /**
  7324. * Testing availability of $this->findQueryType in Model callbacks
  7325. *
  7326. * @return void
  7327. */
  7328. public function testFindQueryTypeInCallbacks() {
  7329. $this->loadFixtures('Comment');
  7330. $Comment = new AgainModifiedComment();
  7331. $comments = $Comment->find('all');
  7332. $this->assertEquals('all', $comments[0]['Comment']['querytype']);
  7333. $comments = $Comment->find('first');
  7334. $this->assertEquals('first', $comments['Comment']['querytype']);
  7335. }
  7336. /**
  7337. * testVirtualFields()
  7338. *
  7339. * Test correct fetching of virtual fields
  7340. * currently is not possible to do Relation.virtualField
  7341. *
  7342. * @return void
  7343. */
  7344. public function testVirtualFields() {
  7345. $this->loadFixtures('Post', 'Author');
  7346. $Post = ClassRegistry::init('Post');
  7347. $Post->virtualFields = array('two' => "1 + 1");
  7348. $result = $Post->find('first');
  7349. $this->assertEquals(2, $result['Post']['two']);
  7350. // SQL Server does not support operators in expressions
  7351. if (!($this->db instanceof Sqlserver)) {
  7352. $Post->Author->virtualFields = array('false' => '1 = 2');
  7353. $result = $Post->find('first');
  7354. $this->assertEquals(2, $result['Post']['two']);
  7355. $this->assertFalse((bool)$result['Author']['false']);
  7356. }
  7357. $result = $Post->find('first',array('fields' => array('author_id')));
  7358. $this->assertFalse(isset($result['Post']['two']));
  7359. $this->assertFalse(isset($result['Author']['false']));
  7360. $result = $Post->find('first',array('fields' => array('author_id', 'two')));
  7361. $this->assertEquals(2, $result['Post']['two']);
  7362. $this->assertFalse(isset($result['Author']['false']));
  7363. $result = $Post->find('first',array('fields' => array('two')));
  7364. $this->assertEquals(2, $result['Post']['two']);
  7365. $Post->id = 1;
  7366. $result = $Post->field('two');
  7367. $this->assertEquals(2, $result);
  7368. $result = $Post->find('first',array(
  7369. 'conditions' => array('two' => 2),
  7370. 'limit' => 1
  7371. ));
  7372. $this->assertEquals(2, $result['Post']['two']);
  7373. $result = $Post->find('first',array(
  7374. 'conditions' => array('two <' => 3),
  7375. 'limit' => 1
  7376. ));
  7377. $this->assertEquals(2, $result['Post']['two']);
  7378. $result = $Post->find('first',array(
  7379. 'conditions' => array('NOT' => array('two >' => 3)),
  7380. 'limit' => 1
  7381. ));
  7382. $this->assertEquals(2, $result['Post']['two']);
  7383. $dbo = $Post->getDataSource();
  7384. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7385. $result = $Post->find('first', array(
  7386. 'conditions' => array('other_field' => 3),
  7387. 'limit' => 1
  7388. ));
  7389. $this->assertEquals(2, $result['Post']['id']);
  7390. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7391. $result = $Post->find('all', array(
  7392. 'fields' => array($dbo->calculate($Post, 'max', array('other_field')))
  7393. ));
  7394. $this->assertEquals(4, $result[0][0]['other_field']);
  7395. ClassRegistry::flush();
  7396. $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
  7397. $Writing->virtualFields = array('two' => "1 + 1");
  7398. $result = $Writing->find('first');
  7399. $this->assertEquals(2, $result['Writing']['two']);
  7400. $Post->create();
  7401. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7402. $result = $Post->field('other_field');
  7403. $this->assertEquals(4, $result);
  7404. }
  7405. /**
  7406. * testVirtualFieldsOrder()
  7407. *
  7408. * Test correct order on virtual fields
  7409. *
  7410. * @return void
  7411. */
  7412. public function testVirtualFieldsOrder() {
  7413. $this->loadFixtures('Post', 'Author');
  7414. $Post = ClassRegistry::init('Post');
  7415. $Post->virtualFields = array('other_field' => '10 - Post.id');
  7416. $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC')));
  7417. $expected = array(
  7418. '3' => 'Third Post',
  7419. '2' => 'Second Post',
  7420. '1' => 'First Post'
  7421. );
  7422. $this->assertEquals($expected, $result);
  7423. $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC')));
  7424. $expected = array(
  7425. '1' => 'First Post',
  7426. '2' => 'Second Post',
  7427. '3' => 'Third Post'
  7428. );
  7429. $this->assertEquals($expected, $result);
  7430. $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id');
  7431. $result = $Post->find('all', array(
  7432. 'order' => array('Post.id' => 'ASC')
  7433. ));
  7434. $result = Hash::extract($result, '{n}.Author.joined');
  7435. $expected = array(1, 6, 3);
  7436. $this->assertEquals($expected, $result);
  7437. $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC')));
  7438. $result = Hash::extract($result, '{n}.Author.joined');
  7439. $expected = array(1, 3, 6);
  7440. $this->assertEquals($expected, $result);
  7441. $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC')));
  7442. $result = Hash::extract($result, '{n}.Author.joined');
  7443. $expected = array(6, 3, 1);
  7444. $this->assertEquals($expected, $result);
  7445. }
  7446. /**
  7447. * testVirtualFieldsMysql()
  7448. *
  7449. * Test correct fetching of virtual fields
  7450. * currently is not possible to do Relation.virtualField
  7451. *
  7452. */
  7453. public function testVirtualFieldsMysql() {
  7454. $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.');
  7455. $this->loadFixtures('Post', 'Author');
  7456. $Post = ClassRegistry::init('Post');
  7457. $Post->create();
  7458. $Post->virtualFields = array(
  7459. 'low_title' => 'lower(Post.title)',
  7460. 'unique_test_field' => 'COUNT(Post.id)'
  7461. );
  7462. $expectation = array(
  7463. 'Post' => array(
  7464. 'low_title' => 'first post',
  7465. 'unique_test_field' => 1
  7466. )
  7467. );
  7468. $result = $Post->find('first', array(
  7469. 'fields' => array_keys($Post->virtualFields),
  7470. 'group' => array('low_title')
  7471. ));
  7472. $this->assertEquals($expectation, $result);
  7473. $Author = ClassRegistry::init('Author');
  7474. $Author->virtualFields = array(
  7475. 'full_name' => 'CONCAT(Author.user, " ", Author.id)'
  7476. );
  7477. $result = $Author->find('first', array(
  7478. 'conditions' => array('Author.user' => 'mariano'),
  7479. 'fields' => array('Author.password', 'Author.full_name'),
  7480. 'recursive' => -1
  7481. ));
  7482. $this->assertTrue(isset($result['Author']['full_name']));
  7483. $result = $Author->find('first', array(
  7484. 'conditions' => array('Author.user' => 'mariano'),
  7485. 'fields' => array('Author.full_name', 'Author.password'),
  7486. 'recursive' => -1
  7487. ));
  7488. $this->assertTrue(isset($result['Author']['full_name']));
  7489. }
  7490. /**
  7491. * test that virtual fields work when they don't contain functions.
  7492. *
  7493. * @return void
  7494. */
  7495. public function testVirtualFieldAsAString() {
  7496. $this->loadFixtures('Post', 'Author');
  7497. $Post = new Post();
  7498. $Post->virtualFields = array(
  7499. 'writer' => 'Author.user'
  7500. );
  7501. $result = $Post->find('first');
  7502. $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
  7503. }
  7504. /**
  7505. * test that isVirtualField will accept both aliased and non aliased fieldnames
  7506. *
  7507. * @return void
  7508. */
  7509. public function testIsVirtualField() {
  7510. $this->loadFixtures('Post');
  7511. $Post = ClassRegistry::init('Post');
  7512. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7513. $this->assertTrue($Post->isVirtualField('other_field'));
  7514. $this->assertTrue($Post->isVirtualField('Post.other_field'));
  7515. $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.');
  7516. $this->assertFalse($Post->isVirtualField('id'));
  7517. $this->assertFalse($Post->isVirtualField('Post.id'));
  7518. $this->assertFalse($Post->isVirtualField(array()));
  7519. }
  7520. /**
  7521. * test that getting virtual fields works with and without model alias attached
  7522. *
  7523. * @return void
  7524. */
  7525. public function testGetVirtualField() {
  7526. $this->loadFixtures('Post');
  7527. $Post = ClassRegistry::init('Post');
  7528. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7529. $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']);
  7530. $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
  7531. }
  7532. /**
  7533. * test that checks for error when NOT condition passed in key and a 1 element array value
  7534. *
  7535. * @return void
  7536. */
  7537. public function testNotInArrayWithOneValue() {
  7538. $this->loadFixtures('Article');
  7539. $Article = new Article();
  7540. $Article->recursive = -1;
  7541. $result = $Article->find(
  7542. 'all',
  7543. array(
  7544. 'conditions' => array(
  7545. 'Article.id NOT' => array(1)
  7546. )
  7547. )
  7548. );
  7549. $this->assertTrue(is_array($result) && !empty($result));
  7550. }
  7551. /**
  7552. * test custom find method
  7553. *
  7554. * @return void
  7555. */
  7556. public function testfindCustom() {
  7557. $this->loadFixtures('Article');
  7558. $Article = new CustomArticle();
  7559. $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  7560. $Article->create($data);
  7561. $Article->save(null, false);
  7562. $this->assertEquals(4, $Article->id);
  7563. $result = $Article->find('published');
  7564. $this->assertEquals(3, count($result));
  7565. $result = $Article->find('unPublished');
  7566. $this->assertEquals(1, count($result));
  7567. }
  7568. }