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
5554e0b8
Commit
5554e0b8
authored
Feb 06, 2012
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ Added method for mocking adminhtml session for controllers
parent
7e769097
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
1 deletion
+73
-1
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
+73
-1
No files found.
app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
View file @
5554e0b8
...
...
@@ -1982,4 +1982,76 @@ abstract class EcomDev_PHPUnit_Test_Case_Controller extends EcomDev_PHPUnit_Test
$this
->
getRequest
()
->
setCookies
(
$customCookies
);
return
$this
;
}
/**
* Creates admin user session stub for testing adminhtml controllers
*
* @param array $aclResources list of allowed ACL resources for user,
* if null then it is super admin
* @param int $userId fake id of the admin user, you can use different one if it is required for your tests
* @return EcomDev_PHPUnit_Test_Case_Controller
*/
protected
function
mockAdminUserSession
(
array
$aclResources
=
null
,
$userId
=
1
)
{
$adminSessionMock
=
$this
->
getModelMock
(
'admin/session'
,
array
(
'init'
,
'getUser'
,
'isLoggedIn'
,
'isAllowed'
)
);
$adminUserMock
=
$this
->
getModelMock
(
'admin/user'
,
array
(
'login'
,
'getId'
,
'save'
,
'authenticate'
,
'getRole'
)
);
$adminRoleMock
=
$this
->
getModelMock
(
'admin/roles'
,
array
(
'getGwsIsAll'
));
$adminRoleMock
->
expects
(
$this
->
any
())
->
method
(
'getGwsIsAll'
)
->
will
(
$this
->
returnValue
(
true
));
$adminUserMock
->
expects
(
$this
->
any
())
->
method
(
'getRole'
)
->
will
(
$this
->
returnValue
(
$adminRoleMock
));
$adminUserMock
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
$userId
));
$adminSessionMock
->
expects
(
$this
->
any
())
->
method
(
'getUser'
)
->
will
(
$this
->
returnValue
(
$adminUserMock
));
$adminSessionMock
->
expects
(
$this
->
any
())
->
method
(
'isLoggedIn'
)
->
will
(
$this
->
returnValue
(
true
));
// Simple isAllowed implementation
$adminSessionMock
->
expects
(
$this
->
any
())
->
method
(
'isAllowed'
)
->
will
(
$this
->
returnCallback
(
function
(
$resource
)
use
(
$aclResources
)
{
if
(
$aclResources
===
null
)
{
return
true
;
}
if
(
strpos
(
$resource
,
'admin/'
)
===
0
)
{
$resource
=
substr
(
$resource
,
strlen
(
'admin/'
));
}
return
in_array
(
$resource
,
$aclResources
);
}));
$this
->
replaceByMock
(
'model'
,
'admin/session'
,
$adminSessionMock
);
$this
->
getRequest
()
->
setParam
(
Mage_Adminhtml_Model_Url
::
SECRET_KEY_PARAM_NAME
,
Mage
::
getSingleton
(
'adminhtml/url'
)
->
getSecretKey
()
);
return
$this
;
}
}
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