Merge "Drop in replacement of eval.php based on psysh"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.upload.test.js
1 ( function ( mw, $ ) {
2 QUnit.module( 'mediawiki.api.upload', QUnit.newMwEnvironment( {} ) );
3
4 QUnit.test( 'Basic functionality', function ( assert ) {
5 var api = new mw.Api();
6 assert.ok( api.upload );
7 assert.throws( function () {
8 api.upload();
9 } );
10 } );
11
12 QUnit.test( 'Set up iframe upload', function ( assert ) {
13 var $iframe, $form, $input,
14 api = new mw.Api();
15
16 this.sandbox.stub( api, 'getEditToken', function () {
17 return $.Deferred().promise();
18 } );
19
20 api.uploadWithIframe( $( '<input>' )[ 0 ], { filename: 'Testing API upload.jpg' } );
21
22 $iframe = $( 'iframe' );
23 $form = $( 'form.mw-api-upload-form' );
24 $input = $form.find( 'input[name=filename]' );
25
26 assert.ok( $form.length > 0 );
27 assert.ok( $input.length > 0 );
28 assert.ok( $iframe.length > 0 );
29 assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ) );
30 assert.strictEqual( $input.val(), 'Testing API upload.jpg' );
31 } );
32
33 }( mediaWiki, jQuery ) );