Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
In test.php file, before including boostrap.php:
----------------------------------------------------------
define('CAKE_UNIT_TEST', true);
 
 
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:
----------------------------------------------------------
if ( !defined('CAKE_UNIT_TEST') ) {
    define('CAKE_UNIT_TEST', false);
}
 
 
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'));
    }
}