01.09
php
saved
robby
Note
This was my solution for the problems I was having with testAction() redirecting because of application settings in the Auth and Security components, and I wanted a solution that was as flexible as possible.
This was my solution for the problems I was having with testAction() redirecting because of application settings in the Auth and Security components, and I wanted a solution that was as flexible as possible.
- In test.php file, before including boostrap.php:
- ----------------------------------------------------------
- In test.php, before creating the dispatcher. (Optional, done mostly
- as a convenience so I remember what the settings are later):
- ----------------------------------------------------------
- Configure::write('UnitTest.bypassSSL', true); // bypass SSL settings
- Configure::write('UnitTest.bypassAuth', true); // bypass Auth settings (auto allow())
- Configure::write('UnitTest.spoofAuthUser', false); // data array to set as the Auth User
- In bootstrap.php, anywhere:
- ----------------------------------------------------------
- }
- In app_controller.php:
- ----------------------------------------------------------
- if ( !CAKE_UNIT_TEST or is_empty(Configure::read('UnitTest.bypassSSL')) ) {
- $this->Security->requireSecure();
- $this->Security->blackHoleCallback = '_blackHole';
- }
- In app_controller, after defining Auth settings.
- Important! must define Auth->sessionKey or this will fail
- ----------------------------------------------------------
- if ( CAKE_UNIT_TEST ) {
- // Allow the user
- if ( !is_empty(Configure::read('UnitTest.bypassAuth')) ) {
- $this->Auth->allow();
- }
- // Spoof the user
- if ( !is_empty(Configure::read('UnitTest.spoofAuthUser')) ) {
- $this->Auth->Session->write($this->Auth->sessionKey, Configure::read('UnitTest.spoofAuthUser'));
- }
- }
Parsed in 0.073 seconds, using GeSHi 1.0.7.14