Skip to content

Commit

Permalink
Merge pull request #28 from schmengler/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
Schrank committed Mar 7, 2016
2 parents 2a575d6 + 2ebf2d2 commit b54955d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
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();

}
}
18 changes: 15 additions & 3 deletions app/code/community/Ikonoshirt/Pbkdf2/Test/Model/Observer.php
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'
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
Expand Down

0 comments on commit b54955d

Please sign in to comment.