1
/* Copyright (c) 2009, Canonical Ltd. All rights reserved. */
3
YUI.add('lazr.testing.mockio', function(Y) {
5
* A utility module for use in YUI unit-tests with a helper for mocking Y.io.
9
var MockIo = function() {
14
/* Save the Y.io() arguments. */
15
MockIo.prototype.io = function(uri, cfg) {
18
return this; // Usually this isn't used, except for logging.
21
/* Simulate the Xhr request/response cycle. */
22
MockIo.prototype.simulateXhr = function(response, is_failure) {
24
var context = cfg.context || this;
25
var args = cfg.arguments;
31
// See the Y.io utility documentation for the signatures.
33
cfg.on.start.call(context, tId, args);
35
if (cfg.on.complete) {
36
cfg.on.complete.call(context, tId, response, args);
38
if (cfg.on.success && !is_failure) {
39
cfg.on.success.call(context, tId, response, args);
41
if (cfg.on.failure && is_failure) {
42
cfg.on.failure.call(context, tId, response, args);
46
/* Make a successful XHR response object. */
47
MockIo.makeXhrSuccessResponse = function(responseText) {
48
var text = responseText || "";
56
/* Make a failed XHR response object. */
57
MockIo.makeXhrFailureResponse = function(responseText) {
58
var text = responseText || "";
61
statusText: "Internal Server Error",
66
Y.namespace("lazr.testing");
67
Y.lazr.testing.MockIo = MockIo;