aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2022-07-15 11:46:38 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2022-07-15 11:46:38 +0200
commitca93122050607f51afd4d571680bd2b4d0fdab10 (patch)
tree6ac68c9f36f6a6f796602d469bf3e3b676784317
parent2b21164387aa3f8ad97eb9d8b1f272089483a6d1 (diff)
fix bad assignments on previously undeclared arrays in StudipController, re #1328
-rw-r--r--app/controllers/calendar/single.php3
-rw-r--r--app/controllers/studip_controller_properties_trait.php7
-rw-r--r--tests/unit/lib/classes/StudipControllerTest.php7
3 files changed, 13 insertions, 4 deletions
diff --git a/app/controllers/calendar/single.php b/app/controllers/calendar/single.php
index 6cfc133..91525aa 100644
--- a/app/controllers/calendar/single.php
+++ b/app/controllers/calendar/single.php
@@ -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);
diff --git a/app/controllers/studip_controller_properties_trait.php b/app/controllers/studip_controller_properties_trait.php
index fb3b68d..4e906fa 100644
--- a/app/controllers/studip_controller_properties_trait.php
+++ b/app/controllers/studip_controller_properties_trait.php
@@ -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];
}
/**
diff --git a/tests/unit/lib/classes/StudipControllerTest.php b/tests/unit/lib/classes/StudipControllerTest.php
index 0eea671..f74eae4 100644
--- a/tests/unit/lib/classes/StudipControllerTest.php
+++ b/tests/unit/lib/classes/StudipControllerTest.php
@@ -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']);
}
/**