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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: justify,image,toolbar */
bender.editor = {
config: { enterMode: CKEDITOR.ENTER_P },
allowedForTests: 'img[align];span[contenteditable]'
};
bender.test(
{
assertCommandState: function( left, right, center, justify, editor ) {
editor = editor || this.editor;
var leftCmd = editor.getCommand( 'justifyleft' );
var rightCmd = editor.getCommand( 'justifyright' );
var centerCmd = editor.getCommand( 'justifycenter' );
var justifyCmd = editor.getCommand( 'justifyblock' );
assert.areSame( left, leftCmd.state, 'leftCmd.state' );
assert.areSame( right, rightCmd.state, 'rightCmd.state' );
assert.areSame( center, centerCmd.state, 'centerCmd.state' );
assert.areSame( justify, justifyCmd.state, 'justifyCmd.state' );
},
// Justify should align selected image.
'test aligment command on selected image': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>[<img src="http://tests/404" style="float:left;"/>]</p>' );
// Check commands state, center/justify should be disabled at this point.
this.assertCommandState( 1, 2, 0, 0 );
// Remove the existing image alignment.
bot.execCommand( 'justifyleft' );
assert.areSame( '<p><img src="http://tests/404" /></p>', bot.getData( true ) );
// Align image right.
bot.execCommand( 'justifyright' );
assert.areSame( '<p><img src="http://tests/404" style="float:right;" /></p>', bot.getData( true ) );
// Align image left again.
bot.execCommand( 'justifyleft' );
assert.areSame( '<p><img src="http://tests/404" style="float:left;" /></p>', bot.getData( true ) );
},
'test aligment command on selected image (align attribute)': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>[<img src="http://tests/404" align="left"/>]</p>' );
// Check commands state, center/justify should be disabled at this point.
this.assertCommandState( 1, 2, 0, 0 );
// Remove the existing image alignment.
bot.execCommand( 'justifyleft' );
assert.areSame( '<p><img src="http://tests/404" /></p>', bot.getData( true ) );
// Align image right.
bot.execCommand( 'justifyright' );
assert.areSame( '<p><img src="http://tests/404" style="float:right;" /></p>', bot.getData( true ) );
},
// Justify should align paragraph.
'test aligment command on paragraph': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>[<img src="http://tests/404"/>bar]</p>' );
// Check commands state, all commands should be enabled, left should be turned on.
this.assertCommandState( 1, 2, 2, 2 );
// Align paragraph right;
bot.execCommand( 'justifyright' );
assert.areSame( '<p style="text-align:right;"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Align paragraph left;
bot.execCommand( 'justifyleft' );
assert.areSame( '<p><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Align paragraph center;
bot.execCommand( 'justifycenter' );
assert.areSame( '<p style="text-align:center;"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Align paragraph justify
bot.execCommand( 'justifyblock' );
assert.areSame( '<p style="text-align:justify;"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
},
'test alignment commands with justifyClasses': function() {
var tc = this;
bender.editorBot.create( {
name: 'editor_classes',
config: {
justifyClasses: [ 'alignLeft', 'alignCenter', 'alignRight', 'alignJustify' ],
plugins: 'justify,toolbar',
extraAllowedContent: 'img[src]',
contentsCss: '_assets/styles.css'
}
}, function( bot ) {
var editor = bot.editor;
bot.setHtmlWithSelection( '<p>[<img src="http://tests/404"/>bar]</p>' );
// Check commands state, all commands should be enabled, left should be turned on.
tc.assertCommandState( 1, 2, 2, 2, editor );
// Align paragraph right;
bot.execCommand( 'justifyright' );
assert.areSame( '<p class="alignright"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Right on.
tc.assertCommandState( 2, 1, 2, 2, editor );
// Align paragraph center;
bot.execCommand( 'justifycenter' );
assert.areSame( '<p class="aligncenter"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Center on.
tc.assertCommandState( 2, 2, 1, 2, editor );
// Align paragraph left;
bot.execCommand( 'justifyleft' );
assert.areSame( '<p><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Left on.
tc.assertCommandState( 1, 2, 2, 2, editor );
// Align paragraph justify
bot.execCommand( 'justifyblock' );
assert.areSame( '<p class="alignjustify"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Justify on.
tc.assertCommandState( 2, 2, 2, 1, editor );
} );
},
'test alignment commands with justifyClasses - one disallowed': function() {
var tc = this;
bender.editorBot.create( {
name: 'editor_classes2',
config: {
justifyClasses: [ 'alignLeft', 'alignCenter', 'alignRight', 'alignJustify' ],
plugins: 'justify,toolbar',
// Note: alignRight is not allowed.
allowedContent: 'p(alignLeft,alignCenter,alignJustify); img[src]',
contentsCss: '_assets/styles.css'
}
}, function( bot ) {
var editor = bot.editor;
bot.setHtmlWithSelection( '<p>[<img src="http://tests/404"/>bar]</p>' );
// Check commands state, left should be turned on, right disabled and the rest off.
tc.assertCommandState( 1, 0, 2, 2, editor );
// Align paragraph right;
bot.execCommand( 'justifyright' );
assert.areSame( '<p><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Check commands state, left should be turned on, right disabled and the rest off.
tc.assertCommandState( 1, 0, 2, 2, editor );
// Align paragraph center;
bot.execCommand( 'justifycenter' );
assert.areSame( '<p class="aligncenter"><img src="http://tests/404" />bar</p>', bot.getData( true ) );
// Check commands state, left should be turned on, right disabled and the rest off.
tc.assertCommandState( 2, 0, 1, 2, editor );
} );
},
'test alignment commands in br mode': function() {
var tc = this;
bender.editorBot.create( {
name: 'editor_enter_br',
config: {
plugins: 'justify,toolbar',
enterMode: CKEDITOR.ENTER_BR
}
}, function( bot ) {
var editor = bot.editor;
bot.setHtmlWithSelection( 'foo^bar<br />bom' );
// None on.
tc.assertCommandState( 2, 2, 2, 2, editor );
// Align paragraph right;
bot.execCommand( 'justifyright' );
assert.areSame( '<div style="text-align:right;">foobar</div>bom', bot.getData( true ) );
// Right on.
tc.assertCommandState( 2, 1, 2, 2, editor );
// Align paragraph center;
bot.execCommand( 'justifyleft' );
assert.areSame( '<div>foobar</div>bom', bot.getData( true ) );
// None on.
tc.assertCommandState( 1, 2, 2, 2, editor );
assert.isTrue( editor.filter.check( 'div{text-align}' ), 'Check whether justify allows div in br mode' );
} );
},
'test alignment commands in div mode and with justifyClasses': function() {
var tc = this;
bender.editorBot.create( {
name: 'editor_enter_div',
config: {
plugins: 'justify,toolbar',
enterMode: CKEDITOR.ENTER_DIV,
justifyClasses: [ 'alignLeft', 'alignCenter', 'alignRight', 'alignJustify' ],
contentsCss: '_assets/styles.css'
}
}, function( bot ) {
var editor = bot.editor;
bot.setHtmlWithSelection( '<div>foo^bar</div>' );
// None on.
tc.assertCommandState( 1, 2, 2, 2, editor );
// Align paragraph right;
bot.execCommand( 'justifyright' );
assert.areSame( '<div class="alignright">foobar</div>', bot.getData( true ) );
// Right on.
tc.assertCommandState( 2, 1, 2, 2, editor );
// Align paragraph center;
bot.execCommand( 'justifyleft' );
assert.areSame( '<div>foobar</div>', bot.getData( true ) );
// None on.
tc.assertCommandState( 1, 2, 2, 2, editor );
} );
},
'test justify on selection containing non-editable inline': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '[<p>xxx<span contenteditable="false">foo</span>zzz</p>]' );
bot.execCommand( 'justifyright' );
assert.areSame( '<p style="text-align:right;">xxx<span contenteditable="false">foo</span>zzz</p>', bot.getData( true ) );
bot.setHtmlWithSelection( '[<p><span contenteditable="false">foo</span></p>]' );
bot.execCommand( 'justifyright' );
assert.areSame( '<p style="text-align:right;"><span contenteditable="false">foo</span></p>', bot.getData( true ) );
}
} );
|