1<?php
2
3/**
4 * General tests for the booking plugin
5 *
6 * @group plugin_booking
7 * @group plugins
8 */
9class booking_plugin_booking_test extends DokuWikiTest
10{
11
12    protected $pluginsEnabled = ['booking'];
13
14    public function test_createbooking()
15    {
16        global $conf;
17
18        /** @var helper_plugin_booking $hlp */
19        $hlp = plugin_load('helper', 'booking');
20
21        try {
22            $hlp->addBooking('test:book', '2020-12-17 13:00', '1.5h', 'andi');
23            $ok = true;
24        } catch (Exception $e) {
25            $ok = false;
26        }
27        $this->assertTrue($ok);
28
29        $this->assertFileExists($conf['metadir'] . '/test/book.booking');
30    }
31
32    /**
33     * @expectedException \Exception
34     * @expectedExceptionCode helper_plugin_booking::E_NOLENGTH
35     */
36    public function test_nolength()
37    {
38        /** @var helper_plugin_booking $hlp */
39        $hlp = plugin_load('helper', 'booking');
40
41        $hlp->addBooking('test:book', '2020-12-17 13:00', 'foobar', 'andi');
42    }
43
44    /**
45     * @expectedException \Exception
46     * @expectedExceptionCode helper_plugin_booking::E_OVERLAP
47     */
48    public function test_overlapbooking()
49    {
50        /** @var helper_plugin_booking $hlp */
51        $hlp = plugin_load('helper', 'booking');
52
53        $hlp->addBooking('test:book', '2020-12-17 13:00', '1.5h', 'andi');
54        $hlp->addBooking('test:book', '2020-12-17 13:20', '1.5h', 'andi');
55    }
56
57
58    public function test_bookAndCancel()
59    {
60        /** @var helper_plugin_booking $hlp */
61        $hlp = plugin_load('helper', 'booking');
62
63        // add three bookings
64        $hlp->addBooking('test:run', '2020-12-17 13:00', '1.5h', 'andi');
65        $hlp->addBooking('test:run', '2020-12-17 14:30', '1.5h', 'andi');
66        $hlp->addBooking('test:run', '2020-12-17 16:00', '1.5h', 'andi');
67
68        $bookings = $hlp->getBookings('test:run');
69        $this->assertSame(3, count($bookings));
70
71        // cancel a booking
72        $ok = $hlp->cancelBooking('test:run', '2020-12-17 14:30');
73        $this->assertTrue($ok);
74
75        // cancel a non-existent booking
76        $ok = $hlp->cancelBooking('test:run', '2020-12-17 14:33');
77        $this->assertFalse($ok);
78
79        $bookings = $hlp->getBookings('test:run');
80        $this->assertSame(2, count($bookings));
81    }
82}
83