Debian Codegraph @

extensions/MultimediaViewer/tests/qunit/mmv/model/mmv.model.Repo.test.js

raw symbols SCIP
1 /*
2 * This file is part of the MediaWiki extension MediaViewer.
3 *
4 * MediaViewer is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * MediaViewer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 const { Repo, ForeignApiRepo, ForeignDbRepo } = require( 'mmv' );
19
20 ( function () {
21 QUnit.module( 'mmv.model.Repo', QUnit.newMwEnvironment() );
22
23 QUnit.test( 'Repo constructor sense check', ( assert ) => {
24 const displayName = 'Wikimedia Commons';
25 const favicon = '//commons.wikimedia.org/favicon.ico';
26 const apiUrl = '//commons.wikimedia.org/w/api.php';
27 const server = '//commons.wikimedia.org';
28 const articlePath = '//commons.wikimedia.org/wiki/$1';
29 const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
30 const localRepo = new Repo( displayName, favicon, true );
31 const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
32 false, apiUrl, server, articlePath );
33 const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
34
35 assert.true( localRepo instanceof Repo, 'Local repo creation works' );
36 assert.true( foreignApiRepo instanceof ForeignApiRepo,
37 'Foreign API repo creation works' );
38 assert.true( foreignDbRepo instanceof ForeignDbRepo, 'Foreign DB repo creation works' );
39 } );
40
41 QUnit.test( 'getArticlePath()', ( assert ) => {
42 const displayName = 'Wikimedia Commons';
43 const favicon = '//commons.wikimedia.org/favicon.ico';
44 const apiUrl = '//commons.wikimedia.org/w/api.php';
45 const server = '//commons.wikimedia.org';
46 const articlePath = '/wiki/$1';
47 const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
48 const localRepo = new Repo( displayName, favicon, true );
49 const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
50 false, apiUrl, server, articlePath );
51 const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
52 const expectedLocalArticlePath = '/wiki/$1';
53 const expectedFullArticlePath = '//commons.wikimedia.org/wiki/$1';
54 const oldWgArticlePath = mw.config.get( 'wgArticlePath' );
55 const oldWgServer = mw.config.get( 'wgServer' );
56
57 mw.config.set( 'wgArticlePath', '/wiki/$1' );
58 mw.config.set( 'wgServer', server );
59
60 assert.strictEqual( localRepo.getArticlePath(), expectedLocalArticlePath,
61 'Local repo article path is correct' );
62 assert.strictEqual( localRepo.getArticlePath( true ), expectedFullArticlePath,
63 'Local repo absolute article path is correct' );
64 assert.strictEqual( foreignApiRepo.getArticlePath(), expectedFullArticlePath,
65 'Foreign API article path is correct' );
66 assert.strictEqual( foreignDbRepo.getArticlePath(), expectedFullArticlePath,
67 'Foreign DB article path is correct' );
68
69 mw.config.set( 'wgArticlePath', oldWgArticlePath );
70 mw.config.set( 'wgServer', oldWgServer );
71 } );
72
73 QUnit.test( 'getSiteLink()', ( assert ) => {
74 const displayName = 'Wikimedia Commons';
75 const favicon = '//commons.wikimedia.org/favicon.ico';
76 const apiUrl = '//commons.wikimedia.org/w/api.php';
77 const server = '//commons.wikimedia.org';
78 const articlePath = '/wiki/$1';
79 const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
80 const localRepo = new Repo( displayName, favicon, true );
81 const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
82 false, apiUrl, server, articlePath );
83 const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
84 const expectedSiteLink = '//commons.wikimedia.org/wiki/';
85 const oldWgArticlePath = mw.config.get( 'wgArticlePath' );
86 const oldWgServer = mw.config.get( 'wgServer' );
87
88 mw.config.set( 'wgArticlePath', '/wiki/$1' );
89 mw.config.set( 'wgServer', server );
90
91 assert.strictEqual( localRepo.getSiteLink(), expectedSiteLink,
92 'Local repo site link is correct' );
93 assert.strictEqual( foreignApiRepo.getSiteLink(), expectedSiteLink,
94 'Foreign API repo site link is correct' );
95 assert.strictEqual( foreignDbRepo.getSiteLink(), expectedSiteLink,
96 'Foreign DB repo site link is correct' );
97
98 mw.config.set( 'wgArticlePath', oldWgArticlePath );
99 mw.config.set( 'wgServer', oldWgServer );
100 } );
101
102 }() );