classOAuth = new OAuth2StorageUserCredential(); session_id('rrrrrr03fff3b8cdc51206244529agb'); $_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() { $calendar = Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar (location, tzid, name, dtstamp, description) values ('location', 'America/Sao_Paulo', 'PHP-UNIt Teste', '".time()."000', 'Agenda de teste :D') returning id;"); if(is_array($calendar)) $calendar = $calendar[0]['id']; $signature = Controller::create(array('concept' => 'calendarSignature'), array('calendar' => $calendar, 'user' => 42798, 'isOwner' => '1', 'fontColor' => '000000', 'backgroundColor' => '000000', 'borderColor' => '000000' )); for($i = 0; $i < 10; $i++){ $date = date('Ymd\THisT'); $unique = substr(microtime(), 2, 4); $base = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPrRsStTuUvVxXuUvVwWzZ1234567890'; $start = 0; $end = strlen( $base ) - 1; $length = 6; $str = null; for( $p = 0; $p < $length; $p++ ) $unique .= $base{mt_rand( $start, $end )}; $uid = $date.$unique.'@expresso-calendar'; $idEvent = Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_object (location, cal_uid, class_id, dtstamp, description, dtstart, dtend, allday, range_start, range_end, summary, type_id, last_update, tzid ) values ('PHP UNIT', '".$uid."', '1', '".time()."000', 'Evento de teste PHP-Unit', '".time()."000', '".(time() - 400)."000', '0', '".time()."000', '".(time() + 400)."000', 'Eventos de teste aqui', '1', '".time()."000', 'America/Sao_Paulo') returning id;"); Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_to_calendar_object (calendar_id, calendar_object_id) values ('".$calendar."', '".$idEvent[0]['id']."')"); } Controller::commit( array( 'service' => 'PostgreSQL' ) ); } public function testCheckMaxResource() { $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r,true); $this->assertCount(10, $body); } public function testCheckResource() { $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r,true); foreach($body as $key => $value){ $this->assertArrayHasKey('allDay', $body[$key]); $this->assertArrayHasKey('calendar', $body[$key]); $this->assertArrayHasKey('class', $body[$key]); $this->assertArrayHasKey('description', $body[$key]); $this->assertArrayHasKey('dtstamp', $body[$key]); $this->assertArrayHasKey('id', $body[$key]); $this->assertArrayHasKey('lastUpdate', $body[$key]); $this->assertArrayHasKey('location', $body[$key]); $this->assertArrayHasKey('rangeEnd', $body[$key]); $this->assertArrayHasKey('rangeStart', $body[$key]); $this->assertArrayHasKey('sequence', $body[$key]); } } public function testCheckFinish() { $calendar = Controller::service('PostgreSQL')->execResultSql("SELECT calendar_id from calendar_signature where user_uidnumber = 42798"); $relation = Controller::service('PostgreSQL')->execResultSql("SELECT calendar_object_id from calendar_to_calendar_object where calendar_id = ".$calendar[0]['calendar_id']); $objects = ""; $count = count($relation); for($i = 0; $i < $count; $i++) $objects .= $relation[$i]['calendar_object_id']. ($i == ($count-1) ? '' : ','); Controller::service('PostgreSQL')->execResultSql("DELETE from calendar_object where id IN (". $objects .")"); $c = curl_init(); curl_setopt_array($c, $this->curlOPT); $r = curl_exec($c); curl_close($c); $body = json_decode($r,true); Controller::service('PostgreSQL')->execResultSql("DELETE from calendar_signature where user_uidnumber = 42798"); Controller::service('PostgreSQL')->execResultSql("DELETE from calendar where id = ".$calendar[0]['calendar_id']); $this->assertCount(0 , $body); } public function tearDown() { $this->classOAuth->unsetRefreshToken($this->refreshToken); $this->classOAuth->unsetAccessToken($this->accessToken); } } ?>