Skip to content

Commit

Permalink
Simplified tests, by fixing #1068 issue in listener for easyimage (on…
Browse files Browse the repository at this point in the history
…ly).
  • Loading branch information
mlewand authored and jacekbogdanski committed Feb 17, 2018
1 parent 6db890a commit c60881d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
3 changes: 2 additions & 1 deletion plugins/easyimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
var data = evt.data,
// Prevent XSS attacks.
tempDoc = document.implementation.createHTMLDocument( '' ),
widgetDef = editor.widgets.registered.uploadeasyimage,
temp = new CKEDITOR.dom.element( tempDoc.body ),
imgs, img, i;

Expand All @@ -203,7 +204,7 @@

// We are not uploading images in non-editable blocs and fake objects (http://dev.ckeditor.com/ticket/13003).
if ( isDataInSrc && isRealObject && !img.data( 'cke-upload-id' ) && !img.isReadOnly( 1 ) ) {
var loader = editor.uploadRepository.create( img.getAttribute( 'src' ) );
var loader = editor.uploadRepository.create( img.getAttribute( 'src' ), undefined, widgetDef.loaderType );
loader.upload();

fileTools.markElement( img, 'uploadeasyimage', loader.id );
Expand Down
23 changes: 4 additions & 19 deletions tests/plugins/easyimage/uploadwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@
}
}

CKEDITOR.on( 'instanceCreated', function() {
if ( !CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) {
// Because of #1068 we can't provide loaderType directly. Instead we just replace cloudServicesLoader
// with our loader stub that is going to be customized in init method.
sinon.stub( CKEDITOR.plugins.cloudservices, 'cloudServicesLoader', CKEDITOR.fileTools.fileLoader );
}
} );

tests = {
init: function() {
var responseData = {
Expand All @@ -68,27 +60,20 @@

resumeAfter = bender.tools.resumeAfter;

// This tests suite could be made much prettier, it would require #1068 to be resolved. Then you
// could just use LoaderStub type with stubbed methods, rather than overwrite base FileLoader type.
CKEDITOR.fileTools.fileLoader.prototype.loadAndUpload = function() {
// Approach taken from tests/plugins/uploadwidget/uploadwidget.js test.
CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.loadAndUpload = function() {
loadAndUploadCount++;

this.responseData = CKEDITOR.tools.clone( responseData );
};

CKEDITOR.fileTools.fileLoader.prototype.load = function() {};
CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.load = function() {};

CKEDITOR.fileTools.fileLoader.prototype.upload = function() {
CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.upload = function() {
uploadCount++;

this.responseData = CKEDITOR.tools.clone( responseData );
};

// Now stub can be safely removed, as it's used only in plugin.init, which has already been called,
// this workaround could be removed once #1068 is fixed.
if ( CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) {
CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore();
}
},

setUp: function() {
Expand Down

0 comments on commit c60881d

Please sign in to comment.