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/UsersIndexTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/UsersIndexTest.php')
| -rw-r--r-- | tests/jsonapi/UsersIndexTest.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/jsonapi/UsersIndexTest.php b/tests/jsonapi/UsersIndexTest.php new file mode 100644 index 0000000..adffee6 --- /dev/null +++ b/tests/jsonapi/UsersIndexTest.php @@ -0,0 +1,57 @@ +<?php + + +use JsonApi\Errors\AuthorizationFailedException; +use JsonApi\Routes\Users\UsersIndex; + +class UsersIndexTest 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 testIndexUsers() + { + $credentials = $this->tester->getCredentialsForTestAutor(); + $response = $this->getUsers($credentials); + $this->tester->assertTrue($response->isSuccessfulDocument([200])); + + $numberOfAllUsers = \User::countBySQL(); + $this->tester->assertSame($numberOfAllUsers, count($response->document()->primaryResources())); + + $this->assertValidResourceObject($response, 'users'); + + $this->tester->storeJsonMd('get_users', $response, 1, '[...]'); + } + + // **** helper functions **** + private function getUsers($credentials) + { + $app = $this->tester->createApp($credentials, 'get', '/users', UsersIndex::class); + + return $this->tester->sendMockRequest( + $app, + $this->tester->createRequestBuilder($credentials) + ->setUri('/users') + ->fetch() + ->getRequest() + ); + } + + public function assertValidResourceObject($response, $type) + { + $this->tester->assertSame($type, $response->document()->primaryResources()[0]->type()); + } +} |
