|
1 |
| -<?php |
2 |
| - |
3 |
| -namespace Codebird; |
4 |
| -require_once ('test/codebirdt.php'); |
5 |
| - |
6 |
| -/** |
7 |
| - * A Twitter library in PHP. |
8 |
| - * |
9 |
| - * @package codebird-test |
10 |
| - * @author Jublo Solutions <support@jublo.net> |
11 |
| - * @copyright 2010-2016 Jublo Solutions <support@jublo.net> |
12 |
| - * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 |
13 |
| - * @link https://github.com/jublonet/codebird-php |
14 |
| - */ |
15 |
| - |
16 |
| -/** |
17 |
| - * Codebird testing class with mock data source |
18 |
| - * |
19 |
| - * @package codebird-test |
20 |
| - */ |
21 |
| -class CodebirdM extends CodebirdT |
22 |
| -{ |
23 |
| - /** |
24 |
| - * Stores the request data |
25 |
| - */ |
26 |
| - protected $_requests = []; |
27 |
| - |
28 |
| - /** |
29 |
| - * Mock API replies |
30 |
| - */ |
31 |
| - protected static $_mock_replies = [ |
32 |
| - 'default' => [ |
33 |
| - 'httpstatus' => 404, |
34 |
| - 'reply' => "HTTP/1.1 404 Not Found\r\ncontent-length: 68\r\ncontent-type: application/json;charset=utf-8\r\ndate: Sun, 06 Dec 2015 14:43:28 GMT\r\nserver: tsa_b\r\nset-cookie: guest_id=v1%3A144941300885288055; Domain=.twitter.com; Path=/; Expires=Tue, 05-Dec-2017 14:43:28 UTC\r\nstrict-transport-security: max-age=631138519\r\nx-connection-hash: 12218aef9e9757609afb08e661fa3b9b\r\nx-response-time: 2\r\n\r\n{\"errors\":[{\"message\":\"Sorry, that page does not exist\",\"code\":34}]}" |
35 |
| - ], |
36 |
| - 'proxy1' => [ |
37 |
| - 'httpstatus' => 404, |
38 |
| - 'reply' => "HTTP/1.1 200 Connection Established\r\n\r\nHTTP/1.1 404 Not Found\r\ncontent-length: 68\r\ncontent-type: application/json;charset=utf-8\r\ndate: Sun, 06 Dec 2015 14:43:28 GMT\r\nserver: tsa_b\r\nset-cookie: guest_id=v1%3A144941300885288055; Domain=.twitter.com; Path=/; Expires=Tue, 05-Dec-2017 14:43:28 UTC\r\nstrict-transport-security: max-age=631138519\r\nx-connection-hash: 12218aef9e9757609afb08e661fa3b9b\r\nx-response-time: 2\r\n\r\n{\"errors\":[{\"message\":\"Sorry, that page does not exist\",\"code\":34}]}" |
39 |
| - ], |
40 |
| - 'GET http://www.example.org/found.txt' => [ |
41 |
| - 'httpstatus' => 200, |
42 |
| - 'reply' => "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nA test file." |
43 |
| - ], |
44 |
| - 'GET https://api.twitter.com/1.1/users/show.json?screen_name=TwitterAPI' => [ |
45 |
| - 'httpstatus' => 200, |
46 |
| - 'reply' => "HTTP/1.1 200 OK\r\ncache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0\r\ncontent-disposition: attachment; filename=json.json\r\ncontent-length: 2801\r\ncontent-type: application/json;charset=utf-8\r\ndate: Sun, 06 Dec 2015 14:55:46 GMT\r\nexpires: Tue, 31 Mar 1981 05:00:00 GMT\r\nlast-modified: Sun, 06 Dec 2015 14:55:46 GMT\r\npragma: no-cache\r\nserver: tsa_b\r\nset-cookie: lang=en-gb; Path=/\r\nset-cookie: guest_id=v1%3A144941374684866365; Domain=.twitter.com; Path=/; Expires=Tue, 05-Dec-2017 14:55:46 UTC\r\nstatus: 200 OK\r\nstrict-transport-security: max-age=631138519\r\nx-access-level: read-write-directmessages\r\nx-connection-hash: 1906b689730b92318bccf65b496f74d0\r\nx-content-type-options: nosniff\r\nx-frame-options: SAMEORIGIN\r\nx-rate-limit-limit: 181\r\nx-rate-limit-remaining: 177\r\nx-rate-limit-reset: 1449414513\r\nx-response-time: 44\r\nx-transaction: 663cc05c64857ba0\r\nx-twitter-response-tags: BouncerCompliant\r\nx-xss-protection: 1; mode=block\r\n\r\n{\"id\":6253282,\"id_str\":\"6253282\",\"name\":\"Twitter API\",\"screen_name\":\"twitterapi\",\"location\":\"San Francisco, CA\",\"profile_location\":null,\"description\":\"The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.\",\"url\":\"http:\/\/t.co\/78pYTvWfJd\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\/\/t.co\/78pYTvWfJd\",\"expanded_url\":\"http:\/\/dev.twitter.com\",\"display_url\":\"dev.twitter.com\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":4993679,\"friends_count\":48,\"listed_count\":13001,\"created_at\":\"Wed May 23 06:01:13 +0000 2007\",\"favourites_count\":27,\"utc_offset\":-28800,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":true,\"verified\":true,\"statuses_count\":3553,\"lang\":\"en\",\"status\":{\"created_at\":\"Tue Nov 24 08:56:07 +0000 2015\",\"id\":669077021138493440,\"id_str\":\"669077021138493440\",\"text\":\"Additional 64-bit entity ID migration coming in Feb 2016 https:\/\/t.co\/eQIGvw1rsJ\",\"source\":\"\u003ca href=\\\"https:\/\/about.twitter.com\/products\/tweetdeck\\\" rel=\\\"nofollow\\\"\u003eTweetDeck\u003c\/a\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":67,\"favorite_count\":79,\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[],\"urls\":[{\"url\":\"https:\/\/t.co\/eQIGvw1rsJ\",\"expanded_url\":\"https:\/\/twittercommunity.com\/t\/migration-of-twitter-core-entities-to-64-bit-ids\/56881\",\"display_url\":\"twittercommunity.com\/t\/migration-of\u2026\",\"indices\":[57,80]}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\/\/pbs.twimg.com\/profile_background_images\/656927849\/miyt9dpjz77sc0w3d4vj.png\",\"profile_background_image_url_https\":\"https:\/\/pbs.twimg.com\/profile_background_images\/656927849\/miyt9dpjz77sc0w3d4vj.png\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\/\/pbs.twimg.com\/profile_images\/2284174872\/7df3h38zabcvjylnyfe3_normal.png\",\"profile_image_url_https\":\"https:\/\/pbs.twimg.com\/profile_images\/2284174872\/7df3h38zabcvjylnyfe3_normal.png\",\"profile_banner_url\":\"https:\/\/pbs.twimg.com\/profile_banners\/6253282\/1431474710\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":false,\"default_profile_image\":false,\"following\":true,\"follow_request_sent\":false,\"notifications\":false}" |
47 |
| - ], |
48 |
| - 'POST https://api.twitter.com/oauth2/token' => [ |
49 |
| - 'httpstatus' => 200, |
50 |
| - 'reply' => "HTTP/1.1 200 OK\r\ncache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0\r\ncontent-disposition: attachment; filename=json.json\r\ncontent-length: 52\r\ncontent-type: application/json;charset=utf-8\r\ndate: Sun, 06 Dec 2015 15:53:02 GMT\r\nexpires: Tue, 31 Mar 1981 05:00:00 GMT\r\nlast-modified: Sun, 06 Dec 2015 15:53:01 GMT\r\nml: S\r\npragma: no-cache\r\nserver: tsa_b\r\nset-cookie: guest_id=v1%3A144941718194388038; Domain=.twitter.com; Path=/; Expires=Tue, 05-Dec-2017 15:53:02 UTC\r\nstatus: 200 OK\r\nstrict-transport-security: max-age=631138519\r\nx-connection-hash: 97f4d4e6a33433b477510d8c58a0b026\r\nx-content-type-options: nosniff\r\nx-frame-options: DENY\r\nx-response-time: 87\r\nx-transaction: 6a0e5e8144d7e6df\r\nx-tsa-request-body-time: 164\r\nx-twitter-response-tags: BouncerCompliant\r\nx-ua-compatible: IE=edge,chrome=1\r\nx-xss-protection: 1; mode=block\r\n\r\n{\"token_type\":\"bearer\",\"access_token\":\"VqiO0n2HrKE\"}" |
51 |
| - ] |
52 |
| - ]; |
53 |
| - |
54 |
| - /** |
55 |
| - * Gets a mock cURL handle |
56 |
| - * @param string $url the URL for the curl initialization |
57 |
| - * @return string connection ID |
58 |
| - */ |
59 |
| - protected function _curl_init($url = null) |
60 |
| - { |
61 |
| - $request = [ |
62 |
| - 'url' => $url, |
63 |
| - CURLOPT_RETURNTRANSFER => false |
64 |
| - ]; |
65 |
| - $id = mt_rand(); |
66 |
| - $this->_requests[$id] = $request; |
67 |
| - |
68 |
| - return $id; |
69 |
| - } |
70 |
| - |
71 |
| - /** |
72 |
| - * Sets mock cURL parameters |
73 |
| - * @param string $id connection ID |
74 |
| - * @param int $option cURL option to set |
75 |
| - * @param mixed $value Value to set for the option |
76 |
| - * @return bool |
77 |
| - */ |
78 |
| - protected function _curl_setopt($id, $option, $value) |
79 |
| - { |
80 |
| - if (!isset($this->_requests[$id])) { |
81 |
| - return false; |
82 |
| - } |
83 |
| - |
84 |
| - $this->_requests[$id][$option] = $value; |
85 |
| - |
86 |
| - return true; |
87 |
| - } |
88 |
| - |
89 |
| - /** |
90 |
| - * Executes mock cURL transfer |
91 |
| - * @param string $id connection ID |
92 |
| - * @return bool|string |
93 |
| - */ |
94 |
| - protected function _curl_exec($id) |
95 |
| - { |
96 |
| - if (!isset($this->_requests[$id])) { |
97 |
| - return false; |
98 |
| - } |
99 |
| - |
100 |
| - $request = $this->_requests[$id]; |
101 |
| - $url = $this->_requests[$id]['url']; |
102 |
| - $reply = self::$_mock_replies['default']; |
103 |
| - |
104 |
| - $httpmethod = 'GET'; |
105 |
| - if (isset($request[CURLOPT_POST]) && $request[CURLOPT_POST]) { |
106 |
| - $httpmethod = 'POST'; |
107 |
| - } |
108 |
| - if (isset($request[CURLOPT_CUSTOMREQUEST])) { |
109 |
| - $httpmethod = $request[CURLOPT_CUSTOMREQUEST]; |
110 |
| - } |
111 |
| - |
112 |
| - $index = $httpmethod . ' ' . $url; |
113 |
| - |
114 |
| - if (isset(self::$_mock_replies[$index])) { |
115 |
| - $reply = self::$_mock_replies[$index]; |
116 |
| - } |
117 |
| - |
118 |
| - $this->_requests[$id][CURLINFO_HTTP_CODE] = $reply['httpstatus']; |
119 |
| - $this->_requests[$id]['reply'] = $reply['reply']; |
120 |
| - |
121 |
| - if (! $this->_requests[$id][CURLOPT_HEADER] |
122 |
| - && stristr($reply['reply'], "\r\n\r\n") |
123 |
| - ) { |
124 |
| - $reply_parts = explode("\r\n\r\n", $reply['reply'], 2); |
125 |
| - $reply['reply'] = $reply_parts[1]; |
126 |
| - } |
127 |
| - |
128 |
| - if ($this->_requests[$id][CURLOPT_RETURNTRANSFER]) { |
129 |
| - return $reply['reply']; |
130 |
| - } |
131 |
| - |
132 |
| - return true; |
133 |
| - } |
134 |
| - |
135 |
| - /** |
136 |
| - * Gets cURL error |
137 |
| - * @param string $id connection ID |
138 |
| - * @return string |
139 |
| - */ |
140 |
| - protected function _curl_error($id) |
141 |
| - { |
142 |
| - return ''; |
143 |
| - } |
144 |
| - |
145 |
| - /** |
146 |
| - * Gets cURL error |
147 |
| - * @param string $id connection ID |
148 |
| - * @return int |
149 |
| - */ |
150 |
| - protected function _curl_errno($id) |
151 |
| - { |
152 |
| - return 0; |
153 |
| - } |
154 |
| - |
155 |
| - /** |
156 |
| - * Gets info about cURL connection |
157 |
| - * @param string $id connection ID |
158 |
| - * @param int $opt option to get |
159 |
| - * @return mixed |
160 |
| - */ |
161 |
| - protected function _curl_getinfo($id, $opt = 0) |
162 |
| - { |
163 |
| - if (!isset($this->_requests[$id])) { |
164 |
| - return false; |
165 |
| - } |
166 |
| - |
167 |
| - $request = $this->_requests[$id]; |
168 |
| - |
169 |
| - if (!$opt) { |
170 |
| - return [ |
171 |
| - 'url' => $request['url'], |
172 |
| - 'http_code' => $request[CURLINFO_HTTP_CODE] |
173 |
| - ]; |
174 |
| - } |
175 |
| - |
176 |
| - if (isset($request[$opt])) { |
177 |
| - return $request[$opt]; |
178 |
| - } |
179 |
| - |
180 |
| - return false; |
181 |
| - } |
182 |
| - |
183 |
| - /** |
184 |
| - * Gets fake time |
185 |
| - * @return int Timestamp |
186 |
| - */ |
187 |
| - protected function _time() |
188 |
| - { |
189 |
| - return 1412345678; |
190 |
| - } |
191 |
| - |
192 |
| - /** |
193 |
| - * Gets fake time |
194 |
| - * @param bool $get_as_float |
195 |
| - * @return int Timestamp |
196 |
| - */ |
197 |
| - protected function _microtime($get_as_float = false) |
198 |
| - { |
199 |
| - if ($get_as_float) { |
200 |
| - return 1412345678.777; |
201 |
| - } |
202 |
| - return '777 1412345678'; |
203 |
| - } |
204 |
| -} |
| 1 | +end |
| 2 | +stop |
| 3 | +delete |
| 4 | +close |
| 5 | +void |
0 commit comments