ContainableBehaviorTest.php 152 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767
  1. <?php
  2. /**
  3. * ContainableBehaviorTest 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.Behavior
  15. * @since CakePHP(tm) v 1.2.0.5669
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. */
  18. App::uses('Model', 'Model');
  19. App::uses('AppModel', 'Model');
  20. require_once dirname(dirname(__FILE__)) . DS . 'models.php';
  21. /**
  22. * ContainableTest class
  23. *
  24. * @package Cake.Test.Case.Model.Behavior
  25. */
  26. class ContainableBehaviorTest extends CakeTestCase {
  27. /**
  28. * Fixtures associated with this test case
  29. *
  30. * @var array
  31. */
  32. public $fixtures = array(
  33. 'core.article', 'core.article_featured', 'core.article_featureds_tags',
  34. 'core.articles_tag', 'core.attachment', 'core.category',
  35. 'core.comment', 'core.featured', 'core.tag', 'core.user',
  36. 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_c', 'core.join_a_b'
  37. );
  38. /**
  39. * Method executed before each test
  40. *
  41. * @return void
  42. */
  43. public function setUp() {
  44. parent::setUp();
  45. $this->User = ClassRegistry::init('User');
  46. $this->Article = ClassRegistry::init('Article');
  47. $this->Tag = ClassRegistry::init('Tag');
  48. $this->User->bindModel(array(
  49. 'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
  50. ), false);
  51. $this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false);
  52. $this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id';
  53. $this->Tag->bindModel(array(
  54. 'hasAndBelongsToMany' => array('Article')
  55. ), false);
  56. $this->User->Behaviors->load('Containable');
  57. $this->Article->Behaviors->load('Containable');
  58. $this->Tag->Behaviors->load('Containable');
  59. }
  60. /**
  61. * Method executed after each test
  62. *
  63. * @return void
  64. */
  65. public function tearDown() {
  66. unset($this->Article);
  67. unset($this->User);
  68. unset($this->Tag);
  69. parent::tearDown();
  70. }
  71. /**
  72. * testContainments method
  73. *
  74. * @return void
  75. */
  76. public function testContainments() {
  77. $r = $this->_containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2))));
  78. $this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r));
  79. $r = $this->_containments($this->User, array(
  80. 'ArticleFeatured' => array(
  81. 'Featured' => array(
  82. 'id',
  83. 'Category' => 'name'
  84. )
  85. )));
  86. $this->assertEquals(array('id'), Hash::extract($r, 'ArticleFeatured.keep.Featured.fields'));
  87. $r = $this->_containments($this->Article, array(
  88. 'Comment' => array(
  89. 'User',
  90. 'conditions' => array('Comment' => array('user_id' => 2)),
  91. ),
  92. ));
  93. $this->assertTrue(Set::matches('/User', $r));
  94. $this->assertTrue(Set::matches('/Comment', $r));
  95. $this->assertTrue(Set::matches('/Article/keep/Comment/conditions/Comment[user_id=2]', $r));
  96. $r = $this->_containments($this->Article, array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'));
  97. $this->assertTrue(Set::matches('/Comment', $r));
  98. $this->assertTrue(Set::matches('/User', $r));
  99. $this->assertTrue(Set::matches('/Article/keep/Comment', $r));
  100. $this->assertTrue(Set::matches('/Article/keep/User', $r));
  101. $this->assertEquals(array('comment', 'published'), Hash::extract($r, 'Article.keep.Comment.fields'));
  102. $this->assertEquals(array('user'), Hash::extract($r, 'Article.keep.User.fields'));
  103. $this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
  104. $this->assertEquals(array('attachment'), Hash::extract($r, 'Comment.keep.Attachment.fields'));
  105. $r = $this->_containments($this->Article, array('Comment' => array('limit' => 1)));
  106. $this->assertEquals(array('Comment', 'Article'), array_keys($r));
  107. $result = Hash::extract($r, 'Comment[keep]');
  108. $this->assertEquals(array('keep' => array()), array_shift($result));
  109. $this->assertTrue(Set::matches('/Article/keep/Comment', $r));
  110. $result = Hash::extract($r, 'Article.keep');
  111. $this->assertEquals(array('limit' => 1), array_shift($result));
  112. $r = $this->_containments($this->Article, array('Comment.User'));
  113. $this->assertEquals(array('User', 'Comment', 'Article'), array_keys($r));
  114. $result = Hash::extract($r, 'User[keep]');
  115. $this->assertEquals(array('keep' => array()), array_shift($result));
  116. $result = Hash::extract($r, 'Comment[keep]');
  117. $this->assertEquals(array('keep' => array('User' => array())), array_shift($result));
  118. $result = Hash::extract($r, 'Article[keep]');
  119. $this->assertEquals(array('keep' => array('Comment' => array())), array_shift($result));
  120. $r = $this->_containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
  121. 'Attachment' => array('conditions' => array('Attachment.id >' => 1))
  122. )))));
  123. $this->assertTrue(Set::matches('/Attachment', $r));
  124. $this->assertTrue(Set::matches('/Comment/keep/Attachment/conditions', $r));
  125. $this->assertEquals(array('Attachment.id >' => 1), $r['Comment']['keep']['Attachment']['conditions']);
  126. $this->assertTrue(Set::matches('/User/keep/Comment', $r));
  127. $this->assertTrue(Set::matches('/Article/keep/User', $r));
  128. $this->assertTrue(Set::matches('/Tag/keep/Article', $r));
  129. }
  130. /**
  131. * testInvalidContainments method
  132. *
  133. * @expectedException PHPUnit_Framework_Error
  134. * @return void
  135. */
  136. public function testInvalidContainments() {
  137. $this->_containments($this->Article, array('Comment', 'InvalidBinding'));
  138. }
  139. /**
  140. * testInvalidContainments method with suppressing error notices
  141. *
  142. * @return void
  143. */
  144. public function testInvalidContainmentsNoNotices() {
  145. $this->Article->Behaviors->load('Containable', array('notices' => false));
  146. $this->_containments($this->Article, array('Comment', 'InvalidBinding'));
  147. }
  148. /**
  149. * testBeforeFind method
  150. *
  151. * @return void
  152. */
  153. public function testBeforeFind() {
  154. $r = $this->Article->find('all', array('contain' => array('Comment')));
  155. $this->assertFalse(Set::matches('/User', $r));
  156. $this->assertTrue(Set::matches('/Comment', $r));
  157. $this->assertFalse(Set::matches('/Comment/User', $r));
  158. $r = $this->Article->find('all', array('contain' => 'Comment.User'));
  159. $this->assertTrue(Set::matches('/Comment/User', $r));
  160. $this->assertFalse(Set::matches('/Comment/Article', $r));
  161. $r = $this->Article->find('all', array('contain' => array('Comment' => array('User', 'Article'))));
  162. $this->assertTrue(Set::matches('/Comment/User', $r));
  163. $this->assertTrue(Set::matches('/Comment/Article', $r));
  164. $r = $this->Article->find('all', array('contain' => array('Comment' => array('conditions' => array('Comment.user_id' => 2)))));
  165. $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
  166. $this->assertTrue(Set::matches('/Comment[user_id=2]', $r));
  167. $r = $this->Article->find('all', array('contain' => array('Comment.user_id = 2')));
  168. $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
  169. $r = $this->Article->find('all', array('contain' => 'Comment.id DESC'));
  170. $ids = $descIds = Hash::extract($r, 'Comment[1].id');
  171. rsort($descIds);
  172. $this->assertEquals($ids, $descIds);
  173. $r = $this->Article->find('all', array('contain' => 'Comment'));
  174. $this->assertTrue(Set::matches('/Comment[user_id!=2]', $r));
  175. $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => 'comment'))));
  176. $this->assertFalse(Set::matches('/Comment/created', $r));
  177. $this->assertTrue(Set::matches('/Comment/comment', $r));
  178. $this->assertFalse(Set::matches('/Comment/updated', $r));
  179. $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => array('comment', 'updated')))));
  180. $this->assertFalse(Set::matches('/Comment/created', $r));
  181. $this->assertTrue(Set::matches('/Comment/comment', $r));
  182. $this->assertTrue(Set::matches('/Comment/updated', $r));
  183. $r = $this->Article->find('all', array('contain' => array('Comment' => array('comment', 'updated'))));
  184. $this->assertFalse(Set::matches('/Comment/created', $r));
  185. $this->assertTrue(Set::matches('/Comment/comment', $r));
  186. $this->assertTrue(Set::matches('/Comment/updated', $r));
  187. $r = $this->Article->find('all', array('contain' => array('Comment(comment,updated)')));
  188. $this->assertFalse(Set::matches('/Comment/created', $r));
  189. $this->assertTrue(Set::matches('/Comment/comment', $r));
  190. $this->assertTrue(Set::matches('/Comment/updated', $r));
  191. $r = $this->Article->find('all', array('contain' => 'Comment.created'));
  192. $this->assertTrue(Set::matches('/Comment/created', $r));
  193. $this->assertFalse(Set::matches('/Comment/comment', $r));
  194. $r = $this->Article->find('all', array('contain' => array('User.Article(title)', 'Comment(comment)')));
  195. $this->assertFalse(Set::matches('/Comment/Article', $r));
  196. $this->assertFalse(Set::matches('/Comment/User', $r));
  197. $this->assertTrue(Set::matches('/Comment/comment', $r));
  198. $this->assertFalse(Set::matches('/Comment/created', $r));
  199. $this->assertTrue(Set::matches('/User/Article/title', $r));
  200. $this->assertFalse(Set::matches('/User/Article/created', $r));
  201. $r = $this->Article->find('all', array('contain' => array()));
  202. $this->assertFalse(Set::matches('/User', $r));
  203. $this->assertFalse(Set::matches('/Comment', $r));
  204. }
  205. /**
  206. * testBeforeFindWithNonExistingBinding method
  207. *
  208. * @expectedException PHPUnit_Framework_Error
  209. * @return void
  210. */
  211. public function testBeforeFindWithNonExistingBinding() {
  212. $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
  213. }
  214. /**
  215. * testContain method
  216. *
  217. * @return void
  218. */
  219. public function testContain() {
  220. $this->Article->contain('Comment.User');
  221. $r = $this->Article->find('all');
  222. $this->assertTrue(Set::matches('/Comment/User', $r));
  223. $this->assertFalse(Set::matches('/Comment/Article', $r));
  224. $r = $this->Article->find('all');
  225. $this->assertFalse(Set::matches('/Comment/User', $r));
  226. }
  227. /**
  228. * testContainFindList method
  229. *
  230. * @return void
  231. */
  232. public function testContainFindList() {
  233. $this->Article->contain('Comment.User');
  234. $result = $this->Article->find('list');
  235. $expected = array(
  236. 1 => 'First Article',
  237. 2 => 'Second Article',
  238. 3 => 'Third Article'
  239. );
  240. $this->assertEquals($expected, $result);
  241. $result = $this->Article->find('list', array('fields' => array('Article.id', 'User.id'), 'contain' => array('User')));
  242. $expected = array(
  243. 1 => '1',
  244. 2 => '3',
  245. 3 => '1'
  246. );
  247. $this->assertEquals($expected, $result);
  248. }
  249. /**
  250. * Test that mixing contain() and the contain find option.
  251. *
  252. * @return void
  253. */
  254. public function testContainAndContainOption() {
  255. $this->Article->contain();
  256. $r = $this->Article->find('all', array(
  257. 'contain' => array('Comment')
  258. ));
  259. $this->assertTrue(isset($r[0]['Comment']), 'No comment returned');
  260. }
  261. /**
  262. * testFindEmbeddedNoBindings method
  263. *
  264. * @return void
  265. */
  266. public function testFindEmbeddedNoBindings() {
  267. $result = $this->Article->find('all', array('contain' => false));
  268. $expected = array(
  269. array('Article' => array(
  270. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  271. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  272. )),
  273. array('Article' => array(
  274. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  275. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  276. )),
  277. array('Article' => array(
  278. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  279. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  280. ))
  281. );
  282. $this->assertEquals($expected, $result);
  283. }
  284. /**
  285. * testFindFirstLevel method
  286. *
  287. * @return void
  288. */
  289. public function testFindFirstLevel() {
  290. $this->Article->contain('User');
  291. $result = $this->Article->find('all', array('recursive' => 1));
  292. $expected = array(
  293. array(
  294. 'Article' => array(
  295. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  296. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  297. ),
  298. 'User' => array(
  299. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  300. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  301. )
  302. ),
  303. array(
  304. 'Article' => array(
  305. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  306. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  307. ),
  308. 'User' => array(
  309. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  310. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  311. )
  312. ),
  313. array(
  314. 'Article' => array(
  315. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  316. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  317. ),
  318. 'User' => array(
  319. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  320. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  321. )
  322. )
  323. );
  324. $this->assertEquals($expected, $result);
  325. $this->Article->contain('User', 'Comment');
  326. $result = $this->Article->find('all', array('recursive' => 1));
  327. $expected = array(
  328. array(
  329. 'Article' => array(
  330. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  331. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  332. ),
  333. 'User' => array(
  334. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  335. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  336. ),
  337. 'Comment' => array(
  338. array(
  339. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  340. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
  341. ),
  342. array(
  343. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  344. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
  345. ),
  346. array(
  347. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  348. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  349. ),
  350. array(
  351. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  352. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  353. )
  354. )
  355. ),
  356. array(
  357. 'Article' => array(
  358. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  359. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  360. ),
  361. 'User' => array(
  362. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  363. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  364. ),
  365. 'Comment' => array(
  366. array(
  367. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  368. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  369. ),
  370. array(
  371. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  372. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
  373. )
  374. )
  375. ),
  376. array(
  377. 'Article' => array(
  378. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  379. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  380. ),
  381. 'User' => array(
  382. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  383. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  384. ),
  385. 'Comment' => array()
  386. )
  387. );
  388. $this->assertEquals($expected, $result);
  389. }
  390. /**
  391. * testFindEmbeddedFirstLevel method
  392. *
  393. * @return void
  394. */
  395. public function testFindEmbeddedFirstLevel() {
  396. $result = $this->Article->find('all', array('contain' => array('User')));
  397. $expected = array(
  398. array(
  399. 'Article' => array(
  400. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  401. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  402. ),
  403. 'User' => array(
  404. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  405. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  406. )
  407. ),
  408. array(
  409. 'Article' => array(
  410. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  411. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  412. ),
  413. 'User' => array(
  414. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  415. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  416. )
  417. ),
  418. array(
  419. 'Article' => array(
  420. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  421. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  422. ),
  423. 'User' => array(
  424. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  425. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  426. )
  427. )
  428. );
  429. $this->assertEquals($expected, $result);
  430. $result = $this->Article->find('all', array('contain' => array('User', 'Comment')));
  431. $expected = array(
  432. array(
  433. 'Article' => array(
  434. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  435. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  436. ),
  437. 'User' => array(
  438. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  439. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  440. ),
  441. 'Comment' => array(
  442. array(
  443. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  444. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
  445. ),
  446. array(
  447. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  448. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
  449. ),
  450. array(
  451. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  452. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  453. ),
  454. array(
  455. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  456. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  457. )
  458. )
  459. ),
  460. array(
  461. 'Article' => array(
  462. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  463. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  464. ),
  465. 'User' => array(
  466. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  467. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  468. ),
  469. 'Comment' => array(
  470. array(
  471. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  472. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  473. ),
  474. array(
  475. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  476. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
  477. )
  478. )
  479. ),
  480. array(
  481. 'Article' => array(
  482. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  483. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  484. ),
  485. 'User' => array(
  486. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  487. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  488. ),
  489. 'Comment' => array()
  490. )
  491. );
  492. $this->assertEquals($expected, $result);
  493. }
  494. /**
  495. * testFindSecondLevel method
  496. *
  497. * @return void
  498. */
  499. public function testFindSecondLevel() {
  500. $this->Article->contain(array('Comment' => 'User'));
  501. $result = $this->Article->find('all', array('recursive' => 2));
  502. $expected = array(
  503. array(
  504. 'Article' => array(
  505. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  506. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  507. ),
  508. 'Comment' => array(
  509. array(
  510. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  511. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  512. 'User' => array(
  513. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  514. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  515. )
  516. ),
  517. array(
  518. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  519. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  520. 'User' => array(
  521. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  522. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  523. )
  524. ),
  525. array(
  526. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  527. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  528. 'User' => array(
  529. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  530. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  531. )
  532. ),
  533. array(
  534. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  535. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  536. 'User' => array(
  537. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  538. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  539. )
  540. )
  541. )
  542. ),
  543. array(
  544. 'Article' => array(
  545. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  546. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  547. ),
  548. 'Comment' => array(
  549. array(
  550. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  551. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  552. 'User' => array(
  553. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  554. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  555. )
  556. ),
  557. array(
  558. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  559. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  560. 'User' => array(
  561. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  562. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  563. )
  564. )
  565. )
  566. ),
  567. array(
  568. 'Article' => array(
  569. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  570. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  571. ),
  572. 'Comment' => array()
  573. )
  574. );
  575. $this->assertEquals($expected, $result);
  576. $this->Article->contain(array('User' => 'ArticleFeatured'));
  577. $result = $this->Article->find('all', array('recursive' => 2));
  578. $expected = array(
  579. array(
  580. 'Article' => array(
  581. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  582. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  583. ),
  584. 'User' => array(
  585. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  586. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  587. 'ArticleFeatured' => array(
  588. array(
  589. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  590. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  591. ),
  592. array(
  593. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  594. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  595. )
  596. )
  597. )
  598. ),
  599. array(
  600. 'Article' => array(
  601. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  602. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  603. ),
  604. 'User' => array(
  605. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  606. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  607. 'ArticleFeatured' => array(
  608. array(
  609. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  610. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  611. )
  612. )
  613. )
  614. ),
  615. array(
  616. 'Article' => array(
  617. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  618. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  619. ),
  620. 'User' => array(
  621. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  622. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  623. 'ArticleFeatured' => array(
  624. array(
  625. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  626. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  627. ),
  628. array(
  629. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  630. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  631. )
  632. )
  633. )
  634. )
  635. );
  636. $this->assertEquals($expected, $result);
  637. $this->Article->contain(array('User' => array('id', 'ArticleFeatured')));
  638. $result = $this->Article->find('all', array('recursive' => 2));
  639. $expected = array(
  640. array(
  641. 'Article' => array(
  642. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  643. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  644. ),
  645. 'User' => array(
  646. 'id' => 1,
  647. 'ArticleFeatured' => array(
  648. array(
  649. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  650. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  651. ),
  652. array(
  653. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  654. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  655. )
  656. )
  657. )
  658. ),
  659. array(
  660. 'Article' => array(
  661. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  662. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  663. ),
  664. 'User' => array(
  665. 'id' => 3,
  666. 'ArticleFeatured' => array(
  667. array(
  668. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  669. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  670. )
  671. )
  672. )
  673. ),
  674. array(
  675. 'Article' => array(
  676. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  677. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  678. ),
  679. 'User' => array(
  680. 'id' => 1,
  681. 'ArticleFeatured' => array(
  682. array(
  683. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  684. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  685. ),
  686. array(
  687. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  688. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  689. )
  690. )
  691. )
  692. )
  693. );
  694. $this->assertEquals($expected, $result);
  695. $this->Article->contain(array('User' => array('ArticleFeatured', 'Comment')));
  696. $result = $this->Article->find('all', array('recursive' => 2));
  697. $expected = array(
  698. array(
  699. 'Article' => array(
  700. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  701. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  702. ),
  703. 'User' => array(
  704. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  705. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  706. 'ArticleFeatured' => array(
  707. array(
  708. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  709. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  710. ),
  711. array(
  712. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  713. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  714. )
  715. ),
  716. 'Comment' => array(
  717. array(
  718. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  719. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  720. ),
  721. array(
  722. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  723. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  724. ),
  725. array(
  726. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  727. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  728. )
  729. )
  730. )
  731. ),
  732. array(
  733. 'Article' => array(
  734. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  735. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  736. ),
  737. 'User' => array(
  738. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  739. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  740. 'ArticleFeatured' => array(
  741. array(
  742. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  743. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  744. )
  745. ),
  746. 'Comment' => array()
  747. )
  748. ),
  749. array(
  750. 'Article' => array(
  751. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  752. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  753. ),
  754. 'User' => array(
  755. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  756. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  757. 'ArticleFeatured' => array(
  758. array(
  759. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  760. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  761. ),
  762. array(
  763. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  764. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  765. )
  766. ),
  767. 'Comment' => array(
  768. array(
  769. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  770. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  771. ),
  772. array(
  773. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  774. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  775. ),
  776. array(
  777. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  778. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  779. )
  780. )
  781. )
  782. )
  783. );
  784. $this->assertEquals($expected, $result);
  785. $this->Article->contain(array('User' => array('ArticleFeatured')), 'Tag', array('Comment' => 'Attachment'));
  786. $result = $this->Article->find('all', array('recursive' => 2));
  787. $expected = array(
  788. array(
  789. 'Article' => array(
  790. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  791. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  792. ),
  793. 'User' => array(
  794. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  795. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  796. 'ArticleFeatured' => array(
  797. array(
  798. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  799. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  800. ),
  801. array(
  802. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  803. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  804. )
  805. )
  806. ),
  807. 'Comment' => array(
  808. array(
  809. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  810. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  811. 'Attachment' => array()
  812. ),
  813. array(
  814. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  815. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  816. 'Attachment' => array()
  817. ),
  818. array(
  819. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  820. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  821. 'Attachment' => array()
  822. ),
  823. array(
  824. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  825. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  826. 'Attachment' => array()
  827. )
  828. ),
  829. 'Tag' => array(
  830. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  831. array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
  832. )
  833. ),
  834. array(
  835. 'Article' => array(
  836. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  837. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  838. ),
  839. 'User' => array(
  840. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  841. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  842. 'ArticleFeatured' => array(
  843. array(
  844. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  845. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  846. )
  847. )
  848. ),
  849. 'Comment' => array(
  850. array(
  851. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  852. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  853. 'Attachment' => array(
  854. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  855. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  856. )
  857. ),
  858. array(
  859. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  860. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  861. 'Attachment' => array()
  862. )
  863. ),
  864. 'Tag' => array(
  865. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  866. array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
  867. )
  868. ),
  869. array(
  870. 'Article' => array(
  871. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  872. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  873. ),
  874. 'User' => array(
  875. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  876. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  877. 'ArticleFeatured' => array(
  878. array(
  879. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  880. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  881. ),
  882. array(
  883. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  884. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  885. )
  886. )
  887. ),
  888. 'Comment' => array(),
  889. 'Tag' => array()
  890. )
  891. );
  892. $this->assertEquals($expected, $result);
  893. }
  894. /**
  895. * testFindEmbeddedSecondLevel method
  896. *
  897. * @return void
  898. */
  899. public function testFindEmbeddedSecondLevel() {
  900. $result = $this->Article->find('all', array('contain' => array('Comment' => 'User')));
  901. $expected = array(
  902. array(
  903. 'Article' => array(
  904. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  905. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  906. ),
  907. 'Comment' => array(
  908. array(
  909. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  910. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  911. 'User' => array(
  912. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  913. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  914. )
  915. ),
  916. array(
  917. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  918. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  919. 'User' => array(
  920. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  921. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  922. )
  923. ),
  924. array(
  925. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  926. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  927. 'User' => array(
  928. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  929. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  930. )
  931. ),
  932. array(
  933. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  934. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  935. 'User' => array(
  936. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  937. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  938. )
  939. )
  940. )
  941. ),
  942. array(
  943. 'Article' => array(
  944. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  945. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  946. ),
  947. 'Comment' => array(
  948. array(
  949. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  950. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  951. 'User' => array(
  952. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  953. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  954. )
  955. ),
  956. array(
  957. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  958. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  959. 'User' => array(
  960. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  961. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  962. )
  963. )
  964. )
  965. ),
  966. array(
  967. 'Article' => array(
  968. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  969. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  970. ),
  971. 'Comment' => array()
  972. )
  973. );
  974. $this->assertEquals($expected, $result);
  975. $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured')));
  976. $expected = array(
  977. array(
  978. 'Article' => array(
  979. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  980. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  981. ),
  982. 'User' => array(
  983. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  984. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  985. 'ArticleFeatured' => array(
  986. array(
  987. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  988. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  989. ),
  990. array(
  991. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  992. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  993. )
  994. )
  995. )
  996. ),
  997. array(
  998. 'Article' => array(
  999. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1000. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1001. ),
  1002. 'User' => array(
  1003. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1004. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  1005. 'ArticleFeatured' => array(
  1006. array(
  1007. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1008. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1009. )
  1010. )
  1011. )
  1012. ),
  1013. array(
  1014. 'Article' => array(
  1015. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1016. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1017. ),
  1018. 'User' => array(
  1019. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1020. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1021. 'ArticleFeatured' => array(
  1022. array(
  1023. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1024. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1025. ),
  1026. array(
  1027. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1028. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1029. )
  1030. )
  1031. )
  1032. )
  1033. );
  1034. $this->assertEquals($expected, $result);
  1035. $result = $this->Article->find('all', array('contain' => array('User' => array('ArticleFeatured', 'Comment'))));
  1036. $expected = array(
  1037. array(
  1038. 'Article' => array(
  1039. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1040. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1041. ),
  1042. 'User' => array(
  1043. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1044. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1045. 'ArticleFeatured' => array(
  1046. array(
  1047. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1048. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1049. ),
  1050. array(
  1051. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1052. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1053. )
  1054. ),
  1055. 'Comment' => array(
  1056. array(
  1057. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1058. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  1059. ),
  1060. array(
  1061. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1062. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1063. ),
  1064. array(
  1065. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1066. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  1067. )
  1068. )
  1069. )
  1070. ),
  1071. array(
  1072. 'Article' => array(
  1073. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1074. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1075. ),
  1076. 'User' => array(
  1077. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1078. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  1079. 'ArticleFeatured' => array(
  1080. array(
  1081. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1082. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1083. )
  1084. ),
  1085. 'Comment' => array()
  1086. )
  1087. ),
  1088. array(
  1089. 'Article' => array(
  1090. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1091. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1092. ),
  1093. 'User' => array(
  1094. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1095. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1096. 'ArticleFeatured' => array(
  1097. array(
  1098. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1099. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1100. ),
  1101. array(
  1102. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1103. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1104. )
  1105. ),
  1106. 'Comment' => array(
  1107. array(
  1108. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1109. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  1110. ),
  1111. array(
  1112. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1113. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1114. ),
  1115. array(
  1116. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1117. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  1118. )
  1119. )
  1120. )
  1121. )
  1122. );
  1123. $this->assertEquals($expected, $result);
  1124. $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured', 'Tag', 'Comment' => 'Attachment')));
  1125. $expected = array(
  1126. array(
  1127. 'Article' => array(
  1128. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1129. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1130. ),
  1131. 'User' => array(
  1132. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1133. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1134. 'ArticleFeatured' => array(
  1135. array(
  1136. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1137. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1138. ),
  1139. array(
  1140. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1141. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1142. )
  1143. )
  1144. ),
  1145. 'Comment' => array(
  1146. array(
  1147. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1148. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1149. 'Attachment' => array()
  1150. ),
  1151. array(
  1152. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1153. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1154. 'Attachment' => array()
  1155. ),
  1156. array(
  1157. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1158. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1159. 'Attachment' => array()
  1160. ),
  1161. array(
  1162. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1163. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1164. 'Attachment' => array()
  1165. )
  1166. ),
  1167. 'Tag' => array(
  1168. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  1169. array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
  1170. )
  1171. ),
  1172. array(
  1173. 'Article' => array(
  1174. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1175. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1176. ),
  1177. 'User' => array(
  1178. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1179. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  1180. 'ArticleFeatured' => array(
  1181. array(
  1182. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1183. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1184. )
  1185. )
  1186. ),
  1187. 'Comment' => array(
  1188. array(
  1189. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1190. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1191. 'Attachment' => array(
  1192. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1193. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1194. )
  1195. ),
  1196. array(
  1197. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1198. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1199. 'Attachment' => array()
  1200. )
  1201. ),
  1202. 'Tag' => array(
  1203. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  1204. array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
  1205. )
  1206. ),
  1207. array(
  1208. 'Article' => array(
  1209. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1210. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1211. ),
  1212. 'User' => array(
  1213. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1214. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1215. 'ArticleFeatured' => array(
  1216. array(
  1217. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1218. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1219. ),
  1220. array(
  1221. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1222. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1223. )
  1224. )
  1225. ),
  1226. 'Comment' => array(),
  1227. 'Tag' => array()
  1228. )
  1229. );
  1230. $this->assertEquals($expected, $result);
  1231. }
  1232. /**
  1233. * testFindThirdLevel method
  1234. *
  1235. * @return void
  1236. */
  1237. public function testFindThirdLevel() {
  1238. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category')));
  1239. $result = $this->User->find('all', array('recursive' => 3));
  1240. $expected = array(
  1241. array(
  1242. 'User' => array(
  1243. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1244. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1245. ),
  1246. 'ArticleFeatured' => array(
  1247. array(
  1248. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1249. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1250. 'Featured' => array(
  1251. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1252. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1253. 'Category' => array(
  1254. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1255. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1256. )
  1257. )
  1258. ),
  1259. array(
  1260. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1261. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1262. 'Featured' => array()
  1263. )
  1264. )
  1265. ),
  1266. array(
  1267. 'User' => array(
  1268. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1269. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1270. ),
  1271. 'ArticleFeatured' => array()
  1272. ),
  1273. array(
  1274. 'User' => array(
  1275. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1276. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1277. ),
  1278. 'ArticleFeatured' => array(
  1279. array(
  1280. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1281. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1282. 'Featured' => array(
  1283. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1284. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1285. 'Category' => array(
  1286. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1287. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1288. )
  1289. )
  1290. )
  1291. )
  1292. ),
  1293. array(
  1294. 'User' => array(
  1295. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1296. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1297. ),
  1298. 'ArticleFeatured' => array()
  1299. )
  1300. );
  1301. $this->assertEquals($expected, $result);
  1302. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
  1303. $result = $this->User->find('all', array('recursive' => 3));
  1304. $expected = array(
  1305. array(
  1306. 'User' => array(
  1307. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1308. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1309. ),
  1310. 'ArticleFeatured' => array(
  1311. array(
  1312. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1313. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1314. 'Featured' => array(
  1315. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1316. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1317. 'Category' => array(
  1318. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1319. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1320. )
  1321. ),
  1322. 'Comment' => array(
  1323. array(
  1324. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1325. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1326. 'Article' => array(
  1327. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1328. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1329. ),
  1330. 'Attachment' => array()
  1331. ),
  1332. array(
  1333. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1334. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1335. 'Article' => array(
  1336. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1337. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1338. ),
  1339. 'Attachment' => array()
  1340. ),
  1341. array(
  1342. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1343. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1344. 'Article' => array(
  1345. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1346. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1347. ),
  1348. 'Attachment' => array()
  1349. ),
  1350. array(
  1351. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1352. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1353. 'Article' => array(
  1354. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1355. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1356. ),
  1357. 'Attachment' => array()
  1358. )
  1359. )
  1360. ),
  1361. array(
  1362. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1363. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1364. 'Featured' => array(),
  1365. 'Comment' => array()
  1366. )
  1367. )
  1368. ),
  1369. array(
  1370. 'User' => array(
  1371. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1372. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1373. ),
  1374. 'ArticleFeatured' => array()
  1375. ),
  1376. array(
  1377. 'User' => array(
  1378. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1379. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1380. ),
  1381. 'ArticleFeatured' => array(
  1382. array(
  1383. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1384. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1385. 'Featured' => array(
  1386. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1387. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1388. 'Category' => array(
  1389. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1390. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1391. )
  1392. ),
  1393. 'Comment' => array(
  1394. array(
  1395. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1396. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1397. 'Article' => array(
  1398. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1399. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1400. ),
  1401. 'Attachment' => array(
  1402. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1403. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1404. )
  1405. ),
  1406. array(
  1407. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1408. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1409. 'Article' => array(
  1410. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1411. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1412. ),
  1413. 'Attachment' => array()
  1414. )
  1415. )
  1416. )
  1417. )
  1418. ),
  1419. array(
  1420. 'User' => array(
  1421. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1422. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1423. ),
  1424. 'ArticleFeatured' => array()
  1425. )
  1426. );
  1427. $this->assertEquals($expected, $result);
  1428. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
  1429. $result = $this->User->find('all', array('recursive' => 3));
  1430. $expected = array(
  1431. array(
  1432. 'User' => array(
  1433. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1434. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1435. ),
  1436. 'Article' => array(
  1437. array(
  1438. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1439. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1440. ),
  1441. array(
  1442. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1443. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1444. )
  1445. ),
  1446. 'ArticleFeatured' => array(
  1447. array(
  1448. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1449. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1450. 'Featured' => array(
  1451. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1452. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1453. 'Category' => array(
  1454. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1455. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1456. )
  1457. ),
  1458. 'Comment' => array(
  1459. array(
  1460. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1461. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1462. 'Attachment' => array()
  1463. ),
  1464. array(
  1465. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1466. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1467. 'Attachment' => array()
  1468. ),
  1469. array(
  1470. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1471. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1472. 'Attachment' => array()
  1473. ),
  1474. array(
  1475. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1476. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1477. 'Attachment' => array()
  1478. )
  1479. )
  1480. ),
  1481. array(
  1482. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1483. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1484. 'Featured' => array(),
  1485. 'Comment' => array()
  1486. )
  1487. )
  1488. ),
  1489. array(
  1490. 'User' => array(
  1491. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1492. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1493. ),
  1494. 'Article' => array(),
  1495. 'ArticleFeatured' => array()
  1496. ),
  1497. array(
  1498. 'User' => array(
  1499. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1500. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1501. ),
  1502. 'Article' => array(
  1503. array(
  1504. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1505. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1506. )
  1507. ),
  1508. 'ArticleFeatured' => array(
  1509. array(
  1510. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1511. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1512. 'Featured' => array(
  1513. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1514. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1515. 'Category' => array(
  1516. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1517. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1518. )
  1519. ),
  1520. 'Comment' => array(
  1521. array(
  1522. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1523. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1524. 'Attachment' => array(
  1525. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1526. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1527. )
  1528. ),
  1529. array(
  1530. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1531. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1532. 'Attachment' => array()
  1533. )
  1534. )
  1535. )
  1536. )
  1537. ),
  1538. array(
  1539. 'User' => array(
  1540. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1541. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1542. ),
  1543. 'Article' => array(),
  1544. 'ArticleFeatured' => array()
  1545. )
  1546. );
  1547. $this->assertEquals($expected, $result);
  1548. }
  1549. /**
  1550. * testFindEmbeddedThirdLevel method
  1551. *
  1552. * @return void
  1553. */
  1554. public function testFindEmbeddedThirdLevel() {
  1555. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
  1556. $expected = array(
  1557. array(
  1558. 'User' => array(
  1559. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1560. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1561. ),
  1562. 'ArticleFeatured' => array(
  1563. array(
  1564. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1565. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1566. 'Featured' => array(
  1567. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1568. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1569. 'Category' => array(
  1570. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1571. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1572. )
  1573. )
  1574. ),
  1575. array(
  1576. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1577. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1578. 'Featured' => array()
  1579. )
  1580. )
  1581. ),
  1582. array(
  1583. 'User' => array(
  1584. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1585. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1586. ),
  1587. 'ArticleFeatured' => array()
  1588. ),
  1589. array(
  1590. 'User' => array(
  1591. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1592. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1593. ),
  1594. 'ArticleFeatured' => array(
  1595. array(
  1596. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1597. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1598. 'Featured' => array(
  1599. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1600. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1601. 'Category' => array(
  1602. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1603. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1604. )
  1605. )
  1606. )
  1607. )
  1608. ),
  1609. array(
  1610. 'User' => array(
  1611. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1612. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1613. ),
  1614. 'ArticleFeatured' => array()
  1615. )
  1616. );
  1617. $this->assertEquals($expected, $result);
  1618. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
  1619. $expected = array(
  1620. array(
  1621. 'User' => array(
  1622. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1623. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1624. ),
  1625. 'ArticleFeatured' => array(
  1626. array(
  1627. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1628. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1629. 'Featured' => array(
  1630. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1631. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1632. 'Category' => array(
  1633. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1634. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1635. )
  1636. ),
  1637. 'Comment' => array(
  1638. array(
  1639. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1640. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1641. 'Article' => array(
  1642. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1643. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1644. ),
  1645. 'Attachment' => array()
  1646. ),
  1647. array(
  1648. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1649. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1650. 'Article' => array(
  1651. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1652. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1653. ),
  1654. 'Attachment' => array()
  1655. ),
  1656. array(
  1657. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1658. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1659. 'Article' => array(
  1660. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1661. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1662. ),
  1663. 'Attachment' => array()
  1664. ),
  1665. array(
  1666. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1667. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1668. 'Article' => array(
  1669. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1670. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1671. ),
  1672. 'Attachment' => array()
  1673. )
  1674. )
  1675. ),
  1676. array(
  1677. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1678. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1679. 'Featured' => array(),
  1680. 'Comment' => array()
  1681. )
  1682. )
  1683. ),
  1684. array(
  1685. 'User' => array(
  1686. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1687. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1688. ),
  1689. 'ArticleFeatured' => array()
  1690. ),
  1691. array(
  1692. 'User' => array(
  1693. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1694. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1695. ),
  1696. 'ArticleFeatured' => array(
  1697. array(
  1698. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1699. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1700. 'Featured' => array(
  1701. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1702. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1703. 'Category' => array(
  1704. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1705. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1706. )
  1707. ),
  1708. 'Comment' => array(
  1709. array(
  1710. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1711. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1712. 'Article' => array(
  1713. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1714. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1715. ),
  1716. 'Attachment' => array(
  1717. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1718. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1719. )
  1720. ),
  1721. array(
  1722. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1723. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1724. 'Article' => array(
  1725. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1726. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1727. ),
  1728. 'Attachment' => array()
  1729. )
  1730. )
  1731. )
  1732. )
  1733. ),
  1734. array(
  1735. 'User' => array(
  1736. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1737. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1738. ),
  1739. 'ArticleFeatured' => array()
  1740. )
  1741. );
  1742. $this->assertEquals($expected, $result);
  1743. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
  1744. $expected = array(
  1745. array(
  1746. 'User' => array(
  1747. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1748. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1749. ),
  1750. 'Article' => array(
  1751. array(
  1752. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1753. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1754. ),
  1755. array(
  1756. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1757. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1758. )
  1759. ),
  1760. 'ArticleFeatured' => array(
  1761. array(
  1762. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1763. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1764. 'Featured' => array(
  1765. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1766. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1767. 'Category' => array(
  1768. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1769. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1770. )
  1771. ),
  1772. 'Comment' => array(
  1773. array(
  1774. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1775. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1776. 'Attachment' => array()
  1777. ),
  1778. array(
  1779. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1780. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1781. 'Attachment' => array()
  1782. ),
  1783. array(
  1784. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1785. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1786. 'Attachment' => array()
  1787. ),
  1788. array(
  1789. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1790. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1791. 'Attachment' => array()
  1792. )
  1793. )
  1794. ),
  1795. array(
  1796. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1797. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1798. 'Featured' => array(),
  1799. 'Comment' => array()
  1800. )
  1801. )
  1802. ),
  1803. array(
  1804. 'User' => array(
  1805. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1806. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1807. ),
  1808. 'Article' => array(),
  1809. 'ArticleFeatured' => array()
  1810. ),
  1811. array(
  1812. 'User' => array(
  1813. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1814. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1815. ),
  1816. 'Article' => array(
  1817. array(
  1818. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1819. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1820. )
  1821. ),
  1822. 'ArticleFeatured' => array(
  1823. array(
  1824. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1825. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1826. 'Featured' => array(
  1827. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1828. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1829. 'Category' => array(
  1830. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1831. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1832. )
  1833. ),
  1834. 'Comment' => array(
  1835. array(
  1836. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1837. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1838. 'Attachment' => array(
  1839. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1840. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1841. )
  1842. ),
  1843. array(
  1844. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1845. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1846. 'Attachment' => array()
  1847. )
  1848. )
  1849. )
  1850. )
  1851. ),
  1852. array(
  1853. 'User' => array(
  1854. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1855. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1856. ),
  1857. 'Article' => array(),
  1858. 'ArticleFeatured' => array()
  1859. )
  1860. );
  1861. $this->assertEquals($expected, $result);
  1862. }
  1863. /**
  1864. * testSettingsThirdLevel method
  1865. *
  1866. * @return void
  1867. */
  1868. public function testSettingsThirdLevel() {
  1869. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => array('Category' => array('id', 'name'))))));
  1870. $expected = array(
  1871. array(
  1872. 'User' => array(
  1873. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1874. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1875. ),
  1876. 'ArticleFeatured' => array(
  1877. array(
  1878. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1879. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1880. 'Featured' => array(
  1881. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1882. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1883. 'Category' => array(
  1884. 'id' => 1, 'name' => 'Category 1'
  1885. )
  1886. )
  1887. ),
  1888. array(
  1889. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1890. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1891. 'Featured' => array()
  1892. )
  1893. )
  1894. ),
  1895. array(
  1896. 'User' => array(
  1897. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1898. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1899. ),
  1900. 'ArticleFeatured' => array()
  1901. ),
  1902. array(
  1903. 'User' => array(
  1904. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1905. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1906. ),
  1907. 'ArticleFeatured' => array(
  1908. array(
  1909. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1910. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1911. 'Featured' => array(
  1912. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1913. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1914. 'Category' => array(
  1915. 'id' => 1, 'name' => 'Category 1'
  1916. )
  1917. )
  1918. )
  1919. )
  1920. ),
  1921. array(
  1922. 'User' => array(
  1923. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1924. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1925. ),
  1926. 'ArticleFeatured' => array()
  1927. )
  1928. );
  1929. $this->assertEquals($expected, $result);
  1930. $r = $this->User->find('all', array('contain' => array(
  1931. 'ArticleFeatured' => array(
  1932. 'id', 'title',
  1933. 'Featured' => array(
  1934. 'id', 'category_id',
  1935. 'Category' => array('id', 'name')
  1936. )
  1937. )
  1938. )));
  1939. $this->assertTrue(Set::matches('/User[id=1]', $r));
  1940. $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
  1941. $this->assertTrue(Set::matches('/ArticleFeatured', $r));
  1942. $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
  1943. $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
  1944. $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
  1945. $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
  1946. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
  1947. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[id=1]', $r));
  1948. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
  1949. $r = $this->User->find('all', array('contain' => array(
  1950. 'ArticleFeatured' => array(
  1951. 'title',
  1952. 'Featured' => array(
  1953. 'id',
  1954. 'Category' => 'name'
  1955. )
  1956. )
  1957. )));
  1958. $this->assertTrue(Set::matches('/User[id=1]', $r));
  1959. $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
  1960. $this->assertTrue(Set::matches('/ArticleFeatured', $r));
  1961. $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
  1962. $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
  1963. $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
  1964. $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
  1965. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
  1966. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
  1967. $result = $this->User->find('all', array('contain' => array(
  1968. 'ArticleFeatured' => array(
  1969. 'title',
  1970. 'Featured' => array(
  1971. 'category_id',
  1972. 'Category' => 'name'
  1973. )
  1974. )
  1975. )));
  1976. $expected = array(
  1977. array(
  1978. 'User' => array(
  1979. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1980. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1981. ),
  1982. 'ArticleFeatured' => array(
  1983. array(
  1984. 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
  1985. 'Featured' => array(
  1986. 'category_id' => 1, 'id' => 1,
  1987. 'Category' => array(
  1988. 'name' => 'Category 1'
  1989. )
  1990. )
  1991. ),
  1992. array(
  1993. 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
  1994. 'Featured' => array()
  1995. )
  1996. )
  1997. ),
  1998. array(
  1999. 'User' => array(
  2000. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2001. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2002. ),
  2003. 'ArticleFeatured' => array()
  2004. ),
  2005. array(
  2006. 'User' => array(
  2007. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2008. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2009. ),
  2010. 'ArticleFeatured' => array(
  2011. array(
  2012. 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
  2013. 'Featured' => array(
  2014. 'category_id' => 1, 'id' => 2,
  2015. 'Category' => array(
  2016. 'name' => 'Category 1'
  2017. )
  2018. )
  2019. )
  2020. )
  2021. ),
  2022. array(
  2023. 'User' => array(
  2024. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2025. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2026. ),
  2027. 'ArticleFeatured' => array()
  2028. )
  2029. );
  2030. $this->assertEquals($expected, $result);
  2031. $orders = array(
  2032. 'title DESC', 'title DESC, published DESC',
  2033. array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'),
  2034. );
  2035. foreach ($orders as $order) {
  2036. $result = $this->User->find('all', array('contain' => array(
  2037. 'ArticleFeatured' => array(
  2038. 'title', 'order' => $order,
  2039. 'Featured' => array(
  2040. 'category_id',
  2041. 'Category' => 'name'
  2042. )
  2043. )
  2044. )));
  2045. $expected = array(
  2046. array(
  2047. 'User' => array(
  2048. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2049. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2050. ),
  2051. 'ArticleFeatured' => array(
  2052. array(
  2053. 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
  2054. 'Featured' => array()
  2055. ),
  2056. array(
  2057. 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
  2058. 'Featured' => array(
  2059. 'category_id' => 1, 'id' => 1,
  2060. 'Category' => array(
  2061. 'name' => 'Category 1'
  2062. )
  2063. )
  2064. )
  2065. )
  2066. ),
  2067. array(
  2068. 'User' => array(
  2069. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2070. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2071. ),
  2072. 'ArticleFeatured' => array()
  2073. ),
  2074. array(
  2075. 'User' => array(
  2076. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2077. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2078. ),
  2079. 'ArticleFeatured' => array(
  2080. array(
  2081. 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
  2082. 'Featured' => array(
  2083. 'category_id' => 1, 'id' => 2,
  2084. 'Category' => array(
  2085. 'name' => 'Category 1'
  2086. )
  2087. )
  2088. )
  2089. )
  2090. ),
  2091. array(
  2092. 'User' => array(
  2093. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2094. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2095. ),
  2096. 'ArticleFeatured' => array()
  2097. )
  2098. );
  2099. $this->assertEquals($expected, $result);
  2100. }
  2101. }
  2102. /**
  2103. * testFindThirdLevelNonReset method
  2104. *
  2105. * @return void
  2106. */
  2107. public function testFindThirdLevelNonReset() {
  2108. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category')));
  2109. $result = $this->User->find('all', array('recursive' => 3));
  2110. $expected = array(
  2111. array(
  2112. 'User' => array(
  2113. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2114. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2115. ),
  2116. 'ArticleFeatured' => array(
  2117. array(
  2118. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2119. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2120. 'Featured' => array(
  2121. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2122. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2123. 'Category' => array(
  2124. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2125. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2126. )
  2127. )
  2128. ),
  2129. array(
  2130. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2131. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2132. 'Featured' => array()
  2133. )
  2134. )
  2135. ),
  2136. array(
  2137. 'User' => array(
  2138. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2139. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2140. ),
  2141. 'ArticleFeatured' => array()
  2142. ),
  2143. array(
  2144. 'User' => array(
  2145. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2146. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2147. ),
  2148. 'ArticleFeatured' => array(
  2149. array(
  2150. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2151. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2152. 'Featured' => array(
  2153. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2154. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2155. 'Category' => array(
  2156. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2157. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2158. )
  2159. )
  2160. )
  2161. )
  2162. ),
  2163. array(
  2164. 'User' => array(
  2165. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2166. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2167. ),
  2168. 'ArticleFeatured' => array()
  2169. )
  2170. );
  2171. $this->assertEquals($expected, $result);
  2172. $this->User->resetBindings();
  2173. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
  2174. $result = $this->User->find('all', array('recursive' => 3));
  2175. $expected = array(
  2176. array(
  2177. 'User' => array(
  2178. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2179. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2180. ),
  2181. 'ArticleFeatured' => array(
  2182. array(
  2183. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2184. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2185. 'Featured' => array(
  2186. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2187. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2188. 'Category' => array(
  2189. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2190. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2191. )
  2192. ),
  2193. 'Comment' => array(
  2194. array(
  2195. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2196. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2197. 'Article' => array(
  2198. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2199. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2200. ),
  2201. 'Attachment' => array()
  2202. ),
  2203. array(
  2204. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2205. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2206. 'Article' => array(
  2207. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2208. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2209. ),
  2210. 'Attachment' => array()
  2211. ),
  2212. array(
  2213. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2214. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2215. 'Article' => array(
  2216. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2217. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2218. ),
  2219. 'Attachment' => array()
  2220. ),
  2221. array(
  2222. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2223. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2224. 'Article' => array(
  2225. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2226. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2227. ),
  2228. 'Attachment' => array()
  2229. )
  2230. )
  2231. ),
  2232. array(
  2233. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2234. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2235. 'Featured' => array(),
  2236. 'Comment' => array()
  2237. )
  2238. )
  2239. ),
  2240. array(
  2241. 'User' => array(
  2242. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2243. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2244. ),
  2245. 'ArticleFeatured' => array()
  2246. ),
  2247. array(
  2248. 'User' => array(
  2249. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2250. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2251. ),
  2252. 'ArticleFeatured' => array(
  2253. array(
  2254. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2255. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2256. 'Featured' => array(
  2257. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2258. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2259. 'Category' => array(
  2260. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2261. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2262. )
  2263. ),
  2264. 'Comment' => array(
  2265. array(
  2266. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2267. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2268. 'Article' => array(
  2269. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2270. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2271. ),
  2272. 'Attachment' => array(
  2273. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2274. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2275. )
  2276. ),
  2277. array(
  2278. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2279. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2280. 'Article' => array(
  2281. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2282. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2283. ),
  2284. 'Attachment' => array()
  2285. )
  2286. )
  2287. )
  2288. )
  2289. ),
  2290. array(
  2291. 'User' => array(
  2292. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2293. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2294. ),
  2295. 'ArticleFeatured' => array()
  2296. )
  2297. );
  2298. $this->assertEquals($expected, $result);
  2299. $this->User->resetBindings();
  2300. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
  2301. $result = $this->User->find('all', array('recursive' => 3));
  2302. $expected = array(
  2303. array(
  2304. 'User' => array(
  2305. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2306. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2307. ),
  2308. 'Article' => array(
  2309. array(
  2310. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2311. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2312. ),
  2313. array(
  2314. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2315. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  2316. )
  2317. ),
  2318. 'ArticleFeatured' => array(
  2319. array(
  2320. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2321. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2322. 'Featured' => array(
  2323. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2324. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2325. 'Category' => array(
  2326. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2327. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2328. )
  2329. ),
  2330. 'Comment' => array(
  2331. array(
  2332. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2333. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2334. 'Attachment' => array()
  2335. ),
  2336. array(
  2337. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2338. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2339. 'Attachment' => array()
  2340. ),
  2341. array(
  2342. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2343. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2344. 'Attachment' => array()
  2345. ),
  2346. array(
  2347. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2348. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2349. 'Attachment' => array()
  2350. )
  2351. )
  2352. ),
  2353. array(
  2354. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2355. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2356. 'Featured' => array(),
  2357. 'Comment' => array()
  2358. )
  2359. )
  2360. ),
  2361. array(
  2362. 'User' => array(
  2363. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2364. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2365. ),
  2366. 'Article' => array(),
  2367. 'ArticleFeatured' => array()
  2368. ),
  2369. array(
  2370. 'User' => array(
  2371. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2372. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2373. ),
  2374. 'Article' => array(
  2375. array(
  2376. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2377. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2378. )
  2379. ),
  2380. 'ArticleFeatured' => array(
  2381. array(
  2382. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2383. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2384. 'Featured' => array(
  2385. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2386. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2387. 'Category' => array(
  2388. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2389. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2390. )
  2391. ),
  2392. 'Comment' => array(
  2393. array(
  2394. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2395. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2396. 'Attachment' => array(
  2397. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2398. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2399. )
  2400. ),
  2401. array(
  2402. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2403. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2404. 'Attachment' => array()
  2405. )
  2406. )
  2407. )
  2408. )
  2409. ),
  2410. array(
  2411. 'User' => array(
  2412. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2413. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2414. ),
  2415. 'Article' => array(),
  2416. 'ArticleFeatured' => array()
  2417. )
  2418. );
  2419. $this->assertEquals($expected, $result);
  2420. }
  2421. /**
  2422. * testFindEmbeddedThirdLevelNonReset method
  2423. *
  2424. * @return void
  2425. */
  2426. public function testFindEmbeddedThirdLevelNonReset() {
  2427. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
  2428. $expected = array(
  2429. array(
  2430. 'User' => array(
  2431. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2432. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2433. ),
  2434. 'ArticleFeatured' => array(
  2435. array(
  2436. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2437. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2438. 'Featured' => array(
  2439. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2440. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2441. 'Category' => array(
  2442. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2443. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2444. )
  2445. )
  2446. ),
  2447. array(
  2448. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2449. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2450. 'Featured' => array()
  2451. )
  2452. )
  2453. ),
  2454. array(
  2455. 'User' => array(
  2456. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2457. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2458. ),
  2459. 'ArticleFeatured' => array()
  2460. ),
  2461. array(
  2462. 'User' => array(
  2463. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2464. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2465. ),
  2466. 'ArticleFeatured' => array(
  2467. array(
  2468. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2469. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2470. 'Featured' => array(
  2471. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2472. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2473. 'Category' => array(
  2474. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2475. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2476. )
  2477. )
  2478. )
  2479. )
  2480. ),
  2481. array(
  2482. 'User' => array(
  2483. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2484. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2485. ),
  2486. 'ArticleFeatured' => array()
  2487. )
  2488. );
  2489. $this->assertEquals($expected, $result);
  2490. $this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2491. $this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured')));
  2492. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2493. $this->User->resetBindings();
  2494. $this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2495. $this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2496. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2497. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2498. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
  2499. $expected = array(
  2500. array(
  2501. 'User' => array(
  2502. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2503. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2504. ),
  2505. 'ArticleFeatured' => array(
  2506. array(
  2507. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2508. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2509. 'Featured' => array(
  2510. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2511. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2512. 'Category' => array(
  2513. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2514. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2515. )
  2516. ),
  2517. 'Comment' => array(
  2518. array(
  2519. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2520. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2521. 'Article' => array(
  2522. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2523. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2524. ),
  2525. 'Attachment' => array()
  2526. ),
  2527. array(
  2528. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2529. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2530. 'Article' => array(
  2531. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2532. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2533. ),
  2534. 'Attachment' => array()
  2535. ),
  2536. array(
  2537. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2538. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2539. 'Article' => array(
  2540. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2541. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2542. ),
  2543. 'Attachment' => array()
  2544. ),
  2545. array(
  2546. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2547. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2548. 'Article' => array(
  2549. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2550. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2551. ),
  2552. 'Attachment' => array()
  2553. )
  2554. )
  2555. ),
  2556. array(
  2557. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2558. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2559. 'Featured' => array(),
  2560. 'Comment' => array()
  2561. )
  2562. )
  2563. ),
  2564. array(
  2565. 'User' => array(
  2566. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2567. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2568. ),
  2569. 'ArticleFeatured' => array()
  2570. ),
  2571. array(
  2572. 'User' => array(
  2573. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2574. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2575. ),
  2576. 'ArticleFeatured' => array(
  2577. array(
  2578. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2579. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2580. 'Featured' => array(
  2581. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2582. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2583. 'Category' => array(
  2584. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2585. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2586. )
  2587. ),
  2588. 'Comment' => array(
  2589. array(
  2590. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2591. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2592. 'Article' => array(
  2593. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2594. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2595. ),
  2596. 'Attachment' => array(
  2597. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2598. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2599. )
  2600. ),
  2601. array(
  2602. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2603. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2604. 'Article' => array(
  2605. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2606. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2607. ),
  2608. 'Attachment' => array()
  2609. )
  2610. )
  2611. )
  2612. )
  2613. ),
  2614. array(
  2615. 'User' => array(
  2616. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2617. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2618. ),
  2619. 'ArticleFeatured' => array()
  2620. )
  2621. );
  2622. $this->assertEquals($expected, $result);
  2623. $this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2624. $this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2625. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2626. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
  2627. $this->User->resetBindings();
  2628. $this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2629. $this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2630. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2631. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2632. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')), false)));
  2633. $expected = array(
  2634. array(
  2635. 'User' => array(
  2636. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2637. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2638. ),
  2639. 'ArticleFeatured' => array(
  2640. array(
  2641. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2642. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2643. 'Featured' => array(
  2644. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2645. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2646. 'Category' => array(
  2647. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2648. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2649. )
  2650. ),
  2651. 'Comment' => array(
  2652. array(
  2653. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2654. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2655. 'Article' => array(
  2656. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2657. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2658. ),
  2659. 'Attachment' => array()
  2660. ),
  2661. array(
  2662. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2663. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2664. 'Article' => array(
  2665. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2666. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2667. ),
  2668. 'Attachment' => array()
  2669. ),
  2670. array(
  2671. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2672. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2673. 'Article' => array(
  2674. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2675. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2676. ),
  2677. 'Attachment' => array()
  2678. ),
  2679. array(
  2680. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2681. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2682. 'Article' => array(
  2683. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2684. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2685. ),
  2686. 'Attachment' => array()
  2687. )
  2688. )
  2689. ),
  2690. array(
  2691. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2692. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2693. 'Featured' => array(),
  2694. 'Comment' => array()
  2695. )
  2696. )
  2697. ),
  2698. array(
  2699. 'User' => array(
  2700. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2701. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2702. ),
  2703. 'ArticleFeatured' => array()
  2704. ),
  2705. array(
  2706. 'User' => array(
  2707. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2708. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2709. ),
  2710. 'ArticleFeatured' => array(
  2711. array(
  2712. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2713. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2714. 'Featured' => array(
  2715. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2716. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2717. 'Category' => array(
  2718. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2719. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2720. )
  2721. ),
  2722. 'Comment' => array(
  2723. array(
  2724. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2725. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2726. 'Article' => array(
  2727. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2728. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2729. ),
  2730. 'Attachment' => array(
  2731. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2732. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2733. )
  2734. ),
  2735. array(
  2736. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2737. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2738. 'Article' => array(
  2739. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2740. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2741. ),
  2742. 'Attachment' => array()
  2743. )
  2744. )
  2745. )
  2746. )
  2747. ),
  2748. array(
  2749. 'User' => array(
  2750. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2751. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2752. ),
  2753. 'ArticleFeatured' => array()
  2754. )
  2755. );
  2756. $this->assertEquals($expected, $result);
  2757. $this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2758. $this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2759. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2760. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
  2761. $this->User->resetBindings();
  2762. $this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2763. $this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2764. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2765. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2766. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
  2767. $expected = array(
  2768. array(
  2769. 'User' => array(
  2770. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2771. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2772. ),
  2773. 'Article' => array(
  2774. array(
  2775. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2776. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2777. ),
  2778. array(
  2779. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2780. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  2781. )
  2782. ),
  2783. 'ArticleFeatured' => array(
  2784. array(
  2785. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2786. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2787. 'Featured' => array(
  2788. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2789. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2790. 'Category' => array(
  2791. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2792. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2793. )
  2794. ),
  2795. 'Comment' => array(
  2796. array(
  2797. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2798. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2799. 'Attachment' => array()
  2800. ),
  2801. array(
  2802. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2803. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2804. 'Attachment' => array()
  2805. ),
  2806. array(
  2807. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2808. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2809. 'Attachment' => array()
  2810. ),
  2811. array(
  2812. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2813. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2814. 'Attachment' => array()
  2815. )
  2816. )
  2817. ),
  2818. array(
  2819. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2820. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2821. 'Featured' => array(),
  2822. 'Comment' => array()
  2823. )
  2824. )
  2825. ),
  2826. array(
  2827. 'User' => array(
  2828. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2829. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2830. ),
  2831. 'Article' => array(),
  2832. 'ArticleFeatured' => array()
  2833. ),
  2834. array(
  2835. 'User' => array(
  2836. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2837. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2838. ),
  2839. 'Article' => array(
  2840. array(
  2841. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2842. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2843. )
  2844. ),
  2845. 'ArticleFeatured' => array(
  2846. array(
  2847. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2848. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2849. 'Featured' => array(
  2850. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2851. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2852. 'Category' => array(
  2853. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2854. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2855. )
  2856. ),
  2857. 'Comment' => array(
  2858. array(
  2859. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2860. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2861. 'Attachment' => array(
  2862. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2863. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2864. )
  2865. ),
  2866. array(
  2867. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2868. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2869. 'Attachment' => array()
  2870. )
  2871. )
  2872. )
  2873. )
  2874. ),
  2875. array(
  2876. 'User' => array(
  2877. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2878. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2879. ),
  2880. 'Article' => array(),
  2881. 'ArticleFeatured' => array()
  2882. )
  2883. );
  2884. $this->assertEquals($expected, $result);
  2885. $this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured')));
  2886. $this->_assertBindings($this->User->Article);
  2887. $this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2888. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2889. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('hasOne' => array('Attachment')));
  2890. $this->User->resetBindings();
  2891. $this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2892. $this->_assertBindings($this->User->Article, array('belongsTo' => array('User'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2893. $this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2894. $this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2895. $this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2896. }
  2897. /**
  2898. * testEmbeddedFindFields method
  2899. *
  2900. * @return void
  2901. */
  2902. public function testEmbeddedFindFields() {
  2903. $result = $this->Article->find('all', array(
  2904. 'contain' => array('User(user)'),
  2905. 'fields' => array('title'),
  2906. 'order' => array('Article.id' => 'ASC')
  2907. ));
  2908. $expected = array(
  2909. array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2910. array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
  2911. array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2912. );
  2913. $this->assertEquals($expected, $result);
  2914. $result = $this->Article->find('all', array(
  2915. 'contain' => array('User(id, user)'),
  2916. 'fields' => array('title'),
  2917. 'order' => array('Article.id' => 'ASC')
  2918. ));
  2919. $expected = array(
  2920. array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2921. array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
  2922. array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2923. );
  2924. $this->assertEquals($expected, $result);
  2925. $result = $this->Article->find('all', array(
  2926. 'contain' => array(
  2927. 'Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'
  2928. ),
  2929. 'fields' => array('title'),
  2930. 'order' => array('Article.id' => 'ASC')
  2931. ));
  2932. if (!empty($result)) {
  2933. foreach ($result as $i => $article) {
  2934. foreach ($article['Comment'] as $j => $comment) {
  2935. $result[$i]['Comment'][$j] = array_diff_key($comment, array('id' => true));
  2936. }
  2937. }
  2938. }
  2939. $expected = array(
  2940. array(
  2941. 'Article' => array('title' => 'First Article', 'id' => 1),
  2942. 'User' => array('user' => 'mariano', 'id' => 1),
  2943. 'Comment' => array(
  2944. array('comment' => 'First Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2945. array('comment' => 'Second Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2946. array('comment' => 'Third Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2947. array('comment' => 'Fourth Comment for First Article', 'published' => 'N', 'article_id' => 1, 'Attachment' => array()),
  2948. )
  2949. ),
  2950. array(
  2951. 'Article' => array('title' => 'Second Article', 'id' => 2),
  2952. 'User' => array('user' => 'larry', 'id' => 3),
  2953. 'Comment' => array(
  2954. array('comment' => 'First Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array(
  2955. 'attachment' => 'attachment.zip', 'id' => 1
  2956. )),
  2957. array('comment' => 'Second Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array())
  2958. )
  2959. ),
  2960. array(
  2961. 'Article' => array('title' => 'Third Article', 'id' => 3),
  2962. 'User' => array('user' => 'mariano', 'id' => 1),
  2963. 'Comment' => array()
  2964. ),
  2965. );
  2966. $this->assertEquals($expected, $result);
  2967. }
  2968. /**
  2969. * test that hasOne and belongsTo fields act the same in a contain array.
  2970. *
  2971. * @return void
  2972. */
  2973. public function testHasOneFieldsInContain() {
  2974. $this->Article->unbindModel(array(
  2975. 'hasMany' => array('Comment')
  2976. ), true);
  2977. unset($this->Article->Comment);
  2978. $this->Article->bindModel(array(
  2979. 'hasOne' => array('Comment')
  2980. ));
  2981. $result = $this->Article->find('all', array(
  2982. 'fields' => array('title', 'body'),
  2983. 'contain' => array(
  2984. 'Comment' => array(
  2985. 'fields' => array('comment')
  2986. ),
  2987. 'User' => array(
  2988. 'fields' => array('user')
  2989. )
  2990. ),
  2991. 'order' => 'Article.id ASC',
  2992. ));
  2993. $this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s');
  2994. $this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s');
  2995. $this->assertTrue(isset($result[0]['Comment']['comment']), 'comment missing %s');
  2996. $this->assertTrue(isset($result[0]['User']['user']), 'body missing %s');
  2997. $this->assertFalse(isset($result[0]['Comment']['published']), 'published found %s');
  2998. $this->assertFalse(isset($result[0]['User']['password']), 'password found %s');
  2999. }
  3000. /**
  3001. * testFindConditionalBinding method
  3002. *
  3003. * @return void
  3004. */
  3005. public function testFindConditionalBinding() {
  3006. $this->Article->contain(array(
  3007. 'User(user)',
  3008. 'Tag' => array(
  3009. 'fields' => array('tag', 'created'),
  3010. 'conditions' => array('created >=' => '2007-03-18 12:24')
  3011. )
  3012. ));
  3013. $result = $this->Article->find('all', array(
  3014. 'fields' => array('title'),
  3015. 'order' => array('Article.id' => 'ASC')
  3016. ));
  3017. $expected = array(
  3018. array(
  3019. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3020. 'User' => array('id' => 1, 'user' => 'mariano'),
  3021. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  3022. ),
  3023. array(
  3024. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3025. 'User' => array('id' => 3, 'user' => 'larry'),
  3026. 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
  3027. ),
  3028. array(
  3029. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3030. 'User' => array('id' => 1, 'user' => 'mariano'),
  3031. 'Tag' => array()
  3032. )
  3033. );
  3034. $this->assertEquals($expected, $result);
  3035. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
  3036. $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
  3037. $expected = array(
  3038. array(
  3039. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3040. 'User' => array('id' => 1, 'user' => 'mariano'),
  3041. 'Tag' => array(
  3042. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3043. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  3044. )
  3045. ),
  3046. array(
  3047. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3048. 'User' => array('id' => 3, 'user' => 'larry'),
  3049. 'Tag' => array(
  3050. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3051. array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
  3052. )
  3053. ),
  3054. array(
  3055. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3056. 'User' => array('id' => 1, 'user' => 'mariano'),
  3057. 'Tag' => array()
  3058. )
  3059. );
  3060. $this->assertEquals($expected, $result);
  3061. $result = $this->Article->find('all', array(
  3062. 'fields' => array('title'),
  3063. 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))),
  3064. 'order' => array('Article.id' => 'ASC')
  3065. ));
  3066. $expected = array(
  3067. array(
  3068. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3069. 'User' => array('id' => 1, 'user' => 'mariano'),
  3070. 'Tag' => array(
  3071. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3072. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  3073. )
  3074. ),
  3075. array(
  3076. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3077. 'User' => array('id' => 3, 'user' => 'larry'),
  3078. 'Tag' => array(
  3079. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3080. array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
  3081. )
  3082. ),
  3083. array(
  3084. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3085. 'User' => array('id' => 1, 'user' => 'mariano'),
  3086. 'Tag' => array()
  3087. )
  3088. );
  3089. $this->assertEquals($expected, $result);
  3090. $this->Article->contain(array(
  3091. 'User(id,user)',
  3092. 'Tag' => array(
  3093. 'fields' => array('tag', 'created'),
  3094. 'conditions' => array('created >=' => '2007-03-18 12:24')
  3095. )
  3096. ));
  3097. $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
  3098. $expected = array(
  3099. array(
  3100. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3101. 'User' => array('id' => 1, 'user' => 'mariano'),
  3102. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  3103. ),
  3104. array(
  3105. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3106. 'User' => array('id' => 3, 'user' => 'larry'),
  3107. 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
  3108. ),
  3109. array(
  3110. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3111. 'User' => array('id' => 1, 'user' => 'mariano'),
  3112. 'Tag' => array()
  3113. )
  3114. );
  3115. $this->assertEquals($expected, $result);
  3116. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
  3117. $result = $this->User->find('all', array('contain' => array(
  3118. 'Article.Tag' => array('conditions' => array('created >=' => '2007-03-18 12:24'))
  3119. )));
  3120. $this->assertTrue(Set::matches('/User[id=1]', $result));
  3121. $this->assertFalse(Set::matches('/Article[id=1]/Tag[id=1]', $result));
  3122. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
  3123. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
  3124. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
  3125. $result = $this->User->find('all', array('contain' => array(
  3126. 'Article.Tag' => array('order' => 'created DESC')
  3127. )));
  3128. $this->assertTrue(Set::matches('/User[id=1]', $result));
  3129. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=1]', $result));
  3130. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
  3131. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
  3132. }
  3133. /**
  3134. * testOtherFinds method
  3135. *
  3136. * @return void
  3137. */
  3138. public function testOtherFinds() {
  3139. $result = $this->Article->find('count');
  3140. $expected = 3;
  3141. $this->assertEquals($expected, $result);
  3142. $result = $this->Article->find('count', array('conditions' => array('Article.id >' => '1')));
  3143. $expected = 2;
  3144. $this->assertEquals($expected, $result);
  3145. $result = $this->Article->find('count', array('contain' => array()));
  3146. $expected = 3;
  3147. $this->assertEquals($expected, $result);
  3148. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24'))));
  3149. $result = $this->Article->find('first', array('fields' => array('title')));
  3150. $expected = array(
  3151. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3152. 'User' => array('id' => 1, 'user' => 'mariano'),
  3153. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  3154. );
  3155. $this->assertEquals($expected, $result);
  3156. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
  3157. $result = $this->Article->find('first', array('fields' => array('title')));
  3158. $expected = array(
  3159. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3160. 'User' => array('id' => 1, 'user' => 'mariano'),
  3161. 'Tag' => array(
  3162. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3163. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  3164. )
  3165. );
  3166. $this->assertEquals($expected, $result);
  3167. $result = $this->Article->find('first', array(
  3168. 'fields' => array('title'),
  3169. 'order' => 'Article.id DESC',
  3170. 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))
  3171. ));
  3172. $expected = array(
  3173. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3174. 'User' => array('id' => 1, 'user' => 'mariano'),
  3175. 'Tag' => array()
  3176. );
  3177. $this->assertEquals($expected, $result);
  3178. $result = $this->Article->find('list', array(
  3179. 'contain' => array('User(id,user)'),
  3180. 'fields' => array('Article.id', 'Article.title')
  3181. ));
  3182. $expected = array(
  3183. 1 => 'First Article',
  3184. 2 => 'Second Article',
  3185. 3 => 'Third Article'
  3186. );
  3187. $this->assertEquals($expected, $result);
  3188. }
  3189. /**
  3190. * testOriginalAssociations method
  3191. *
  3192. * @return void
  3193. */
  3194. public function testOriginalAssociations() {
  3195. $this->Article->Comment->Behaviors->load('Containable');
  3196. $options = array(
  3197. 'conditions' => array(
  3198. 'Comment.published' => 'Y',
  3199. ),
  3200. 'contain' => 'User',
  3201. 'recursive' => 1
  3202. );
  3203. $firstResult = $this->Article->Comment->find('all', $options);
  3204. $this->Article->Comment->find('all', array(
  3205. 'conditions' => array(
  3206. 'User.user' => 'mariano'
  3207. ),
  3208. 'fields' => array('User.password'),
  3209. 'contain' => array('User.password'),
  3210. ));
  3211. $result = $this->Article->Comment->find('all', $options);
  3212. $this->assertEquals($firstResult, $result);
  3213. $this->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
  3214. $this->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
  3215. $r = $this->Article->find('all', array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
  3216. $this->assertTrue(Set::matches('/Article[id=1]', $r));
  3217. $this->assertTrue(Set::matches('/User[id=1]', $r));
  3218. $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
  3219. $this->assertFalse(Set::matches('/Comment[id=1]', $r));
  3220. $r = $this->Article->find('all');
  3221. $this->assertTrue(Set::matches('/Article[id=1]', $r));
  3222. $this->assertTrue(Set::matches('/User[id=1]', $r));
  3223. $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
  3224. $this->assertTrue(Set::matches('/Comment[id=1]', $r));
  3225. $this->Article->bindModel(array('hasAndBelongsToMany' => array('Tag')), false);
  3226. $this->Article->contain(false, array('User(id,user)', 'Comment' => array('fields' => array('comment'), 'conditions' => array('created >=' => '2007-03-18 10:49'))));
  3227. $result = $this->Article->find('all', array('fields' => array('title'), 'limit' => 1, 'page' => 1, 'order' => 'Article.id ASC'));
  3228. $expected = array(array(
  3229. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3230. 'User' => array('id' => 1, 'user' => 'mariano'),
  3231. 'Comment' => array(
  3232. array('comment' => 'Third Comment for First Article', 'article_id' => 1),
  3233. array('comment' => 'Fourth Comment for First Article', 'article_id' => 1)
  3234. )
  3235. ));
  3236. $this->assertEquals($expected, $result);
  3237. $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 2, 'order' => 'Article.id ASC'));
  3238. $expected = array(array(
  3239. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3240. 'User' => array('id' => 3, 'user' => 'larry'),
  3241. 'Comment' => array(
  3242. array('comment' => 'First Comment for Second Article', 'article_id' => 2),
  3243. array('comment' => 'Second Comment for Second Article', 'article_id' => 2)
  3244. )
  3245. ));
  3246. $this->assertEquals($expected, $result);
  3247. $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 3, 'order' => 'Article.id ASC'));
  3248. $expected = array(array(
  3249. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3250. 'User' => array('id' => 1, 'user' => 'mariano'),
  3251. 'Comment' => array()
  3252. ));
  3253. $this->assertEquals($expected, $result);
  3254. $this->Article->contain(false, array('User' => array('fields' => 'user'), 'Comment'));
  3255. $result = $this->Article->find('all');
  3256. $this->assertTrue(Set::matches('/Article[id=1]', $result));
  3257. $this->assertTrue(Set::matches('/User[user=mariano]', $result));
  3258. $this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
  3259. $this->Article->resetBindings();
  3260. $this->Article->contain(false, array('User' => array('fields' => array('user')), 'Comment'));
  3261. $result = $this->Article->find('all');
  3262. $this->assertTrue(Set::matches('/Article[id=1]', $result));
  3263. $this->assertTrue(Set::matches('/User[user=mariano]', $result));
  3264. $this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
  3265. $this->Article->resetBindings();
  3266. }
  3267. /**
  3268. * testResetAddedAssociation method
  3269. *
  3270. * @return void
  3271. */
  3272. public function testResetAddedAssociation() {
  3273. $this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
  3274. $this->Article->bindModel(array(
  3275. 'hasMany' => array('ArticlesTag')
  3276. ));
  3277. $this->assertTrue(!empty($this->Article->hasMany['ArticlesTag']));
  3278. $result = $this->Article->find('first', array(
  3279. 'conditions' => array('Article.id' => 1),
  3280. 'contain' => array('ArticlesTag')
  3281. ));
  3282. $expected = array('Article', 'ArticlesTag');
  3283. $this->assertTrue(!empty($result));
  3284. $this->assertEquals('First Article', $result['Article']['title']);
  3285. $this->assertTrue(!empty($result['ArticlesTag']));
  3286. $this->assertEquals($expected, array_keys($result));
  3287. $this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
  3288. $this->JoinA = ClassRegistry::init('JoinA');
  3289. $this->JoinB = ClassRegistry::init('JoinB');
  3290. $this->JoinC = ClassRegistry::init('JoinC');
  3291. $this->JoinA->Behaviors->load('Containable');
  3292. $this->JoinB->Behaviors->load('Containable');
  3293. $this->JoinC->Behaviors->load('Containable');
  3294. $this->JoinA->JoinB->find('all', array('contain' => array('JoinA')));
  3295. $this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false);
  3296. $result = $this->JoinA->hasOne;
  3297. $this->JoinA->find('all');
  3298. $resultAfter = $this->JoinA->hasOne;
  3299. $this->assertEquals($result, $resultAfter);
  3300. }
  3301. /**
  3302. * testResetAssociation method
  3303. *
  3304. * @return void
  3305. */
  3306. public function testResetAssociation() {
  3307. $this->Article->Behaviors->load('Containable');
  3308. $this->Article->Comment->Behaviors->load('Containable');
  3309. $this->Article->User->Behaviors->load('Containable');
  3310. $initialOptions = array(
  3311. 'conditions' => array(
  3312. 'Comment.published' => 'Y',
  3313. ),
  3314. 'contain' => 'User',
  3315. 'recursive' => 1,
  3316. );
  3317. $initialModels = $this->Article->Comment->find('all', $initialOptions);
  3318. $findOptions = array(
  3319. 'conditions' => array(
  3320. 'User.user' => 'mariano',
  3321. ),
  3322. 'fields' => array('User.password'),
  3323. 'contain' => array('User.password')
  3324. );
  3325. $result = $this->Article->Comment->find('all', $findOptions);
  3326. $result = $this->Article->Comment->find('all', $initialOptions);
  3327. $this->assertEquals($initialModels, $result);
  3328. }
  3329. /**
  3330. * testResetDeeperHasOneAssociations method
  3331. *
  3332. * @return void
  3333. */
  3334. public function testResetDeeperHasOneAssociations() {
  3335. $this->Article->User->unbindModel(array(
  3336. 'hasMany' => array('ArticleFeatured', 'Comment')
  3337. ), false);
  3338. $userHasOne = array('hasOne' => array('ArticleFeatured', 'Comment'));
  3339. $this->Article->User->bindModel($userHasOne, false);
  3340. $expected = $this->Article->User->hasOne;
  3341. $this->Article->find('all');
  3342. $this->assertEquals($expected, $this->Article->User->hasOne);
  3343. $this->Article->User->bindModel($userHasOne, false);
  3344. $expected = $this->Article->User->hasOne;
  3345. $this->Article->find('all', array(
  3346. 'contain' => array(
  3347. 'User' => array('ArticleFeatured', 'Comment')
  3348. )
  3349. ));
  3350. $this->assertEquals($expected, $this->Article->User->hasOne);
  3351. $this->Article->User->bindModel($userHasOne, false);
  3352. $expected = $this->Article->User->hasOne;
  3353. $this->Article->find('all', array(
  3354. 'contain' => array(
  3355. 'User' => array(
  3356. 'ArticleFeatured',
  3357. 'Comment' => array('fields' => array('created'))
  3358. )
  3359. )
  3360. ));
  3361. $this->assertEquals($expected, $this->Article->User->hasOne);
  3362. $this->Article->User->bindModel($userHasOne, false);
  3363. $expected = $this->Article->User->hasOne;
  3364. $this->Article->find('all', array(
  3365. 'contain' => array(
  3366. 'User' => array(
  3367. 'Comment' => array('fields' => array('created'))
  3368. )
  3369. )
  3370. ));
  3371. $this->assertEquals($expected, $this->Article->User->hasOne);
  3372. $this->Article->User->bindModel($userHasOne, false);
  3373. $expected = $this->Article->User->hasOne;
  3374. $this->Article->find('all', array(
  3375. 'contain' => array(
  3376. 'User.ArticleFeatured' => array(
  3377. 'conditions' => array('ArticleFeatured.published' => 'Y')
  3378. ),
  3379. 'User.Comment'
  3380. )
  3381. ));
  3382. $this->assertEquals($expected, $this->Article->User->hasOne);
  3383. }
  3384. /**
  3385. * testResetMultipleHabtmAssociations method
  3386. *
  3387. * @return void
  3388. */
  3389. public function testResetMultipleHabtmAssociations() {
  3390. $articleHabtm = array(
  3391. 'hasAndBelongsToMany' => array(
  3392. 'Tag' => array(
  3393. 'className' => 'Tag',
  3394. 'joinTable' => 'articles_tags',
  3395. 'foreignKey' => 'article_id',
  3396. 'associationForeignKey' => 'tag_id'
  3397. ),
  3398. 'ShortTag' => array(
  3399. 'className' => 'Tag',
  3400. 'joinTable' => 'articles_tags',
  3401. 'foreignKey' => 'article_id',
  3402. 'associationForeignKey' => 'tag_id',
  3403. // LENGTH function mysql-only, using LIKE does almost the same
  3404. 'conditions' => "ShortTag.tag LIKE '???'"
  3405. )
  3406. )
  3407. );
  3408. $this->Article->resetBindings();
  3409. $this->Article->bindModel($articleHabtm, false);
  3410. $expected = $this->Article->hasAndBelongsToMany;
  3411. $this->Article->find('all');
  3412. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3413. $this->Article->resetBindings();
  3414. $this->Article->bindModel($articleHabtm, false);
  3415. $expected = $this->Article->hasAndBelongsToMany;
  3416. $this->Article->find('all', array('contain' => 'Tag.tag'));
  3417. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3418. $this->Article->resetBindings();
  3419. $this->Article->bindModel($articleHabtm, false);
  3420. $expected = $this->Article->hasAndBelongsToMany;
  3421. $this->Article->find('all', array('contain' => 'Tag'));
  3422. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3423. $this->Article->resetBindings();
  3424. $this->Article->bindModel($articleHabtm, false);
  3425. $expected = $this->Article->hasAndBelongsToMany;
  3426. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array(null)))));
  3427. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3428. $this->Article->resetBindings();
  3429. $this->Article->bindModel($articleHabtm, false);
  3430. $expected = $this->Article->hasAndBelongsToMany;
  3431. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag')))));
  3432. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3433. $this->Article->resetBindings();
  3434. $this->Article->bindModel($articleHabtm, false);
  3435. $expected = $this->Article->hasAndBelongsToMany;
  3436. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag', 'Tag.created')))));
  3437. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3438. $this->Article->resetBindings();
  3439. $this->Article->bindModel($articleHabtm, false);
  3440. $expected = $this->Article->hasAndBelongsToMany;
  3441. $this->Article->find('all', array('contain' => 'ShortTag.tag'));
  3442. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3443. $this->Article->resetBindings();
  3444. $this->Article->bindModel($articleHabtm, false);
  3445. $expected = $this->Article->hasAndBelongsToMany;
  3446. $this->Article->find('all', array('contain' => 'ShortTag'));
  3447. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3448. $this->Article->resetBindings();
  3449. $this->Article->bindModel($articleHabtm, false);
  3450. $expected = $this->Article->hasAndBelongsToMany;
  3451. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array(null)))));
  3452. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3453. $this->Article->resetBindings();
  3454. $this->Article->bindModel($articleHabtm, false);
  3455. $expected = $this->Article->hasAndBelongsToMany;
  3456. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag')))));
  3457. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3458. $this->Article->resetBindings();
  3459. $this->Article->bindModel($articleHabtm, false);
  3460. $expected = $this->Article->hasAndBelongsToMany;
  3461. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag', 'ShortTag.created')))));
  3462. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3463. }
  3464. /**
  3465. * test that bindModel and unbindModel work with find() calls in between.
  3466. *
  3467. * @return void
  3468. */
  3469. public function testBindMultipleTimesWithFind() {
  3470. $binding = array(
  3471. 'hasOne' => array(
  3472. 'ArticlesTag' => array(
  3473. 'foreignKey' => false,
  3474. 'type' => 'INNER',
  3475. 'conditions' => array(
  3476. 'ArticlesTag.article_id = Article.id'
  3477. )
  3478. ),
  3479. 'Tag' => array(
  3480. 'type' => 'INNER',
  3481. 'foreignKey' => false,
  3482. 'conditions' => array(
  3483. 'ArticlesTag.tag_id = Tag.id'
  3484. )
  3485. )
  3486. )
  3487. );
  3488. $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
  3489. $this->Article->bindModel($binding);
  3490. $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
  3491. $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
  3492. $this->Article->bindModel($binding);
  3493. $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
  3494. $associated = $this->Article->getAssociated();
  3495. $this->assertEquals('hasAndBelongsToMany', $associated['Tag']);
  3496. $this->assertFalse(isset($associated['ArticleTag']));
  3497. }
  3498. /**
  3499. * test that autoFields doesn't splice in fields from other databases.
  3500. *
  3501. * @return void
  3502. */
  3503. public function testAutoFieldsWithMultipleDatabases() {
  3504. $config = new DATABASE_CONFIG();
  3505. $this->skipIf(
  3506. !isset($config->test) || !isset($config->test2),
  3507. 'Primary and secondary test databases not configured, ' .
  3508. 'skipping cross-database join tests. ' .
  3509. ' To run these tests, you must define $test and $test2 ' .
  3510. 'in your database configuration.'
  3511. );
  3512. $db = ConnectionManager::getDataSource('test2');
  3513. $this->fixtureManager->loadSingle('User', $db);
  3514. $this->Article->User->setDataSource('test2');
  3515. $result = $this->Article->find('all', array(
  3516. 'fields' => array('Article.title'),
  3517. 'contain' => array('User')
  3518. ));
  3519. $this->assertTrue(isset($result[0]['Article']));
  3520. $this->assertTrue(isset($result[0]['User']));
  3521. }
  3522. /**
  3523. * test that autoFields doesn't splice in columns that aren't part of the join.
  3524. *
  3525. * @return void
  3526. */
  3527. public function testAutoFieldsWithRecursiveNegativeOne() {
  3528. $this->Article->recursive = -1;
  3529. $result = $this->Article->field('title', array('Article.title' => 'First Article'));
  3530. $this->assertNoErrors();
  3531. $this->assertEquals('First Article', $result, 'Field is wrong');
  3532. }
  3533. /**
  3534. * test that find(all) doesn't return incorrect values when mixed with containable.
  3535. *
  3536. * @return void
  3537. */
  3538. public function testFindAllReturn() {
  3539. $result = $this->Article->find('all', array(
  3540. 'conditions' => array('Article.id' => 999999999)
  3541. ));
  3542. $this->assertEmpty($result, 'Should be empty.');
  3543. }
  3544. /**
  3545. * testLazyLoad method
  3546. *
  3547. * @return void
  3548. */
  3549. public function testLazyLoad() {
  3550. // Local set up
  3551. $this->User = ClassRegistry::init('User');
  3552. $this->User->bindModel(array(
  3553. 'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
  3554. ), false);
  3555. try {
  3556. $this->User->find('first', array(
  3557. 'contain' => 'Comment',
  3558. 'lazyLoad' => true
  3559. ));
  3560. } catch (Exception $e) {
  3561. $exceptions = true;
  3562. }
  3563. $this->assertTrue(empty($exceptions));
  3564. }
  3565. /**
  3566. * _containments method
  3567. *
  3568. * @param Model $Model
  3569. * @param array $contain
  3570. * @return void
  3571. */
  3572. protected function _containments($Model, $contain = array()) {
  3573. if (!is_array($Model)) {
  3574. $result = $Model->containments($contain);
  3575. return $this->_containments($result['models']);
  3576. }
  3577. $result = $Model;
  3578. foreach ($result as $i => $containment) {
  3579. $result[$i] = array_diff_key($containment, array('instance' => true));
  3580. }
  3581. return $result;
  3582. }
  3583. /**
  3584. * _assertBindings method
  3585. *
  3586. * @param Model $Model
  3587. * @param array $expected
  3588. * @return void
  3589. */
  3590. protected function _assertBindings(Model $Model, $expected = array()) {
  3591. $expected = array_merge(array(
  3592. 'belongsTo' => array(),
  3593. 'hasOne' => array(),
  3594. 'hasMany' => array(),
  3595. 'hasAndBelongsToMany' => array()
  3596. ), $expected);
  3597. foreach ($expected as $binding => $expect) {
  3598. $this->assertEquals($expect, array_keys($Model->$binding));
  3599. }
  3600. }
  3601. }