|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__.'/V2TestCase.php'; |
|
5
|
|
|
|
|
6
|
|
|
require_once __DIR__.'/../../../../vendor/autoload.php'; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class SubscribeUserToSessionFromUsernameTest |
|
11
|
|
|
* |
|
12
|
|
|
* SUBSCRIBE_USER_TO_SESSION_FROM_USERNAME webservice unit tests |
|
13
|
|
|
*/ |
|
14
|
|
|
class SubscribeUserToSessionFromUsernameTest extends V2TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function action() |
|
17
|
|
|
{ |
|
18
|
|
|
return 'subscribe_user_to_session_from_username'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* subscribes a test user to a test session that already has another user subscribed |
|
23
|
|
|
* asserts that the user was subscribed to the session |
|
24
|
|
|
* asserts that the other user was not unsubscribed from the session |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testSubscribeWithoutUnsubscribe() |
|
27
|
|
|
{ |
|
28
|
|
|
// create a test session |
|
29
|
|
|
$sessionId = SessionManager::create_session( |
|
30
|
|
|
'Session to subscribe'.time(), |
|
31
|
|
|
'2019-01-01 00:00', |
|
32
|
|
|
'2019-08-31 00:00', |
|
33
|
|
|
'2019-01-01 00:00', |
|
34
|
|
|
'2019-08-31 00:00', |
|
35
|
|
|
'2019-01-01 00:00', |
|
36
|
|
|
'2019-08-31 00:00', |
|
37
|
|
|
null, |
|
38
|
|
|
null |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
// create a test user |
|
42
|
|
|
$loginName = 'tester'.time(); |
|
43
|
|
|
$userId = UserManager::create_user('Tester', 'Tester', 5, 'tester@local', $loginName, 'xXxxXxxXX'); |
|
44
|
|
|
|
|
45
|
|
|
// create another user and subscribe it to the session |
|
46
|
|
|
$anotherUserId = UserManager::create_user('Tester 2', 'Tester 2', 5, 'tester2@local', $loginName.'t2', 'xXxxX'); |
|
47
|
|
|
SessionManager::subscribeUsersToSession($sessionId, [$anotherUserId]); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
// call the webservice to subscribe the first user to the session |
|
50
|
|
|
$subscribed = $this->boolean(['sessionId' => $sessionId, 'loginname' => $loginName]); |
|
51
|
|
|
$this->assertTrue($subscribed); |
|
52
|
|
|
|
|
53
|
|
|
// assert we now have two users subscribed to the session |
|
54
|
|
|
$sessionRelUsers = Database::getManager() |
|
55
|
|
|
->getRepository('ChamiloCoreBundle:SessionRelUser') |
|
56
|
|
|
->findBy(['session' => $sessionId]); |
|
57
|
|
|
$this->assertSame(2, count($sessionRelUsers)); |
|
58
|
|
|
|
|
59
|
|
|
// clean up |
|
60
|
|
|
UserManager::delete_users([$userId, $anotherUserId]); |
|
61
|
|
|
SessionManager::delete($sessionId); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|