aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/UserEventsIcalTest.php
blob: 81230d457c65d13c44f6ccb6c5fd2ab55f7ebe4f (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
<?php

use JsonApi\Routes\Events\UserEventsIcal;

class UserEventsIcalTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {
        \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh);
    }

    protected function _after()
    {
    }

    // tests
    public function testIcalUserEvents()
    {
        $credentials = $this->tester->getCredentialsForTestAutor();

        $calendar = new \SingleCalendar($credentials['id']);
        $event = $calendar->getNewEvent();
        $event->setTitle('blypyp');

        $oldUser = $GLOBALS['user'] ?? null;
        $GLOBALS['user'] = \User::find($credentials['id']);

        $calendar->storeEvent($event, [$credentials['id']]);

        $GLOBALS['user'] = $oldUser;

        $app = $this->tester->createApp($credentials, 'get', '/users/{id}/events.ics', UserEventsIcal::class);

        $requestBuilder = $this->tester->createRequestBuilder($credentials);
        $requestBuilder->setUri('/users/'.$credentials['id'].'/events.ics')->fetch();

        $response = $app->handle($requestBuilder->getRequest());

        $this->tester->assertEquals(200, $response->getStatusCode());
        $this->tester->assertStringContainsString('BEGIN:VEVENT', (string) $response->getBody());
        $this->tester->assertStringContainsString('SUMMARY:blypyp', (string) $response->getBody());
    }
}