Index: branches/JSTesting/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js |
— | — | @@ -16,6 +16,19 @@ |
17 | 17 | test( 'User login status', function() { |
18 | 18 | expect(5); |
19 | 19 | |
| 20 | + /** |
| 21 | + * Tests can be run under three different conditions: |
| 22 | + * 1) From tests/qunit/index.html, user will be anonymous. |
| 23 | + * 2) Logged in on [[Special:JavaScriptTest/qunit]] |
| 24 | + * 3) Anonymously at the same special page. |
| 25 | + */ |
| 26 | + |
| 27 | + // remember current user to restore it later on. |
| 28 | + var savedUsername = mw.config.get( 'wgUserName' ); |
| 29 | + |
| 30 | + // Forge an anonymous user: |
| 31 | + mw.config.set( 'wgUserName', null); |
| 32 | + |
20 | 33 | strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' ); |
21 | 34 | ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' ); |
22 | 35 | |
— | — | @@ -26,4 +39,7 @@ |
27 | 40 | ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' ); |
28 | 41 | |
29 | 42 | equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' ); |
| 43 | + |
| 44 | + // restore previous user |
| 45 | + mw.config.set( 'wgUserName', savedUsername ); |
30 | 46 | }); |