Topic: new flag for php debugging and automated webtest

When debugging the php code or running automated webtests it is not handy to work in asynchronous mode.
A general article about ajax and webtest I read somewhere (possibly ajaxian.com) proposed to introduce a global variable to generally switch into synchronous mode when debugging or testing.
I tried that with the xajax 0.5 and it worked out quite good.

Therefore I propose to add another flag (e.g. defaultModeAsynchronous) to xajax.

Here is what I did:

xajax.inc.php:
1) new member variable

    /**
     * @var boolean this will set the defaultMode (default true -> 'asynchronous')
     */
    var $bDefaultModeAsynchronous;

2) Modified constructor to set default

    function xajax($sRequestURI='')
    {
                ....
        $this->setFlags(array(
                        .....
            'allowBlankResponse' => false,
            'defaultModeAsynchronous'  => true,
            'allowAllResponseTypes' => false));
                ....
         }

xajaxDefaultIncludePlugin.inc.php:
3) Write the value into the javascript code

     function getJavascriptConfig()
     {
                 ...
        $html .= "\t\txajax.config.defaultMode = ".($this->_objXajax->getFlag('defaultModeAsynchronous')?'\'asynchronous\'':'\'synchronous\'').";\n";        
                ....
        }

xajax_core.js:
4) Use the config value as default instead of hardcoded asynchronous

xajax.submitRequest = function(requestType, sFunction, uri, parameters, objOptions) {
    var r = xajax.tools.getRequestObject();
    if (null == r) 
        return false;
        
    var mode = xajax.config.defaultMode; // was var mode = 'asynchronous';
        ....
}

With this tiny modifications one can easily switch to a debugger/webtest friendly mode by simply setting a flag:

$xajax->setFlag("defaultModeAsynchronous", false);

Hope you like it :-)
Please comment if I missed something.

ralf

Re: new flag for php debugging and automated webtest

ralf,

Great idea.  In fact, as of beta 2, the javascript side of xajax already has the defaultMode config variable.  Before xajax 0.5 release, the PHP side will need to get caught up.

I'll use your list above to update the PHP code for the beta 3 release.

Thanks!

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct