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/UserEventsIndexTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/UserEventsIndexTest.php')
| -rw-r--r-- | tests/jsonapi/UserEventsIndexTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/jsonapi/UserEventsIndexTest.php b/tests/jsonapi/UserEventsIndexTest.php new file mode 100644 index 0000000..0941f09 --- /dev/null +++ b/tests/jsonapi/UserEventsIndexTest.php @@ -0,0 +1,68 @@ +<?php + +use JsonApi\Routes\Events\UserEventsIndex; + +class UserEventsIndexTest extends \Codeception\Test\Unit +{ + /** + * @var \UnitTester + */ + protected $tester; + + protected function _before() + { + \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh); + } + + protected function _after() + { + } + + // tests + public function testIndexUserEvents() + { + $credentials = $this->tester->getCredentialsForTestAutor(); + $response = $this->getEvents($credentials); + $this->assertSuccessfulResponse($response); + + $response = $this->getEvents($credentials); + $this->assertSuccessfulResponse($response); + $numEvents = count($response->document()->primaryResources()); + + $this->createEvent($credentials); + + $response = $this->getEvents($credentials); + $this->assertSuccessfulResponse($response); + $this->tester->assertCount($numEvents + 1, $response->document()->primaryResources()); + } + + private function getEvents($credentials) + { + $app = $this->tester->createApp($credentials, 'get', '/users/{id}/events', UserEventsIndex::class); + + $requestBuilder = $this->tester->createRequestBuilder($credentials); + $requestBuilder->setUri('/users/' . $credentials['id'] . '/events')->fetch(); + + return $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); + } + + private function assertSuccessfulResponse($response) + { + $this->tester->assertTrue($response->isSuccessfulDocument([200])); + $document = $response->document(); + $this->tester->assertTrue($document->isResourceCollectionDocument()); + } + + private function createEvent($credentials) + { + $calendar = new \SingleCalendar($credentials['id']); + $event = $calendar->getNewEvent(); + + $oldUser = $GLOBALS['user']; + $GLOBALS['user'] = \User::find($credentials['id']); + + $calendar->storeEvent($event, [$credentials['id']]); + + $GLOBALS['user'] = $oldUser; + } +} |
