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/ForumEntriesUpdateTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/ForumEntriesUpdateTest.php')
| -rw-r--r-- | tests/jsonapi/ForumEntriesUpdateTest.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/jsonapi/ForumEntriesUpdateTest.php b/tests/jsonapi/ForumEntriesUpdateTest.php new file mode 100644 index 0000000..91f2c54 --- /dev/null +++ b/tests/jsonapi/ForumEntriesUpdateTest.php @@ -0,0 +1,71 @@ +<?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() + { + $this->tester->expectThrowable(RecordNotFoundException::class, function () { + $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->assertTrue($response->isSuccessfulDocument([200])); + $document = $response->document(); + $resourceObject = $document->primaryResource(); + $this->tester->assertNotEquals($entry->name, $resourceObject->attribute('title')); + }); + } +} |
