2014-03-21 01:17:45 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MediaViewer.
|
|
|
|
*
|
|
|
|
* MediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
const { Repo, ForeignApiRepo, ForeignDbRepo } = require( 'mmv' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-03-21 01:17:45 +00:00
|
|
|
QUnit.module( 'mmv.model.Repo', QUnit.newMwEnvironment() );
|
|
|
|
|
2021-12-10 00:43:28 +00:00
|
|
|
QUnit.test( 'Repo constructor sense check', function ( assert ) {
|
2014-03-21 01:17:45 +00:00
|
|
|
var displayName = 'Wikimedia Commons',
|
2016-08-03 21:41:35 +00:00
|
|
|
favicon = '//commons.wikimedia.org/favicon.ico',
|
2014-03-21 01:17:45 +00:00
|
|
|
apiUrl = '//commons.wikimedia.org/w/api.php',
|
|
|
|
server = '//commons.wikimedia.org',
|
|
|
|
articlePath = '//commons.wikimedia.org/wiki/$1',
|
|
|
|
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
2023-05-20 08:30:52 +00:00
|
|
|
localRepo = new Repo( displayName, favicon, true ),
|
|
|
|
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
2014-03-21 01:17:45 +00:00
|
|
|
false, apiUrl, server, articlePath ),
|
2023-05-20 08:30:52 +00:00
|
|
|
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
|
2014-03-21 01:17:45 +00:00
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
assert.true( localRepo instanceof Repo, 'Local repo creation works' );
|
|
|
|
assert.true( foreignApiRepo instanceof ForeignApiRepo,
|
2014-03-21 01:17:45 +00:00
|
|
|
'Foreign API repo creation works' );
|
2023-05-20 08:30:52 +00:00
|
|
|
assert.true( foreignDbRepo instanceof ForeignDbRepo, 'Foreign DB repo creation works' );
|
2014-03-21 01:17:45 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'getArticlePath()', function ( assert ) {
|
2014-03-21 01:17:45 +00:00
|
|
|
var displayName = 'Wikimedia Commons',
|
2016-08-03 21:41:35 +00:00
|
|
|
favicon = '//commons.wikimedia.org/favicon.ico',
|
2014-03-21 01:17:45 +00:00
|
|
|
apiUrl = '//commons.wikimedia.org/w/api.php',
|
|
|
|
server = '//commons.wikimedia.org',
|
|
|
|
articlePath = '/wiki/$1',
|
|
|
|
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
2023-05-20 08:30:52 +00:00
|
|
|
localRepo = new Repo( displayName, favicon, true ),
|
|
|
|
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
2014-03-21 01:17:45 +00:00
|
|
|
false, apiUrl, server, articlePath ),
|
2023-05-20 08:30:52 +00:00
|
|
|
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
|
2014-03-21 01:17:45 +00:00
|
|
|
expectedLocalArticlePath = '/wiki/$1',
|
|
|
|
expectedFullArticlePath = '//commons.wikimedia.org/wiki/$1',
|
|
|
|
oldWgArticlePath = mw.config.get( 'wgArticlePath' ),
|
|
|
|
oldWgServer = mw.config.get( 'wgServer' );
|
|
|
|
|
|
|
|
mw.config.set( 'wgArticlePath', '/wiki/$1' );
|
|
|
|
mw.config.set( 'wgServer', server );
|
|
|
|
|
|
|
|
assert.strictEqual( localRepo.getArticlePath(), expectedLocalArticlePath,
|
|
|
|
'Local repo article path is correct' );
|
|
|
|
assert.strictEqual( localRepo.getArticlePath( true ), expectedFullArticlePath,
|
|
|
|
'Local repo absolute article path is correct' );
|
|
|
|
assert.strictEqual( foreignApiRepo.getArticlePath(), expectedFullArticlePath,
|
|
|
|
'Foreign API article path is correct' );
|
|
|
|
assert.strictEqual( foreignDbRepo.getArticlePath(), expectedFullArticlePath,
|
|
|
|
'Foreign DB article path is correct' );
|
|
|
|
|
|
|
|
mw.config.set( 'wgArticlePath', oldWgArticlePath );
|
|
|
|
mw.config.set( 'wgServer', oldWgServer );
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'getSiteLink()', function ( assert ) {
|
2014-03-21 01:17:45 +00:00
|
|
|
var displayName = 'Wikimedia Commons',
|
2016-08-03 21:41:35 +00:00
|
|
|
favicon = '//commons.wikimedia.org/favicon.ico',
|
2014-03-21 01:17:45 +00:00
|
|
|
apiUrl = '//commons.wikimedia.org/w/api.php',
|
|
|
|
server = '//commons.wikimedia.org',
|
|
|
|
articlePath = '/wiki/$1',
|
|
|
|
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
2023-05-20 08:30:52 +00:00
|
|
|
localRepo = new Repo( displayName, favicon, true ),
|
|
|
|
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
2014-03-21 01:17:45 +00:00
|
|
|
false, apiUrl, server, articlePath ),
|
2023-05-20 08:30:52 +00:00
|
|
|
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
|
2014-03-21 01:17:45 +00:00
|
|
|
expectedSiteLink = '//commons.wikimedia.org/wiki/',
|
|
|
|
oldWgArticlePath = mw.config.get( 'wgArticlePath' ),
|
|
|
|
oldWgServer = mw.config.get( 'wgServer' );
|
|
|
|
|
|
|
|
mw.config.set( 'wgArticlePath', '/wiki/$1' );
|
|
|
|
mw.config.set( 'wgServer', server );
|
|
|
|
|
|
|
|
assert.strictEqual( localRepo.getSiteLink(), expectedSiteLink,
|
|
|
|
'Local repo site link is correct' );
|
|
|
|
assert.strictEqual( foreignApiRepo.getSiteLink(), expectedSiteLink,
|
|
|
|
'Foreign API repo site link is correct' );
|
|
|
|
assert.strictEqual( foreignDbRepo.getSiteLink(), expectedSiteLink,
|
|
|
|
'Foreign DB repo site link is correct' );
|
|
|
|
|
|
|
|
mw.config.set( 'wgArticlePath', oldWgArticlePath );
|
|
|
|
mw.config.set( 'wgServer', oldWgServer );
|
|
|
|
} );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|