Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 23... Línea 23...
23
 * @category   test
23
 * @category   test
24
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
24
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
26
 */
27
class session_manager_test extends \advanced_testcase {
27
class session_manager_test extends \advanced_testcase {
28
    public function test_start() {
28
    public function test_start(): void {
29
        $this->resetAfterTest();
29
        $this->resetAfterTest();
30
        // Session must be started only once...
30
        // Session must be started only once...
31
        \core\session\manager::start();
31
        \core\session\manager::start();
32
        $this->assertDebuggingCalled('Session was already started!', DEBUG_DEVELOPER);
32
        $this->assertDebuggingCalled('Session was already started!', DEBUG_DEVELOPER);
33
    }
33
    }
Línea 34... Línea 34...
34
 
34
 
35
    public function test_init_empty_session() {
35
    public function test_init_empty_session(): void {
36
        global $SESSION, $USER;
36
        global $SESSION, $USER;
Línea 37... Línea 37...
37
        $this->resetAfterTest();
37
        $this->resetAfterTest();
Línea 90... Línea 90...
90
        $_SESSION['USER']->test3 = true;
90
        $_SESSION['USER']->test3 = true;
91
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
91
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
92
        $this->assertSame($GLOBALS['USER'], $USER);
92
        $this->assertSame($GLOBALS['USER'], $USER);
93
    }
93
    }
Línea 94... Línea 94...
94
 
94
 
95
    public function test_set_user() {
95
    public function test_set_user(): void {
96
        global $USER;
96
        global $USER;
Línea 97... Línea 97...
97
        $this->resetAfterTest();
97
        $this->resetAfterTest();
Línea 111... Línea 111...
111
        $this->assertSame($user, $GLOBALS['USER']);
111
        $this->assertSame($user, $GLOBALS['USER']);
112
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
112
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
113
        $this->assertSame($GLOBALS['USER'], $USER);
113
        $this->assertSame($GLOBALS['USER'], $USER);
114
    }
114
    }
Línea 115... Línea 115...
115
 
115
 
116
    public function test_login_user() {
116
    public function test_login_user(): void {
117
        global $USER;
117
        global $USER;
Línea 118... Línea 118...
118
        $this->resetAfterTest();
118
        $this->resetAfterTest();
Línea 129... Línea 129...
129
        $this->assertSame($user, $GLOBALS['USER']);
129
        $this->assertSame($user, $GLOBALS['USER']);
130
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
130
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
131
        $this->assertSame($GLOBALS['USER'], $USER);
131
        $this->assertSame($GLOBALS['USER'], $USER);
132
    }
132
    }
Línea 133... Línea 133...
133
 
133
 
134
    public function test_terminate_current() {
134
    public function test_terminate_current(): void {
135
        global $USER, $SESSION;
135
        global $USER, $SESSION;
Línea 136... Línea 136...
136
        $this->resetAfterTest();
136
        $this->resetAfterTest();
137
 
137
 
Línea 148... Línea 148...
148
        $this->assertEqualsCanonicalizing(array('id' => 0, 'mnethostid' => 1), (array)$USER);
148
        $this->assertEqualsCanonicalizing(array('id' => 0, 'mnethostid' => 1), (array)$USER);
149
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
149
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
150
        $this->assertSame($GLOBALS['USER'], $USER);
150
        $this->assertSame($GLOBALS['USER'], $USER);
151
    }
151
    }
Línea 152... Línea 152...
152
 
152
 
153
    public function test_write_close() {
153
    public function test_write_close(): void {
154
        global $USER;
154
        global $USER;
Línea 155... Línea 155...
155
        $this->resetAfterTest();
155
        $this->resetAfterTest();
156
 
156
 
Línea 162... Línea 162...
162
 
162
 
163
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
163
        $this->assertSame($GLOBALS['USER'], $_SESSION['USER']);
164
        $this->assertSame($GLOBALS['USER'], $USER);
164
        $this->assertSame($GLOBALS['USER'], $USER);
Línea 165... Línea 165...
165
    }
165
    }
166
 
166
 
167
    public function test_session_exists() {
167
    public function test_session_exists(): void {
Línea 168... Línea 168...
168
        global $CFG, $DB;
168
        global $CFG, $DB;
Línea 208... Línea 208...
208
        $CFG->sessiontimeout = $CFG->sessiontimeout + 3000;
208
        $CFG->sessiontimeout = $CFG->sessiontimeout + 3000;
Línea 209... Línea 209...
209
 
209
 
210
        $this->assertTrue(\core\session\manager::session_exists($sid));
210
        $this->assertTrue(\core\session\manager::session_exists($sid));
Línea 211... Línea 211...
211
    }
211
    }
212
 
212
 
213
    public function test_touch_session() {
213
    public function test_touch_session(): void {
Línea 214... Línea 214...
214
        global $DB;
214
        global $DB;
215
        $this->resetAfterTest();
215
        $this->resetAfterTest();
Línea 231... Línea 231...
231
 
231
 
232
        $this->assertGreaterThanOrEqual($now, $updated);
232
        $this->assertGreaterThanOrEqual($now, $updated);
233
        $this->assertLessThanOrEqual(time(), $updated);
233
        $this->assertLessThanOrEqual(time(), $updated);
Línea 234... Línea 234...
234
    }
234
    }
235
 
235
 
236
    public function test_kill_session() {
236
    public function test_kill_session(): void {
Línea 237... Línea 237...
237
        global $DB, $USER;
237
        global $DB, $USER;
238
        $this->resetAfterTest();
238
        $this->resetAfterTest();
Línea 263... Línea 263...
263
        $this->assertFalse($DB->record_exists('sessions', array('sid'=>$sid)));
263
        $this->assertFalse($DB->record_exists('sessions', array('sid'=>$sid)));
Línea 264... Línea 264...
264
 
264
 
265
        $this->assertSame($userid, $USER->id);
265
        $this->assertSame($userid, $USER->id);
Línea 266... Línea 266...
266
    }
266
    }
267
 
267
 
268
    public function test_kill_user_sessions() {
268
    public function test_kill_user_sessions(): void {
Línea 269... Línea 269...
269
        global $DB, $USER;
269
        global $DB, $USER;
270
        $this->resetAfterTest();
270
        $this->resetAfterTest();
Línea 315... Línea 315...
315
 
315
 
316
        $this->assertEquals(1, $DB->count_records('sessions', array('userid' => $userid)));
316
        $this->assertEquals(1, $DB->count_records('sessions', array('userid' => $userid)));
317
        $this->assertEquals(1, $DB->count_records('sessions', array('userid' => $userid, 'sid' => md5('pokus5'))));
317
        $this->assertEquals(1, $DB->count_records('sessions', array('userid' => $userid, 'sid' => md5('pokus5'))));
Línea 318... Línea 318...
318
    }
318
    }
319
 
319
 
320
    public function test_apply_concurrent_login_limit() {
320
    public function test_apply_concurrent_login_limit(): void {
Línea 321... Línea 321...
321
        global $DB;
321
        global $DB;
322
        $this->resetAfterTest();
322
        $this->resetAfterTest();
Línea 438... Línea 438...
438
        \core\session\manager::apply_concurrent_login_limit($guest->id);
438
        \core\session\manager::apply_concurrent_login_limit($guest->id);
439
        \core\session\manager::apply_concurrent_login_limit(0);
439
        \core\session\manager::apply_concurrent_login_limit(0);
440
        $this->assertCount(8, $DB->get_records('sessions'));
440
        $this->assertCount(8, $DB->get_records('sessions'));
441
    }
441
    }
Línea 442... Línea 442...
442
 
442
 
443
    public function test_kill_all_sessions() {
443
    public function test_kill_all_sessions(): void {
444
        global $DB, $USER;
444
        global $DB, $USER;
Línea 445... Línea 445...
445
        $this->resetAfterTest();
445
        $this->resetAfterTest();
446
 
446
 
Línea 471... Línea 471...
471
 
471
 
472
        $this->assertEquals(0, $DB->count_records('sessions'));
472
        $this->assertEquals(0, $DB->count_records('sessions'));
473
        $this->assertSame(0, $USER->id);
473
        $this->assertSame(0, $USER->id);
Línea 474... Línea 474...
474
    }
474
    }
475
 
475
 
476
    public function test_gc() {
476
    public function test_gc(): void {
Línea 477... Línea 477...
477
        global $CFG, $DB, $USER;
477
        global $CFG, $DB, $USER;
478
        $this->resetAfterTest();
478
        $this->resetAfterTest();
Línea 544... Línea 544...
544
 
544
 
545
    /**
545
    /**
546
     * Test loginas.
546
     * Test loginas.
547
     * @copyright  2103 Rajesh Taneja <rajesh@moodle.com>
547
     * @copyright  2103 Rajesh Taneja <rajesh@moodle.com>
548
     */
548
     */
549
    public function test_loginas() {
549
    public function test_loginas(): void {
550
        global $USER, $SESSION;
550
        global $USER, $SESSION;
Línea 551... Línea 551...
551
        $this->resetAfterTest();
551
        $this->resetAfterTest();
552
 
552
 
Línea 602... Línea 602...
602
        $this->assertEquals($coursecontext, $event->get_context());
602
        $this->assertEquals($coursecontext, $event->get_context());
603
        $oldfullname = fullname($user, true);
603
        $oldfullname = fullname($user, true);
604
        $newfullname = fullname($adminuser, true);
604
        $newfullname = fullname($adminuser, true);
605
    }
605
    }
Línea 606... Línea 606...
606
 
606
 
607
    public function test_is_loggedinas() {
607
    public function test_is_loggedinas(): void {
Línea 608... Línea 608...
608
        $this->resetAfterTest();
608
        $this->resetAfterTest();
609
 
609
 
Línea 616... Línea 616...
616
        \core\session\manager::loginas($user2->id, \context_system::instance());
616
        \core\session\manager::loginas($user2->id, \context_system::instance());
Línea 617... Línea 617...
617
 
617
 
618
        $this->assertTrue(\core\session\manager::is_loggedinas());
618
        $this->assertTrue(\core\session\manager::is_loggedinas());
Línea 619... Línea 619...
619
    }
619
    }
620
 
620
 
Línea 621... Línea 621...
621
    public function test_get_realuser() {
621
    public function test_get_realuser(): void {
622
        $this->resetAfterTest();
622
        $this->resetAfterTest();
Línea 670... Línea 670...
670
    }
670
    }
Línea 671... Línea 671...
671
 
671
 
672
    /**
672
    /**
673
     * Test to get recent session locks.
673
     * Test to get recent session locks.
674
     */
674
     */
675
    public function test_get_recent_session_locks() {
675
    public function test_get_recent_session_locks(): void {
Línea 676... Línea 676...
676
        global $CFG;
676
        global $CFG;
677
 
677
 
678
        $this->resetAfterTest();
678
        $this->resetAfterTest();
Línea 700... Línea 700...
700
    }
700
    }
Línea 701... Línea 701...
701
 
701
 
702
    /**
702
    /**
703
     * Test to update recent session locks.
703
     * Test to update recent session locks.
704
     */
704
     */
705
    public function test_update_recent_session_locks() {
705
    public function test_update_recent_session_locks(): void {
Línea 706... Línea 706...
706
        global $CFG;
706
        global $CFG;
707
 
707
 
708
        $this->resetAfterTest();
708
        $this->resetAfterTest();
Línea 720... Línea 720...
720
    }
720
    }
Línea 721... Línea 721...
721
 
721
 
722
    /**
722
    /**
723
     * Test to get session lock info.
723
     * Test to get session lock info.
724
     */
724
     */
725
    public function test_get_session_lock_info() {
725
    public function test_get_session_lock_info(): void {
Línea 726... Línea 726...
726
        global $PERF;
726
        global $PERF;
Línea 727... Línea 727...
727
 
727
 
Línea 814... Línea 814...
814
     *
814
     *
815
     * @dataProvider sessionlocks_info_provider
815
     * @dataProvider sessionlocks_info_provider
816
     * @param array $url Session lock page url.
816
     * @param array $url Session lock page url.
817
     * @param array $time Session lock time.
817
     * @param array $time Session lock time.
818
     */
818
     */
819
    public function test_get_locked_page_at($url, $time) {
819
    public function test_get_locked_page_at($url, $time): void {
820
        global $CFG, $SESSION;
820
        global $CFG, $SESSION;
Línea 821... Línea 821...
821
 
821
 
822
        $this->resetAfterTest();
822
        $this->resetAfterTest();
823
        $CFG->debugsessionlock = 5;
823
        $CFG->debugsessionlock = 5;
Línea 828... Línea 828...
828
    }
828
    }
Línea 829... Línea 829...
829
 
829
 
830
    /**
830
    /**
831
     * Test cleanup recent session locks.
831
     * Test cleanup recent session locks.
832
     */
832
     */
833
    public function test_cleanup_recent_session_locks() {
833
    public function test_cleanup_recent_session_locks(): void {
Línea 834... Línea 834...
834
        global $CFG, $SESSION;
834
        global $CFG, $SESSION;
835
 
835
 
Línea 911... Línea 911...
911
     * @covers \core\session\manager::array_session_diff
911
     * @covers \core\session\manager::array_session_diff
912
     * @param array $a first value.
912
     * @param array $a first value.
913
     * @param array $b second value to compare to $a.
913
     * @param array $b second value to compare to $a.
914
     * @param array $expected the expected difference.
914
     * @param array $expected the expected difference.
915
     */
915
     */
916
    public function test_array_session_diff(array $a, array $b, array $expected) {
916
    public function test_array_session_diff(array $a, array $b, array $expected): void {
917
        $class = new \ReflectionClass('\core\session\manager');
917
        $class = new \ReflectionClass('\core\session\manager');
918
        $method = $class->getMethod('array_session_diff');
918
        $method = $class->getMethod('array_session_diff');
Línea 919... Línea 919...
919
 
919
 
920
        $result = $method->invokeArgs(null, [$a, $b]);
920
        $result = $method->invokeArgs(null, [$a, $b]);