aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ForumTestHelper.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:07:19 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:19:12 +0200
commita3da1483a9e689846179159355badfec8073dbec (patch)
tree770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /tests/jsonapi/ForumTestHelper.php
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/ForumTestHelper.php')
-rw-r--r--tests/jsonapi/ForumTestHelper.php116
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/jsonapi/ForumTestHelper.php b/tests/jsonapi/ForumTestHelper.php
new file mode 100644
index 0000000..25e868d
--- /dev/null
+++ b/tests/jsonapi/ForumTestHelper.php
@@ -0,0 +1,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;
+ }
+}