aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/NewsTestHelper.php
blob: 59ac9c4f6dc6d6dc0a7c6e5bd702bc9f46cc226a (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

trait NewsTestHelper
{
    private function createNews($credentials, $title, $content, $rangeId = null)
    {
        $news = \StudipNews::create(
            [
                'user_id'        => $credentials['id'],
                'author'         => $credentials['username'],
                'topic'          => $title,
                'body'           => $content,
                'date'           => time()- (15 * 60),
                'expire'         => 2 * 7 * 24 * 60 * 60,
                'allow_comments' => true
            ]
        );
        if ($rangeId) {

            $news->addRange($rangeId);
            $news->storeRanges();
        }

        return $news;
    }
    
    private function buildValidResourceEntry($content, $title)
    {
        return ['data' => [
                'type' => 'news',
                'attributes' => [
                    'title' => $title,
                    'content' => $content,
                    'comments-allowed' => true,
                    'publication-start' => "2020-01-01T12:12:12+00:00",
                    'publication-end' => "2021-01-01T12:12:12+00:00"
                ],
            ],
        ];
    }
    private function buildValidCommentEntry($comment)
    {
        return [
            'data' => [
                'type' => 'comments',
                'attributes' => [
                    'content' => $comment
                ],
            ],
        ];
    }
    private function buildValidUpdateEntry($comment)
    {
        return [
            'data' => [
                'type' => 'news',
                'attributes' => [
                    'content' => 'testy',
                    'comments-allowed' => true,
                    'publication-start' => "2020-01-01T12:12:12+00:00",
                    'publication-end' => "2021-01-01T12:12:12+00:00"
                ],
            ],
        ];
    }
    private function createComment(array $credentials, \StudipNews $news, $content)
    {
        $comment = new \StudipComment();
        $comment->user_id = $credentials['id'];
        $comment->content = $content;
        $comment->object_id = $news->id;

        $comment->store();

        return $comment;
    }
}