-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from schmengler/unit-tests
Unit tests
- Loading branch information
Showing
2 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
app/code/community/Ikonoshirt/Pbkdf2/Test/Controller/AccountController.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
class Ikonoshirt_Pbkdf2_Test_Controller_AccountController extends EcomDev_PHPUnit_Test_Case_Controller | ||
{ | ||
/* | ||
* Test data | ||
*/ | ||
const OLD_PASSWORD = 'oldpass', | ||
NEW_PASSWORD = 'newpass', | ||
STORE_ID = 1, | ||
FIRST_NAME = 'X', | ||
LAST_NAME = 'X', | ||
EMAIL = '[email protected]'; | ||
|
||
/** | ||
* User should be able to change password from account settings | ||
* | ||
* @test | ||
* @registry isSecureArea | ||
* @singleton customer/session | ||
*/ | ||
public function testChangePasssword() | ||
{ | ||
//Allow deleting customer model without adminhtml context | ||
Mage::register('isSecureArea', true); | ||
|
||
/* @var $store Mage_Core_Model_Store */ | ||
$store = Mage::getModel('core/store')->load(self::STORE_ID); | ||
|
||
// delete account if existing | ||
$customer = Mage::getModel('customer/customer'); | ||
$customer->setStore($store)->loadByEmail(self::EMAIL); | ||
if (!$customer->isObjectNew()) { | ||
$customer->delete(); | ||
} | ||
|
||
$customer = Mage::getModel('customer/customer'); | ||
/* @var $customer Mage_Customer_Model_Customer */ | ||
$customer->setPassword(self::OLD_PASSWORD); | ||
$customer->setEmail(self::EMAIL); | ||
$customer->setStore($store); | ||
$customerId = $customer->save()->getId(); | ||
$oldPasswordHash = $customer->getPasswordHash(); | ||
|
||
$this->customerSession($customerId); | ||
$this->getRequest()->setMethod('POST') | ||
->setPost(array( | ||
'firstname' => self::FIRST_NAME, | ||
'lastname' => self::LAST_NAME, | ||
'change_password' => '1', | ||
'current_password' => self::OLD_PASSWORD, | ||
'password' => self::NEW_PASSWORD, | ||
'confirmation' => self::NEW_PASSWORD | ||
)); | ||
$this->dispatch('customer/account/editPost'); | ||
/* @var Mage_Core_Model_Message_Collection $messages */ | ||
$messages = Mage::getSingleton('customer/session')->getMessages(); | ||
$this->assertEquals('success: The account information has been saved.', $messages->toString()); | ||
$this->assertRedirectTo('customer/account'); | ||
|
||
// and the password must be changed | ||
$customerReloaded = Mage::getModel('customer/customer') | ||
->load($customerId); | ||
|
||
$this->assertNotEquals( | ||
$oldPasswordHash, | ||
$customerReloaded->getPasswordHash() | ||
); | ||
|
||
$customer->delete(); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
<?php | ||
|
||
class Ikonoshirt_Pbkdf2_Test_Model_Observer extends EcomDev_PHPUnit_Test_Case | ||
class Ikonoshirt_Pbkdf2_Test_Model_Observer extends EcomDev_PHPUnit_Test_Case_Controller | ||
{ | ||
|
||
/** | ||
* @test | ||
* @singleton admin/session | ||
*/ | ||
public function testAdminPasswordReplaced() | ||
{ | ||
//Mock session model to prevent session_start() | ||
$this->replaceByMock('singleton', 'admin/session', | ||
$this->getModelMock('admin/session', array(), false, array(), '', false)); | ||
//Reflection to set old password | ||
$dataReflection = new ReflectionProperty( | ||
'Mage_Admin_Model_User', '_data' | ||
|
@@ -201,12 +204,14 @@ public function testApiPasswordReplaced() | |
} | ||
|
||
/** | ||
* | ||
* | ||
* @test | ||
* @registry isSecureArea | ||
*/ | ||
public function testCustomerPasswordReplaced() | ||
{ | ||
//Allow deleting customer model without adminhtml context | ||
Mage::register('isSecureArea', true); | ||
// TODO remove static 1 for store id | ||
$store = Mage::getModel('core/store')->load(1); | ||
/* @var $store Mage_Core_Model_Store */ | ||
|
@@ -216,6 +221,13 @@ public function testCustomerPasswordReplaced() | |
/* @var $enc Mage_Core_Model_Encryption */ | ||
$hash = $enc->getHash('password', 2); | ||
|
||
// delete account if existing | ||
$customer = Mage::getModel('customer/customer'); | ||
$customer->setStore($store)->loadByEmail('[email protected]'); | ||
if (!$customer->isObjectNew()) { | ||
$customer->delete(); | ||
} | ||
|
||
$customer = Mage::getModel('customer/customer'); | ||
/* @var $customer Mage_Customer_Model_Customer */ | ||
$customer->setPasswordHash($hash); | ||
|