Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit afa7292

Browse files
committed
Merge branch 'dev' of github.com:EcomDev/EcomDev_PHPUnit into dev
2 parents 8f559cb + 285ce6e commit afa7292

File tree

1 file changed

+90
-46
lines changed

1 file changed

+90
-46
lines changed

app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php

Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,73 @@ public static function assertLayoutBlockPropertyNotNull($blockName, $propertyNam
17721772
);
17731773
}
17741774

1775+
1776+
/**
1777+
* Dispatch a request.
1778+
*
1779+
* @param $baseUrl
1780+
* @param $requestUri
1781+
* @param $urlModel
1782+
*
1783+
* @return $this
1784+
*/
1785+
protected function _dispatch($baseUrl, $requestUri, $urlModel)
1786+
{
1787+
$this->getRequest()->resetInternalProperties();
1788+
1789+
$this->getRequest()->setBaseUrl($baseUrl)
1790+
->setRequestUri($requestUri)
1791+
->setPathInfo();
1792+
1793+
$customCookies = $this->getRequest()->getCookie();
1794+
1795+
$autoCookies = $this->getCookies()->getMatchingCookies($requestUri);
1796+
1797+
/* @var $cookie Zend_Http_Cookie */
1798+
foreach ($autoCookies as $cookie)
1799+
{
1800+
$this->getRequest()->setCookie(
1801+
$cookie->getName(),
1802+
$cookie->getValue()
1803+
);
1804+
}
1805+
1806+
if ($urlModel instanceof Mage_Adminhtml_Model_Url)
1807+
{
1808+
// Workaround for secret key in admin
1809+
$this->getRequest()->setParam(
1810+
Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME,
1811+
$urlModel->getSecretKey()
1812+
);
1813+
}
1814+
1815+
if (!$this->getRequest()->getMethod())
1816+
{
1817+
$this->getRequest()->setMethod('GET');
1818+
}
1819+
1820+
// Workaround for form key
1821+
if ($this->getRequest()->isPost())
1822+
{
1823+
$this->getRequest()->setPost(
1824+
'form_key',
1825+
Mage::getSingleton('core/session')->getFormKey()
1826+
);
1827+
}
1828+
1829+
$this->getLayout()->reset();
1830+
$this->getResponse()->reset();
1831+
1832+
$this->app()->getFrontController()->dispatch();
1833+
1834+
// Unset changed cookies
1835+
$this->getRequest()->resetCookies();
1836+
$this->getRequest()->setCookies($customCookies);
1837+
1838+
return $this;
1839+
}
1840+
1841+
17751842
/**
17761843
* Set up controller params
17771844
* (non-PHPdoc)
@@ -1941,12 +2008,32 @@ protected function getUrlModel($route = null, array &$params)
19412008
return $urlModel;
19422009
}
19432010

2011+
19442012
/**
1945-
* Dispatches controller action
2013+
* Dispatch an URL to magento.
2014+
*
2015+
* @param string $requestUri
2016+
* @param array $params
2017+
*
2018+
* @return $this
2019+
*/
2020+
public function dispatchUrl($requestUri, $params = array())
2021+
{
2022+
$urlModel = $this->getUrlModel(null, $params);
2023+
$baseUrl = $urlModel->getBaseUrl($params);
2024+
2025+
return $this->_dispatch($baseUrl, $requestUri, $urlModel);
2026+
}
2027+
2028+
2029+
/**
2030+
* Dispatches a route.
19462031
*
19472032
*
19482033
* @param string $route
1949-
* @param array $params
2034+
* @param array $params
2035+
*
2036+
* @return $this
19502037
*/
19512038
public function dispatch($route = null, array $params = array())
19522039
{
@@ -1957,50 +2044,7 @@ public function dispatch($route = null, array $params = array())
19572044
$requestUri = $urlModel->getUrl($route, $params);
19582045
$baseUrl = $urlModel->getBaseUrl($params);
19592046

1960-
$this->getRequest()->resetInternalProperties();
1961-
1962-
$this->getRequest()->setBaseUrl($baseUrl)
1963-
->setRequestUri($requestUri)
1964-
->setPathInfo();
1965-
1966-
$customCookies = $this->getRequest()->getCookie();
1967-
1968-
$autoCookies = $this->getCookies()->getMatchingCookies($requestUri);
1969-
1970-
/* @var $cookie Zend_Http_Cookie */
1971-
foreach ($autoCookies as $cookie) {
1972-
$this->getRequest()->setCookie(
1973-
$cookie->getName(),
1974-
$cookie->getValue()
1975-
);
1976-
}
1977-
1978-
if ($urlModel instanceof Mage_Adminhtml_Model_Url) {
1979-
// Workaround for secret key in admin
1980-
$this->getRequest()->setParam(
1981-
Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME,
1982-
$urlModel->getSecretKey()
1983-
);
1984-
}
1985-
1986-
if (!$this->getRequest()->getMethod()) {
1987-
$this->getRequest()->setMethod('GET');
1988-
}
1989-
1990-
// Workaround for form key
1991-
if ($this->getRequest()->isPost()) {
1992-
$this->getRequest()->setPost('form_key', Mage::getSingleton('core/session')->getFormKey());
1993-
}
1994-
1995-
$this->getLayout()->reset();
1996-
$this->getResponse()->reset();
1997-
1998-
$this->app()->getFrontController()->dispatch();
1999-
2000-
// Unset changed cookies
2001-
$this->getRequest()->resetCookies();
2002-
$this->getRequest()->setCookies($customCookies);
2003-
return $this;
2047+
return $this->_dispatch($baseUrl, $requestUri, $urlModel);
20042048
}
20052049

20062050
/**

0 commit comments

Comments
 (0)