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/NewsRelationshipRangesAddTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/NewsRelationshipRangesAddTest.php')
| -rw-r--r-- | tests/jsonapi/NewsRelationshipRangesAddTest.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/jsonapi/NewsRelationshipRangesAddTest.php b/tests/jsonapi/NewsRelationshipRangesAddTest.php new file mode 100644 index 0000000..177a772 --- /dev/null +++ b/tests/jsonapi/NewsRelationshipRangesAddTest.php @@ -0,0 +1,76 @@ +<?php + + +require_once 'NewsTestHelper.php'; + +use JsonApi\Routes\News\Rel\Ranges; + +class NewsRelationshipRangesAddTest extends \Codeception\Test\Unit +{ + use NewsTestHelper; + + /** + * @var \UnitTester + */ + protected $tester; + + protected function _before() + { + \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh); + } + + protected function _after() + { + } + + // tests + public function testShouldAddRangeToNews() + { + $credentials = $this->tester->getCredentialsForTestDozent(); + + $title = ''; + $content = ''; + + \StudipNews::deleteBySQL('1'); + $this->assertSame(0, \StudipNews::countBySQL('1')); + $news = $this->createNews($credentials, $title, $content, $credentials['id']); + $this->assertSame(1, \StudipNews::countBySQL('1')); + + $courseId = 'a07535cf2f8a72df33c12ddfa4b53dde'; + + $response = $this->addRangeToNews($credentials, $news, $courseId); + $this->tester->assertSame(204, $response->getStatusCode()); + + $news->restoreRanges(); + $this->assertCount(2, $news->getRanges()); + } + + // **** helper functions **** + private function addRangeToNews($credentials, \StudipNews $news, $rangeId) + { + return $this->tester->sendMockRequest( + $this->tester->createApp($credentials, 'post', '/news/{id}/relationships/ranges', Ranges::class), + $this->tester->createRequestBuilder($credentials) + ->setUri('/news/'.$news->id.'/relationships/ranges') + ->setJsonApiBody($this->prepareValidBody([$rangeId])) + ->create() + ->getRequest() + ); + } + + + private function prepareValidBody(array $rangeIds) + { + return [ + 'data' => array_map( + function ($rangeId) { + return [ + 'type' => \JsonApi\Schemas\Course::TYPE, + 'id' => $rangeId, + ]; + }, + $rangeIds + ), + ]; + } +} |
