summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/MultimediaViewer/tests/qunit/mmv/model/mmv.model.Repo.test.js
blob: a9bc7a2dde023564d6ed480a889004959a90234b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * 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/>.
 */

( function ( mw ) {
	QUnit.module( 'mmv.model.Repo', QUnit.newMwEnvironment() );

	QUnit.test( 'Repo constructor sanity check', function ( assert ) {
		var displayName = 'Wikimedia Commons',
			favicon = '//commons.wikimedia.org/favicon.ico',
			apiUrl = '//commons.wikimedia.org/w/api.php',
			server = '//commons.wikimedia.org',
			articlePath = '//commons.wikimedia.org/wiki/$1',
			descBaseUrl = '//commons.wikimedia.org/wiki/File:',
			localRepo = new mw.mmv.model.Repo( displayName, favicon, true ),
			foreignApiRepo = new mw.mmv.model.ForeignApiRepo( displayName, favicon,
				false, apiUrl, server, articlePath ),
			foreignDbRepo = new mw.mmv.model.ForeignDbRepo( displayName, favicon, false, descBaseUrl );

		assert.ok( localRepo, 'Local repo creation works' );
		assert.ok( foreignApiRepo,
			'Foreign API repo creation works' );
		assert.ok( foreignDbRepo, 'Foreign DB repo creation works' );
	} );

	QUnit.test( 'getArticlePath()', function ( assert ) {
		var displayName = 'Wikimedia Commons',
			favicon = '//commons.wikimedia.org/favicon.ico',
			apiUrl = '//commons.wikimedia.org/w/api.php',
			server = '//commons.wikimedia.org',
			articlePath = '/wiki/$1',
			descBaseUrl = '//commons.wikimedia.org/wiki/File:',
			localRepo = new mw.mmv.model.Repo( displayName, favicon, true ),
			foreignApiRepo = new mw.mmv.model.ForeignApiRepo( displayName, favicon,
				false, apiUrl, server, articlePath ),
			foreignDbRepo = new mw.mmv.model.ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
			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 );
	} );

	QUnit.test( 'getSiteLink()', function ( assert ) {
		var displayName = 'Wikimedia Commons',
			favicon = '//commons.wikimedia.org/favicon.ico',
			apiUrl = '//commons.wikimedia.org/w/api.php',
			server = '//commons.wikimedia.org',
			articlePath = '/wiki/$1',
			descBaseUrl = '//commons.wikimedia.org/wiki/File:',
			localRepo = new mw.mmv.model.Repo( displayName, favicon, true ),
			foreignApiRepo = new mw.mmv.model.ForeignApiRepo( displayName, favicon,
				false, apiUrl, server, articlePath ),
			foreignDbRepo = new mw.mmv.model.ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
			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 );
	} );

}( mediaWiki ) );