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

require_once 'BlubberTestHelper.php';

class BlubberCommentsByThreadIndexTest extends \Codeception\Test\Unit
{
    use BlubberTestHelper;

    /**
     * @var \UnitTester
     */
    protected $tester;

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

    protected function _after()
    {
    }

    // tests

    /**
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    public function testShowThread()
    {
        // given
        $credentials = $this->tester->getCredentialsForTestAutor();
        $thread = $this->createPublicBlubberThreadForUser($credentials, 'Who knows Daskylos?');

        // Workaround old-style Stud.IP-API using $GLOBALS['user']
        $oldUser = $GLOBALS['user'];
        $GLOBALS['user'] = new \Seminar_User(\User::find($credentials['id']));

        $this->createBlubberComment($credentials, $thread, 'Autolykos knows him.');
        $this->createBlubberComment($credentials, $thread, 'Butes knows him too.');

        // Workaround old-style Stud.IP-API using $GLOBALS['user']
        $GLOBALS['user'] = $oldUser;

        $response = $this->fetchComments($credentials, $thread);

        $this->tester->assertTrue($response->isSuccessfulDocument([200]));

        $document = $response->document();
        $this->tester->assertTrue($document->isResourceCollectionDocument());

        $resources = $document->primaryResources();
        $this->tester->assertCount(2, $resources);
    }
}