classOAuth = new OAuth2StorageUserCredential(); session_id($this->refreshToken); $_SESSION['wallet']['user']['uid'] = $this->user; $_SESSION['wallet']['user']['password'] = $this->pass; $_SESSION['wallet']['user']['uidNumber'] = 42798; //insere access token $this->classOAuth->setAccessToken($this->accessToken, $this->client_id, $this->user_id, (time() + 3600), 'all', $this->refreshToken); //insere refresh token $this->classOAuth->setRefreshToken($this->refreshToken, $this->client_id, $this->user_id, (time() + 3600), 'all'); $this->curlOPT = array(CURLOPT_URL => $this->url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_TIMEOUT => 4, CURLOPT_HTTPHEADER => array('Authorization: OAUTH Bearer aaaaaa259f553ac148f01b6bbcbb101')); } public function testcreateResource() { Controller::service('PostgreSQL')->execResultSql("INSERT INTO expressomail_dynamic_contact (owner, name, mail, timestamp) values ('42798', 'nameTeste', 'name@teste.com', '" . time() . "000');"); Controller::commit(array('service' => 'PostgreSQL')); } public function testCheckMaxResource() { $contact = Controller::service('PostgreSQL')->execResultSql("SELECT id from expressomail_dynamic_contact where owner = 42798"); $this->curlOPT[CURLOPT_URL] = $this->curlOPT[CURLOPT_URL] . '/' . $contact[0]['id']; $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertCount(1, $body['collection']['items']); } public function testCheckResource() { $contact = Controller::service('PostgreSQL')->execResultSql("SELECT id from expressomail_dynamic_contact where owner = 42798"); $this->curlOPT[CURLOPT_URL] = $this->curlOPT[CURLOPT_URL] . '/' . $contact[0]['id']; $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertArrayHasKey('collection', $body); $this->assertArrayHasKey('data', $body['collection']); $this->assertArrayHasKey('name', $body['collection']['data']); $this->assertArrayHasKey('prompt', $body['collection']['data']); $this->assertArrayHasKey('error', $body['collection']); $this->assertArrayHasKey('href', $body['collection']); $this->assertArrayHasKey('items', $body['collection']); $this->assertArrayHasKey('pagination', $body['collection']); $this->assertArrayHasKey('queries', $body['collection']); $this->assertArrayHasKey('template', $body['collection']); $this->assertArrayHasKey('dataType', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('maxLength', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('minLength', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('name', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('prompt', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('value', $body['collection']['template']['data'][0]); $this->assertArrayHasKey('type', $body['collection']); $this->assertArrayHasKey('version', $body); } public function testCheckInvalidId() { $this->curlOPT[CURLOPT_URL] = $this->curlOPT[CURLOPT_URL] . '/invalidIdXXX'; $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertArrayHasKey('version', $body); $this->assertArrayHasKey('collection', $body); $this->assertArrayHasKey('error', $body['collection']); $this->assertArrayHasKey('code', $body['collection']['error']); $this->assertArrayHasKey('title', $body['collection']['error']); $this->assertArrayHasKey('description', $body['collection']['error']); } public function testCheckInvalidDelete() { $this->curlOPT[CURLOPT_URL] = $this->curlOPT[CURLOPT_URL] . '/invalidXXX'; $c = curl_init(); curl_setopt_array($c, $this->curlOPT); curl_setopt($c, CURLOPT_CUSTOMREQUEST, "DELETE"); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertArrayHasKey('version', $body); $this->assertArrayHasKey('collection', $body); $this->assertArrayHasKey('code', $body['collection']['error']); $this->assertArrayHasKey('title', $body['collection']['error']); $this->assertArrayHasKey('description', $body['collection']['error']); } public function testCheckDelete() { $contact = Controller::service('PostgreSQL')->execResultSql("SELECT id from expressomail_dynamic_contact where owner = 42798"); $this->curlOPT[CURLOPT_URL] = $this->curlOPT[CURLOPT_URL] . '/' . $contact[0]['id']; $c = curl_init(); curl_setopt_array($c, $this->curlOPT); curl_setopt($c, CURLOPT_CUSTOMREQUEST, "DELETE"); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertNull($body); } public function testCheckFinish() { Controller::service('PostgreSQL')->execResultSql("DELETE from expressomail_dynamic_contact where owner = ('42798')"); $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r, true); $this->assertNull($body['collection']['items']); } public function tearDown() { $this->classOAuth->unsetRefreshToken($this->refreshToken); $this->classOAuth->unsetAccessToken($this->accessToken); } } ?>