Created
July 13, 2012 08:34
-
-
Save marcinrogacki/3103679 to your computer and use it in GitHub Desktop.
Magento Admin login test case - fails on master branch, dev branch fix it but have propably another bugs
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
class Nexway_Customer_Test_Controller_AccountController | |
extends EcomDev_PHPUnit_Test_Case_Controller | |
{ | |
/** | |
* @var int | |
*/ | |
const FAKE_USER_ID = 999999999; | |
public function setUp() | |
{ | |
$this->_registerCustomerMock(); | |
$this->_registerCustomerResourceMock(); | |
$this->_fakeLogin(); | |
parent::setUp(); | |
} | |
public function tearDown() | |
{ | |
$this->_clearSession(); | |
parent::tearDown(); | |
} | |
/** | |
* Logged in to Magento with fake user to test an customer controllers | |
* | |
* @return void | |
*/ | |
protected function _fakeLogin() | |
{ | |
$session = Mage::getSingleton('customer/session'); | |
$session->login('fakeuser', 'fakeuser_pass'); | |
} | |
/** | |
* Deletes cookies and unset data from customer/session singleton | |
* | |
* @return void | |
*/ | |
protected function _clearSession() | |
{ | |
$customerSession = Mage::getSingleton('customer/session'); | |
$customerSession->unsetAll(); | |
$customerSession->getCookie()->delete($customerSession->getSessionName()); | |
} | |
/** | |
* Creates a mock model for customer/customer | |
* | |
* @return void | |
*/ | |
protected function _registerCustomerMock() | |
{ | |
$methodsToMock = array('authenticate', 'getId'); | |
$customer = $this->getModelMock('customer/customer', $methodsToMock); | |
/** | |
* customer/session follow: | |
* login() => line: $customer->authenticate() => should return true | |
*/ | |
$customer->expects($this->any()) | |
->method('authenticate') | |
->will($this->returnValue(true)); | |
/** | |
* customer/session follow: | |
* login() => line: setCustomerAsLoggedIn() => go to this method => | |
* line: setCustomer() => $customert is a customer/customer object => | |
* customer/customer should return an user id | |
*/ | |
$customer->expects($this->any()) | |
->method('getId') | |
->will($this->returnValue(self::FAKE_USER_ID)); | |
/** replace object by mock */ | |
$this->replaceByMock('model', 'customer/customer', $customer); | |
} | |
/** | |
* Creates a mock resource for customer/customer | |
* | |
* @return void | |
*/ | |
protected function _registerCustomerResourceMock() | |
{ | |
$methodsToMock = array('checkCustomerId'); | |
$customerResource = $this->getResourceModelMock( | |
'customer/customer', $methodsToMock | |
); | |
$customerResource->expects($this->any()) | |
->method('checkCustomerId') | |
->will($this->returnValue(true)); | |
/** replace object by mock */ | |
$this->replaceByMock( | |
'resource_model', 'customer/customer', $customerResource | |
); | |
} | |
/** | |
* @test | |
*/ | |
public function isLoggedIn() | |
{ | |
$this->assertTrue( | |
Mage::getSingleton('customer/session')->isLoggedIn(), | |
"User is not logged in" | |
); | |
} | |
/** | |
* @test | |
*/ | |
public function isLoggedOut() | |
{ | |
Mage::getSingleton('customer/session')->logout(); | |
$this->assertTrue( | |
Mage::getSingleton('customer/session')->isLoggedIn() === false, | |
"User is not logged out" | |
); | |
} | |
/** | |
* @test | |
*/ | |
public function redirectFromLoginToIndexWhenLoggedIn() | |
{ | |
$action = 'customer/account/login'; | |
$expectedRedirect = 'customer/account'; | |
$this->dispatch($action); | |
$msg = "Redirect was not occurred"; | |
$this->assertRedirect($msg); | |
$msg = "'$action' was not redirect to"; | |
$this->assertRedirectTo($expectedRedirect, array(), $msg); | |
} | |
/** | |
* @test | |
* @depends isLoggedOut | |
*/ | |
public function redirectFromIndexToLoginWhenNotLoggedIn() | |
{ | |
Mage::getSingleton('customer/session')->logout(); | |
$action = 'customer/account/index'; | |
$expectedRedirect = 'customer/account/login'; | |
$this->dispatch($action); | |
$msg = "Redirect was not occurred"; | |
$this->assertRedirect($msg); | |
$msg = "'$action' was not redirect to '$expectedRedirect'"; | |
$this->assertRedirectTo($expectedRedirect, array(), $msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment