Get model attribute after save

Dear Experts,

I am writing yii application with test driven development.

Somehow I save an account. The account model has encrypt password implementation which I encrypt the password and save to encrypted_password attribute.

Now, I need to test the encrypted_password attribute after save. How can I do that?

Below is my test methods:




public function testEncryptedPasswordAttributeExist(){

    	$account = new Account;

    	$account->setAttributes($this->attr);

    	$this->assertTrue($account->hasAttribute('encrypted_password'));

    	return $account;

    }

    

    /**

     * @depends testEncryptedPasswordAttributeExist

     */

    public function testEncryptedPasswordShouldNotBeBlank(Account $account){

    	$account->save();

    	echo $account->encrypted_password;

    	$this->assertTrue($account->getAttribute('encrypted_password') != '');

    }



Below is my model implementation in which I think is correct:




	public function onBeforeSave(){

		parent::onBeforeSave();

		$this->encrypt_password($this->$password);

	}

	

	public function validatePassword($password)

    {

        return $this->hashPassword($password, $this->salt)===$this->password;

    }

 

    public function hashPassword($password,$salt)

    {

        return md5($salt.$password);

    }

    

    private function encrypt_password($password){

    	$this->encrypted_password = encrpyt_password($password);

    }

    

    private function encrpyt_password($password){

    	return $password;

    }



Thanks.

Regards,

Cato

Hi Cato,

this doesn’t look right to me?

Can you explain?

Thanks.

Problem solved.