-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
require_once APPPATH . '/libraries/REST_Controller.php'; | ||
|
||
class Rest_test extends REST_Controller | ||
{ | ||
public function index_get() | ||
{ | ||
$data['get'] = $this->get(); | ||
$data['query'] = $this->query(); | ||
$this->response($data, REST_Controller::HTTP_OK); | ||
} | ||
|
||
public function index_post() | ||
{ | ||
$data['post'] = $this->post(); | ||
$data['query'] = $this->query(); | ||
$this->response($data, REST_Controller::HTTP_OK); | ||
} | ||
|
||
public function index_put() | ||
{ | ||
$data['put'] = $this->put(); | ||
$data['query'] = $this->query(); | ||
$this->response($data, REST_Controller::HTTP_OK); | ||
} | ||
|
||
public function index_delete() | ||
{ | ||
$data['delete'] = $this->delete(); | ||
$data['query'] = $this->query(); | ||
$this->response($data, REST_Controller::HTTP_OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
class Rest_test_test extends TestCase | ||
{ | ||
public function test_index_get() | ||
{ | ||
set_is_cli(FALSE); | ||
$this->warningOff(); | ||
try { | ||
$output = $this->request( | ||
'GET', 'api/rest_test?name=John%20O%27reilly&city=Tokyo' | ||
); | ||
} catch (CIPHPUnitTestExitException $e) { | ||
$output = ob_get_clean(); | ||
} | ||
set_is_cli(TRUE); | ||
$this->warningOn(); | ||
|
||
$expected = <<< 'EOL' | ||
{"get":{"name":"John O'reilly","city":"Tokyo"},"query":{"name":"John O'reilly","city":"Tokyo"}} | ||
EOL; | ||
$this->assertEquals($expected, $output); | ||
$this->assertResponseCode(200); | ||
} | ||
|
||
public function test_index_post() | ||
{ | ||
set_is_cli(FALSE); | ||
$this->warningOff(); | ||
try { | ||
$output = $this->request( | ||
'POST', 'api/rest_test?name=John%20O%27reilly&city=Tokyo', | ||
[ | ||
'id' => 'abc', | ||
'password' => 'xyz' | ||
] | ||
); | ||
} catch (CIPHPUnitTestExitException $e) { | ||
$output = ob_get_clean(); | ||
} | ||
set_is_cli(TRUE); | ||
$this->warningOn(); | ||
|
||
$expected = <<< 'EOL' | ||
{"post":{"id":"abc","password":"xyz"},"query":{"name":"John O'reilly","city":"Tokyo"}} | ||
EOL; | ||
$this->assertEquals($expected, $output); | ||
$this->assertResponseCode(200); | ||
} | ||
|
||
public function test_index_put() | ||
{ | ||
set_is_cli(FALSE); | ||
$this->warningOff(); | ||
try { | ||
$output = $this->request( | ||
'PUT', 'api/rest_test?name=John%20O%27reilly&city=Tokyo', | ||
'id=abc&password=xyz' | ||
); | ||
} catch (CIPHPUnitTestExitException $e) { | ||
$output = ob_get_clean(); | ||
} | ||
set_is_cli(TRUE); | ||
$this->warningOn(); | ||
|
||
$expected = <<< 'EOL' | ||
{"put":{"id":"abc","password":"xyz"},"query":{"name":"John O'reilly","city":"Tokyo"}} | ||
EOL; | ||
$this->assertEquals($expected, $output); | ||
$this->assertResponseCode(200); | ||
} | ||
|
||
public function test_index_delete() | ||
{ | ||
set_is_cli(FALSE); | ||
$this->warningOff(); | ||
try { | ||
$output = $this->request( | ||
'DELETE', 'api/rest_test?name=John%20O%27reilly&city=Tokyo', | ||
'id=abc&password=xyz' | ||
); | ||
} catch (CIPHPUnitTestExitException $e) { | ||
$output = ob_get_clean(); | ||
} | ||
set_is_cli(TRUE); | ||
$this->warningOn(); | ||
|
||
$expected = <<< 'EOL' | ||
{"delete":{"id":"abc","password":"xyz"},"query":{"name":"John O'reilly","city":"Tokyo"}} | ||
EOL; | ||
$this->assertEquals($expected, $output); | ||
$this->assertResponseCode(200); | ||
} | ||
} |