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

fix bad assignments on previously undeclared arrays in StudipController, re #1328

parent 2b211643
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] =
......@@ -126,6 +127,8 @@ class Calendar_SingleController extends Calendar_CalendarController
$cor = date('n', $this->atime) == 3 ? 1 : 0;
$this->first_day = $month_start - $adow * 86400;
$this->last_day = ((42 - ($adow + date('t', $this->atime))) % 7 + $cor) * 86400 + $month_end;
$this->calendars = [];
for ($start_day = $this->first_day; $start_day <= $this->last_day; $start_day += 86400) {
$this->calendars[] = SingleCalendar::getDayCalendar($this->range_id,
$start_day, null, $this->restrictions);
......
......@@ -44,11 +44,10 @@ trait StudipControllerPropertiesTrait
*/
public function &__get(string $offset)
{
$result = null;
if (isset($this->_template_variables[$offset])) {
$result = &$this->_template_variables[$offset];
if (!isset($this->_template_variables[$offset])) {
$this->_template_variables[$offset] = null;
}
return $result;
return $this->_template_variables[$offset];
}
/**
......
......@@ -200,6 +200,9 @@ final class StudipControllerTest extends Codeception\Test\Unit
$controller->baz[] = 23;
$this->assertEquals([23], $controller->baz);
$controller->bad[] = 23;
$this->assertEquals([23], $controller->bad);
// Test fetching all variables
$variables = $controller->get_assigned_variables();
......@@ -219,6 +222,10 @@ final class StudipControllerTest extends Codeception\Test\Unit
$this->assertArrayHasKey('baz', $variables);
$this->assertCount(1, $variables['baz']);
$this->assertEquals([23], $variables['baz']);
$this->assertArrayHasKey('bad', $variables);
$this->assertCount(1, $variables['bad']);
$this->assertEquals([23], $variables['bad']);
}
/**
......
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