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

use JsonApi\Routes\Institutes\InstituteMembershipsIndex;

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

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

    protected function _after()
    {
    }

    public function testIndexMemberships()
    {
        $credentials = $this->tester->getCredentialsForTestAutor();
        $instituteId = '2560f7c7674942a7dce8eeb238e15d93';

        $institute = \Institute::find($instituteId);

        $app = $this->tester->createApp($credentials, 'get', '/institutes/{id}/memberships', InstituteMembershipsIndex::class);

        $requestBuilder = $this->tester->createRequestBuilder($credentials);
        $requestBuilder->setUri('/institutes/'.$instituteId.'/memberships')->fetch();

        $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());

        $this->tester->assertTrue($response->isSuccessfulDocument([200]));
        $document = $response->document();
        $this->tester->assertTrue($document->isResourceCollectionDocument());
        $resources = $document->primaryResources();
        $this->tester->assertCount(count($institute->members), $resources);
    }
}