1 | <?php |
---|
2 | require_once(__DIR__ . '/../../../api/controller.php'); |
---|
3 | require_once(__DIR__ . '/../../../rest/oauth/OAuth2StorageUserCredential.php'); |
---|
4 | |
---|
5 | |
---|
6 | class NewsLastResourceTest extends PHPUnit_Framework_TestCase { |
---|
7 | |
---|
8 | private $classOAuth = null; |
---|
9 | |
---|
10 | private $user = 'user2'; |
---|
11 | private $pass = 'prognus'; |
---|
12 | private $accessToken = 'aaaaaa259f553ac148f01b6bbcbb101'; |
---|
13 | private $refreshToken = 'rrrrrr03fff3b8cdc51206244529abd'; |
---|
14 | private $url = 'http://expressodev.prognus.com.br/cristiano/expresso-api/rest/newslast'; |
---|
15 | private $curlOPT; |
---|
16 | private $client_id = 666; |
---|
17 | private $user_id = 666; |
---|
18 | |
---|
19 | |
---|
20 | public function setUp(){ |
---|
21 | $this->classOAuth = new OAuth2StorageUserCredential(); |
---|
22 | |
---|
23 | $_SESSION['wallet']['user']['uid'] = $this->user; |
---|
24 | $_SESSION['wallet']['user']['password'] = $this->pass; |
---|
25 | |
---|
26 | //insere access token |
---|
27 | $this->classOAuth->setAccessToken($this->accessToken, $this->client_id, $this->user_id, (time() + 3600), 'all', $this->refreshToken); |
---|
28 | |
---|
29 | //insere refresh token |
---|
30 | $this->classOAuth->setRefreshToken($this->refreshToken, $this->client_id, $this->user_id, (time() + 3600), 'all'); |
---|
31 | $this->curlOPT = array( CURLOPT_URL => $this->url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_TIMEOUT => 4 , CURLOPT_HTTPHEADER => array( 'Authorization: OAUTH Bearer aaaaaa259f553ac148f01b6bbcbb101')); |
---|
32 | |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | public $provider= |
---|
37 | array( |
---|
38 | array( 1332877974, 'teste de aplicação 1', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
39 | array( 1332877974, 'teste de aplicação 2', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
40 | array( 1332877974, 'teste de aplicação 3', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
41 | array( 1332877974, 'teste de aplicação 4', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
42 | array( 1332877974, 'teste de aplicação 5', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
43 | array( 1332877974, 'teste de aplicação 6', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
44 | array( 1332877974, 'teste de aplicação 7', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
45 | array( 1332877974, 'teste de aplicação 8', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
46 | array( 1332877974, 'teste de aplicação 9', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
47 | array( 1332877974, 'teste de aplicação 10', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1), |
---|
48 | array( 1332877974, 'teste de aplicação 11', 'php unit teste', '<div>Teste de funcionamento</div>', '0', 2147483647, 1, 1) |
---|
49 | ); |
---|
50 | |
---|
51 | public function testcreateResource() { |
---|
52 | foreach($this->provider as $key => $value){ |
---|
53 | Controller::service('PostgreSQL')->execResultSql( "INSERT INTO phpgw_news (news_date,news_subject, |
---|
54 | news_submittedby, news_content, news_begin, news_end, news_cat, is_html)VALUES('".$value[0]."', |
---|
55 | '".$value[1]."', '".$value[2]."','".$value[3]."','".$value[4]."','".$value[5]."', '".$value[6]."', '".$value[7]."')"); |
---|
56 | } |
---|
57 | //Controller::service('PostgreSQL')->commit(); |
---|
58 | } |
---|
59 | |
---|
60 | public function testCheckMaxResource() { |
---|
61 | $c = curl_init(); |
---|
62 | curl_setopt_array($c, $this->curlOPT); |
---|
63 | $r = curl_exec($c); |
---|
64 | curl_close($c); |
---|
65 | |
---|
66 | $body = json_decode($r,true); |
---|
67 | $this->assertCount(10, $body); |
---|
68 | } |
---|
69 | |
---|
70 | public function testCheckResource() { |
---|
71 | $c = curl_init(); |
---|
72 | curl_setopt_array($c, $this->curlOPT); |
---|
73 | $r = curl_exec($c); |
---|
74 | curl_close($c); |
---|
75 | |
---|
76 | $body = json_decode($r,true); |
---|
77 | |
---|
78 | foreach($body as $key => $value){ |
---|
79 | $this->assertArrayHasKey('subject', $body[$key]); |
---|
80 | $this->assertArrayHasKey('content', $body[$key]); |
---|
81 | $this->assertArrayHasKey('startTime', $body[$key]); |
---|
82 | $this->assertArrayHasKey('endTime', $body[$key]); |
---|
83 | $this->assertArrayHasKey('id', $body[$key]); |
---|
84 | $this->assertArrayHasKey('subject', $body[$key]); |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | public function testCheckFinish() { |
---|
90 | |
---|
91 | $c = curl_init(); |
---|
92 | curl_setopt_array($c, $this->curlOPT); |
---|
93 | $r = curl_exec($c); |
---|
94 | curl_close($c); |
---|
95 | |
---|
96 | $body = json_decode($r,true); |
---|
97 | $countCurrent = count($body) - 9; |
---|
98 | |
---|
99 | Controller::service('PostgreSQL')->execResultSql( "DELETE FROM phpgw_news where news_submittedby = 'php unit teste'"); |
---|
100 | |
---|
101 | $c = curl_init(); |
---|
102 | curl_setopt_array($c, $this->curlOPT); |
---|
103 | $r = curl_exec($c); |
---|
104 | curl_close($c); |
---|
105 | |
---|
106 | $body = json_decode($r,true); |
---|
107 | $this->assertCount($countCurrent , $body); |
---|
108 | } |
---|
109 | |
---|
110 | public function tearDown() { |
---|
111 | $this->classOAuth->unsetRefreshToken($this->refreshToken); |
---|
112 | $this->classOAuth->unsetAccessToken($this->accessToken); |
---|
113 | } |
---|
114 | } |
---|
115 | ?> |
---|