Changeset 9036
- Timestamp:
- 03/16/08 18:53:51 (7 months ago)
- Files:
-
- spinoffs/prototype/trunk/CHANGELOG (modified) (1 diff)
- spinoffs/prototype/trunk/ext/update_helper/prototype_update_helper.html (modified) (2 diffs)
- spinoffs/prototype/trunk/test/unit/ajax.html (modified) (17 diffs)
- spinoffs/prototype/trunk/test/unit/array.html (modified) (2 diffs)
- spinoffs/prototype/trunk/test/unit/base.html (modified) (10 diffs)
- spinoffs/prototype/trunk/test/unit/dom.html (modified) (17 diffs)
- spinoffs/prototype/trunk/test/unit/element_mixins.html (modified) (2 diffs)
- spinoffs/prototype/trunk/test/unit/enumerable.html (modified) (5 diffs)
- spinoffs/prototype/trunk/test/unit/event.html (modified) (8 diffs)
- spinoffs/prototype/trunk/test/unit/form.html (modified) (10 diffs)
- spinoffs/prototype/trunk/test/unit/hash.html (modified) (2 diffs)
- spinoffs/prototype/trunk/test/unit/number.html (modified) (1 diff)
- spinoffs/prototype/trunk/test/unit/position.html (modified) (1 diff)
- spinoffs/prototype/trunk/test/unit/range.html (modified) (3 diffs)
- spinoffs/prototype/trunk/test/unit/selector.html (modified) (2 diffs)
- spinoffs/prototype/trunk/test/unit/string.html (modified) (7 diffs)
- spinoffs/prototype/trunk/test/unit/unit_tests.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/trunk/CHANGELOG
r9026 r9036 1 * Remove usage of the `with` statement from unit tests. [Tobie Langel] 2 1 3 * Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel] 2 4 spinoffs/prototype/trunk/ext/update_helper/prototype_update_helper.html
r9026 r9036 77 77 78 78 new Test.Unit.Runner({ 79 testGetStack: function() { with(this){80 assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());81 } },82 83 testDisplay: function() { with(this){79 testGetStack: function() { 80 this.assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack()); 81 }, 82 83 testDisplay: function() { 84 84 Toggle.display('foo'); 85 assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');85 this.assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.'); 86 86 87 87 Element.show('foo', 'bar', 'bla'); 88 assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +88 this.assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' + 89 89 'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.'); 90 90 91 91 $('foo', 'bar', 'bla').each(Element.hide); 92 assertNotNotified();92 this.assertNotNotified(); 93 93 94 94 Element.show('foo'); 95 assertNotNotified();95 this.assertNotNotified(); 96 96 97 97 Element.hide('foo', 'bar', 'bla'); 98 assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +98 this.assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' + 99 99 'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.'); 100 100 101 101 Element.toggle('foo', 'bar', 'bla'); 102 assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +102 this.assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' + 103 103 'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.'); 104 } },105 106 testElementStyle: function() { with(this){104 }, 105 106 testElementStyle: function() { 107 107 Element.setStyle('foo', { 'fontSize': '18px' }); 108 assertNotNotified();108 this.assertNotNotified(); 109 109 110 110 Element.setStyle('foo', { 'font-size': '18px' }); 111 assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +111 this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + 112 112 'Use either camelized style-property names or a regular CSS string instead (see online documentation).') 113 113 114 114 Element.setStyle('foo', 'font-size: 18px;'); 115 assertNotNotified();115 this.assertNotNotified(); 116 116 117 117 $('foo').setStyle({ 'font-size': '18px' }); 118 assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +118 this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' + 119 119 'Use either camelized style-property names or a regular CSS string instead (see online documentation).') 120 } },121 122 testClassNames: function() { with(this){120 }, 121 122 testClassNames: function() { 123 123 new Element.ClassNames('foo'); 124 assertInfoNotified('Element.ClassNames has been deprecated.')124 this.assertInfoNotified('Element.ClassNames has been deprecated.') 125 125 126 126 $('foo').classNames(); 127 assertInfoNotified('Element#classNames has been deprecated.\n' +127 this.assertInfoNotified('Element#classNames has been deprecated.\n' + 128 128 'If you need to access CSS class names as an array, try: $w(element.classname).') 129 129 130 130 Element.getElementsByClassName('foo', 'className'); 131 assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')131 this.assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.') 132 132 133 133 document.getElementsByClassName('className'); 134 assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')135 } },136 137 testDomSelectors: function() { with(this){134 this.assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.') 135 }, 136 137 testDomSelectors: function() { 138 138 Element.childOf('foo', 'bar'); 139 assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');139 this.assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.'); 140 140 141 141 $('foo').immediateDescendants(); 142 assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');142 this.assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.'); 143 143 144 144 $('foo').getElementsBySelector('a'); 145 assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');145 this.assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.'); 146 146 147 147 $('foo').select('a'); 148 assertNotNotified();149 } },150 151 testField: function() { with(this){148 this.assertNotNotified(); 149 }, 150 151 testField: function() { 152 152 Field.clear('foo', 'bar', 'bla'); 153 assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +153 this.assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' + 154 154 'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.'); 155 155 156 156 Field.present('foo', 'bar', 'bla'); 157 assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +157 this.assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' + 158 158 'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.'); 159 } },160 161 testInsertion: function() { with(this){159 }, 160 161 testInsertion: function() { 162 162 Insertion.Before('foo', 'text'); 163 assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');163 this.assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.'); 164 164 165 165 Insertion.Top('foo', 'text'); 166 assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');166 this.assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.'); 167 167 168 168 Insertion.Bottom('foo', 'text'); 169 assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');169 this.assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.'); 170 170 171 171 Insertion.After('foo', 'text'); 172 assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');173 } },174 175 testPosition: function() { with(this){172 this.assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.'); 173 }, 174 175 testPosition: function() { 176 176 Position.prepare('foo'); 177 assertInfoNotified('Position.prepare has been deprecated.');177 this.assertInfoNotified('Position.prepare has been deprecated.'); 178 178 179 179 Position.within('foo'); 180 assertInfoNotified('Position.within has been deprecated.');180 this.assertInfoNotified('Position.within has been deprecated.'); 181 181 182 182 Position.withinIncludingScrolloffsets('foo'); 183 assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');183 this.assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.'); 184 184 185 185 Position.overlap('foo'); 186 assertInfoNotified('Position.overlap has been deprecated.');186 this.assertInfoNotified('Position.overlap has been deprecated.'); 187 187 188 188 Position.cumulativeOffset('foo'); 189 assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');189 this.assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.'); 190 190 191 191 Position.positionedOffset('foo'); 192 assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');192 this.assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.'); 193 193 194 194 Position.absolutize('foo'); 195 assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');195 this.assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.'); 196 196 197 197 Position.relativize('foo'); 198 assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');198 this.assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.'); 199 199 200 200 Position.realOffset('foo'); 201 assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');201 this.assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.'); 202 202 203 203 Position.offsetParent('foo'); 204 assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');204 this.assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.'); 205 205 206 206 Position.page('foo'); 207 assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');207 this.assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.'); 208 208 209 209 Position.clone('foo', 'bar'); 210 assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');211 } },212 213 testEvent: function() { with(this){210 this.assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.'); 211 }, 212 213 testEvent: function() { 214 214 Event.unloadCache(); 215 assertErrorNotified('Event.unloadCache has been deprecated.')216 } },217 218 testHash: function() { with(this){215 this.assertErrorNotified('Event.unloadCache has been deprecated.') 216 }, 217 218 testHash: function() { 219 219 Hash.toQueryString({}); 220 assertInfoNotified('Hash.toQueryString has been deprecated.\n' +220 this.assertInfoNotified('Hash.toQueryString has been deprecated.\n' + 221 221 'Use the instance method Hash#toQueryString or Object.toQueryString instead.'); 222 222 223 223 Hash.toJSON({}); 224 assertErrorNotified('Hash.toJSON has been removed.\n' +224 this.assertErrorNotified('Hash.toJSON has been removed.\n' + 225 225 'Use the instance method Hash#toJSON or Object.toJSON instead.'); 226 226 … … 228 228 229 229 h.remove('foo'); 230 assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +230 this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + 231 231 'Please note that Hash#unset only accepts one argument.'); 232 232 233 233 h.merge('foo'); 234 assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');234 this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); 235 235 236 236 h['foo']; 237 assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +237 this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + 238 238 'Please use Hash#get(\'foo\') instead.') 239 239 240 240 h.foo = 3; 241 assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +241 this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 242 242 'Please use Hash#set(\'foo\', 3) instead.') 243 243 244 244 h.bar = 'bar'; 245 245 h.toJSON(); 246 assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +246 this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 247 247 'Please use Hash#set(\'bar\', \'bar\') instead.') 248 248 249 249 h.bar; 250 assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +250 this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' + 251 251 'Please use Hash#get(\'bar\') instead.') 252 252 253 253 h.baz = 'baz'; 254 254 h.bar; 255 assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +255 this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' + 256 256 'Please use Hash#set(\'baz\', \'baz\') instead.') 257 257 258 258 h.set('toJSON', 'arg'); // make sure hash methods are not overwritten 259 assertRespondsTo('toJSON', h)260 } },261 262 testClass: function() { with(this){259 this.assertRespondsTo('toJSON', h) 260 }, 261 262 testClass: function() { 263 263 Class.create(); 264 assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +264 this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' + 265 265 'You can find more about it here: http://prototypejs.org/learn/class-inheritance'); 266 266 Class.create({}); 267 assertNotNotified();268 } },269 270 testLogDeprecationOption: function() { with(this){267 this.assertNotNotified(); 268 }, 269 270 testLogDeprecationOption: function() { 271 271 prototypeUpdateHelper.logLevel = UpdateHelper.Warn; 272 272 var h = $H({ foo: 2 }); 273 273 274 274 h.merge({ foo: 3 }); 275 assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');275 this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.'); 276 276 277 277 h.remove('foo'); 278 assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +278 this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' + 279 279 'Please note that Hash#unset only accepts one argument.'); 280 280 281 281 document.getElementsByClassName('className'); 282 assertNotNotified();282 this.assertNotNotified(); 283 283 prototypeUpdateHelper.logLevel = UpdateHelper.Info; 284 } }284 } 285 285 }); 286 286 spinoffs/prototype/trunk/test/unit/ajax.html
r8693 r9036 82 82 83 83 new Test.Unit.Runner({ 84 setup: function() {84 setup: function() { 85 85 $('content').update(''); 86 86 $('content2').update(''); 87 87 }, 88 88 89 teardown: function() {89 teardown: function() { 90 90 // hack to cleanup responders 91 91 Ajax.Responders.responders = [Ajax.Responders.responders[0]]; 92 92 }, 93 93 94 testSynchronousRequest: function() { with(this) {95 assertEqual("", $("content").innerHTML);96 97 assertEqual(0, Ajax.activeRequestCount);94 testSynchronousRequest: function() { 95 this.assertEqual("", $("content").innerHTML); 96 97 this.assertEqual(0, Ajax.activeRequestCount); 98 98 new Ajax.Request("fixtures/hello.js", { 99 99 asynchronous: false, … … 101 101 evalJS: 'force' 102 102 }); 103 assertEqual(0, Ajax.activeRequestCount);103 this.assertEqual(0, Ajax.activeRequestCount); 104 104 105 105 var h2 = $("content").firstChild; 106 assertEqual("Hello world!", h2.innerHTML);107 } },108 109 testAsynchronousRequest: function() { with(this) {110 assertEqual("", $("content").innerHTML);106 this.assertEqual("Hello world!", h2.innerHTML); 107 }, 108 109 testAsynchronousRequest: function() { 110 this.assertEqual("", $("content").innerHTML); 111 111 112 112 new Ajax.Request("fixtures/hello.js", { … … 115 115 evalJS: 'force' 116 116 }); 117 wait(1000, function() {117 this.wait(1000, function() { 118 118 var h2 = $("content").firstChild; 119 assertEqual("Hello world!", h2.innerHTML);120 }); 121 } },122 123 testUpdater: function() { with(this) {124 assertEqual("", $("content").innerHTML);119 this.assertEqual("Hello world!", h2.innerHTML); 120 }); 121 }, 122 123 testUpdater: function() { 124 this.assertEqual("", $("content").innerHTML); 125 125 126 126 new Ajax.Updater("content", "fixtures/content.html", { method:'get' }); 127 127 128 wait(1000, function() {129 assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());128 this.wait(1000, function() { 129 this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 130 130 131 131 $('content').update(''); 132 assertEqual("", $("content").innerHTML);132 this.assertEqual("", $("content").innerHTML); 133 133 134 134 new Ajax.Updater({ success:"content", failure:"content2" }, … … 137 137 new Ajax.Updater("", "fixtures/content.html", { method:'get', parameters:"pet=monkey" }); 138 138 139 wait(1000, function() {140 assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());141 assertEqual("", $("content2").innerHTML);139 this.wait(1000, function() { 140 this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 141 this.assertEqual("", $("content2").innerHTML); 142 142 }); 143 143 }); 144 } },145 146 testUpdaterWithInsertion: function() { with(this) {144 }, 145 146 testUpdaterWithInsertion: function() { 147 147 $('content').update(); 148 148 new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: Insertion.Top }); 149 wait(1000, function() {150 assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());149 this.wait(1000, function() { 150 this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 151 151 $('content').update(); 152 152 new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'bottom' }); 153 wait(1000, function() {154 assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());153 this.wait(1000, function() { 154 this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); 155 155 156 156 $('content').update(); 157 157 new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'after' }); 158 wait(1000, function() {159 assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());158 this.wait(1000, function() { 159 this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase()); 160 160 }); 161 161 }); 162 162 }); 163 } },164 165 testUpdaterOptions: function() { with(this) {163 }, 164 165 testUpdaterOptions: function() { 166 166 var options = { 167 167 method: 'get', … … 172 172 var request = new Ajax.Updater("content", "fixtures/hello.js", options); 173 173 request.options.onComplete = function() {}; 174 assertIdentical(Prototype.emptyFunction, options.onComplete);175 } },176 177 testResponders: function(){ with(this) {174 this.assertIdentical(Prototype.emptyFunction, options.onComplete); 175 }, 176 177 testResponders: function(){ 178 178 // check for internal responder 179 assertEqual(1, Ajax.Responders.responders.length);179 this.assertEqual(1, Ajax.Responders.responders.length); 180 180 181 181 var dummyResponder = { … … 184 184 185 185 Ajax.Responders.register(dummyResponder); 186 assertEqual(2, Ajax.Responders.responders.length);186 this.assertEqual(2, Ajax.Responders.responders.length); 187 187 188 188 // don't add twice 189 189 Ajax.Responders.register(dummyResponder); 190 assertEqual(2, Ajax.Responders.responders.length);190 this.assertEqual(2, Ajax.Responders.responders.length); 191 191 192 192 Ajax.Responders.unregister(dummyResponder); 193 assertEqual(1, Ajax.Responders.responders.length);193 this.assertEqual(1, Ajax.Responders.responders.length); 194 194 195 195 var responder = { … … 200 200 Ajax.Responders.register(responder); 201 201 202 assertEqual(0, responderCounter);203 assertEqual(0, Ajax.activeRequestCount);202 this.assertEqual(0, responderCounter); 203 this.assertEqual(0, Ajax.activeRequestCount); 204 204 new Ajax.Request("fixtures/content.html", { method:'get', parameters:"pet=monkey" }); 205 assertEqual(1, responderCounter);206 assertEqual(1, Ajax.activeRequestCount);207 208 wait(1000,function() {209 assertEqual(3, responderCounter);210 assertEqual(0, Ajax.activeRequestCount);211 }); 212 } },213 214 testEvalResponseShouldBeCalledBeforeOnComplete: function() { with(this) {215 if ( isRunningFromRake) {216 assertEqual("", $("content").innerHTML);217 218 assertEqual(0, Ajax.activeRequestCount);205 this.assertEqual(1, responderCounter); 206 this.assertEqual(1, Ajax.activeRequestCount); 207 208 this.wait(1000,function() { 209 this.assertEqual(3, responderCounter); 210 this.assertEqual(0, Ajax.activeRequestCount); 211 }); 212 }, 213 214 testEvalResponseShouldBeCalledBeforeOnComplete: function() { 215 if (this.isRunningFromRake) { 216 this.assertEqual("", $("content").innerHTML); 217 218 this.assertEqual(0, Ajax.activeRequestCount); 219 219 new Ajax.Request("fixtures/hello.js", extendDefault({ 220 onComplete: function(response) { assertNotEqual("", $("content").innerHTML) }221 })); 222 assertEqual(0, Ajax.activeRequestCount);220 onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this) 221 })); 222 this.assertEqual(0, Ajax.activeRequestCount); 223 223 224 224 var h2 = $("content").firstChild; 225 assertEqual("Hello world!", h2.innerHTML);226 } else { 227 info(message);228 } 229 } },230 231 testContentTypeSetForSimulatedVerbs: function() { with(this) {232 if ( isRunningFromRake) {225 this.assertEqual("Hello world!", h2.innerHTML); 226 } else { 227 this.info(message); 228 } 229 }, 230 231 testContentTypeSetForSimulatedVerbs: function() { 232 if (this.isRunningFromRake) { 233 233 new Ajax.Request('/inspect', extendDefault({ 234 234 method: 'put', 235 235 contentType: 'application/bogus', 236 236 onComplete: function(response) { 237 assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);238 } 239 })); 240 } else { 241 info(message);242 } 243 } },244 245 testOnCreateCallback: function() { with(this) {237 this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); 238 }.bind(this) 239 })); 240 } else { 241 this.info(message); 242 } 243 }, 244 245 testOnCreateCallback: function() { 246 246 new Ajax.Request("fixtures/content.html", extendDefault({ 247 onCreate: function(transport) { assertEqual(0, transport.readyState) },248 onComplete: function(transport) { assertNotEqual(0, transport.readyState) }247 onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this), 248 onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this) 249 249 })); 250 } },251 252 testEvalJS: function() { with(this) {253 if ( isRunningFromRake) {250 }, 251 252 testEvalJS: function() { 253 if (this.isRunningFromRake) { 254 254 255 255 $('content').update(); … … 258 258 onComplete: function(transport) { 259 259 var h2 = $("content").firstChild; 260 assertEqual("Hello world!", h2.innerHTML);261 } 260 this.assertEqual("Hello world!", h2.innerHTML); 261 }.bind(this) 262 262 })); 263 263 … … 267 267 parameters: Fixtures.js, 268 268 onComplete: function(transport) { 269 assertEqual("", $("content").innerHTML);270 } 271 })); 272 } else { 273 info(message);269 this.assertEqual("", $("content").innerHTML); 270 }.bind(this) 271 })); 272 } else { 273 this.info(message); 274 274 } 275 275 … … 279 279 onComplete: function(transport) { 280 280 var h2 = $("content").firstChild; 281 assertEqual("Hello world!", h2.innerHTML);282 } 281 this.assertEqual("Hello world!", h2.innerHTML); 282 }.bind(this) 283 283 })); 284 } },285 286 testCallbacks: function() { with(this) {284 }, 285 286 testCallbacks: function() { 287 287 var options = extendDefault({ 288 onCreate: function(transport) { assertInstanceOf(Ajax.Response, transport) }288 onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this) 289 289 }); 290 290 … … 294 294 295 295 new Ajax.Request("fixtures/content.html", options); 296 } },297 298 testResponseText: function() { with(this) {296 }, 297 298 testResponseText: function() { 299 299 new Ajax.Request("fixtures/empty.html", extendDefault({ 300 onComplete: function(transport) { assertEqual('', transport.responseText) }300 onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this) 301 301 })); 302 302 303 303 new Ajax.Request("fixtures/content.html", extendDefault({ 304 onComplete: function(transport) { assertEqual(sentence, transport.responseText.toLowerCase()) }304 onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this) 305 305 })); 306 } },307 308 testResponseXML: function() { with(this) {309 if ( isRunningFromRake) {306 }, 307 308 testResponseXML: function() { 309 if (this.isRunningFromRake) { 310 310 new Ajax.Request("/response", extendDefault({ 311 311 parameters: Fixtures.xml, 312 312 onComplete: function(transport) { 313 assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))314 } 315 })); 316 } else { 317 info(message);318 } 319 } },320 321 testResponseJSON: function() { with(this) {322 if ( isRunningFromRake) {313 this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) 314 }.bind(this) 315 })); 316 } else { 317 this.info(message); 318 } 319 }, 320 321 testResponseJSON: function() { 322 if (this.isRunningFromRake) { 323 323 new Ajax.Request("/response", extendDefault({ 324 324 parameters: Fixtures.json, 325 onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) }325 onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) 326 326 })); 327 327 … … 331 331 'Content-Type': 'application/json' 332 332 }, 333 onComplete: function(transport) { assertNull(transport.responseJSON) }333 onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 334 334 })); 335 335 … … 337 337 evalJSON: false, 338 338 parameters: Fixtures.json, 339 onComplete: function(transport) { assertNull(transport.responseJSON) }339 onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 340 340 })); 341 341 342 342 new Ajax.Request("/response", extendDefault({ 343 343 parameters: Fixtures.jsonWithoutContentType, 344 onComplete: function(transport) { assertNull(transport.responseJSON) }344 onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) 345 345 })); 346 346 … … 349 349 parameters: Fixtures.invalidJson, 350 350 onException: function(request, error) { 351 assert(error.message.include('Badly formed JSON string'));352 assertInstanceOf(Ajax.Request, request);353 } 354 })); 355 } else { 356 info(message);351 this.assert(error.message.include('Badly formed JSON string')); 352 this.assertInstanceOf(Ajax.Request, request); 353 }.bind(this) 354 })); 355 } else { 356 this.info(message); 357 357 } 358 358 359 359 new Ajax.Request("fixtures/data.json", extendDefault({ 360 360 evalJSON: 'force', 361 onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) }361 onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) 362 362 })); 363 } },364 365 testHeaderJSON: function() { with(this) {366 if ( isRunningFromRake) {363 }, 364 365 testHeaderJSON: function() { 366 if (this.isRunningFromRake) { 367 367 new Ajax.Request("/response", extendDefault({ 368 368 parameters: Fixtures.headerJson, 369 369 onComplete: function(transport, json) { 370 assertEqual('hello #éà ', transport.headerJSON.test);371 assertEqual('hello #éà ', json.test);372 } 370 this.assertEqual('hello #éà ', transport.headerJSON.test); 371 this.assertEqual('hello #éà ', json.test); 372 }.bind(this) 373 373 })); 374 374 375 375 new Ajax.Request("/response", extendDefault({ 376 376 onComplete: function(transport, json) { 377 assertNull(transport.headerJSON)378 assertNull(json)379 } 380 })); 381 } else { 382 info(message);383 } 384 } },385 386 testGetHeader: function() { with(this) {387 if ( isRunningFromRake) {377 this.assertNull(transport.headerJSON) 378 this.assertNull(json) 379 }.bind(this) 380 })); 381 } else { 382 this.info(message); 383 } 384 }, 385 386 testGetHeader: function() { 387 if (this.isRunningFromRake) { 388 388 new Ajax.Request("/response", extendDefault({ 389 389 parameters: { 'X-TEST': 'some value' }, 390 390 onComplete: function(transport) { 391 assertEqual('some value', transport.getHeader('X-Test'));392 assertNull(transport.getHeader('X-Inexistant'));393 } 394 })); 395 } else { 396 info(message);397 } 398 } },399 400 testParametersCanBeHash: function() { with(this) {401 if ( isRunningFromRake) {391 this.assertEqual('some value', transport.getHeader('X-Test')); 392 this.assertNull(transport.getHeader('X-Inexistant')); 393 }.bind(this) 394 })); 395 } else { 396 this.info(message); 397 } 398 }, 399 400 testParametersCanBeHash: function() { 401 if (this.isRunningFromRake) { 402 402 new Ajax.Request("/response", extendDefault({ 403 403 parameters: $H({ "one": "two", "three": "four" }), 404 404 onComplete: function(transport) { 405 assertEqual("two", transport.getHeader("one"));406 assertEqual("four", transport.getHeader("three"));407 assertNull(transport.getHeader("toObject"));408 } 409 })); 410 } else { 411 info(message);412 } 413 } },414 415 testIsSameOriginMethod: function() { with(this) {405 this.assertEqual("two", transport.getHeader("one")); 406 this.assertEqual("four", transport.getHeader("three")); 407 this.assertNull(transport.getHeader("toObject")); 408 }.bind(this) 409 })); 410 } else { 411 this.info(message); 412 } 413 }, 414 415 testIsSameOriginMethod: function() { 416 416 var isSameOrigin = Ajax.Request.prototype.isSameOrigin; 417 assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');418 assert(isSameOrigin.call({ url: window.location.toString() }), window.location);419 assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');420 421 if ( isRunningFromRake) {417 this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); 418 this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location); 419 this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); 420 421 if (this.isRunningFromRake) { 422 422 Ajax.Request.prototype.isSameOrigin = function() { 423 423 return false … … 428 428 parameters: Fixtures.js, 429 429 onComplete: function(transport) { 430 assertEqual("same origin policy", $("content").innerHTML);431 } 430 this.assertEqual("same origin policy", $("content").innerHTML); 431 }.bind(this) 432 432 })); 433 433 … … 435 435 parameters: Fixtures.invalidJson, 436 436 onException: function(request, error) { 437 assert(error.message.include('Badly formed JSON string'));438 } 437 this.assert(error.message.include('Badly formed JSON string')); 438 }.bind(this) 439 439 })); 440 440 … … 442 442 parameters: { 'X-JSON': '{});window.attacked = true;({}' }, 443 443 onException: function(request, error) { 444 assert(error.message.include('Badly formed JSON string'));445 } 444 this.assert(error.message.include('Badly formed JSON string')); 445 }.bind(this) 446 446 })); 447 447 448 448 Ajax.Request.prototype.isSameOrigin = isSameOrigin; 449 449 } else { 450 info(message);451 } 452 } }450 this.info(message); 451 } 452 } 453 453 }); 454 454 // ]]> spinoffs/prototype/trunk/test/unit/array.html
r8572 r9036 33 33 34 34 new Test.Unit.Runner({ 35 test$A: function(){ with(this) {36 assertEnumEqual([], $A({}));37 } },38 39 testToArrayOnArguments: function(){ with(this) {35 test$A: function(){ 36 this.assertEnumEqual([], $A({})); 37 }, 38 39 testToArrayOnArguments: function(){ 40 40 function toArrayOnArguments(){ 41 41 globalArgsTest = $A(arguments); 42 42 } 43 43 toArrayOnArguments(); 44 assertEnumEqual([], globalArgsTest);44 this.assertEnumEqual([], globalArgsTest); 45 45 toArrayOnArguments('foo'); 46 assertEnumEqual(['foo'], globalArgsTest);46 this.assertEnumEqual(['foo'], globalArgsTest); 47 47 toArrayOnArguments('foo','bar'); 48 assertEnumEqual(['foo','bar'], globalArgsTest);49 } },50 51 testToArrayOnNodeList: function(){ with(this) {48 this.assertEnumEqual(['foo','bar'], globalArgsTest);