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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
( function ( mw ) {
QUnit.module( 'mediawiki.api.category', QUnit.newMwEnvironment( {
setup: function () {
this.server = this.sandbox.useFakeServer();
this.server.respondImmediately = true;
}
} ) );
QUnit.test( '.getCategoriesByPrefix()', function ( assert ) {
this.server.respondWith( [ 200, { 'Content-Type': 'application/json' },
'{ "query": { "allpages": [ ' +
'{ "title": "Category:Food" },' +
'{ "title": "Category:Fool Supermarine S.6" },' +
'{ "title": "Category:Fools" }' +
'] } }'
] );
return new mw.Api().getCategoriesByPrefix( 'Foo' ).then( function ( matches ) {
assert.deepEqual(
matches,
[ 'Food', 'Fool Supermarine S.6', 'Fools' ]
);
} );
} );
QUnit.test( '.isCategory("")', function ( assert ) {
this.server.respondWith( /titles=$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true}'
] );
return new mw.Api().isCategory( '' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.isCategory("#")', function ( assert ) {
this.server.respondWith( /titles=%23$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
] );
return new mw.Api().isCategory( '#' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.isCategory("mw:")', function ( assert ) {
this.server.respondWith( /titles=mw%3A$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
] );
return new mw.Api().isCategory( 'mw:' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.isCategory("|")', function ( assert ) {
this.server.respondWith( /titles=%1F%7C$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
] );
return new mw.Api().isCategory( '|' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.getCategories("")', function ( assert ) {
this.server.respondWith( /titles=$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true}'
] );
return new mw.Api().getCategories( '' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.getCategories("#")', function ( assert ) {
this.server.respondWith( /titles=%23$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
] );
return new mw.Api().getCategories( '#' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.getCategories("mw:")', function ( assert ) {
this.server.respondWith( /titles=mw%3A$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
] );
return new mw.Api().getCategories( 'mw:' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
QUnit.test( '.getCategories("|")', function ( assert ) {
this.server.respondWith( /titles=%1F%7C$/, [
200,
{ 'Content-Type': 'application/json' },
'{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
] );
return new mw.Api().getCategories( '|' ).then( function ( response ) {
assert.equal( response, false );
} );
} );
}( mediaWiki ) );
|