* @category Community Framework
*/
class AJAXProxyAction extends AbstractSecureAction {
+ /**
+ * action name
+ * @var string
+ */
+ protected $actionName = '';
+
/**
* class name
* @var string
protected $className = '';
/**
- * action name
- * @var string
+ * debug mode
+ * @var boolean
*/
- protected $actionName = '';
+ protected $inDebugMode = false;
+
+ /**
+ * object action
+ * @var wcf\data\IDatabaseObjectAction
+ */
+ protected $objectAction = null;
/**
* list of object ids
*/
protected $parameters = array();
- /**
- * object action
- * @var wcf\data\IDatabaseObjectAction
- */
- protected $objectAction = null;
-
/**
* results of the executed action
* @var mixed
$this->executed();
// send JSON-encoded response
- header('Content-type: application/json');
- echo JSON::encode($this->response);
- exit;
+ if (!$this->inDebugMode) {
+ header('Content-type: application/json');
+ echo JSON::encode($this->response);
+ exit;
+ }
}
/**
* @param \Exception $e
*/
protected function throwException(\Exception $e) {
+ if ($this->inDebugMode) {
+ throw $e;
+ }
+
if ($e instanceof IllegalLinkException) {
throw new AJAXException(WCF::getLanguage()->get('wcf.global.ajax.error.sessionExpired'), AJAXException::SESSION_EXPIRED);
}
throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString());
}
}
+
+ /**
+ * Returns action response.
+ *
+ * @return mixed
+ */
+ public function getResponse() {
+ return $this->response;
+ }
+
+ /**
+ * Enables debug mode.
+ */
+ public function enableDebugMode() {
+ $this->inDebugMode = true;
+ }
+
+ /**
+ * Performs a debug call to AJAXProxyAction, allowing testing without relying on JavaScript.
+ * The $data-array should be build like within WCF.Action.Proxy, look below for an example:
+ *
+ * $data = array(
+ * 'actionName' => 'foo',
+ * 'className' => 'wcf\foo\bar\FooBarAction',
+ * 'objectIDs' => array(1, 2, 3, 4, 5), // optional
+ * 'parameters' => array( // optional
+ * 'foo' => 'bar',
+ * 'data' => array(
+ * 'baz' => 'foobar'
+ * )
+ * )
+ * )
+ *
+ * @param array $data
+ * @param string $className
+ * @param string $actionName
+ * @return wcf\action\AJAXProxyAction
+ */
+ public static function debugCall(array $data) {
+ // validate $data array
+ if (!isset($data['actionName'])) {
+ throw new SystemException("Could not execute debug call, 'actionName' is missing.");
+ }
+ else if (!isset($data['className'])) {
+ throw new SystemException("Could not execute debug call, 'className' is missing.");
+ }
+
+ // save $_POST variables
+ $postVars = $_POST;
+
+ // fake request
+ $_POST['actionName'] = $data['actionName'];
+ $_POST['className'] = $data['className'];
+ if (isset($data['objectIDs'])) {
+ $_POST['objectIDs'] = $data['objectIDs'];
+ }
+ if (isset($data['parameters'])) {
+ $_POST['parameters'] = $data['parameters'];
+ }
+
+ // execute request
+ $actionObject = new AJAXProxyAction();
+ $actionObject->enableDebugMode();
+ $actionObject->__run();
+
+ // restore $_POST variables
+ $_POST = $postVars;
+
+ return $actionObject;
+ }
}