ModelReadTest.php 194 KB

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