ContainableBehaviorTest.php 150 KB

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