File: plugins.js

package info (click to toggle)
ckeditor 4.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 290,372 kB
  • sloc: javascript: 242,409; sh: 202; makefile: 64; python: 37; php: 15; xml: 5
file content (177 lines) | stat: -rw-r--r-- 4,876 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* bender-tags: editor */

( function() {
	bender.test( {
		'test: Loading self defined external plugin file paths': testAddExternal( {
			plugin: 'myplugin',
			path: '%TEST_DIR%_assets/myplugins/sample/',
			file: 'my_plugin.js',
			expectedFileName: 'my_plugin.js'
		} ),

		// (https://dev.ckeditor.com/ticket/10913)
		'test addExternal with file name separated': testAddExternal( {
			plugin: 'plugin1',
			path: '%TEST_DIR%_assets/myplugins/plugin1/',
			file: 'plugin.js',
			expectedFileName: 'plugin.js'
		} ),

		// (https://dev.ckeditor.com/ticket/10913)
		'test addExternal with file name empty': testAddExternal( {
			plugin: 'plugin2',
			path: '%TEST_DIR%_assets/myplugins/plugin2/plugin.js',
			file: '',
			expectedFileName: 'plugin.js'
		} ),

		// (#3477, https://dev.ckeditor.com/ticket/10913)
		'test addExternal with file name included in path': testAddExternal( {
			plugin: 'plugin3',
			path: '%TEST_DIR%_assets/myplugins/plugin3/myplugin.js',
			expectedFileName: 'myplugin.js'
		} ),

		// (#3477, https://dev.ckeditor.com/ticket/10913)
		'test addExternal with file name missing and path ending with slash': testAddExternal( {
			plugin: 'plugin4',
			path: '%TEST_DIR%_assets/myplugins/plugin4/',
			expectedFileName: 'plugin.js'
		} ),

		'errors thrown when required plugin specified in removePlugins list': function() {
			var log = sinon.stub( CKEDITOR, 'error' );

			CKEDITOR.plugins.add( 'errorplugin1', {
				requires: 'errorplugin3,errorplugin2'
			} );

			CKEDITOR.plugins.add( 'errorplugin2', {
				requires: 'errorplugin3,errorplugin4'
			} );

			CKEDITOR.plugins.add( 'errorplugin3', {
				init: function( editor ) {
					editor.plugin3Inited = true;
				}
			} );

			CKEDITOR.plugins.add( 'errorplugin4', {
				init: function( editor ) {
					editor.plugin4Inited = true;
				}
			} );

			setTimeout( function() {
				CKEDITOR.replace( 'errortest', {
					plugins: 'wysiwygarea,errorplugin1,errorplugin3',
					extraPlugins: 'errorplugin2',
					removePlugins: 'errorplugin3,errorplugin4',

					on: {
						instanceReady: function( evt ) {
							resume( function() {

								log.restore();

								// plugin 3 reqed by plugin 1 and plugins 4 & 3 reqed by plugin 2.
								assert.isTrue( log.calledThrice, 'CKEDITOR.error should be called three times.' );

								var call;
								for ( var i = 0; i < log.callCount; i++ ) {
									call = log.getCall( i );
									assert.areEqual( 'editor-plugin-required', call.args[ 0 ], 'Required plugin error should be logged.' );
								}

								// Plugins are corretly inited.
								assert.isTrue( evt.editor.plugin3Inited );
								assert.isTrue( evt.editor.plugin4Inited );
							} );
						}
					}
				} );
			} );

			wait();
		},

		// (#1791)
		'test detect plugins conflict - with conflicting plugins': function() {
			var editor = {
					plugins: {
						'plugin1': 1,
						'plugin2': 2
					}
				},
				spy = sinon.spy( CKEDITOR, 'warn' ),

				result = CKEDITOR.editor.prototype.plugins.detectConflict.call( editor.plugins,
					'plugin', [ 'plugin1', 'plugin2' ] );

			spy.restore();

			assert.isTrue( result, 'Conflicts detected.' );
			assert.isTrue( spy.calledWith( 'editor-plugin-conflict', { plugin: 'plugin', replacedWith: 'plugin1' } ) );
		},

		// (#1791)
		'test detect plugins conflict - without conflicting plugins': function() {
			var editor = {
					plugins: {}
				},
				spy = sinon.spy( CKEDITOR, 'warn' ),

				result = CKEDITOR.editor.prototype.plugins.detectConflict.call( editor.plugins,
					'plugin', [ 'plugin1', 'plugin2' ] );

			spy.restore();

			assert.isFalse( result, 'Conflicts not detected.' );
			assert.isFalse( spy.called );
		},

		// (#2692)
		'test supported environment': function() {
			CKEDITOR.plugins.add( 'envdefault', {} );
			CKEDITOR.plugins.add( 'envcustom', {
				isSupportedEnvironment: function() {
					return false;
				}
			} );

			var editor = CKEDITOR.replace( 'env', {
				plugins: 'wysiwygarea,envdefault,envcustom',
				on: {
					instanceReady: function() {
						resume( function() {
							assert.isTrue( editor.plugins.envdefault.isSupportedEnvironment(),
								'Plugin should be supported by default' );

							assert.isFalse( editor.plugins.envcustom.isSupportedEnvironment(),
								'Plugin should allow for custom isSupportedEnvironment implementation' );
						} );
					}
				}
			} );

			wait();
		}
	} );

	function testAddExternal( options ) {
		return function() {
			CKEDITOR.plugins.addExternal( options.plugin, options.path, options.file );

			CKEDITOR.plugins.load( options.plugin, function() {
				resume( function() {
					var plugin = CKEDITOR.plugins.get( options.plugin );

					assert.areEqual( options.expectedFileName, CKEDITOR.plugins.externals[ options.plugin ].file );
					assert.isTrue( plugin.definition );
				} );
			}, this );

			wait();
		};
	}
}() );