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/WikiCreateTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/WikiCreateTest.php')
| -rw-r--r-- | tests/jsonapi/WikiCreateTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/jsonapi/WikiCreateTest.php b/tests/jsonapi/WikiCreateTest.php new file mode 100644 index 0000000..993fe74 --- /dev/null +++ b/tests/jsonapi/WikiCreateTest.php @@ -0,0 +1,68 @@ +<?php + +use JsonApi\Routes\Wiki\WikiCreate; + +class WikiCreateTest extends \Codeception\Test\Unit +{ + /** + * @var \UnitTester + */ + protected $tester; + + protected function _before() + { + \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh); + } + + protected function _after() + { + } + + //testszenario: + public function testWikiCreate() + { + $credentials = $this->tester->getCredentialsForTestAutor(); + $rangeId = 'a07535cf2f8a72df33c12ddfa4b53dde'; + + $keyword = 'IphiklosIphitos'; + $content = 'This is just fake wiki.'; + + $json = [ + 'data' => [ + 'type' => 'wiki', + 'attributes' => compact('keyword', 'content'), + ], + ]; + + $this->tester->assertCount(0, \WikiPage::findLatestPages($rangeId)); + + $response = $this->createWikiPage($credentials, $rangeId, $json); + $this->tester->assertSame(201, $response->getStatusCode()); + + $this->tester->assertCount(1, \WikiPage::findLatestPages($rangeId)); + + $page = $response->document()->primaryResource(); + + $this->tester->assertEquals($content, $page->attribute('content')); + } + + //helpers: + private function createWikiPage($credentials, $rangeId, $json) + { + $app = $this->tester->createApp( + $credentials, + 'post', + '/courses/{id}/wiki', + WikiCreate::class + ); + + return $this->tester->sendMockRequest( + $app, + $this->tester->createRequestBuilder($credentials) + ->setUri('/courses/'.$rangeId.'/wiki') + ->setJsonApiBody($json) + ->create() + ->getRequest() + ); + } +} |
