mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-04 14:34:49 +01:00
added tests to verify issue #16484
the case is to match all module names before a catch-all URL rule. module routes should work with "module name only", "module name+controller name" and "module/controller/action".
This commit is contained in:
@@ -147,6 +147,49 @@ class ModuleTest extends TestCase
|
||||
$route = 'very---complex---name---test';
|
||||
$this->assertNotInstanceOf(VeryComplexNameTestController::className(), $module->createControllerByID($route));
|
||||
}
|
||||
|
||||
public function testCreateController()
|
||||
{
|
||||
// app module has a submodule "base" which has two controllers: "default" and "other"
|
||||
$module = new Module('app');
|
||||
$module->setModule('base', new Module('base'));
|
||||
$defaultController = ['class' => 'yii\web\Controller'];
|
||||
$otherController = ['class' => 'yii\web\Controller'];
|
||||
$module->getModule('base')->controllerMap = [
|
||||
'default' => $defaultController,
|
||||
'other' => $otherController,
|
||||
];
|
||||
|
||||
list($controller, $action) = $module->createController('base');
|
||||
$this->assertSame('', $action);
|
||||
$this->assertSame('base/default', $controller->uniqueId);
|
||||
|
||||
list($controller, $action) = $module->createController('base/default');
|
||||
$this->assertSame('', $action);
|
||||
$this->assertSame('base/default', $controller->uniqueId);
|
||||
|
||||
list($controller, $action) = $module->createController('base/other');
|
||||
$this->assertSame('', $action);
|
||||
$this->assertSame('base/other', $controller->uniqueId);
|
||||
|
||||
list($controller, $action) = $module->createController('base/default/index');
|
||||
$this->assertSame('index', $action);
|
||||
$this->assertSame('base/default', $controller->uniqueId);
|
||||
|
||||
list($controller, $action) = $module->createController('base/other/index');
|
||||
$this->assertSame('index', $action);
|
||||
$this->assertSame('base/other', $controller->uniqueId);
|
||||
|
||||
list($controller, $action) = $module->createController('base/other/someaction');
|
||||
$this->assertSame('someaction', $action);
|
||||
$this->assertSame('base/other', $controller->uniqueId);
|
||||
|
||||
$controller = $module->createController('bases/default/index');
|
||||
$this->assertFalse($controller);
|
||||
|
||||
$controller = $module->createController('nocontroller');
|
||||
$this->assertFalse($controller);
|
||||
}
|
||||
}
|
||||
|
||||
class TestModule extends \yii\base\Module
|
||||
|
||||
Reference in New Issue
Block a user