aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2025-07-04 06:13:27 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2025-07-04 06:13:27 +0000
commitd25a23a626b43baab9714c8a4a68a20144cb3f00 (patch)
treeea948244609f587a3fb9f1e5ab89fd996b30d73c /tests
parentaacbfe703e9e45fd9e8c11a60c3f1ad77593d981 (diff)
Resolve "Forum 3"
Closes #5146 Merge request studip/studip!3845
Diffstat (limited to 'tests')
-rw-r--r--tests/jsonapi/ForumCategoriesCreateTest.php67
-rw-r--r--tests/jsonapi/ForumCategoriesIndexTest.php60
-rw-r--r--tests/jsonapi/ForumCategoriesShowTest.php62
-rw-r--r--tests/jsonapi/ForumCategoriesUpdateTest.php64
-rw-r--r--tests/jsonapi/ForumCategoryDeleteTest.php60
-rw-r--r--tests/jsonapi/ForumEntriesCreateTest.php115
-rw-r--r--tests/jsonapi/ForumEntriesDeleteTest.php61
-rw-r--r--tests/jsonapi/ForumEntriesShowTest.php154
-rw-r--r--tests/jsonapi/ForumEntriesUpdateTest.php66
-rw-r--r--tests/jsonapi/ForumTestHelper.php116
10 files changed, 0 insertions, 825 deletions
diff --git a/tests/jsonapi/ForumCategoriesCreateTest.php b/tests/jsonapi/ForumCategoriesCreateTest.php
deleted file mode 100644
index 4fd96d4..0000000
--- a/tests/jsonapi/ForumCategoriesCreateTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?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()
- {
- $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->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumCategoriesIndexTest.php b/tests/jsonapi/ForumCategoriesIndexTest.php
deleted file mode 100644
index 01ba294..0000000
--- a/tests/jsonapi/ForumCategoriesIndexTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Routes\Forum\ForumCategoriesIndex;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumCategoriesIndexTest 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 testShouldShowCategory()
- {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $course_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
- $cat = $this->createCategory($credentials);
- $app = $this->tester->createApp($credentials, 'get', '/course/{id}/forum-categories', ForumCategoriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/course/'.$course_id.'/forum-categories')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- }
-
- public function testShouldNotShowCategory()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $course_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
- $cat = $this->createCategory($credentials);
-
- $app = $this->tester->createApp($credentials, 'get', '/course/{id}/forum-categories', ForumCategoriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/course/badID/forum-categories')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumCategoriesShowTest.php b/tests/jsonapi/ForumCategoriesShowTest.php
deleted file mode 100644
index 4e8df26..0000000
--- a/tests/jsonapi/ForumCategoriesShowTest.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Routes\Forum\ForumCategoriesShow;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumCategoriesShowTest 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 testShouldShowCategories()
- {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $cat = $this->createCategory($credentials);
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}', ForumCategoriesShow::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.$cat->category_id)
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
-
- $this->tester->assertSame($cat->entry_name, $resourceObject->attribute('title'));
- $this->tester->assertSame((int) $cat->pos, $resourceObject->attribute('position'));
- }
-
- public function testShouldNotShowCategories()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
-
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}', ForumCategoriesShow::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.'badId')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumCategoriesUpdateTest.php b/tests/jsonapi/ForumCategoriesUpdateTest.php
deleted file mode 100644
index f2015cb..0000000
--- a/tests/jsonapi/ForumCategoriesUpdateTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Routes\Forum\ForumCategoriesUpdate;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumCategoriesUpdateTest 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 testShouldUpdateCategory()
- {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $cat = $this->createCategory($credentials);
- $cat_document = $this->buildValidResourceCategoryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-categories/{id}', ForumCategoriesUpdate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.$cat->id)
- ->update()
- ->setJsonApiBody($cat_document);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotEquals($cat->entry_name, $resourceObject->attribute('title'));
- }
-
- public function testShouldNotUpdateCategory()
- {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $cat = $this->createCategory($credentials);
- $cat_document = $this->buildValidResourceCategoryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-categories/{id}', ForumCategoriesUpdate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badId')
- ->update()
- ->setJsonApiBody($cat_document);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumCategoryDeleteTest.php b/tests/jsonapi/ForumCategoryDeleteTest.php
deleted file mode 100644
index 8d144f2..0000000
--- a/tests/jsonapi/ForumCategoryDeleteTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Models\ForumCat;
-use JsonApi\Routes\Forum\ForumCategoriesDelete;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumCategoryDeleteTest 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 testShouldDeleteEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-categories/{id}', ForumCategoriesDelete::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.$cat->id)
- ->delete();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertIsEmpty(ForumCat::find($cat->id));
- }
-
- public function testShouldNotDeleteEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-categories/{id}', ForumCategoriesDelete::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badId')
- ->delete();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumEntriesCreateTest.php b/tests/jsonapi/ForumEntriesCreateTest.php
deleted file mode 100644
index 04d119e..0000000
--- a/tests/jsonapi/ForumEntriesCreateTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Routes\Forum\ForumCategoryEntriesCreate;
-use JsonApi\Routes\Forum\ForumEntryEntriesCreate;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumEntriesCreateTest 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 testShouldCreateEntryForCategory()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $content = 'some content to test';
- $title = 'entry-test-title';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-categories/{id}/entries', ForumCategoryEntriesCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.$cat->id.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- }
-
- public function testShouldNotCreateEntryForCategory()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $content = 'some content to test';
- $title = 'entry-test-title';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-categories/{id}/entries', ForumCategoryEntriesCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.'badId'.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-
- public function testShouldCreateEntryForEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $content = 'some new content to test';
- $title = 'entry-test-title new';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-entries/{id}/entries', ForumEntryEntriesCreate::class);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.$entry->id.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- }
-
- public function testShouldNotCreateEntryForEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $content = 'some new content to test';
- $title = 'entry-test-title new';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-entries/{id}/entries', ForumEntryEntriesCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.'badID'.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumEntriesDeleteTest.php b/tests/jsonapi/ForumEntriesDeleteTest.php
deleted file mode 100644
index e2f0a7e..0000000
--- a/tests/jsonapi/ForumEntriesDeleteTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Models\ForumEntry;
-use JsonApi\Routes\Forum\ForumEntriesDelete;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumEntriesDeleteTest 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 testShouldDeleteEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.$entry->id)
- ->delete();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertIsEmpty(ForumEntry::find($entry->id));
- }
-
- public function testShouldNotDeleteEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badId')
- ->delete();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumEntriesShowTest.php b/tests/jsonapi/ForumEntriesShowTest.php
deleted file mode 100644
index e823842..0000000
--- a/tests/jsonapi/ForumEntriesShowTest.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Models\ForumEntry as ForumEntryModel;
-use JsonApi\Routes\Forum\ForumEntriesShow;
-use JsonApi\Routes\Forum\ForumCategoryEntriesIndex;
-use JsonApi\Routes\Forum\ForumEntryEntriesIndex;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumEntriesShowTest 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 testShouldShowEntry()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $course = \Course::find('a07535cf2f8a72df33c12ddfa4b53dde');
-
- $this->tester->assertSame(0, ForumEntryModel::countBySql('1'));
- \ForumEntry::checkRootEntry($course->id);
- $entries = ForumEntryModel::findBySql(
- 'seminar_id = ? ORDER BY depth DESC',
- [$course->id]
- );
- $this->tester->assertCount(2, $entries);
- $entry = current($entries);
-
- $app = $this->tester->createApp(
- $credentials,
- 'get',
- '/forum-entries/{id}',
- ForumEntriesShow::class
- );
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.$entry->id)
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- }
-
- public function testShouldNotShowEntry()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}', ForumEntriesShow::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.'badEntry')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-
- public function testShouldNotShowEntriesForCategory()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
-
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}/entries', ForumCategoryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badID/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-
- public function testShouldShowEntriesForCategory()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
-
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}/entries', ForumCategoryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.$cat->id.'/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $document = $response->document();
- $resourceObject = $document->primaryResources();
- $this->tester->assertNotNull($resourceObject);
- }
-
- public function testShouldShowEntriesForEntry()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $target_entry = $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $target_entry->id);
- $this->createEntry($credentials, $target_entry->id);
- $this->createEntry($credentials, $target_entry->id);
- $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}/entries', ForumEntryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.$target_entry->topic_id.'/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $document = $response->document();
- $resourceObject = $document->primaryResources();
- $this->tester->assertNotNull($resourceObject);
- }
-
- public function testShouldNotShowEntriesForEntry()
- {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $targetEntry = $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $targetEntry->id);
- $this->createEntry($credentials, $targetEntry->id);
- $this->createEntry($credentials, $targetEntry->id);
- $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}/entries', ForumEntryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badTopic/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumEntriesUpdateTest.php b/tests/jsonapi/ForumEntriesUpdateTest.php
deleted file mode 100644
index db08917..0000000
--- a/tests/jsonapi/ForumEntriesUpdateTest.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-require_once 'ForumTestHelper.php';
-
-use JsonApi\Routes\Forum\ForumEntriesUpdate;
-use JsonApi\Errors\RecordNotFoundException;
-
-class ForumEntriesUpdateTest 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 testShouldUpdateEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $entry_json = $this->buildValidResourceEntryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-entries/{id}', ForumEntriesUpdate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.$entry->id)
- ->update()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotEquals($entry->name, $resourceObject->attribute('title'));
- }
-
- public function testShouldNotUpdateEntry()
- {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $entry_json = $this->buildValidResourceEntryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-entries/{id}', ForumEntriesUpdate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badId')
- ->update()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertSame(404, $response->getStatusCode());
- }
-}
diff --git a/tests/jsonapi/ForumTestHelper.php b/tests/jsonapi/ForumTestHelper.php
deleted file mode 100644
index 25e868d..0000000
--- a/tests/jsonapi/ForumTestHelper.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?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;
- }
-}