aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/lib/resources/RoomManagerTest.php
blob: 910a5760259c4fd33627a7714e917e1b5e07d8f7 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php


require_once __DIR__ . '/../../_bootstrap.php';
require_once 'lib/resources/RoomManager.class.php';
require_once 'lib/resources/ResourceManager.class.php';


class RoomManagerTest extends \Codeception\Test\Unit
{
    protected $db_handle;


    protected function _before()
    {
        //First we must initialise the StudipPDO database connection:
        $this->db_handle = new \StudipPDO(
            'mysql:host='
                . $GLOBALS['DB_STUDIP_HOST']
                . ';dbname='
                . $GLOBALS['DB_STUDIP_DATABASE'],
            $GLOBALS['DB_STUDIP_USER'],
            $GLOBALS['DB_STUDIP_PASSWORD']
        );

        //Then we must start a transaction before we access the database,
        //otherwise we would spam the live database with test data!
        $this->db_handle->beginTransaction();

        //Now we tell the DBManager about the connection
        //we have established to the Stud.IP database:
        \DBManager::getInstance()->setConnection('studip', $this->db_handle);

        $this->user = new User();
        $this->user->username = 'test_user_' . date('YmdHis');
        $this->user->vorname = 'Test';
        $this->user->nachname = 'User';
        $this->user->perms = 'admin';
        $this->user->store();

        ResourceManager::setGlobalResourcePermission($this->user, 'admin');

        $this->location_cat = ResourceManager::createLocationCategory(
            'TestLocation'
        );
        $this->building_cat = ResourceManager::createBuildingCategory(
            'TestBuilding'
        );
        $this->room_cat = ResourceManager::createRoomCategory(
            'TestRoom'
        );

        $this->location = $this->location_cat->createResource(
            'Test location object'
        );
        $this->building = $this->building_cat->createResource(
            'Test building object',
            '',
            $this->location->id
        );
        $this->room = $this->room_cat->createResource(
            'Test room object',
            '',
            $this->building->id
        );

        $this->room->seats = 25;

        $this->room->createLock(
            $this->user,
            new DateTime('2017-10-02 8:00:00 +0000'),
            new DateTime('2017-10-02 18:00:00 +0000')
        );

        $this->course = new Course();
        $this->course->name = 'test_course_' . date('YmdHis');
        $this->course->store();

        $this->course_date = new CourseDate();
        $this->course_date->range_id = $this->course->id;
        $this->course_date->autor_id = $this->user->id;
        $this->course_date->date = strtotime('2017-10-01 8:00:00 +0000');
        $this->course_date->end_time = strtotime('2017-10-01 10:00:00 +0000');
        $this->course_date->store();
    }

    protected function _after()
    {
        //We must roll back the changes we made in this test
        //so that the live database remains unchanged after
        //all the test cases of this test have been finished:
        $this->db_handle->rollBack();
    }
}