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:
Carsten Brandt
2018-07-24 16:43:50 +02:00
parent 60d79aa18e
commit d0712e4918
2 changed files with 71 additions and 0 deletions

View File

@@ -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