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

fix fallout from 76967507 and provide test for...

fix fallout from 76967507 and provide test for variable assignments in StudipController, re #1328
parent ca923e5e
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,7 @@ class Calendar_SingleController extends Calendar_CalendarController
$timestamp = mktime(12, 0, 0, date('n', $this->atime), date('j', $this->atime), date('Y', $this->atime));
$monday = $timestamp - 86400 * (strftime('%u', $timestamp) - 1);
$day_count = $this->settings['type_week'] == 'SHORT' ? 5 : 7;
$this->calendars = [];
for ($i = 0; $i < $day_count; $i++) {
$this->calendars[$i] =
SingleCalendar::getDayCalendar(
......
......@@ -42,9 +42,13 @@ trait StudipControllerPropertiesTrait
* @param string $offset
* @return mixed
*/
public function __get(string $offset)
public function &__get(string $offset)
{
return $this->_template_variables[$offset] ?? null;
$result = null;
if (isset($this->_template_variables[$offset])) {
$result = &$this->_template_variables[$offset];
}
return $result;
}
/**
......
......@@ -182,6 +182,42 @@ final class StudipControllerTest extends Codeception\Test\Unit
$this->getController()->relocate(...$args);
}
public function testVariableAssignment(): void
{
$controller = $this->getController();
// Set and test assignments
$controller->foo = 'bar';
$this->assertEquals('bar', $controller->foo);
$controller->bar = 42;
$this->assertEquals(42, $controller->bar);
$controller->baz = [];
$controller->baz[] = 23;
$this->assertEquals([23], $controller->baz);
// Test fetching all variables
$variables = $controller->get_assigned_variables();
$this->assertIsArray($variables);
// - Implicit variables
$this->assertArrayHasKey('controller', $variables);
$this->assertArrayHasKey('current_action', $variables);
// - Explicit variables
$this->assertArrayHasKey('foo', $variables);
$this->assertEquals('bar', $variables['foo']);
$this->assertArrayHasKey('bar', $variables);
$this->assertEquals(42, $variables['bar']);
$this->assertArrayHasKey('baz', $variables);
$this->assertCount(1, $variables['baz']);
$this->assertEquals([23], $variables['baz']);
}
/**
* Returns a relative url for Stud.IP if given url matches.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment