diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /tests/jsonapi/ForumCategoryDeleteTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/ForumCategoryDeleteTest.php')
| -rw-r--r-- | tests/jsonapi/ForumCategoryDeleteTest.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/jsonapi/ForumCategoryDeleteTest.php b/tests/jsonapi/ForumCategoryDeleteTest.php new file mode 100644 index 0000000..2805f53 --- /dev/null +++ b/tests/jsonapi/ForumCategoryDeleteTest.php @@ -0,0 +1,62 @@ +<?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() + { + $this->tester->expectThrowable(RecordNotFoundException::class, function () { + $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->assertIsEmpty(ForumCat::find($cat->id)); + }); + } +} |
