aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/CoursesIndexTest.php
blob: 6c9db346952ec73d6ffacba0047a3833d4cda697 (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\Courses\CoursesIndex;

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

    protected function _before()
    {
        \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh);
        //Initialize $SEM_TYPE and $SEM_CLASS arrays
        $GLOBALS['SEM_CLASS'] = SemClass::getClasses();
        $GLOBALS['SEM_TYPE'] = SemType::getTypes();
    }

    protected function _after()
    {
    }

    // tests

    public function testShouldIndexCourse()
    {
        $credentials = $this->tester->getCredentialsForRoot();
        $response = $this->getCourses($credentials);
        $this->tester->assertTrue($response->isSuccessfulDocument([200]));
        $this->tester->assertCount(2, $response->document()->primaryResources());
    }

    // **** helper functions ****
    private function getCourses($credentials)
    {
        $app = $this->tester->createApp($credentials, 'get', '/courses', CoursesIndex::class);

        return $this->tester->sendMockRequest(
            $app,
            $this->tester->createRequestBuilder($credentials)
            ->setUri('/courses')
            ->fetch()
            ->getRequest()
        );
    }
}