| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <title>CKEDITOR.tools</title> |
| 5 | <link rel="stylesheet" type="text/css" href="../test.css" /> |
| 6 | <script type="text/javascript" src="../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE% |
| 7 | <script type="text/javascript" src="../../ckeditor.js"></script> |
| 8 | %REMOVE_LINE% --> |
| 9 | <script type="text/javascript" src="../test.js"></script> |
| 10 | <script type="text/javascript"> |
| 11 | //<![CDATA[ |
| 12 | |
| 13 | CKEDITOR.test.addTestCase( (function() |
| 14 | { |
| 15 | // Local reference to the "assert" object. |
| 16 | var assert = CKEDITOR.test.assert; |
| 17 | |
| 18 | return { |
| 19 | |
| 20 | /** |
| 21 | * Test 'constructor' property is correctly revised after prototype inheritance. |
| 22 | */ |
| 23 | test_createClass2 : function() |
| 24 | { |
| 25 | var class0 = function(){}; |
| 26 | class0.prototype = {}; |
| 27 | var class1 = CKEDITOR.tools.createClass( { |
| 28 | $ : function(){}, |
| 29 | base : class0 |
| 30 | } ); |
| 31 | var class1Instance = new class1(); |
| 32 | assert.areSame( class1, class1Instance.constructor , |
| 33 | '"Constructor" property not correct.'); |
| 34 | }, |
| 35 | |
| 36 | /** |
| 37 | * Test private/public/static/base definitions. |
| 38 | */ |
| 39 | test_createClass3 : function() |
| 40 | { |
| 41 | // A plain old prototype based class |
| 42 | var class0 = function() |
| 43 | { |
| 44 | this._ = this._ || {}; |
| 45 | var self = this; |
| 46 | this._.private0a = function() |
| 47 | { |
| 48 | // Instance reference not available yet, test it by constructor. |
| 49 | assert.areSame( class1, self.constructor ); |
| 50 | }; |
| 51 | this._.private0a(); |
| 52 | }; |
| 53 | class0.prototype.public0a = function() |
| 54 | { |
| 55 | assert.areSame( class1Instance, this ); |
| 56 | } |
| 57 | class0.prototype.public0b = 'public'; |
| 58 | |
| 59 | // A CKEDITOR stylish base class |
| 60 | var class1 = CKEDITOR.tools.createClass( { |
| 61 | |
| 62 | base : class0, |
| 63 | |
| 64 | $ : function() |
| 65 | { |
| 66 | // Examine existance of privates |
| 67 | assert.isNotUndefined( this._, 'Private definitons unreachable in constructor.' ); |
| 68 | assert.isNotUndefined( this._.private1a, 'Private method unreachable in constructor.' ); |
| 69 | assert.isNotUndefined( this._.private1b, 'Private field unreachable in constructor.' ); |
| 70 | |
| 71 | // Examine existance of statics |
| 72 | assert.isNotUndefined( class1.static1a, 'Static method unreachable in constructor.' ); |
| 73 | assert.isNotUndefined( class1.static1b, 'Static field unreachable in constructor.' ); |
| 74 | |
| 75 | // Examine existance of publics |
| 76 | assert.isNotUndefined( this.public1a, 'Public method unreachable in constructor.' ); |
| 77 | assert.isNotUndefined( this.public1b, 'Public field unreachable in constructor.' ); |
| 78 | |
| 79 | // Examine inheirted publics |
| 80 | assert.isNotUndefined( this.public0a, 'Baseclass public method unreachable in constructor.' ); |
| 81 | assert.isNotUndefined( this.public0b, 'Baseclass public field unreachable in constructor.' ); |
| 82 | |
| 83 | // Examine base class constructor |
| 84 | assert.isNotUndefined( this.base, 'Baseclass constructor unreachable.' ); |
| 85 | this.base(); |
| 86 | }, |
| 87 | |
| 88 | privates : { |
| 89 | private1a: function() |
| 90 | { |
| 91 | assert.areSame( class1Instance, this ); |
| 92 | }, |
| 93 | private1b: 'private' |
| 94 | }, |
| 95 | |
| 96 | statics : { |
| 97 | static1a: function() |
| 98 | { |
| 99 | assert.areSame( class1, this ); |
| 100 | }, |
| 101 | static1b: 'static' |
| 102 | }, |
| 103 | |
| 104 | proto : { |
| 105 | public1a : function() |
| 106 | { |
| 107 | assert.areSame( class1Instance, this ); |
| 108 | }, |
| 109 | public1b : 'proto' |
| 110 | } |
| 111 | } ); |
| 112 | |
| 113 | var class1Instance = new class1(); |
| 114 | |
| 115 | // Test privates correctness. |
| 116 | class1Instance._.private1a(); |
| 117 | assert.areEqual( 'private', class1Instance._.private1b ); |
| 118 | |
| 119 | // Test prototypes correctness. |
| 120 | class1Instance.public1a(); |
| 121 | assert.areEqual( 'proto', class1Instance.public1b ); |
| 122 | |
| 123 | // Test statics correctness. |
| 124 | class1.static1a(); |
| 125 | assert.areEqual( 'static', class1.static1b ); |
| 126 | |
| 127 | // Test inheirted publics correctness. |
| 128 | class1Instance.public0a(); |
| 129 | assert.areEqual( 'public', class1Instance.public0b ); |
| 130 | |
| 131 | }, |
| 132 | |
| 133 | /** |
| 134 | * Test base class chainability. |
| 135 | */ |
| 136 | test_createClass4 : function() |
| 137 | { |
| 138 | var counter = 0; |
| 139 | |
| 140 | // Different constructor is reinforced. |
| 141 | function getContructor(){ |
| 142 | |
| 143 | return function() |
| 144 | { |
| 145 | counter ++; |
| 146 | assert.areSame( class2, this.constructor ); |
| 147 | if ( this.base ) |
| 148 | this.base(); |
| 149 | }; |
| 150 | } |
| 151 | |
| 152 | var class0 = CKEDITOR.tools.createClass({ |
| 153 | $ : getContructor() |
| 154 | }), |
| 155 | class1 = CKEDITOR.tools.createClass({ |
| 156 | $ : getContructor(), |
| 157 | base : class0 |
| 158 | }), |
| 159 | class2 = CKEDITOR.tools.createClass({ |
| 160 | $ : getContructor(), |
| 161 | base : class1 |
| 162 | }); |
| 163 | |
| 164 | new class2(); |
| 165 | assert.areEqual( 3, counter ); |
| 166 | }, |
| 167 | |
| 168 | name : document.title |
| 169 | }; |
| 170 | })() ); |
| 171 | |
| 172 | //]]> |
| 173 | </script> |
| 174 | </head> |
| 175 | <body> |
| 176 | <iframe></iframe> |
| 177 | </body> |
| 178 | </html> |