Issues

ZF-8444: AjaxContext always calls isXmlHttpRequest(), which may result in a fatal error | Fix sponsored by Enrise - www.enrise.com

Description

I have a controller with actions for normal webpages, AJAX callbacks and CLI calls. The AjaxContext helper is used for the AJAX callbacks. The CLI frontcontroller uses Zend_Controller_Request_Simple instead of Zend_Controller_Request_Http.

Now if I call the controller from CLI I get:

Fatal error: Call to undefined method Zend_Controller_Request_Simple::isXmlHttpRequest() in /.../Zend/Controller/Action/Helper/AjaxContext.php on line 71

AjaxContext should either check if the method is implemented or isXmlHttpRequest() needs to be added to Zend_Controller_Request_Abstract.

Comments

To this case I usually using Zend_Controller_Request_HttpTestCase.

Confirmed. Will fix asap.

Will commit later today (or tomorrow).

Diff:

Index: tests/Zend/Controller/Action/Helper/AjaxContextTest.php

--- tests/Zend/Controller/Action/Helper/AjaxContextTest.php (revision 24040) +++ tests/Zend/Controller/Action/Helper/AjaxContextTest.php (working copy) @@ -32,6 +32,7 @@ require_once 'Zend/Controller/Action/HelperBroker.php'; require_once 'Zend/Controller/Front.php'; require_once 'Zend/Controller/Request/Http.php'; +require_once 'Zend/Controller/Request/Simple.php'; require_once 'Zend/Controller/Response/Cli.php'; require_once 'Zend/Layout.php'; require_once 'Zend/View.php'; @@ -197,6 +198,25 @@ $this->helper->initContext(); $this->assertNull($this->helper->getCurrentContext()); } + + /** + * @group ZF-8444 + */ + public function testAjaxContextIsRequestDependent() + { + $request = new Zend_Controller_Request_Simple(); + $helper = new Zend_Controller_Action_Helper_AjaxContext(); + + $helper->setActionController( + new Zend_Controller_Action_Helper_AjaxContextTestController( + $request, + $this->response, + array() + ) + ); + + $helper->initContext(); $this->assertTrue(true); // This will fatal error if it's wrong + } }

class Zend_Controller_Action_Helper_AjaxContextTestController extends Zend_Controller_Action

Index: library/Zend/Controller/Action/Helper/AjaxContext.php

--- library/Zend/Controller/Action/Helper/AjaxContext.php (revision 24040) +++ library/Zend/Controller/Action/Helper/AjaxContext.php (working copy) @@ -68,7 +68,10 @@ { $this->_currentContext = null;

  • if (!$this->getRequest()->isXmlHttpRequest()) {
  • $request = $this->getRequest();
  • if (!method_exists($request, 'isXmlHttpRequest') ||
  • !$this->getRequest()->isXmlHttpRequest())
  • { return; }

Committed in r24130. Merged in r24131 with release 1.11 branch. Will be released in next mini release.