Skip to content
Snippets Groups Projects
Commit 2c384d9c authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

allow no parameters for url_for(), fixes #642

parent 462a4673
No related branches found
No related tags found
No related merge requests found
...@@ -65,10 +65,6 @@ class Search_ModuleController extends MVVController ...@@ -65,10 +65,6 @@ class Search_ModuleController extends MVVController
return MVV::isVisibleSearch(); return MVV::isVisibleSearch();
} }
public function after_filter($action, $args) {
parent::after_filter($action, $args);
}
public function index_action() public function index_action()
{ {
$template = $this->get_template_factory() $template = $this->get_template_factory()
...@@ -134,8 +130,11 @@ class Search_ModuleController extends MVVController ...@@ -134,8 +130,11 @@ class Search_ModuleController extends MVVController
$sidebar = Sidebar::get(); $sidebar = Sidebar::get();
$widget = new SelectWidget(_('Semesterauswahl'), $widget = new SelectWidget(
$this->url_for('',['sterm' => $this->sterm]), 'sem_select'); _('Semesterauswahl'),
$this->indexURL(['sterm' => $this->sterm]),
'sem_select'
);
$options = []; $options = [];
$semester = Semester::findAllVisible(); $semester = Semester::findAllVisible();
unset($semester[0]); unset($semester[0]);
...@@ -160,8 +159,11 @@ class Search_ModuleController extends MVVController ...@@ -160,8 +159,11 @@ class Search_ModuleController extends MVVController
|| count($drill_down['studiengaenge']['objects']) || count($drill_down['studiengaenge']['objects'])
|| count($drill_down['faecher']['objects'])) { || count($drill_down['faecher']['objects'])) {
$widget = new SelectWidget(_('Studiengänge'), $widget = new SelectWidget(
$this->url_for('',['sterm' => $this->sterm, 'type' => 'Studiengang']), 'id'); _('Studiengänge'),
$this->indexURL(['sterm' => $this->sterm, 'type' => 'Studiengang']),
'id'
);
$options = [0 => 'Alle']; $options = [0 => 'Alle'];
if(!empty($drill_down['studiengaenge']['objects'])){ if(!empty($drill_down['studiengaenge']['objects'])){
foreach ($drill_down['studiengaenge']['objects'] as $studiengang) { foreach ($drill_down['studiengaenge']['objects'] as $studiengang) {
...@@ -173,8 +175,11 @@ class Search_ModuleController extends MVVController ...@@ -173,8 +175,11 @@ class Search_ModuleController extends MVVController
$sidebar->addWidget($widget, 'studiengaenge_filter'); $sidebar->addWidget($widget, 'studiengaenge_filter');
$widget = new SelectWidget(_('Fächer'), $widget = new SelectWidget(
$this->url_for('',['sterm' => $this->sterm, 'type' => 'Fach']), 'id'); _('Fächer'),
$this->indexURL(['sterm' => $this->sterm, 'type' => 'Fach']),
'id'
);
$options = [0 => 'Alle']; $options = [0 => 'Alle'];
if(!empty($drill_down['faecher']['objects'])){ if(!empty($drill_down['faecher']['objects'])){
foreach ($drill_down['faecher']['objects'] as $fach) { foreach ($drill_down['faecher']['objects'] as $fach) {
...@@ -186,8 +191,11 @@ class Search_ModuleController extends MVVController ...@@ -186,8 +191,11 @@ class Search_ModuleController extends MVVController
$sidebar->addWidget($widget, 'faecher_filter'); $sidebar->addWidget($widget, 'faecher_filter');
$widget = new SelectWidget(_('Verantwortliche Einrichtungen'), $widget = new SelectWidget(
$this->url_for('',['sterm' => $this->sterm, 'type' => 'Fachbereich']), 'id'); _('Verantwortliche Einrichtungen'),
$this->indexURL(['sterm' => $this->sterm, 'type' => 'Fachbereich']),
'id'
);
$widget->class = 'institute-list'; $widget->class = 'institute-list';
$options = [0 => 'Alle']; $options = [0 => 'Alle'];
$widget->addElement(new SelectElement(0, _('Alle')), 'select-all'); $widget->addElement(new SelectElement(0, _('Alle')), 'select-all');
......
...@@ -252,6 +252,14 @@ abstract class StudipController extends Trails_Controller ...@@ -252,6 +252,14 @@ abstract class StudipController extends Trails_Controller
{ {
$args = func_get_args(); $args = func_get_args();
// Try to create route if none given
if ($to === '') {
$to = $this->parent_controller
? $this->parent_controller->current_action
: $this->current_action;
return $this->action_url($to);
}
// Create url for a specific action // Create url for a specific action
// TODO: This seems odd. You kinda specify an absolute path // TODO: This seems odd. You kinda specify an absolute path
// to receive a relative url. Meh... // to receive a relative url. Meh...
...@@ -287,14 +295,6 @@ abstract class StudipController extends Trails_Controller ...@@ -287,14 +295,6 @@ abstract class StudipController extends Trails_Controller
//preserve fragment //preserve fragment
[$to, $fragment] = explode('#', $to); [$to, $fragment] = explode('#', $to);
// Try to create route if none given
if (!$to) {
$to = '/';
$to .= $this->parent_controller
? $this->parent_controller->current_action
: $this->current_action;
}
$url = parent::url_for($to); $url = parent::url_for($to);
if ($fragment) { if ($fragment) {
...@@ -365,15 +365,15 @@ abstract class StudipController extends Trails_Controller ...@@ -365,15 +365,15 @@ abstract class StudipController extends Trails_Controller
*/ */
private function adjustToArguments(...$args): string private function adjustToArguments(...$args): string
{ {
if ($this->isURL($args[0]) && count($args) > 1) { if (count($args) > 1 && $this->isURL($args[0])) {
throw new InvalidArgumentException('Method may not be used with a URL and multiple parameters'); throw new InvalidArgumentException('Method may not be used with a URL and multiple parameters');
} }
if (count($args) > 1 || !$this->isURL($args[0])) { if (count($args) === 1 && $this->isURL($args[0])) {
return $this->url_for(...$args); return $args[0];
} }
return $args[0]; return $this->url_for(...$args);
} }
/** /**
......
...@@ -60,6 +60,19 @@ StudipAutoloader::addAutoloadPath('lib/plugins/engine'); ...@@ -60,6 +60,19 @@ StudipAutoloader::addAutoloadPath('lib/plugins/engine');
StudipAutoloader::addAutoloadPath('lib/plugins/core'); StudipAutoloader::addAutoloadPath('lib/plugins/core');
StudipAutoloader::addAutoloadPath('lib/plugins/db'); StudipAutoloader::addAutoloadPath('lib/plugins/db');
StudipAutoloader::addClassLookup('StudipController', 'app/controllers/studip_controller.php');
$trails_classes = [
'Trails_Dispatcher', 'Trails_Response', 'Trails_Controller',
'Trails_Inflector', 'Trails_Flash',
'Trails_Exception', 'Trails_DoubleRenderError', 'Trails_MissingFile',
'Trails_RoutingError', 'Trails_UnknownAction', 'Trails_UnknownController',
'Trails_SessionRequiredException',
];
StudipAutoloader::addClassLookup(
$trails_classes,
'vendor/trails/trails.php'
);
// load config-variables // load config-variables
StudipFileloader::load( StudipFileloader::load(
'config_defaults.inc.php config_local.inc.php', 'config_defaults.inc.php config_local.inc.php',
......
...@@ -12,14 +12,6 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -12,14 +12,6 @@ final class StudipControllerTest extends Codeception\Test\Unit
{ {
private $old_uri; private $old_uri;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
require_once 'vendor/trails/trails-abridged.php';
require_once 'app/controllers/studip_controller.php';
}
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
...@@ -47,9 +39,7 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -47,9 +39,7 @@ final class StudipControllerTest extends Codeception\Test\Unit
private function getController(): StudipController private function getController(): StudipController
{ {
$dispatcher = $this->getDispatcher(); $dispatcher = $this->getDispatcher();
return new class($dispatcher) extends StudipController { return new StudipControllerTestController($dispatcher);
};
} }
/** /**
...@@ -76,7 +66,7 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -76,7 +66,7 @@ final class StudipControllerTest extends Codeception\Test\Unit
} }
/** /**
* @dataProvider UrlForProvider * @dataProvider RedirectProvider
* @covers StudipController::redirect * @covers StudipController::redirect
*/ */
public function testRedirect(string $expected, ...$args): void public function testRedirect(string $expected, ...$args): void
...@@ -106,7 +96,7 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -106,7 +96,7 @@ final class StudipControllerTest extends Codeception\Test\Unit
} }
/** /**
* @dataProvider UrlForProvider * @dataProvider RedirectProvider
* @covers StudipController::relocate * @covers StudipController::relocate
*/ */
public function testRelocate(string $expected, ...$args): void public function testRelocate(string $expected, ...$args): void
...@@ -136,7 +126,7 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -136,7 +126,7 @@ final class StudipControllerTest extends Codeception\Test\Unit
} }
/** /**
* @dataProvider UrlForProvider * @dataProvider RedirectProvider
* @covers StudipController::relocate * @covers StudipController::relocate
* @backupGlobals enabled * @backupGlobals enabled
*/ */
...@@ -187,6 +177,7 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -187,6 +177,7 @@ final class StudipControllerTest extends Codeception\Test\Unit
public function UrlForProvider(): array public function UrlForProvider(): array
{ {
return [ return [
'0-action' => ['dispatch.php/studip_controller_test/foo'],
'1-action' => ['dispatch.php/foo', 'foo'], '1-action' => ['dispatch.php/foo', 'foo'],
'1-action-and-parameter' => ['dispatch.php/foo?bar=42', 'foo', ['bar' => 42]], '1-action-and-parameter' => ['dispatch.php/foo?bar=42', 'foo', ['bar' => 42]],
'1-action-and-parameters' => ['dispatch.php/foo?bar=42&baz=23', 'foo', ['bar' => 42, 'baz' => 23]], '1-action-and-parameters' => ['dispatch.php/foo?bar=42&baz=23', 'foo', ['bar' => 42, 'baz' => 23]],
...@@ -197,6 +188,13 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -197,6 +188,13 @@ final class StudipControllerTest extends Codeception\Test\Unit
]; ];
} }
public function RedirectProvider(): array
{
$result = $this->UrlForProvider();
unset($result['0-action']);
return $result;
}
public function absoluteUrlForProvider(): array public function absoluteUrlForProvider(): array
{ {
return [ return [
...@@ -214,3 +212,12 @@ final class StudipControllerTest extends Codeception\Test\Unit ...@@ -214,3 +212,12 @@ final class StudipControllerTest extends Codeception\Test\Unit
} }
} }
class StudipControllerTestController extends StudipController
{
public function __construct($dispatcher)
{
parent::__construct($dispatcher);
$this->current_action = 'foo';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment