blob: 6c79cae8fd6397b5e0be004a3c369f77d1d92872 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<?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]));
$vis_query = get_vis_query(context: 'search');
$condition = "LEFT JOIN user_visibility ON (user_visibility.user_id = auth_user_md5.user_id) WHERE {$vis_query}";
$numberOfAllUsers = \User::countBySQL($condition);
$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());
}
}
|