Last active
December 22, 2015 14:18
-
-
Save ScreamingDev/6484696 to your computer and use it in GitHub Desktop.
Magento UnitTest Adminhtml does not work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| abstract class LeMike_DevMode_Test_Adminhtml extends EcomDev_PHPUnit_Test_Case_Controller | |
| { | |
| const FAKE_USER_ID = 42; | |
| public function setUp() | |
| { | |
| $this->_fakeLogin(); | |
| parent::setUp(); | |
| } | |
| public function tearDown() | |
| { | |
| $adminSession = Mage::getSingleton('admin/session'); | |
| $adminSession->unsetAll(); | |
| $adminSession->getCookie()->delete($adminSession->getSessionName()); | |
| parent::tearDown(); | |
| } | |
| /** | |
| * Test whether fake user successfully logged in | |
| */ | |
| public function testLoggedIn() | |
| { | |
| $this->assertTrue(Mage::getSingleton('admin/session')->isLoggedIn()); | |
| } | |
| /** | |
| * Test whether logged user is fake | |
| */ | |
| public function testLoggedUserIsFakeUser() | |
| { | |
| $this->assertEquals(Mage::getSingleton('admin/session')->getUser()->getId(), self::FAKE_USER_ID); | |
| } | |
| /** | |
| * Logged in to Magento with fake user to test an adminhtml controllers | |
| */ | |
| protected function _fakeLogin() | |
| { | |
| $sessionMock = $this->getModelMockBuilder('admin/session') | |
| ->disableOriginalConstructor() | |
| ->setMethods(null) | |
| ->getMock(); | |
| $this->replaceByMock('singleton', 'admin/session', $sessionMock); | |
| $this->_registerUserMock(); | |
| Mage::getSingleton('adminhtml/url')->turnOffSecretKey(); | |
| $session = Mage::getSingleton('admin/session'); | |
| $user = $session->login('fakeuser', 'fakeuser_pass'); | |
| } | |
| /** | |
| * Creates a mock object for admin/user Magento Model | |
| * | |
| * @return My_Module_Test_Controller_Adminhtml_Controller | |
| */ | |
| protected function _registerUserMock() | |
| { | |
| $user = $this->getModelMock('admin/user'); | |
| $user->expects($this->any())->method('getId')->will($this->returnValue(self::FAKE_USER_ID)); | |
| $this->replaceByMock('model', 'admin/user', $user); | |
| return $this; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment