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


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

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

    protected function _after()
    {
    }

    //testszenario:
    public function testCourseCreateNews()
    {
        $courseId = 'a07535cf2f8a72df33c12ddfa4b53dde';
        $title = 'Fakenews';
        $content = 'This is just fake news.';
        $date = time();
        $expire = $date + 1 * 7 * 24 * 60 * 60;
        $credentials = $this->tester->getCredentialsForRoot();
        $response = $this->createCourseNews($credentials, $courseId, $title, $content, $date, $expire);
    }

    //helpers:
    private function createCourseNews($credentials, $courseId, $title, $content, $date, $expire)
    {
        $app = $this->tester->createApp($credentials, 'post', '/courses/{id}/news', CourseNewsCreate::class);

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