diff options
| author | Simon Rettberg | 2025-11-26 10:46:51 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-12-12 15:16:59 +0100 |
| commit | 7c173411785f959d250d3dfbd7d4cfcb0e20f0e0 (patch) | |
| tree | 242157791a76afb7af23ec2cd3d22b599e54ce9d /tests/Modules/Locations/OpeningTimesTest.php | |
| parent | [exams] Fix incorrect count() clause (diff) | |
| download | slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.gz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.xz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.zip | |
Add tests using PHPUnit
Tests generated by Junie AI. Might not have the best possible quality
but at least we got something, and if it turns out to be complete
rubbish, we can just throw it out again without any issues, as this is
independent of the actual code base.
Diffstat (limited to 'tests/Modules/Locations/OpeningTimesTest.php')
| -rw-r--r-- | tests/Modules/Locations/OpeningTimesTest.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/Modules/Locations/OpeningTimesTest.php b/tests/Modules/Locations/OpeningTimesTest.php new file mode 100644 index 00000000..094d8687 --- /dev/null +++ b/tests/Modules/Locations/OpeningTimesTest.php @@ -0,0 +1,56 @@ +<?php + +use PHPUnit\Framework\TestCase; + +/** + * Tests for modules-available/locations/inc/openingtimes.inc.php using the SQLite-backed DB + * and the real Location class. + * + */ +class OpeningTimesTest extends TestCase +{ + protected function setUp(): void + { + Database::resetSchema(); + Message::reset(); + // Use the real Location implementation + $GLOBALS['__TEST_USE_REAL_CLASSES'] = ['Location']; + require_once __DIR__ . '/../../../modules-available/locations/inc/location.inc.php'; + require_once __DIR__ . '/../../../modules-available/locations/inc/openingtimes.inc.php'; + } + + public function testForLocationReturnsNearestAncestorOpeningTimes(): void + { + // Seed: location 1 has all-day opening time from Database::seedData; ensure child (2) has no specific times + $times1 = OpeningTimes::forLocation(1); + $this->assertIsArray($times1); + $this->assertNotEmpty($times1); + $this->assertSame('00:00', $times1[0]['openingtime']); + $this->assertSame('23:59', $times1[0]['closingtime']); + + // For location 2 (child of 1), it should inherit from 1 + $times2 = OpeningTimes::forLocation(2); + $this->assertIsArray($times2); + $this->assertSame($times1, $times2); + } + + public function testIsRoomOpenTrueWhenNoOpeningTimes(): void + { + // Remove opening times for all locations to simulate no configuration + Database::exec('UPDATE location SET openingtime = NULL'); + $this->assertTrue(OpeningTimes::isRoomOpen(3)); + } + + public function testIsRoomOpenRespectsOffsets(): void + { + // Without offset, should be closed (opening time is in the future) + $this->assertFalse(OpeningTimes::isRoomOpen(5)); + // With openOffsetMin large enough to shift opening time earlier, it should be open + $this->assertTrue(OpeningTimes::isRoomOpen(5, 90)); + + // Without offset, should be closed (opening time is in the future) + $this->assertFalse(OpeningTimes::isRoomOpen(4)); + // With closeOffsetMin large enough to shift closing time later, it should be open + $this->assertTrue(OpeningTimes::isRoomOpen(4, 0, 90)); + } +} |
