|
@@ 58-82 (lines=25) @@
|
| 55 |
|
Injector::inst()->unregisterAllObjects(); |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
function testRequiresLoginForTest() { |
| 59 |
|
Session::set("loggedInAs", null); |
| 60 |
|
|
| 61 |
|
$ctrl = new Controller(); |
| 62 |
|
$req = new SS_HTTPRequest('GET', '/'); |
| 63 |
|
$dataModel = new DataModel(); |
| 64 |
|
|
| 65 |
|
$directorClass = $this->getMockClass('Director', array('isTest')); |
| 66 |
|
Injector::inst()->registerNamedService('Director', new $directorClass); |
| 67 |
|
|
| 68 |
|
$directorClass::staticExpects($this->any()) |
| 69 |
|
->method('isTest') |
| 70 |
|
->will($this->returnValue(true)); |
| 71 |
|
|
| 72 |
|
try { |
| 73 |
|
$response = $ctrl->handleRequest($req, $dataModel); |
| 74 |
|
} catch (Exception $e) { |
| 75 |
|
$this->assertEquals($e->getResponse()->getStatusCode(), '401', 'Forces BasicAuth on test'); |
| 76 |
|
|
| 77 |
|
// We need to pop manually, since throwing an SS_HTTPResponse_Exception in onBeforeInit hijacks |
| 78 |
|
// the normal Controller control flow and confuses TestRunner (as they share global controller stack). |
| 79 |
|
$ctrl->popCurrent(); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
function testRequiresLoginForNonTest() { |
| 85 |
|
Session::set("loggedInAs", null); |
|
@@ 84-101 (lines=18) @@
|
| 81 |
|
|
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
function testRequiresLoginForNonTest() { |
| 85 |
|
Session::set("loggedInAs", null); |
| 86 |
|
|
| 87 |
|
$ctrl = new Controller(); |
| 88 |
|
$req = new SS_HTTPRequest('GET', '/'); |
| 89 |
|
$dataModel = new DataModel(); |
| 90 |
|
|
| 91 |
|
$directorClass = $this->getMockClass('Director', array('isTest')); |
| 92 |
|
Injector::inst()->registerNamedService('Director', new $directorClass); |
| 93 |
|
|
| 94 |
|
$directorClass::staticExpects($this->any()) |
| 95 |
|
->method('isTest') |
| 96 |
|
->will($this->returnValue(false)); |
| 97 |
|
|
| 98 |
|
$response = $ctrl->handleRequest($req, $dataModel); |
| 99 |
|
$this->assertEquals($response->getStatusCode(), '200', 'Does not force BasicAuth on live'); |
| 100 |
|
|
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
function testRequiresLoginForLiveWhenEnabled() { |
| 104 |
|
Session::set("loggedInAs", null); |