@@ -158,6 +158,7 @@ public function testController() {
158
158
public function testControllerVariations ($ name ) {
159
159
$ this ->Task ->controller ($ name );
160
160
$ this ->assertEquals ('ViewTaskComments ' , $ this ->Task ->controllerName );
161
+ $ this ->assertEquals ('ViewTaskComments ' , $ this ->Task ->tableName );
161
162
}
162
163
163
164
/**
@@ -169,6 +170,7 @@ public function testControllerPlugin() {
169
170
$ this ->Task ->params ['plugin ' ] = 'TestPlugin ' ;
170
171
$ this ->Task ->controller ('Tests ' );
171
172
$ this ->assertEquals ('Tests ' , $ this ->Task ->controllerName );
173
+ $ this ->assertEquals ('Tests ' , $ this ->Task ->tableName );
172
174
$ this ->assertEquals (
173
175
'TestPlugin\Controller\TestsController ' ,
174
176
$ this ->Task ->controllerClass
@@ -184,6 +186,7 @@ public function testControllerPrefix() {
184
186
$ this ->Task ->params ['prefix ' ] = 'Admin ' ;
185
187
$ this ->Task ->controller ('Posts ' );
186
188
$ this ->assertEquals ('Posts ' , $ this ->Task ->controllerName );
189
+ $ this ->assertEquals ('Posts ' , $ this ->Task ->tableName );
187
190
$ this ->assertEquals (
188
191
'TestApp\Controller\Admin\PostsController ' ,
189
192
$ this ->Task ->controllerClass
@@ -192,12 +195,28 @@ public function testControllerPrefix() {
192
195
$ this ->Task ->params ['plugin ' ] = 'TestPlugin ' ;
193
196
$ this ->Task ->controller ('Comments ' );
194
197
$ this ->assertEquals ('Comments ' , $ this ->Task ->controllerName );
198
+ $ this ->assertEquals ('Comments ' , $ this ->Task ->tableName );
195
199
$ this ->assertEquals (
196
200
'TestPlugin\Controller\Admin\CommentsController ' ,
197
201
$ this ->Task ->controllerClass
198
202
);
199
203
}
200
204
205
+ /**
206
+ * test controller with a non-conventional controller name
207
+ *
208
+ * @return void
209
+ */
210
+ public function testControllerWithOverride () {
211
+ $ this ->Task ->controller ('Comments ' , 'Posts ' );
212
+ $ this ->assertEquals ('Posts ' , $ this ->Task ->controllerName );
213
+ $ this ->assertEquals ('Comments ' , $ this ->Task ->tableName );
214
+ $ this ->assertEquals (
215
+ 'TestApp\Controller\PostsController ' ,
216
+ $ this ->Task ->controllerClass
217
+ );
218
+ }
219
+
201
220
/**
202
221
* Test getPath()
203
222
*
@@ -313,6 +332,7 @@ public function testGetContentWithRoutingPrefix() {
313
332
*/
314
333
public function testBakeView () {
315
334
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
335
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
316
336
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
317
337
318
338
$ this ->Task ->expects ($ this ->at (0 ))
@@ -332,6 +352,7 @@ public function testBakeView() {
332
352
*/
333
353
public function testBakeEdit () {
334
354
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
355
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
335
356
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
336
357
337
358
$ this ->Task ->expects ($ this ->at (0 ))->method ('createFile ' )
@@ -352,6 +373,7 @@ public function testBakeEdit() {
352
373
*/
353
374
public function testBakeIndex () {
354
375
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
376
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
355
377
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
356
378
357
379
$ this ->Task ->expects ($ this ->at (0 ))->method ('createFile ' )
@@ -369,6 +391,7 @@ public function testBakeIndex() {
369
391
*/
370
392
public function testBakeWithNoTemplate () {
371
393
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
394
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
372
395
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
373
396
374
397
$ this ->Task ->expects ($ this ->never ())->method ('createFile ' );
@@ -382,6 +405,7 @@ public function testBakeWithNoTemplate() {
382
405
*/
383
406
public function testBakeActions () {
384
407
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
408
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
385
409
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
386
410
387
411
$ this ->Task ->expects ($ this ->at (0 ))
@@ -411,6 +435,7 @@ public function testBakeActions() {
411
435
*/
412
436
public function testCustomAction () {
413
437
$ this ->Task ->controllerName = 'ViewTaskComments ' ;
438
+ $ this ->Task ->tableName = 'ViewTaskComments ' ;
414
439
$ this ->Task ->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController ' ;
415
440
416
441
$ this ->Task ->expects ($ this ->any ())->method ('in ' )
@@ -495,12 +520,34 @@ public function testExecuteWithController() {
495
520
* @return void
496
521
*/
497
522
public static function nameVariations () {
498
- return array (array ('ViewTaskComments ' ), array ('ViewTaskComment ' ), array ('view_task_comment ' ));
523
+ return [['ViewTaskComments ' ], ['ViewTaskComment ' ], ['view_task_comment ' ]];
524
+ }
525
+
526
+ /**
527
+ * test `cake bake view $table --controller Blog`
528
+ *
529
+ * @return void
530
+ */
531
+ public function testExecuteWithControllerFlag () {
532
+ $ this ->Task ->args [0 ] = 'Posts ' ;
533
+ $ this ->Task ->params ['controller ' ] = 'Blog ' ;
534
+
535
+ $ this ->Task ->expects ($ this ->exactly (4 ))
536
+ ->method ('createFile ' );
537
+
538
+ $ views = array ('index.ctp ' , 'view.ctp ' , 'add.ctp ' , 'edit.ctp ' );
539
+ foreach ($ views as $ i => $ view ) {
540
+ $ this ->Task ->expects ($ this ->at ($ i ))->method ('createFile ' )
541
+ ->with (
542
+ TMP . 'Blog/ ' . $ view ,
543
+ $ this ->anything ()
544
+ );
545
+ }
546
+ $ this ->Task ->execute ();
499
547
}
500
548
501
549
/**
502
- * test `cake bake view $controller --admin`
503
- * Which only bakes admin methods, not non-admin methods.
550
+ * test `cake bake view $controller --prefix Admin`
504
551
*
505
552
* @return void
506
553
*/
0 commit comments