8
0

tools.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. ( () => {
  7. bender.tools.core = {
  8. /**
  9. * Defines CKEditor plugin which is a mock of an editor creator.
  10. *
  11. * If `proto` is not set or it does not define `create()` and `destroy()` methods,
  12. * then they will be set to Sinon spies. Therefore the shortest usage is:
  13. *
  14. * bender.tools.defineEditorCreatorMock( 'test1' );
  15. *
  16. * The mocked creator is available under:
  17. *
  18. * editor.plugins.get( 'creator-thename' );
  19. *
  20. * @param {String} creatorName Name of the creator.
  21. * @param {Object} [proto] Prototype of the creator. Properties from the proto param will
  22. * be copied to the prototype of the creator.
  23. */
  24. defineEditorCreatorMock: ( creatorName, proto ) => {
  25. CKEDITOR.define( 'plugin!creator-' + creatorName, [ 'creator' ], ( Creator ) => {
  26. return mockCreator( Creator );
  27. } );
  28. function mockCreator( Creator ) {
  29. class TestCreator extends Creator {}
  30. if ( proto ) {
  31. for ( let propName in proto ) {
  32. TestCreator.prototype[ propName ] = proto[ propName ];
  33. }
  34. }
  35. if ( !TestCreator.prototype.create ) {
  36. TestCreator.prototype.create = sinon.spy().named( creatorName + '-create' );
  37. }
  38. if ( !TestCreator.prototype.destroy ) {
  39. TestCreator.prototype.destroy = sinon.spy().named( creatorName + '-destroy' );
  40. }
  41. return TestCreator;
  42. }
  43. }
  44. };
  45. } )();