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