diff --git a/app/controllers/studip_controller.php b/app/controllers/studip_controller.php index cddb82e5035afba2d893decdb5d060c1ea09e763..a08a9463c386d013cf3007ee4fe61a551debc91e 100644 --- a/app/controllers/studip_controller.php +++ b/app/controllers/studip_controller.php @@ -717,7 +717,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 3675f58f14b0ca765c56e963d2406eb715394262..a7009fe2aa504c4a8f23e662203e3ccd71f11d81 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 @@ -192,6 +205,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();