@@ -140,6 +140,19 @@ class ScaffoldMock extends CakeTestModel {
140
140
'foreignKey ' => 'article_id ' ,
141
141
)
142
142
);
143
+ /**
144
+ * hasAndBelongsToMany property
145
+ *
146
+ * @var string
147
+ **/
148
+ var $ hasAndBelongsToMany = array (
149
+ 'ScaffoldTag ' => array (
150
+ 'className ' => 'ScaffoldTag ' ,
151
+ 'foreignKey ' => 'post_id ' ,
152
+ 'associationForeignKey ' => 'tag_id ' ,
153
+ 'joinTable ' => 'posts_tags '
154
+ )
155
+ );
143
156
}
144
157
/**
145
158
* ScaffoldUser class
@@ -195,6 +208,21 @@ class ScaffoldComment extends CakeTestModel {
195
208
)
196
209
);
197
210
}
211
+ /**
212
+ * ScaffoldTag class
213
+ *
214
+ * @package cake
215
+ * @subpackage cake.tests.cases.libs.controller
216
+ */
217
+ class ScaffoldTag extends CakeTestModel {
218
+ /**
219
+ * useTable property
220
+ *
221
+ * @var string 'posts'
222
+ * @access public
223
+ */
224
+ var $ useTable = 'tags ' ;
225
+ }
198
226
/**
199
227
* TestScaffoldView class
200
228
*
@@ -226,7 +254,7 @@ class ScaffoldViewTest extends CakeTestCase {
226
254
* @var array
227
255
* @access public
228
256
*/
229
- var $ fixtures = array ('core.article ' , 'core.user ' , 'core.comment ' );
257
+ var $ fixtures = array ('core.article ' , 'core.user ' , 'core.comment ' , ' core.posts_tag ' , ' core.tag ' );
230
258
/**
231
259
* startTest method
232
260
*
@@ -559,7 +587,7 @@ class ScaffoldTest extends CakeTestCase {
559
587
* @var array
560
588
* @access public
561
589
*/
562
- var $ fixtures = array ('core.article ' , 'core.user ' , 'core.comment ' );
590
+ var $ fixtures = array ('core.article ' , 'core.user ' , 'core.comment ' , ' core.posts_tag ' , ' core.tag ' );
563
591
/**
564
592
* startTest method
565
593
*
@@ -648,6 +676,40 @@ function testScaffoldVariableSetting() {
648
676
$ this ->assertEqual ($ result ['pluralVar ' ], 'scaffoldMock ' );
649
677
$ this ->assertEqual ($ result ['scaffoldFields ' ], array ('id ' , 'user_id ' , 'title ' , 'body ' , 'published ' , 'created ' , 'updated ' ));
650
678
}
679
+ /**
680
+ * test that habtm relationship keys get added to scaffoldFields.
681
+ *
682
+ * @see http://code.cakephp.org/tickets/view/48
683
+ * @return void
684
+ **/
685
+ function testHabtmFieldAdditionWithScaffoldForm () {
686
+ $ this ->Controller ->action = 'edit ' ;
687
+ $ this ->Controller ->here = '/scaffold_mock ' ;
688
+ $ this ->Controller ->webroot = '/ ' ;
689
+ $ params = array (
690
+ 'plugin ' => null ,
691
+ 'pass ' => array (1 ),
692
+ 'form ' => array (),
693
+ 'named ' => array (),
694
+ 'url ' => array ('url ' =>'scaffold_mock ' ),
695
+ 'controller ' => 'scaffold_mock ' ,
696
+ 'action ' => 'edit ' ,
697
+ );
698
+ //set router.
699
+ Router::reload ();
700
+ Router::setRequestInfo (array ($ params , array ('base ' => '/ ' , 'here ' => '/scaffold_mock ' , 'webroot ' => '/ ' )));
701
+ $ this ->Controller ->params = $ params ;
702
+ $ this ->Controller ->controller = 'scaffold_mock ' ;
703
+ $ this ->Controller ->base = '/ ' ;
704
+ $ this ->Controller ->constructClasses ();
705
+ ob_start ();
706
+ $ Scaffold = new Scaffold ($ this ->Controller , $ params );
707
+ $ result = ob_get_clean ();
708
+ $ this ->assertPattern ('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/ ' , $ result );
709
+
710
+ $ result = $ Scaffold ->controller ->viewVars ;
711
+ $ this ->assertEqual ($ result ['scaffoldFields ' ], array ('id ' , 'user_id ' , 'title ' , 'body ' , 'published ' , 'created ' , 'updated ' , 'ScaffoldTag ' ));
712
+ }
651
713
/**
652
714
* test that the proper names and variable values are set by Scaffold
653
715
*
0 commit comments