aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ScheduleEntriesShowTest.php
blob: 99dc8950a9e6b92947b6eb6ba71c585cf55e0047 (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
<?php

use JsonApi\Routes\Schedule\ScheduleEntriesShow;

class ScheduleEntriesShowTest 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 testShouldShowEntriesOfSchedule()
    {
        $credentials = $this->tester->getCredentialsForTestAutor();

        \CalendarScheduleModel::storeEntry(
            [
                'start' => 9,
                'end' => 10,
                'day' => 1,
                'title' => 'test title',
                'content' => 'test content',
                'user_id' => $credentials['id'],
                'color' => DEFAULT_COLOR_NEW
            ]
        );
        $scheduleEntryId = \DBManager::get()->lastInsertId();

        $app = $this->tester->createApp($credentials, 'get', '/schedule-entries/{id}', ScheduleEntriesShow::class);

        $response = $this->tester->sendMockRequest(
            $app,
            $this->tester->createRequestBuilder($credentials)
            ->setUri('/schedule-entries/'.$scheduleEntryId)
            ->fetch()
            ->getRequest()
        );

        $this->tester->assertTrue($response->isSuccessfulDocument([200]));
        $document = $response->document();
        $this->tester->assertTrue($document->isSingleResourceDocument());
        $resource = $document->primaryResource();
        $this->tester->assertNotNull($resource);
        $this->tester->assertEquals($scheduleEntryId, $resource->id());

    }
}