2019-07-02 21:10:10 +00:00
|
|
|
( function () {
|
2024-08-27 20:05:52 +00:00
|
|
|
const UriUtil = require( '../../../resources/skins.minerva.scripts/UriUtil.js' );
|
2024-03-24 20:53:43 +00:00
|
|
|
const mwUriOrg = mw.Uri;
|
2019-03-04 22:19:33 +00:00
|
|
|
|
2022-05-15 00:41:24 +00:00
|
|
|
QUnit.module( 'Minerva UriUtil', {
|
2022-05-15 00:27:53 +00:00
|
|
|
beforeEach: function () {
|
2019-03-04 22:19:33 +00:00
|
|
|
mw.Uri = mw.UriRelative( 'https://meta.wikimedia.org/w/index.php' );
|
|
|
|
},
|
2022-05-15 00:27:53 +00:00
|
|
|
afterEach: function () {
|
2022-05-15 00:41:24 +00:00
|
|
|
mw.Uri = mwUriOrg;
|
2019-03-04 22:19:33 +00:00
|
|
|
}
|
2022-05-15 00:41:24 +00:00
|
|
|
} );
|
2019-03-04 22:19:33 +00:00
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( '.isInternal()', ( assert ) => {
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.true(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( '/relative' ) ),
|
|
|
|
'relative URLs are internal'
|
|
|
|
);
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.true(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( 'http://meta.wikimedia.org/' ) ),
|
|
|
|
'matching hosts are internal'
|
|
|
|
);
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.true(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( 'https:/meta.wikimedia.org/' ) ),
|
|
|
|
'protocol is irrelevant'
|
|
|
|
);
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.true(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( 'https://meta.wikimedia.org/path' ) ),
|
|
|
|
'path is irrelevant'
|
|
|
|
);
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.false(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( 'https://archive.org/' ) ),
|
|
|
|
'external links are not internal'
|
|
|
|
);
|
2022-05-15 00:41:24 +00:00
|
|
|
assert.false(
|
2019-03-04 22:19:33 +00:00
|
|
|
UriUtil.isInternal( new mw.Uri( 'https://www.meta.wikimedia.org/' ) ),
|
|
|
|
'differing subdomains are not internal'
|
|
|
|
);
|
|
|
|
} );
|
2019-07-02 21:10:10 +00:00
|
|
|
}() );
|