aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ForumTestHelper.php
blob: 25e868d7422a532b141b4484a534b73742792032 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php

use JsonApi\Models\ForumCat;
use JsonApi\Models\ForumEntry;

trait ForumTestHelper
{
    private function buildValidResourceEntry($content, $title)
    {
        return ['data' => [
                'type' => 'forum-entries',
                'attributes' => [
                    'title' => $title,
                    'content' => $content,
                ],
            ],
        ];
    }

    private function buildValidResourceEntryUpdate()
    {
        return ['data' => [
                'type' => 'forum-entries',
                'attributes' => [
                    'title' => 'updated entry',
                    'content' => 'this has been updated by testcase',
                ],
            ],
        ];
    }

    private function buildValidResourceCategory()
    {
        return [
            'data' => [
                'type' => 'forum-categories',
                'attributes' => [
                    'title' => 'Test-Kategorie',
                ],
            ],
        ];
    }

    private function buildValidResourceCategoryUpdate()
    {
        return [
            'data' => [
                'type' => 'forum-categories',
                'attributes' => [
                    'title' => 'Updated-Kategorie',
                ],
            ],
        ];
    }

    private function createCategory($credentials)
    {
        $seminar_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
        $cat_name = 'Test-Kategorie';
        $cat = new ForumCat();
        $cat->seminar_id = $seminar_id;
        $cat->entry_name = $cat_name;
        $cat->store();

        return $cat;
    }

    private function createBadCategory($credentials)
    {
        $seminar_id = 'badCourse';
        $cat_name = 'Test-Kategorie';
        $cat = new ForumCat();
        $cat->seminar_id = $seminar_id;
        $cat->entry_name = $cat_name;
        $cat->store();

        return $cat;
    }

    private function createEntry($credentials, $category_id)
    {
        echo 'test:'.$category_id;
        if (!$parent = ForumCat::find($category_id)) {
            $entry_id = $category_id;
            $parent = ForumEntry::find($entry_id);
        }

        $topic_id = md5(uniqid(rand()));
        $data = array(
            'topic_id' => $topic_id,
            'seminar_id' => $parent->seminar_id,
            'user_id' => $credentials['id'],
            'name' => 'Test-Entry',
            'content' => 'Try to append new entries',
            'author' => $credentials['username'],
            'anonymous' => 0,
        );
        $entry = new ForumEntry();
        $entry->setData($data);

        $entry->storeWith($parent, $entry);

        return $entry;
    }

    private function createBadEntry($credentials)
    {
        $entry_name = 'Test-Entry';
        $entry = new ForumEntry();
        $entry->seminar_id = 'badSeminar';
        $entry->entry_name = $entry_name;
        $entry->store();

        return $entry;
    }
}