Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EcomDev_PHPUnit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Open
EcomDev_PHPUnit
Commits
285ce6ed
Commit
285ce6ed
authored
Sep 22, 2013
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #141 from sourcerer-mike/dev-dispatchUrl
Possibility to dispatch an URL
parents
5cf27c31
1105c01f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
46 deletions
+90
-46
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
+90
-46
No files found.
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
View file @
285ce6ed
...
...
@@ -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
* (non-PHPdoc)
...
...
@@ -1941,12 +2008,32 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
return
$urlModel
;
}
/**
* Dispatches controller action
* 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 a route.
*
*
* @param string $route
* @param array $params
* @param array $params
*
* @return $this
*/
public
function
dispatch
(
$route
=
null
,
array
$params
=
array
())
{
...
...
@@ -1957,50 +2044,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
$requestUri
=
$urlModel
->
getUrl
(
$route
,
$params
);
$baseUrl
=
$urlModel
->
getBaseUrl
(
$params
);
$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
;
return
$this
->
_dispatch
(
$baseUrl
,
$requestUri
,
$urlModel
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment