Вход Регистрация
Файл: module-assets/admin/plupload/tests/auto/Uploader.html
Строк: 246
<?php
<!DOCTYPE html>
<
html lang="en">
<
head>
<
meta charset="UTF-8" />
<
title>PluploadTest Uploader</title>

<!-- 
qunit -->
<
script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<
link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<
script src="http://code.jquery.com/qunit/qunit-git.js"></script>

<!-- 
testrunner -->
<
script src="../js/reporter.js"></script>
<
script src="../scriptloader.js"></script>
<
script src="../FileHash.js"></script>

<
script type="text/javascript">

QUnit.config.reorder false;
QUnit.config.autostart false;

FileHash.init({
    
files: ['files/01.min.js''files/02.min.js'],
    
onready: function() {
        
QUnit.start();
    }
});

o.Env.swf_url "../../js/flash/Moxie.swf";
o.Env.xap_url "../../js/silverlight/Moxie.xap";

module("plupload.Uploader", {
    
setup: function() {
        var 
optionsup;

        $(
'#qunit-fixture').html('<div id="uploader" />');

        
options this.options = {
            
browse_button'uploader',
            
container'qunit-fixture',
            
url"Plupload/upload.php"
        
};

        
up this.up = new plupload.Uploader(options);

        
up.bind('PostInit', function() {
            
QUnit.start();
        });

        
QUnit.stop();
        
up.init();
    },

    
teardown: function() {
        
this.up.destroy();
    }
});

// test initialization and options

test('addFile()', function() {
    
expect(8);
    
    var 
filefiles FileHash.nativeFiles;
    
// window.Blob
    
this.up.addFile(files[0].blobfiles[0].name);
    
equal(this.up.files.length1"window.Blob added.");
    
equal(this.up.files[0].namefiles[0].name"File name set properly through the second, optional argument.");

    
// o.Blob
    
file = new o.Blob(nullfiles[0].blob);
    
this.up.addFile(filefiles[0].name);
    
equal(this.up.files.length2"o.Blob added (file name: " this.up.files[1].name  ").");

    
// o.File
    
file = new o.File(nullfiles[1].blob);
    
file.name files[1].name;
    
this.up.addFile(file);
    
equal(this.up.files.length3"o.File added (file name: " this.up.files[2].name  ").");

    
// plupload.File
    
file = new plupload.File(new o.File(nullfiles[1].blob));
    
this.up.addFile(file);
    
equal(this.up.files.length4"plupload.File added (file name: " this.up.files[3].name  ").");

    
this.up.bind('FilesAdded', function(upfiles) {
        
equal(files.length4"FilesAdded triggered, " files.length " files were passed to listener.");
    });

    
// array of file objects
    
this.up.addFile([
        
files[0].blob,
        new 
o.Blob(nullfiles[0].blob),
        new 
o.File(nullfiles[1].blob),
        new 
plupload.File(new o.File(nullfiles[1].blob))
    ], 
files[0].name);
    
equal(this.up.files.length8"Mixed array of various file objects added.");
    
notEqual(this.up.files[7].namefiles[0].name"Second parameter (fileName) properly ignored, when first one is an array.");
});


test('getFile()', function() {
    
expect(1);

    var 
filefiles FileHash.nativeFiles;

    
this.up.addFile([
        
files[0].blob,
        new 
o.Blob(nullfiles[0].blob),
        new 
o.File(nullfiles[1].blob),
        new 
plupload.File(new o.File(nullfiles[1].blob))
    ]);

    
file this.up.getFile(this.up.files[0].id);
    
deepEqual(filethis.up.files[0], "File retrieved by id with getFile().");
});


test('removeFile() / splice()', function() {
    
expect(5);

    var 
countFilesfiles FileHash.nativeFiles;

    
this.up.addFile([
        
files[0].blob,
        new 
o.Blob(nullfiles[0].blob),
        new 
o.File(nullfiles[1].blob),
        new 
plupload.File(new o.File(nullfiles[1].blob))
    ]);

    
countFiles this.up.files.length;

    
this.up.removeFile(this.up.files[0]);
    
equal(this.up.files.length, --countFiles"File removed from the queue by passing a plupload.File object.");

    
this.up.removeFile(this.up.files[0].id);
    
equal(this.up.files.length, --countFiles"File removed from the queue by passing file id.");


    
this.up.bind('FilesRemoved', function(upfiles) {
        
equal(files.length2"FilesRemoved triggred, " files.length " removed.");
    });

    
this.up.bind('QueueChanged', function(up) {
        
ok(true"QueueChanged triggered.");
    });
    
this.up.splice(02);
    
equal(this.up.files.length0"Two files removed simultaneously with splice().");
});


// test internal filters
test('options.filters', function() {
    
expect(3);

    var 
files FileHash.nativeFiles;

    
// test file type check by extension
    
var up = new plupload.Uploader(o.extend({
        
filters : [
            {
title "Image files"extensions "jpg,jpeg,gif,png"}
        ]
    }, 
this.options));


    
up.bind('PostInit', function() {
        
start();

        
up.addFile(files[1].blobfiles[1].name);
        
equal(up.files.length0"No files were added to the queue.");

        
// add asterisk wildcard
        
up.settings.filters.push({title"All files"extensions"*"});
        
up.addFile(files[1].blobfiles[1].name);
        
equal(up.files.length1"Asterisk wildcard as one of the extensions filters allows any file.");

        
up.destroy();
    });

    
up.bind('Error', function(uperror) {
        
equal(error.codeplupload.FILE_EXTENSION_ERROR"Error triggered, code: FILE_EXTENSION_ERROR.");
    });

    
stop();
    
up.init();
});


test('options.max_file_size', function() {
    
expect(2);

    var 
files FileHash.nativeFiles;

    
// test file type check by extension
    
var up = new plupload.Uploader(o.extend({
        
max_file_size'100kb'
    
}, this.options));


    
up.bind('PostInit', function() {
        
start();

        
up.addFile(files[1].blobfiles[1].name);
        
equal(up.files.length0"No files were added to the queue.");

        
up.destroy();
    });

    
up.bind('Error', function(uperror) {
        
equal(error.codeplupload.FILE_SIZE_ERROR"Error triggered, code: FILE_SIZE_ERROR.");
    });

    
stop();
    
up.init();
});


test('options.prevent_duplicates', function() {
    
expect(4);

    var 
files FileHash.nativeFiles;

    
// test file type check by extension
    
var up = new plupload.Uploader(o.extend({
        
prevent_duplicatestrue
    
}, this.options));


    
up.bind('PostInit', function() {
        
start();

        
up.addFile(files[1].blobfiles[1].name);
        
up.addFile(files[0].blobfiles[1].name); // another file but with the same name
        
equal(up.files.length2"Another file, with the same name still added, 'cause sizes differ.");

        
up.addFile(files[0].blobfiles[0].name);
        
equal(up.files.length3"The same file, but with another name still added, 'cause names must differ.");

        
up.addFile(files[0].blobfiles[0].name);
        
equal(up.files.length3"File ignored, 'cause a file with the same and size already in the queue.");

        
up.destroy();
    });

    
up.bind('Error', function(uperror) {
        
equal(error.codeplupload.FILE_DUPLICATE_ERROR"Error triggered, code: FILE_DUPLICATE_ERROR.");
    });

    
stop();
    
up.init();
});

// test upload

</script>
</
head>
<
body>
    <
h1 id="qunit-header">PluploadTest Uploader</h1>
    <
h2 id="qunit-banner"></h2>
    <
h2 id="qunit-userAgent"></h2>
    <
ol id="qunit-tests">
    </
ol>
    <
div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
</
body>
</
html>
?>
Онлайн: 1
Реклама