diff --git a/app/controllers/studip_controller.php b/app/controllers/studip_controller.php index e7e46ced292b569326339c00ce592fd085f9dde5..d3a28ccdbecf1a6439072668b430d98b705cab2a 100644 --- a/app/controllers/studip_controller.php +++ b/app/controllers/studip_controller.php @@ -718,7 +718,7 @@ abstract class StudipController extends Trails_Controller public function action_url($action) { $arguments = func_get_args(); - array_unshift($arguments, $this->controller_path()); + $arguments[0] = $this->controller_path() . '/' . $arguments[0]; return $this->url_for(...$arguments); } diff --git a/tests/unit/lib/classes/StudipControllerTest.php b/tests/unit/lib/classes/StudipControllerTest.php index fae7628d269c0d94a153d2c9eb3c9b73d3796e7b..61ff2d999ed260b54e023b08482922f5e326f63d 100644 --- a/tests/unit/lib/classes/StudipControllerTest.php +++ b/tests/unit/lib/classes/StudipControllerTest.php @@ -65,6 +65,19 @@ final class StudipControllerTest extends Codeception\Test\Unit $this->getController()->url_for(...$args); } + /** + * @dataProvider actionUrlProvider + * @covers StudipController::action_url + */ + public function testActionUrl(string $expected, ...$args): void + { + $url = $this->getController()->action_url(...$args); + $this->assertEquals( + $expected, + $this->getRelativeURL($url) + ); + } + /** * @dataProvider RedirectProvider * @covers StudipController::redirect @@ -188,6 +201,19 @@ final class StudipControllerTest extends Codeception\Test\Unit ]; } + public function actionUrlProvider(): array + { + return [ + 'action' => ['dispatch.php/studip_controller_test/foo', 'foo'], + 'action-and-parameter' => ['dispatch.php/studip_controller_test/foo/23', 'foo/23'], + 'action-and-parameters' => ['dispatch.php/studip_controller_test/foo/23?bar=42', 'foo/23', ['bar' => 42]], + + 'fragment' => ['dispatch.php/studip_controller_test/foo/42/23#jump', 'foo/42/23#jump'], + 'fragment-and-parameters' => ['dispatch.php/studip_controller_test/foo/42/23#jump', 'foo#jump', 42, 23], + 'url-encoding-parameters' => ['dispatch.php/studip_controller_test/foo/%3Fabc/%2F', 'foo', '?abc', '/'], + ]; + } + public function RedirectProvider(): array { $result = $this->UrlForProvider();