Commit 1105c01f authored by Mike Pretzlaw's avatar Mike Pretzlaw

#140 dispatch an url, not only routes

parent 0188c388
...@@ -1772,6 +1772,73 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test ...@@ -1772,6 +1772,73 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
); );
} }
/**
* Dispatch a request.
*
* @param $baseUrl
* @param $requestUri
* @param $urlModel
*
* @return $this
*/
protected function _dispatch($baseUrl, $requestUri, $urlModel)
{
$this->getRequest()->resetInternalProperties();
$this->getRequest()->setBaseUrl($baseUrl)
->setRequestUri($requestUri)
->setPathInfo();
$customCookies = $this->getRequest()->getCookie();
$autoCookies = $this->getCookies()->getMatchingCookies($requestUri);
/* @var $cookie Zend_Http_Cookie */
foreach ($autoCookies as $cookie)
{
$this->getRequest()->setCookie(
$cookie->getName(),
$cookie->getValue()
);
}
if ($urlModel instanceof Mage_Adminhtml_Model_Url)
{
// Workaround for secret key in admin
$this->getRequest()->setParam(
Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME,
$urlModel->getSecretKey()
);
}
if (!$this->getRequest()->getMethod())
{
$this->getRequest()->setMethod('GET');
}
// Workaround for form key
if ($this->getRequest()->isPost())
{
$this->getRequest()->setPost(
'form_key',
Mage::getSingleton('core/session')->getFormKey()
);
}
$this->getLayout()->reset();
$this->getResponse()->reset();
$this->app()->getFrontController()->dispatch();
// Unset changed cookies
$this->getRequest()->resetCookies();
$this->getRequest()->setCookies($customCookies);
return $this;
}
/** /**
* Set up controller params * Set up controller params
* (non-PHPdoc) * (non-PHPdoc)
...@@ -1941,12 +2008,32 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test ...@@ -1941,12 +2008,32 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
return $urlModel; return $urlModel;
} }
/**
* Dispatch an URL to magento.
*
* @param string $requestUri
* @param array $params
*
* @return $this
*/
public function dispatchUrl($requestUri, $params = array())
{
$urlModel = $this->getUrlModel(null, $params);
$baseUrl = $urlModel->getBaseUrl($params);
return $this->_dispatch($baseUrl, $requestUri, $urlModel);
}
/** /**
* Dispatches controller action * Dispatches a route.
* *
* *
* @param string $route * @param string $route
* @param array $params * @param array $params
*
* @return $this
*/ */
public function dispatch($route = null, array $params = array()) public function dispatch($route = null, array $params = array())
{ {
...@@ -1957,50 +2044,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test ...@@ -1957,50 +2044,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
$requestUri = $urlModel->getUrl($route, $params); $requestUri = $urlModel->getUrl($route, $params);
$baseUrl = $urlModel->getBaseUrl($params); $baseUrl = $urlModel->getBaseUrl($params);
$this->getRequest()->resetInternalProperties(); return $this->_dispatch($baseUrl, $requestUri, $urlModel);
$this->getRequest()->setBaseUrl($baseUrl)
->setRequestUri($requestUri)
->setPathInfo();
$customCookies = $this->getRequest()->getCookie();
$autoCookies = $this->getCookies()->getMatchingCookies($requestUri);
/* @var $cookie Zend_Http_Cookie */
foreach ($autoCookies as $cookie) {
$this->getRequest()->setCookie(
$cookie->getName(),
$cookie->getValue()
);
}
if ($urlModel instanceof Mage_Adminhtml_Model_Url) {
// Workaround for secret key in admin
$this->getRequest()->setParam(
Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME,
$urlModel->getSecretKey()
);
}
if (!$this->getRequest()->getMethod()) {
$this->getRequest()->setMethod('GET');
}
// Workaround for form key
if ($this->getRequest()->isPost()) {
$this->getRequest()->setPost('form_key', Mage::getSingleton('core/session')->getFormKey());
}
$this->getLayout()->reset();
$this->getResponse()->reset();
$this->app()->getFrontController()->dispatch();
// Unset changed cookies
$this->getRequest()->resetCookies();
$this->getRequest()->setCookies($customCookies);
return $this;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment