diff --git a/app/controllers/calendar/single.php b/app/controllers/calendar/single.php index e2ea4c7e9d2bf4e1489606c28007740a6eb0c4c1..6cfc133dc27714c1a3a65f647b49555b072d587c 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] = SingleCalendar::getDayCalendar( diff --git a/app/controllers/studip_controller_properties_trait.php b/app/controllers/studip_controller_properties_trait.php index 4246da05f98db6bd96d27136e8243f2d34c8f570..fb3b68d57d65a6ef83b66266db8038550c7b514c 100644 --- a/app/controllers/studip_controller_properties_trait.php +++ b/app/controllers/studip_controller_properties_trait.php @@ -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; } /** diff --git a/tests/unit/lib/classes/StudipControllerTest.php b/tests/unit/lib/classes/StudipControllerTest.php index 532116677ae115810f20a2a15750318d1a9eaafe..2b25bc4435ff2a28e7f43c0842a249e768678fcb 100644 --- a/tests/unit/lib/classes/StudipControllerTest.php +++ b/tests/unit/lib/classes/StudipControllerTest.php @@ -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. */