ContainableBehaviorTest.php 150 KB

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