ModelReadTest.php 205 KB

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