|
@@ 21-40 (lines=20) @@
|
| 18 |
|
'RestfulServerTest_AuthorRating', |
| 19 |
|
); |
| 20 |
|
|
| 21 |
|
public function testApiAccess() |
| 22 |
|
{ |
| 23 |
|
$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1'); |
| 24 |
|
$page1 = $this->objFromFixture('RestfulServerTest_Page', 'page1'); |
| 25 |
|
|
| 26 |
|
// normal GET should succeed with $api_access enabled |
| 27 |
|
$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID; |
| 28 |
|
$response = Director::test($url, null, null, 'GET'); |
| 29 |
|
$this->assertEquals($response->getStatusCode(), 200); |
| 30 |
|
|
| 31 |
|
$_SERVER['PHP_AUTH_USER'] = '[email protected]'; |
| 32 |
|
$_SERVER['PHP_AUTH_PW'] = 'user'; |
| 33 |
|
|
| 34 |
|
// even with logged in user a GET with $api_access disabled should fail |
| 35 |
|
$url = "/api/v1/RestfulServerTest_Page/" . $page1->ID; |
| 36 |
|
$response = Director::test($url, null, null, 'GET'); |
| 37 |
|
$this->assertEquals($response->getStatusCode(), 401); |
| 38 |
|
|
| 39 |
|
unset($_SERVER['PHP_AUTH_USER']); |
| 40 |
|
unset($_SERVER['PHP_AUTH_PW']); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
public function testApiAccessBoolean() |
|
@@ 56-74 (lines=19) @@
|
| 53 |
|
$this->assertContains('<Author', $response->getBody()); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
public function testAuthenticatedGET() |
| 57 |
|
{ |
| 58 |
|
$thing1 = $this->objFromFixture('RestfulServerTest_SecretThing', 'thing1'); |
| 59 |
|
$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1'); |
| 60 |
|
|
| 61 |
|
// @todo create additional mock object with authenticated VIEW permissions |
| 62 |
|
$url = "/api/v1/RestfulServerTest_SecretThing/" . $thing1->ID; |
| 63 |
|
$response = Director::test($url, null, null, 'GET'); |
| 64 |
|
$this->assertEquals($response->getStatusCode(), 401); |
| 65 |
|
|
| 66 |
|
$_SERVER['PHP_AUTH_USER'] = '[email protected]'; |
| 67 |
|
$_SERVER['PHP_AUTH_PW'] = 'user'; |
| 68 |
|
|
| 69 |
|
$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID; |
| 70 |
|
$response = Director::test($url, null, null, 'GET'); |
| 71 |
|
$this->assertEquals($response->getStatusCode(), 200); |
| 72 |
|
|
| 73 |
|
unset($_SERVER['PHP_AUTH_USER']); |
| 74 |
|
unset($_SERVER['PHP_AUTH_PW']); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
public function testAuthenticatedPUT() |