2 QUnit
.module( 'mediawiki.api.category', QUnit
.newMwEnvironment( {
4 this.server
= this.sandbox
.useFakeServer();
5 this.server
.respondImmediately
= true;
9 QUnit
.test( '.getCategoriesByPrefix()', function ( assert
) {
10 this.server
.respondWith( [ 200, { 'Content-Type': 'application/json' },
11 '{ "query": { "allpages": [ ' +
12 '{ "title": "Category:Food" },' +
13 '{ "title": "Category:Fool Supermarine S.6" },' +
14 '{ "title": "Category:Fools" }' +
18 return new mw
.Api().getCategoriesByPrefix( 'Foo' ).then( function ( matches
) {
21 [ 'Food', 'Fool Supermarine S.6', 'Fools' ]
26 QUnit
.test( '.isCategory("")', function ( assert
) {
27 this.server
.respondWith( /titles=$/, [
29 { 'Content-Type': 'application/json' },
30 '{"batchcomplete":true}'
32 return new mw
.Api().isCategory( '' ).then( function ( response
) {
33 assert
.equal( response
, false );
37 QUnit
.test( '.isCategory("#")', function ( assert
) {
38 this.server
.respondWith( /titles=%23$/, [
40 { 'Content-Type': 'application/json' },
41 '{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
43 return new mw
.Api().isCategory( '#' ).then( function ( response
) {
44 assert
.equal( response
, false );
48 QUnit
.test( '.isCategory("mw:")', function ( assert
) {
49 this.server
.respondWith( /titles=mw%3A$/, [
51 { 'Content-Type': 'application/json' },
52 '{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
54 return new mw
.Api().isCategory( 'mw:' ).then( function ( response
) {
55 assert
.equal( response
, false );
59 QUnit
.test( '.isCategory("|")', function ( assert
) {
60 this.server
.respondWith( /titles=%1F%7C$/, [
62 { 'Content-Type': 'application/json' },
63 '{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
65 return new mw
.Api().isCategory( '|' ).then( function ( response
) {
66 assert
.equal( response
, false );
70 QUnit
.test( '.getCategories("")', function ( assert
) {
71 this.server
.respondWith( /titles=$/, [
73 { 'Content-Type': 'application/json' },
74 '{"batchcomplete":true}'
76 return new mw
.Api().getCategories( '' ).then( function ( response
) {
77 assert
.equal( response
, false );
81 QUnit
.test( '.getCategories("#")', function ( assert
) {
82 this.server
.respondWith( /titles=%23$/, [
84 { 'Content-Type': 'application/json' },
85 '{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
87 return new mw
.Api().getCategories( '#' ).then( function ( response
) {
88 assert
.equal( response
, false );
92 QUnit
.test( '.getCategories("mw:")', function ( assert
) {
93 this.server
.respondWith( /titles=mw%3A$/, [
95 { 'Content-Type': 'application/json' },
96 '{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
98 return new mw
.Api().getCategories( 'mw:' ).then( function ( response
) {
99 assert
.equal( response
, false );
103 QUnit
.test( '.getCategories("|")', function ( assert
) {
104 this.server
.respondWith( /titles=%1F%7C$/, [
106 { 'Content-Type': 'application/json' },
107 '{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
109 return new mw
.Api().getCategories( '|' ).then( function ( response
) {
110 assert
.equal( response
, false );