25
25
getAttrData = widgetTestsTools . getAttributeData ,
26
26
getWidgetById = widgetTestsTools . getWidgetById ,
27
27
obj2Array = widgetTestsTools . obj2Array ,
28
- classes2Array = widgetTestsTools . classes2Array ;
28
+ classes2Array = widgetTestsTools . classes2Array ,
29
+ prefix ;
29
30
30
31
bender . test ( {
32
+
33
+ setUp : function ( ) {
34
+ // Class prefix for widget wrapper classes (#13828).
35
+ prefix = CKEDITOR . plugins . widget . WRAPPER_CLASS_PREFIX ;
36
+ } ,
37
+
31
38
'test initialization - init method and data event' : function ( ) {
32
39
var editor = this . editor ,
33
40
order = [ ] ,
341
348
} ) ;
342
349
343
350
this . editorBot . setData ( '<p data-widget="testclassesloading1" id="w1" class="foo bar">foo</p>' , function ( ) {
344
- var widget = getWidgetById ( editor , 'w1' ) ;
351
+ var widget = getWidgetById ( editor , 'w1' ) ,
352
+ wrapper = widget . wrapper ;
345
353
346
354
assert . areSame ( 1 , onDataFired , 'data event fired once' ) ;
347
355
assert . areSame ( 'bar,foo' , getClasses ( widget ) . join ( ',' ) , 'widget.data.classes is loaded' ) ;
348
356
assert . isTrue ( widget . hasClass ( 'foo' ) ) ;
349
357
assert . isTrue ( widget . hasClass ( 'bar' ) ) ;
358
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'Prefixed class should be applied on wrapper.' ) ;
359
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'Prefixed class should be applied on wrapper.' ) ;
350
360
} ) ;
351
361
} ,
352
362
367
377
} ) ;
368
378
369
379
this . editorBot . setData ( '<p data-widget="testclassesloading2" data-cke-widget-data="' + data2Attr ( { classes : { foo : 1 , bar : 1 } } ) + '" id="w1">foo</p>' , function ( ) {
370
- var widget = getWidgetById ( editor , 'w1' ) ;
380
+ var widget = getWidgetById ( editor , 'w1' ) ,
381
+ wrapper = widget . wrapper ;
371
382
372
383
assert . areSame ( 1 , onDataFired , 'data event fired once' ) ;
373
384
assert . areSame ( 2 , addClassCalled , 'addClass was used to add classes' ) ;
374
385
assert . areSame ( 'bar,foo' , getClasses ( widget ) . join ( ',' ) , 'widget.data.classes is loaded' ) ;
375
386
assert . isTrue ( widget . hasClass ( 'foo' ) ) ;
376
387
assert . isTrue ( widget . hasClass ( 'bar' ) ) ;
388
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'Prefixed class should be applied on wrapper.' ) ;
389
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'Prefixed class should be applied on wrapper.' ) ;
377
390
} ) ;
378
391
} ,
379
392
384
397
385
398
this . editorBot . setData ( '<p data-widget="testaddremoveclass1" id="w1">foo</p>' , function ( ) {
386
399
var widget = getWidgetById ( editor , 'w1' ) ,
387
- element = widget . element ;
400
+ element = widget . element ,
401
+ wrapper = widget . wrapper ;
388
402
389
403
widget . addClass ( 'foo' ) ;
390
404
assert . isTrue ( element . hasClass ( 'foo' ) , 'element has class foo' ) ;
405
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper has class ' + prefix + 'foo' ) ;
391
406
392
407
widget . addClass ( 'bar' ) ;
393
408
assert . isTrue ( element . hasClass ( 'bar' ) , 'element has class bar' ) ;
409
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'wrapper has class ' + prefix + 'bar' ) ;
394
410
assert . isTrue ( element . hasClass ( 'foo' ) , 'element still has class foo' ) ;
411
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper has class ' + prefix + 'foo' ) ;
395
412
396
413
widget . removeClass ( 'foo' ) ;
397
414
assert . isFalse ( element . hasClass ( 'foo' ) , 'element does not have class foo' ) ;
415
+ assert . isFalse ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper does not have class ' + prefix + 'foo' ) ;
398
416
assert . isTrue ( element . hasClass ( 'bar' ) , 'element still has class bar' ) ;
417
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'wrapper does not have class ' + prefix + 'bar' ) ;
399
418
} ) ;
400
419
} ,
401
420
442
461
editor . widgets . add ( widgetName , { } ) ;
443
462
444
463
this . editorBot . setData ( '<p data-widget="testapplyremovestyle1" id="w1">foo</p>' , function ( ) {
445
- var widget = getWidgetById ( editor , 'w1' ) ;
446
-
447
- var style1 = st ( { type : 'widget' , widget : widgetName , attributes : { 'class' : 'foo' } } ) ,
464
+ var widget = getWidgetById ( editor , 'w1' ) ,
465
+ wrapper = widget . wrapper ,
466
+ style1 = st ( { type : 'widget' , widget : widgetName , attributes : { 'class' : 'foo' } } ) ,
448
467
style2 = st ( { type : 'widget' , widget : widgetName , attributes : { 'class' : 'bar' } } ) ;
449
468
450
469
widget . applyStyle ( style1 ) ;
451
470
assert . isTrue ( widget . hasClass ( 'foo' ) , 'style 1 has been applied' ) ;
471
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'style 1 has been applied to the wrapper too' ) ;
452
472
453
473
widget . applyStyle ( style2 ) ;
454
474
assert . isTrue ( widget . hasClass ( 'foo' ) , 'style 1 is still applied' ) ;
475
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'style 1 is still applied to the wrapper' ) ;
455
476
assert . isTrue ( widget . hasClass ( 'bar' ) , 'style 2 has been applied' ) ;
477
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'style 2 has been applied to the wrapper too' ) ;
456
478
457
479
widget . removeStyle ( style1 ) ;
458
480
assert . isFalse ( widget . hasClass ( 'foo' ) , 'style 1 has been removed' ) ;
481
+ assert . isFalse ( wrapper . hasClass ( prefix + 'foo' ) , 'style 1 has been removed from the wrapper' ) ;
459
482
assert . isTrue ( widget . hasClass ( 'bar' ) , 'style 2 is sitll applied' ) ;
483
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'style 2 is still applied to the wrapper' ) ;
460
484
461
485
widget . removeStyle ( style2 ) ;
462
486
assert . isFalse ( widget . hasClass ( 'bar' ) , 'style 2 has been removed' ) ;
487
+ assert . isFalse ( wrapper . hasClass ( prefix + 'bar' ) , 'style 2 has been removed from the wrapper' ) ;
463
488
} ) ;
464
489
} ,
465
490
470
495
editor . widgets . add ( widgetName , { } ) ;
471
496
472
497
this . editorBot . setData ( '<p data-widget="testapplyremovestyle2" id="w1">foo</p>' , function ( ) {
473
- var widget = getWidgetById ( editor , 'w1' ) ;
498
+ var widget = getWidgetById ( editor , 'w1' ) ,
499
+ wrapper = widget . wrapper ;
474
500
475
501
var style = st ( { type : 'widget' , widget : widgetName , attributes : { 'class' : 'foo bar' } } ) ;
476
502
477
503
widget . applyStyle ( style ) ;
478
504
assert . isTrue ( widget . hasClass ( 'foo' ) , '1st class has been applied' ) ;
505
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , '1st class has been applied to the wrapper' ) ;
479
506
assert . isTrue ( widget . hasClass ( 'bar' ) , '2nd class has been applied' ) ;
507
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , '2nd class has been applied to the wrapper' ) ;
480
508
481
509
widget . addClass ( 'bom' ) ;
482
-
483
510
widget . removeStyle ( style ) ;
511
+
484
512
assert . isFalse ( widget . hasClass ( 'foo' ) , '1st class has been removed' ) ;
513
+ assert . isFalse ( wrapper . hasClass ( prefix + 'foo' ) , '1st class has been removed from the wrapper' ) ;
485
514
assert . isFalse ( widget . hasClass ( 'bar' ) , '2nd class has been removed' ) ;
515
+ assert . isFalse ( wrapper . hasClass ( prefix + 'bar' ) , '2nd class has been removed from the wrapper' ) ;
486
516
487
- assert . isTrue ( widget . hasClass ( 'bom' ) , 'unrelated class has been left' ) ;
517
+ assert . isTrue ( widget . hasClass ( 'bom' ) , 'unrelated class remains untouched' ) ;
518
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bom' ) , 'unrelated class remains untouched on the wrapper' ) ;
488
519
} ) ;
489
520
} ,
490
521
589
620
editor . widgets . add ( widgetName , { } ) ;
590
621
591
622
this . editorBot . setData ( '<p data-widget="testsetdataclasses1" id="w1">foo</p>' , function ( ) {
592
- var widget = getWidgetById ( editor , 'w1' ) ;
623
+ var widget = getWidgetById ( editor , 'w1' ) ,
624
+ wrapper = widget . wrapper ;
593
625
594
626
widget . setData ( 'classes' , { foo : 1 , bar : 1 } ) ;
595
627
596
628
assert . isTrue ( widget . hasClass ( 'foo' ) , '1 - foo' ) ;
629
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper: 1 - ' + prefix + 'foo' ) ;
597
630
assert . isTrue ( widget . hasClass ( 'bar' ) , '1 - bar' ) ;
631
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bar' ) , 'wrapper: 1 - ' + prefix + 'foo' ) ;
598
632
599
633
widget . setData ( 'classes' , { foo : 1 , bom : 1 } ) ;
600
634
601
635
assert . isTrue ( widget . hasClass ( 'foo' ) , '2 - foo' ) ;
636
+ assert . isTrue ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper: 2 - ' + prefix + 'foo' ) ;
602
637
assert . isTrue ( widget . hasClass ( 'bom' ) , '2 - bom' ) ;
638
+ assert . isTrue ( wrapper . hasClass ( prefix + 'bom' ) , 'wrapper: 2 - ' + prefix + 'bom' ) ;
603
639
assert . isFalse ( widget . hasClass ( 'bar' ) , '2 - bar' ) ;
640
+ assert . isFalse ( wrapper . hasClass ( prefix + 'bar' ) , 'wrapper: 2 - ' + prefix + 'bar' ) ;
604
641
605
642
widget . setData ( 'classes' , { } ) ;
606
643
607
644
assert . isFalse ( widget . hasClass ( 'foo' ) , '3 - foo' ) ;
645
+ assert . isFalse ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper: 3 - ' + prefix + 'foo' ) ;
608
646
assert . isFalse ( widget . hasClass ( 'bom' ) , '3 - bom' ) ;
647
+ assert . isFalse ( wrapper . hasClass ( prefix + 'bom' ) , 'wrapper: 3 - ' + prefix + 'bom' ) ;
609
648
610
649
widget . setData ( 'classes' , { foo : 1 } ) ;
611
650
widget . setData ( 'classes' , null ) ;
612
651
613
652
assert . isFalse ( widget . hasClass ( 'foo' ) , '4 - foo' ) ;
653
+ assert . isFalse ( wrapper . hasClass ( prefix + 'foo' ) , 'wrapper: 4 - ' + prefix + 'foo' ) ;
614
654
} ) ;
615
655
} ,
616
656
757
797
} ) ;
758
798
}
759
799
} ) ;
760
- } ) ( ) ;
800
+ } ) ( ) ;
0 commit comments