Hi guys this is my first post here, and I've not been using Cake for
long.

I am writing some unit tests for the models a new application. For the
most part it works well, however in my User model I use the cake
security component to do some custom validation of a password
confirmation. When I run the test using the validates method I get the
following line:

Fatal error: Class 'Security' not found in D:\Workspace\*application*
\models\user.php on line 50

Here is some of the other code:

File: user.php

class User extends AppModel {
        var $name = 'User';
        var $validate = array(
                'email' => array(
                        array('rule' => array('minLength', 1), 'message' => 
'Please enter
an email address.', 'last' => true),
                        array('rule' => 'email', 'message' => 'The email 
address is not a
valid email address.', 'last' => true),
                        array('rule' => 'isUnique', 'message' => 'This email 
address is
already in use. Please enter a different email address.', 'last' =>
true)),
                'password' => array(
                        array('rule' => array('minLength', 1), 'message' => 
'Please enter a
password.', 'last' => true),
                        array('rule' => array('minLength', 6), 'message' => 
'The password
must be at least 6 characters.', 'last' => true)),
                'confirm_password' => array(
                        array('rule' => array('minLength', 1), 'message' => 
'Please confirm
password.', 'last' => true),
                        array('rule' => array('comparePassword'), 'message' => 
'Sorry,
confirmation and password entered do not match. Please re-enter
password information.'))
        );

        /**
         * Check if two given passwords are equal
         */
        function comparePassword($data) {
                $confirmPasswordHashed = Security::hash(Configure::read
('Security.salt') . $data['confirm_password']);

                $confirmPassword = $data['confirm_password'];

                if (($this->data[$this->name]['password'] == 
$confirmPasswordHashed)
||
                        ($this->data[$this->name]['password'] == 
$confirmPassword)) {
                        return true;
                }
                return false;
        }
}

File: user.test.php

App::import('Model', 'User');

class UserTestCase extends CakeTestCase {
        var $User = null;
        var $fixtures = array('app.user');

        function startTest() {
                $this->User =& ClassRegistry::init('User');
        }

        function testUserInstance() {
                $this->assertTrue(is_a($this->User, 'User'));
        }

        function testUserValidates() {
                // Valid user information
                $data = array('User' => array(
                        'id' => '00000000-0000-0000-0000-000000000000',
                        'email' => '[email protected]',
                        'password' => 
'18b300bb0e3ed08e692d8c1cc7b95aab6cb6c64f',
                        'confirm_password' => 'password'
                ));
                $this->User->set($data);
                $this->assertTrue($this->User->validates());
        }
}

Do I need to include something for the Security component to work in
the unit tests, or is it a limitation? If it is a limitation, then is
there a work around?

Thanks for your help.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to