aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ForumCategoriesCreateTest.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/ForumCategoriesCreateTest.php
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/ForumCategoriesCreateTest.php')
-rw-r--r--tests/jsonapi/ForumCategoriesCreateTest.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/jsonapi/ForumCategoriesCreateTest.php b/tests/jsonapi/ForumCategoriesCreateTest.php
new file mode 100644
index 0000000..c9a12fb
--- /dev/null
+++ b/tests/jsonapi/ForumCategoriesCreateTest.php
@@ -0,0 +1,72 @@
+<?php
+
+require_once 'ForumTestHelper.php';
+
+use JsonApi\Routes\Forum\ForumCategoriesCreate;
+use JsonApi\Errors\RecordNotFoundException;
+
+class ForumCategoriesCreateTest extends \Codeception\Test\Unit
+{
+ use ForumTestHelper;
+
+ /**
+ * @var \UnitTester
+ */
+ protected $tester;
+
+ protected function _before()
+ {
+ \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh);
+ }
+
+ protected function _after()
+ {
+ }
+
+ // tests
+ public function testShouldCreateCategory()
+ {
+ $credentials = $this->tester->getCredentialsForTestAutor();
+ $cat = $this->createCategory($credentials);
+ $course_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
+ $cat_document = $this->buildValidResourceCategory();
+ $app = $this->tester->createApp($credentials, 'POST', '/courses/{id}/forum-categories', ForumCategoriesCreate::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/courses/'.$course_id.'/forum-categories')
+ ->create()
+ ->setJsonApiBody($cat_document);
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+
+ $this->tester->assertTrue($response->isSuccessfulDocument([201]));
+ $document = $response->document();
+ $resourceObject = $document->primaryResource();
+ $this->tester->assertSame($cat->entry_name, $resourceObject->attribute('title'));
+ }
+
+ public function testShouldNotCreateCategory()
+ {
+ $this->tester->expectThrowable(RecordNotFoundException::class, function () {
+ $credentials = $this->tester->getCredentialsForTestAutor();
+ $cat = $this->createCategory($credentials);
+ $course_id = 'badCourse';
+ $cat_document = $this->buildValidResourceCategory();
+ $app = $this->tester->createApp($credentials, 'POST', '/courses/{id}/forum-categories', ForumCategoriesCreate::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/courses/'.$course_id.'/forum-categories')
+ ->create()
+ ->setJsonApiBody($cat_document);
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+
+ $this->tester->assertTrue($response->isSuccessfulDocument([201]));
+ $document = $response->document();
+ $resourceObject = $document->primaryResource();
+ $this->tester->assertSame($cat->entry_name, $resourceObject->attribute('title'));
+ });
+ }
+}