blob: 094d86871438a277fe7f8f682a7382573210d338 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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));
}
}
|