コード例 #1
0
 public function testImproperInstantiation()
 {
     global $_SERVER;
     // emulate client request
     $_SERVER["REQUEST_METHOD"] = "FOOBAR";
     $_SERVER["SCRIPT_NAME"] = "/service.php";
     $vo_response = new ResponseHTTP();
     $vo_request = new RequestHTTP($vo_response, array("dont_create_new_session" => true));
     $vo_request->setRawPostData('This is not JSON!');
     $vo_service = new BaseJSONService($vo_request, "invalid_table");
     $this->assertTrue($vo_service->hasErrors());
     // we don't check error messages because they tend to change frequently but
     // the above code should generate 3 errors (invalid table, no JSON request body
     // and invalid request method)
     $this->assertEquals(3, sizeof($vo_service->getErrors()));
 }
コード例 #2
0
    /**
     * This part of the service is basically a wrapper around BaseModel::get so we don't
     * need to test that extensively here. We "just" have to make sure the integration works.
     */
    public function testGetSpecificItemInfo()
    {
        global $_SERVER;
        // emulate client request
        $_SERVER["REQUEST_METHOD"] = "GET";
        $_SERVER["SCRIPT_NAME"] = "/service.php";
        $vo_response = new ResponseHTTP();
        $vo_request = new RequestHTTP($vo_response);
        $vs_request_body = <<<JSON
{
\t"bundles" : {
\t\t"ca_objects.access" : {
\t\t\t"convertCodesToDisplayText" : true
\t\t},
\t\t"ca_objects.preferred_labels.name" : {
\t\t\t"delimiter" : "; "
\t\t},
\t\t"ca_entities.entity_id" : {
\t\t\t"returnAsArray" : true
\t\t}
\t}
}
JSON;
        $vo_request->setParameter("id", 27, "GET");
        $vo_request->setRawPostData($vs_request_body);
        $vo_service = new ItemService($vo_request, "ca_objects");
        $va_return = $vo_service->dispatch();
        $this->assertFalse($vo_service->hasErrors());
        $this->assertEquals("Public", $va_return["ca_objects.access"]);
        $this->assertEquals("Astroland arcade, Surf Avenue", $va_return["ca_objects.preferred_labels.name"]);
        $this->assertEquals(array("4"), $va_return["ca_entities.entity_id"]);
    }