ActionRoutesTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace yiiunit\debug\router;
  3. use yii\debug\models\router\ActionRoutes;
  4. use yiiunit\debug\TestCase;
  5. class ActionRoutesTest extends TestCase
  6. {
  7. /**
  8. * @test
  9. */
  10. public function shouldDetectPrettyUrlEnabled()
  11. {
  12. $this->mockWebApplication(
  13. [
  14. 'controllerNamespace' => 'yiiunit\debug\router\controllers',
  15. 'components' => [
  16. 'urlManager' => [
  17. 'enablePrettyUrl' => true,
  18. 'rules' => [
  19. '<controller>/<action>' => '<controller>/<action>',
  20. [
  21. 'class' => 'yii\web\GroupUrlRule',
  22. 'prefix' => 'admin',
  23. 'rules' => [
  24. 'inside' => 'module-web/inside',
  25. ],
  26. ]
  27. ]
  28. ],
  29. ],
  30. 'modules' => [
  31. 'admin' => 'yiiunit\debug\router\module\Module'
  32. ]
  33. ]
  34. );
  35. $routes = new ActionRoutes();
  36. $this->assertSame(
  37. [
  38. 'yiiunit\debug\router\controllers\BadController::actionOnly()' => [
  39. 'route' => 'bad/only',
  40. 'rule' => '<controller>/<action>',
  41. 'count' => 1,
  42. ],
  43. 'yiiunit\debug\router\controllers\BadController::actions()' => [
  44. 'route' => 'bad/[external-action]',
  45. 'rule' => null,
  46. 'count' => 0,
  47. ],
  48. 'yiiunit\debug\router\controllers\RedirectController::actionOnly()' => [
  49. 'route' => 'redirect/only',
  50. 'rule' => '<controller>/<action>',
  51. 'count' => 1,
  52. ],
  53. 'yiiunit\debug\router\controllers\RedirectController::actions()' => [
  54. 'route' => 'redirect/[external-action]',
  55. 'rule' => null,
  56. 'count' => 0,
  57. ],
  58. 'yiiunit\debug\router\controllers\RestController::actions()' => [
  59. 'route' => 'rest/[external-action]',
  60. 'rule' => null,
  61. 'count' => 0,
  62. ],
  63. 'yiiunit\debug\router\controllers\WebController::actionFirst()' => [
  64. 'route' => 'web/first',
  65. 'rule' => '<controller>/<action>',
  66. 'count' => 1,
  67. ],
  68. 'yiiunit\debug\router\controllers\WebController::actionSecond()' => [
  69. 'route' => 'web/second',
  70. 'rule' => '<controller>/<action>',
  71. 'count' => 1,
  72. ],
  73. 'yiiunit\debug\router\controllers\WebController::actions()' => [
  74. 'route' => 'web/[external-action]',
  75. 'rule' => null,
  76. 'count' => 0,
  77. ],
  78. 'yiiunit\debug\router\module\controllers\ModuleWebController::actionInside()' => [
  79. 'route' => 'admin/module-web/inside',
  80. 'rule' => 'admin/inside',
  81. 'count' => 2,
  82. ],
  83. 'yiiunit\debug\router\module\controllers\ModuleWebController::actions()' => [
  84. 'route' => 'admin/module-web/[external-action]',
  85. 'rule' => null,
  86. 'count' => 0,
  87. ],
  88. ],
  89. $routes->routes
  90. );
  91. }
  92. }