Book Image

Learning Yii Testing

Book Image

Learning Yii Testing

Overview of this book

Table of Contents (16 chapters)
Learning Yii Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Listening for calls with an observer


As User::validatePassword() is now using Security::validatePassword() in its implementation in a transparent way, we don't want to expose any of this when setting the password to whoever is going to use the User model.

So, we'd like to think that when setting the password, our implementation will use Security::generatePasswordHash() in some way, so that when calling User::validatePassword(), we close the circle and everything should work without having to worry too much about encryption schemes and what not.

An immediate, somewhat logical, but quite abused way to implement a test that could cover this bit is the following:

public function testSetPasswordEncryptsThePasswordCorrectly()
{
    $clearTextPassword = 'some password';
    $encryptedPassword = 'encrypted password';

    // here, we need to stub our security component

    $this->_user->setPassword($clearTextPassword);

    $this->assertNotEquals(
        $clearTextPassword, $this->_user...