Passed
Push — master ( 482b77...45d699 )
by Julito
09:12
created

testSubscribeWithoutUnsubscribe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 22
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 36
rs 9.568
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]);
0 ignored issues
show
Bug introduced by
It seems like $sessionId can also be of type false and string; however, parameter $sessionId of SessionManager::subscribeUsersToSession() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        SessionManager::subscribeUsersToSession(/** @scrutinizer ignore-type */ $sessionId, [$anotherUserId]);
Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $sessionId can also be of type false and integer and string; however, parameter $id_checked of SessionManager::delete() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        SessionManager::delete(/** @scrutinizer ignore-type */ $sessionId);
Loading history...
62
    }
63
}
64