ModelReadTest.php 212 KB

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