Sfoglia il codice sorgente

Added tests for CKEDITOR.

fredck 11 anni fa
parent
commit
47cde86b6e
2 ha cambiato i file con 113 aggiunte e 0 eliminazioni
  1. 70 0
      tests/ckeditor/basepath.js
  2. 43 0
      tests/ckeditor/ckeditor.js

+ 70 - 0
tests/ckeditor/basepath.js

@@ -0,0 +1,70 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals beforeEach, describe, it, expect, CKEDITOR, window, document */
+
+'use strict';
+
+beforeEach( function() {
+	// Ensure that no CKEDITOR_BASEPATH global is available.
+	delete window.CKEDITOR_BASEPATH;
+
+	// Remove all script elements from the document.
+	removeScripts();
+} );
+
+describe( 'ckeditor.basePath', function() {
+	it( 'Full URL', function( done ) {
+		CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) {
+			addScript( 'http://bar.com/ckeditor/ckeditor.js' );
+			expect( CKEDITOR._getBasePath() ).equals( 'http://bar.com/ckeditor/' );
+			done();
+		} );
+	} );
+
+	it( 'CKEDITOR_BASEPATH', function( done ) {
+		CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) {
+			window.CKEDITOR_BASEPATH = 'http://foo.com/ckeditor/';
+			expect( CKEDITOR._getBasePath() ).equals( 'http://foo.com/ckeditor/' );
+			done();
+		} );
+	} );
+
+	it( 'Ensure that no browser keep script URLs absolute or relative', function( done ) {
+		// Browsers should convert absolute and relative URLs to full URLs.
+		// If this test fails in any browser, _getBasePath() must be reviewed to deal with such case (v4 does it).
+
+		test( '/absolute/url/ckeditor.js' );
+		test( '../relative/url/ckeditor.js' );
+
+		done();
+
+		function test( url ) {
+			removeScripts();
+
+			var script = addScript( url );
+
+			// Test if the src now contains '://'.
+			expect( /:\/\//.test( script.src ) ).to.be.true();
+		}
+	} );
+} );
+
+function addScript( url ) {
+	var script = document.createElement( 'script' );
+	script.src = url;
+	document.head.appendChild( script );
+
+	return script;
+}
+
+function removeScripts() {
+	var scripts = [].slice.call( document.getElementsByTagName( 'script' ) );
+	var script;
+
+	while ( ( script = scripts.shift() ) ) {
+		script.parentNode.removeChild( script );
+	}
+}

+ 43 - 0
tests/ckeditor/ckeditor.js

@@ -0,0 +1,43 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals describe, it, expect, CKEDITOR */
+
+'use strict';
+
+describe( 'ckeditor', function() {
+	it( 'getPluginPath() with development source code', function( done ) {
+		CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) {
+			var basePath = CKEDITOR.basePath;
+			var path = CKEDITOR.getPluginPath( 'test' );
+
+			if ( CKEDITOR.isDev ) {
+				expect( path ).equals( basePath + 'node_modules/ckeditor-plugin-test/src/' );
+			} else {
+				expect( path ).equals( basePath + 'plugins/test/' );
+			}
+			done();
+		} );
+	} );
+
+	it( 'getPluginPath() with production code', function( done ) {
+		CKEDITOR.require( [ 'ckeditor', 'ckeditor-core' ], function( CKEDITOR, core ) {
+			// To be able to run this test on both dev and production code, we need to override getPluginPath with the
+			// core version of it and restore it after testing.
+			var originalGetPluginPath = CKEDITOR.getPluginPath;
+			CKEDITOR.getPluginPath = core.getPluginPath;
+
+			// This test is good for both the development and production codes.
+			var basePath = CKEDITOR.basePath;
+			var path = CKEDITOR.getPluginPath( 'test' );
+
+			expect( path ).equals( basePath + 'plugins/test/' );
+
+			CKEDITOR.getPluginPath = originalGetPluginPath;
+
+			done();
+		} );
+	} );
+} );