ContainableBehaviorTest.php 152 KB

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