@ -165,8 +165,10 @@ define([
var getHTML = function ( inner ) {
var getHTML = function ( inner ) {
return ( '<!DOCTYPE html>\n' + '<html>\n' +
return ( '<!DOCTYPE html>\n' + '<html>\n' +
' <head><meta charset="utf-8"></head>\n <body>' +
' <head><meta charset="utf-8"></head>\n <body>' +
inner . innerHTML . replace ( /<img[^>]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/ ,
inner . innerHTML . replace ( /<img[^>]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/g ,
function ( match , realElt ) { return unescape ( realElt ) ; } ) +
function ( match , realElt ) {
//console.log("returning realElt \"" + unescape(realElt)+ "\".");
return unescape ( realElt ) ; } ) +
' </body>\n</html>'
' </body>\n</html>'
) ;
) ;
} ;
} ;
@ -764,37 +766,65 @@ define([
// -------- anchor test: make sure the exported anchor contains <a name="..."> -------
// -------- anchor test: make sure the exported anchor contains <a name="..."> -------
console . log ( '---- anchor test: make sure the exported anchor contains <a name="..."> -----.' ) ;
console . log ( '---- anchor test: make sure the exported anchor contains <a name="..."> -----.' ) ;
// TODO: cleanup fixme, too much ---, and removed tests
// TODO: any other unwanted changes (sframe-app?)?
// TODO: upgrade to latest of master, create branch
// TODO: any way to make sure that content contains anchors? Seems to need selenium-driven clicks and inputs
function tryAndTestExport ( ) {
function tryAndTestExport ( ) {
// window.setContent("This goes before the anchor");
console . log ( "Starting tryAndTestExport." ) ;
var anchors = CKEDITOR . plugins [ "link" ] . getEditorAnchors ( editor ) ;
editor . on ( 'dialogShow' , function ( evt ) {
if ( ! anchors || anchors . length === 0 ) {
console . log ( "Anchor dialog detected." ) ;
test . fail ( "No anchors found. Please adjust document" ) ;
var dialog = evt . data ;
} else {
$ ( dialog . parts . contents . $ ) . find ( "input" ) . val ( 'xx-' + Math . round ( Math . random ( ) * 1000 ) ) ;
console . log ( anchors . length + " anchors found." ) ;
dialog . click ( CKEDITOR . dialog . okButton ( editor ) . id ) ;
var exported = getHTML ( inner ) ;
} ) ;
console . log ( "Obtained exported: " + exported ) ;
var existingText = editor . getData ( ) ;
var allFound = true ;
editor . insertText ( "A bit of text" ) ;
for ( var i = 0 ; i < anchors . length ; i ++ ) {
console . log ( "Launching anchor command." ) ;
var anchor = anchors [ i ] ;
editor . execCommand ( editor . ui . get ( 'Anchor' ) . command ) ;
console . log ( "Anchor " + anchor . name ) ;
console . log ( "Anchor command launched." ) ;
var expected = "<a id=\"" + anchor . id + "\" name=\"" + anchor . name + "\" " ;
var found = exported . indexOf ( expected ) >= 0 ;
var waitH = window . setInterval ( function ( ) {
console . log ( "Found " + expected + " " + found + "." ) ;
console . log ( "Waited 2s for the dialog to appear" ) ;
allFound = allFound && found ;
var anchors = CKEDITOR . plugins [ "link" ] . getEditorAnchors ( editor ) ;
if ( ! anchors || anchors . length === 0 ) {
test . fail ( "No anchors found. Please adjust document" ) ;
} else {
console . log ( anchors . length + " anchors found." ) ;
var exported = getHTML ( inner ) ;
console . log ( "Obtained exported: " + exported ) ;
var allFound = true ;
for ( var i = 0 ; i < anchors . length ; i ++ ) {
var anchor = anchors [ i ] ;
console . log ( "Anchor " + anchor . name ) ;
var expected = "<a id=\"" + anchor . id + "\" name=\"" + anchor . name + "\" " ;
var found = exported . indexOf ( expected ) >= 0 ;
console . log ( "Found " + expected + " " + found + "." ) ;
allFound = allFound && found ;
}
console . log ( "Cleaning up." ) ;
if ( allFound ) {
// clean-up
editor . execCommand ( 'undo' ) ;
editor . execCommand ( 'undo' ) ;
var nint = window . setInterval ( function ( ) {
console . log ( "Waiting for undo to yield same result." )
if ( existingText === editor . getData ( ) ) {
window . clearInterval ( nint ) ;
test . pass ( ) ;
}
} , 500 ) ;
} else
{
test . fail ( "Not all expected a elements found for document at " + window . top . location + "." ) ;
}
}
}
console . log ( "Finished anchor test." ) ;
window . clearInterval ( waitH ) ;
if ( allFound ) { test . pass ( ) ; }
} , 2000 ) ;
else
{ test . fail ( "Not all expected a elements found." ) ; }
}
}
}
var intervalHandle = window . setInterval ( function ( ) {
var intervalHandle = window . setInterval ( function ( ) {
if ( editor . status === "ready" ) {
if ( editor . status === "ready" ) {
window . clearInterval ( intervalHandle ) ;
window . clearInterval ( intervalHandle ) ;
console . log ( "Editor is ready." ) ;
tryAndTestExport ( ) ;
tryAndTestExport ( ) ;
} else {
} else {
console . log ( "Waiting for editor to be ready." ) ;
console . log ( "Waiting for editor to be ready." ) ;