ModelReadTest.php 194 KB

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