Created
March 9, 2012 13:43
-
-
Save Demoli/2006542 to your computer and use it in GitHub Desktop.
Double dispatch error
This file contains 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
abstract class Skywire_PressRelease_Test_Controller_Adminhtml_Abstract | |
extends EcomDev_PHPUnit_Test_Case_Controller | |
{ | |
const FAKE_USER_ID = 999999999; | |
/** | |
* Login to the admin store | |
* | |
* @return null | |
*/ | |
public function setUp() | |
{ | |
$this->_fakeLogin(); | |
parent::setUp(); | |
} | |
/** | |
* Destroy admin session and cookies | |
* | |
* @return null | |
*/ | |
public function tearDown() | |
{ | |
$adminSession = Mage::getSingleton('admin/session'); | |
$adminSession->unsetAll(); | |
$adminSession->getCookie()->delete($adminSession->getSessionName()); | |
parent::tearDown(); | |
} | |
/** | |
* Logged in to Magento with fake user to test an adminhtml controllers | |
* | |
* @return null | |
*/ | |
protected function _fakeLogin() | |
{ | |
$this->_registerUserMock(); | |
Mage::getSingleton('adminhtml/url')->turnOffSecretKey(); | |
$session = Mage::getSingleton('admin/session'); | |
$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; | |
} | |
/** | |
* Test whether fake user successfully logged in | |
* | |
* @return null | |
*/ | |
public function testLoggedIn() | |
{ | |
$this->assertTrue(Mage::getSingleton('admin/session')->isLoggedIn()); | |
} | |
/** | |
* Test whether logged user is fake | |
* | |
* @return null | |
*/ | |
public function testLoggedUserIsFakeUser() | |
{ | |
$this->assertEquals( | |
Mage::getSingleton('admin/session') | |
->getUser()->getId(), | |
self::FAKE_USER_ID | |
); | |
} | |
} |
This file contains 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
class Company_Module_Test_Controller_Adminhtml_IndexAction | |
extends Company_Module_Test_Controller_Adminhtml_Abstract | |
{ | |
/** | |
* Test loading and rendering of index action | |
* | |
* @return null | |
*/ | |
public function testIndexAction() | |
{ | |
$expectedRoute = 'pressrelease/adminhtml_index'; | |
$this->dispatch($expectedRoute); | |
$this->assertRequestRoute($expectedRoute); | |
$this->assertLayoutBlockRendered('grid.container'); | |
} | |
public function testGridRowUrl() | |
{ | |
$expectedRoute = 'pressrelease/adminhtml_index'; | |
$this->dispatch($expectedRoute); | |
$item = Mage::getModel('pressrelease/release')->load(1); | |
$block = $this->getLayout()->getBlock('grid.container') | |
->getChild('grid'); | |
$this->assertContains( | |
$this->_getExpectations()->getExpectedUrlPart(), | |
$block->getRowUrl($item) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment