forked from jmathai/twitter-async
/
EpiTwitterTest.php
494 lines (441 loc) · 26 KB
/
EpiTwitterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<?php
error_reporting(E_STRICT);
require_once '../EpiCurl.php';
require_once '../EpiOAuth.php';
require_once '../EpiTwitter.php';
require_once 'PHPUnit/Framework.php';
class EpiTwitterTest extends PHPUnit_Framework_TestCase
{
public $consumer_key = 'jdv3dsDhsYuJRlZFSuI2fg';
public $consumer_secret = 'NNXamBsBFG8PnEmacYs0uCtbtsz346OJSod7Dl94';
public $token = '25451974-uakRmTZxrSFQbkDjZnTAsxDO5o9kacz2LT6kqEHA';
public $secret= 'CuQPQ1WqIdSJDTIkDUlXjHpbcRao9lcKhQHflqGE8';
public $id = '25451974';
public $screenName = 'jmathai_test';
public $twitterUsername = 'jmathai_test';
public $twitterPassword = 'jmathai_test';
function setUp()
{
// key and secret for a test app (don't really care if this is public)
$this->twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this->token, $this->secret);
$this->twitterObjUnAuth = new EpiTwitter($this->consumer_key, $this->consumer_secret);
$this->twitterObjBasic = new EpiTwitter();
$this->twitterObjBadAuth = new EpiTwitter('foo', 'bar', 'foo', 'bar');
}
function testGetAuthenticateurl()
{
$aUrl = $this->twitterObjUnAuth->getAuthenticateUrl();
$this->assertTrue(strstr($aUrl, 'http://twitter.com/oauth/authenticate') !== false, 'Authenticate url did not contain member definition from EpiTwitter class');
$aUrl = $this->twitterObjUnAuth->getAuthenticateUrl(null, array('force_login'=>'true'));
$this->assertTrue(strstr($aUrl, 'http://twitter.com/oauth/authenticate') !== false, 'Authenticate url did not contain member definition from EpiTwitter class');
$this->assertTrue(strstr($aUrl, 'force_login=true') !== false, 'Authenticate url did not contain member definition from EpiTwitter class');
}
function testGetAuthorizeUrl()
{
$aUrl = $this->twitterObjUnAuth->getAuthorizeUrl($this->token);
$this->assertTrue(strstr($aUrl, 'http://twitter.com/oauth/authorize') !== false, 'Authorize url did not contain member definition from EpiTwitter class');
}
function testGetRequestToken()
{
$resp = $this->twitterObjUnAuth->getRequestToken();
$this->assertTrue(strlen($resp->oauth_token) > 0, "oauth_token is longer than 0");
$this->assertTrue(strlen($resp->oauth_token_secret) > 0, "oauth_token_secret is longer than 0");
$this->assertTrue(strlen($resp->oauth_callback_confirmed) == 0, "oauth_callback is not = true");
$resp = $this->twitterObjUnAuth->getRequestToken(array('oauth_callback' => urlencode('http://www.yahoo.com')));
$this->assertTrue(strlen($resp->oauth_token) > 0, "oauth_token is longer than 0");
$this->assertTrue(strlen($resp->oauth_token_secret) > 0, "oauth_token_secret is longer than 0");
$this->assertTrue($resp->oauth_callback_confirmed == 'true', "oauth_callback is not = true");
}
function testBooleanResponse()
{
$resp = $this->twitterObj->get('/friendships/exists.json', array('user_a' => 'jmathai_test','user_b' => 'jmathai'));
$this->assertTrue(gettype($resp->response) === 'boolean', 'response should be a boolean for friendship exists');
$this->assertTrue($resp->response, 'response should be true for friendship exists');
// __call
$resp = $this->twitterObj->get_friendshipsExists(array('user_a' => 'jmathai_test','user_b' => 'jmathai'));
$this->assertTrue(gettype($resp->response) === 'boolean', 'response should be a boolean for friendship exists');
$this->assertTrue($resp->response, 'response should be true for friendship exists');
}
function testGetVerifyCredentials()
{
$resp = $this->twitterObj->get('/account/verify_credentials.json');
$this->assertTrue(strlen($resp->responseText) > 0, 'responseText was empty');
$this->assertTrue($resp instanceof EpiTwitterJson, 'response is not an array');
$this->assertTrue(!empty($resp->screen_name), 'member property screen_name is empty');
$this->assertFalse($resp->protected, 'protected is false');
// __call
$resp = $this->twitterObj->get_accountVerify_credentials();
$this->assertTrue(strlen($resp->responseText) > 0, 'responseText was empty');
$this->assertTrue($resp instanceof EpiTwitterJson, 'response is not an array');
$this->assertTrue(!empty($resp->screen_name), 'member property screen_name is empty');
$this->assertFalse($resp->protected, 'protected is false');
}
function testGetWithParameters()
{
$resp = $this->twitterObj->get('/statuses/friends_timeline.json', array('since_id' => 1));
$this->assertTrue(!empty($resp->response[0]['user']['screen_name']), 'first status has no screen name');
// __call
$resp = $this->twitterObj->get_statusesFriends_timeline(array('since_id' => 1));
$this->assertTrue(!empty($resp->response[0]['user']['screen_name']), 'first status has no screen name');
}
function testGetFollowers()
{
$resp = $this->twitterObj->get('/statuses/followers.json');
$this->assertTrue(count($resp) > 0, 'Count of followers is not greater than 0');
$this->assertTrue(!empty($resp[0]), 'array access for resp is empty');
foreach($resp as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
$this->assertTrue($k > 0, 'test did not properly loop over followers');
// __call
$resp = $this->twitterObj->get_statusesFollowers();
$this->assertTrue(count($resp) > 0, 'Count of followers is not greater than 0');
$this->assertTrue(!empty($resp[0]), 'array access for resp is empty');
foreach($resp as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
$this->assertTrue($k > 0, 'test did not properly loop over followers');
}
function testPostStatus()
{
$statusText = 'Testing really weird chars "~!@#$%^&*()-+\[]{}:\'>?<≈ç∂´ß©ƒ˙˙∫√√ƒƒ∂∂†¥∆∆∆ (time: ' . time() . ')';
$resp = $this->twitterObj->post('/statuses/update.json', array('status' => $statusText));
$this->assertEquals($resp->text, str_replace(array('<','>'),array('<','>'),$statusText), 'The status was not updated correctly');
// starting with @ addresses gh-40 (basic)
$statusText = '@ (start with an at sign) at time of ' . time();
$resp = $this->twitterObjBasic->post_basic('/statuses/update.json', array('status' => $statusText), 'jmathai_test', 'jmathai_test');
$this->assertEquals($resp->text, str_replace(array('<','>'),array('<','>'),$statusText), 'The status was not updated correctly when starting witn an @ sign');
// __call
$statusText = '_call version of the randomness ∂´ßƒƒ∂∂†¥©ƒ˙˙∫√√"~!@#$%^&*()-+\[]{}:\'>?<≈ç∆∆∆ (time: ' . time() . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
$this->assertEquals($resp->text, str_replace(array('<','>'),array('<','>'),$statusText), 'The status was not updated correctly for __call');
$statusText = 'Testing a random status (time: ' . time() . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
$this->assertEquals($resp->text, $statusText, 'The status was not updated correctly_ for call w/o randomness');
// reply to it
$statusText = 'Testing a random status with reply to id (reply to: ' . $resp->id . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText, 'in_reply_to_status_id' => "{$resp->id}"));
$this->assertEquals($resp->text, $statusText, 'The status with reply to id was not updated correctly for __call');
}
function testRetweet()
{
srand((float) microtime() * 10000000);
$input = array("hello", "matrix", "twitter", "internet", "textbook");
$rand_key = array_rand($input);
$term = $input[$rand_key];
$statusText = 'This test is to check if the retweet functionality is working (time: ' . time() . ')';
$resp = $this->twitterObj->post('/statuses/update.json', array('status' => $statusText));
$this->assertEquals($resp->text, $statusText, 'The status was not updated correctly prior to checking retweet');
// get a public status and retweet it
$public = $this->twitterObjBasic->get_basic('/search.json', array('q' => $term));
$resp = $this->twitterObj->post("/statuses/retweet/{$public->results[rand(0,5)]->id}.json");
$this->assertEquals('RT', substr($resp->text, 0, 2), 'Retweet response text did not start with RT');
// reply to it
$statusText = 'This is a random reply to a retweet test with a replyto status id (reply to: ' . $resp->id . ')';
$resp = $this->twitterObj->post('/statuses/update.json', array('status' => $statusText, 'in_reply_to_status_id' => "{$resp->id}"));
$this->assertEquals($resp->text, $statusText, 'The status with reply to id was not updated correctly when replying to an update');
}
function testPostStatusUnicode()
{
$statusText = 'Testing a random status with unicode בוקר טוב (' . time() . ')';
$resp = $this->twitterObj->post('/statuses/update.json', array('status' => $statusText));
$this->assertEquals($resp->text, $statusText, 'The status was not updated correctly');
// __call
$statusText = 'Testing a random status with unicode בוקר טוב (' . time() . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
$this->assertEquals($resp->text, $statusText, 'The status was not updated correctly');
}
function testDirectMessage()
{
$resp = $this->twitterObj->post('/direct_messages/new.json', array ( 'user' => $this->screenName, 'text' => "@username that's dirt cheap man, good looking out. I shall buy soon.You still play Halo at all?"));
$this->assertTrue(!empty($resp->response['id']), "response id is empty");
// __call
$resp = $this->twitterObj->post_direct_messagesNew( array ( 'user' => $this->screenName, 'text' => "@username that's dirt cheap man, good looking out. I shall buy soon.You still play Halo at all?"));
$this->assertTrue(!empty($resp->response['id']), "response id is empty");
}
function testPassingInTokenParams()
{
$this->twitterObj->setToken(null, null);
$token = $this->twitterObj->getRequestToken();
$authenticateUrl = $this->twitterObj->getAuthorizationUrl($token);
$this->assertEquals($token->oauth_token, substr($authenticateUrl, (strpos($authenticateUrl, '=')+1)), "token does not equal the one which was passed in");
}
function testResponseAccess()
{
$resp = $this->twitterObj->get('/statuses/followers.json');
$this->assertTrue(!empty($resp[0]), 'array access for resp is empty');
$this->assertEquals($resp[0], $resp->response[0], 'array access for resp is empty');
foreach($resp as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
$this->assertTrue($k > 0, 'test did not properly loop over followers');
// __call
$resp = $this->twitterObj->get_statusesFollowers();
$this->assertTrue(!empty($resp[0]), 'array access for resp is empty');
$this->assertEquals($resp[0], $resp->response[0], 'array access for resp is empty');
foreach($resp as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
$this->assertTrue($k > 0, 'test did not properly loop over followers');
}
function testSearch()
{
$resp = $this->twitterObjBasic->get_basic('/search.json', array('q' => 'hello'));
$this->assertTrue(is_array($resp->response['results']));
$this->assertTrue(!empty($resp->results[0]->text), "search response is not an array {$resp->results[0]->text}");
$resp = $this->twitterObjBasic->get_basic('/search.json', array('geocode' => '40.757929,-73.985506,25km', 'rpp' => 10));
$this->assertTrue(is_array($resp->response['results']));
$this->assertTrue(!empty($resp->results[0]->text), "search response is not an array {$resp->results[0]->text}");
// __call
$resp = $this->twitterObjBasic->get_search(array('q' => 'hello'));
$this->assertTrue(is_array($resp->response['results']));
$this->assertTrue(!empty($resp->results[0]->text), "search response is not an array {$resp->results[0]->text}");
$resp = $this->twitterObjBasic->get_search(array('geocode' => '40.757929,-73.985506,25km', 'rpp' => 10));
$this->assertTrue(is_array($resp->response['results']));
$this->assertTrue(!empty($resp->results[0]->text), "search response is not an array {$resp->results[0]->text}");
}
function testTrends()
{
$resp = $this->twitterObjBasic->get('/trends.json');
$this->assertTrue(is_array($resp->response['trends']), "trends is empty");
$this->assertTrue(!empty($resp->trends[0]->name), "current trends is not an array " . $resp->trends[0]->name);
$resp = $this->twitterObjBasic->get('/trends/current.json');
$this->assertTrue(is_array($resp->response['trends']), "current trends is empty");
// __call
$resp = $this->twitterObjBasic->get_trends();
$this->assertTrue(is_array($resp->response['trends']), "trends is empty");
$this->assertTrue(!empty($resp->trends[0]->name), "current trends is not an array " . $resp->trends[0]->name);
$resp = $this->twitterObjBasic->get_trendsCurrent();
$this->assertTrue(is_array($resp->response['trends']), "current trends is empty");
}
function testGetTrendsAvailable()
{
$trends = $this->twitterObj->get('/trends/available.json');
$this->assertTrue($trends->response[0]['woeid'] > 0, 'woeid should be < 0');;
}
function testBasicAuth()
{
$resp = $this->twitterObjBasic->get_basic('/account/verify_credentials.json', null, $this->twitterUsername, $this->twitterPassword);
$this->assertEquals($resp->screen_name, $this->screenName, "Screenname from response is not {$this->screenName} when using get_basic");
$status = 'Basic auth status update ' . time();
$resp = $this->twitterObjBasic->post_basic('/statuses/update.json', array('status' => $status), $this->twitterUsername, $this->twitterPassword);
$this->assertEquals(200, $resp->code, "Status update response code was not 200");
$newStatus = $this->twitterObjBasic->get_basic('/statuses/show.json', array('id' => $resp->id));
$this->assertEquals($status, $newStatus->text, "Updated status is not what it should be");
// testing __call
$resp = $this->twitterObjBasic->get_accountVerify_credentials(null, $this->twitterUsername, $this->twitterPassword);
$this->assertEquals($resp->screen_name, $this->screenName, "Screenname from response is not {$this->screenName}");
$status = 'Basic auth status update ' . time();
$resp = $this->twitterObjBasic->post_statusesUpdate(array('status' => $status), $this->twitterUsername, $this->twitterPassword);
$this->assertEquals(200, $resp->code, "Status update response code was not 200");
$newStatus = $this->twitterObjBasic->get_statusesShow(array('id' => $resp->id));
$this->assertEquals($status, $newStatus->text, "Updated status is not what it should be");
}
function testSSl()
{
$this->twitterObj->useSSL(true);
$resp = $this->twitterObj->get('/account/verify_credentials.json');
$this->assertTrue(strlen($resp->responseText) > 0, 'responseText was empty');
$this->assertTrue($resp instanceof EpiTwitterJson, 'response is not an array');
$this->assertTrue(!empty($resp->screen_name), 'member property screen_name is empty');
$this->twitterObj->useSSL(false);
// __call
$this->twitterObj->useSSL(true);
$resp = $this->twitterObj->get_accountVerify_credentials();
$this->assertTrue(strlen($resp->responseText) > 0, 'responseText was empty');
$this->assertTrue($resp instanceof EpiTwitterJson, 'response is not an array');
$this->assertTrue(!empty($resp->screen_name), 'member property screen_name is empty');
$this->twitterObj->useSSL(false);
}
function testCount()
{
$screenName = ucwords(strtolower($this->screenName));
$resp = $this->twitterObj->get("/statuses/followers/{$screenName}.json");
$this->assertTrue(count($resp) > 0, "Count for followers was not larger than 0");
// __call
$method = "get_statusesFollowers{$screenName}";
$resp = $this->twitterObj->$method();
$this->assertTrue(count($resp) > 0, "Count for followers was not larger than 0");
}
function testFavorites()
{
// get favs
$resp = $this->twitterObj->get("/favorites/{$this->screenName}.json");
$this->assertEquals(count($resp), 0, "Favorites should be length 0");
// create fav
$public = $this->twitterObjBasic->get_basic('/search.json', array('q' => 'hello'));
$resp = $this->twitterObj->post("/favorites/create/{$public->results[0]->id}.json");
$this->assertEquals($resp->id, $public->results[0]->id, "Created fav should have same id");
// destroy fav
$resp = $this->twitterObj->post("/favorites/destroy/{$public->results[0]->id}.json");
$this->assertEquals($resp->id, $public->results[0]->id, "Destroy fav should have same id");
$resp = $this->twitterObj->get("/favorites/{$this->screenName}.json");
$this->assertEquals(count($resp), 0, "Favorites should be length 0 after destroying");
}
function testUpdateAvatar()
{
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post('/account/update_profile_image.json', array('@image' => "@{$file}"));
// api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
$this->assertEquals($resp->code, 200, 'Response code was not 200');
// __call
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post_accountUpdate_profile_image(array('@image' => "@{$file}"));
// api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
$this->assertEquals($resp->code, 200, 'Response code was not 200');
}
function testUpdateBackground()
{
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post('/account/update_profile_background_image.json', array('@image' => "@{$file}", 'tile' => 'true'));
// api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
$this->assertEquals($resp->code, 200, 'Response code was not 200');
// __call
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post_accountUpdate_profile_background_image(array('@image' => "@{$file}"));
// api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
$this->assertEquals($resp->code, 200, 'Response code was not 200');
}
function testCreateFriendship()
{
// check if friendship exists
$exists = $this->twitterObj->get('/friendships/exists.json', array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
if($exists->response)
{
$destroy = $this->twitterObj->post('/friendships/destroy.json', array('id' => 'pbct_test'));
$destroy->responseText;
}
// perform checks now that env is set up
$exists = $this->twitterObj->get('/friendships/exists.json', array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
$this->assertFalse($exists->response, 'Friendship already exists and should not for create test');
$create = $this->twitterObj->post('/friendships/create.json', array('id' => 'pbct_test'));
$this->assertTrue($create->id > 0, 'ID is empty from create friendship call');
// __call
// check if friendship exists
$exists = $this->twitterObj->get_friendshipsExists(array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
if($exists->response)
{
$destroy = $this->twitterObj->post_friendshipsDestroy(array('id' => 'pbct_test'));
$destroy->responseText;
}
// perform checks now that env is set up
$exists = $this->twitterObj->get_friendshipsExists(array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
$this->assertFalse($exists->response, 'Friendship already exists and should not for create test');
$create = $this->twitterObj->post_friendshipsCreate(array('id' => 'pbct_test'));
$this->assertTrue($create->id > 0, 'ID is empty from create friendship call');
}
function testDestroyFriendship()
{
// check if friendship exists
$exists = $this->twitterObj->get('/friendships/exists.json', array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
if(!$exists->response)
{
$create = $this->twitterObj->post('/friendships/create.json', array('id' => 'pbct_test'));
$create->responseText;
}
// perform checks now that env is set up
$exists = $this->twitterObj->get('/friendships/exists.json', array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
$this->assertTrue($exists->response, 'Friendship does not exist to be destroyed');
$destroy = $this->twitterObj->post('/friendships/destroy.json', array('id' => 'pbct_test'));
$this->assertTrue($destroy->id > 0, 'ID is empty from destroy friendship call');
//__call
// check if friendship exists
$exists = $this->twitterObj->get_friendshipsExists(array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
if(!$exists->response)
{
$create = $this->twitterObj->post_friendshipsCreate(array('id' => 'pbct_test'));
$create->responseText;
}
// perform checks now that env is set up
$exists = $this->twitterObj->get_friendshipsExists(array('user_a' => $this->screenName, 'user_b' => 'pbct_test'));
$this->assertTrue($exists->response, 'Friendship does not exist to be destroyed');
$destroy = $this->twitterObj->post_friendshipsDestroy(array('id' => 'pbct_test'));
$this->assertTrue($destroy->id > 0, 'ID is empty from destroy friendship call');
}
function testGetFriendsIds()
{
$twitterFriends = $this->twitterObj->get('/friends/ids.json', array('screen_name' => $this->screenName));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get friend ids is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get friend ids is empty');;
$twitterFriends = $this->twitterObj->get('/friends/ids.json', array('user_id' => $this->id));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get friend ids is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get friend ids is empty');;
// __call
$twitterFriends = $this->twitterObj->get_friendsIds(array('screen_name' => $this->screenName));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get friend ids is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get friend ids is empty');;
$twitterFriends = $this->twitterObj->get_friendsIds(array('user_id' => $this->id));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get friend ids is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get friend ids is empty');;
}
function testGetStatusesFriends()
{
$twitterFriends = $this->twitterObj->get('/statuses/friends.json', array('screen_name' => $this->screenName));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get statuses friends is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get statuses friends is empty');;
$twitterFriends = $this->twitterObj->get('/statuses/friends.json', array('user_id' => $this->id));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get statuses friends is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get statuses friends is empty');;
// __call
$twitterFriends = $this->twitterObj->get_statusesFriends(array('screen_name' => $this->screenName));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get statuses friends is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get statuses friends is empty');;
$twitterFriends = $this->twitterObj->get_statusesFriends(array('user_id' => $this->id));
$this->assertTrue(count($twitterFriends->response) > 0, 'Count of get statuses friends is 0');;
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get statuses friends is empty');;
}
function testCreateAndDeleteList()
{
// create the list
$name = 'test list ' . rand(0,1000);
$resp = $this->twitterObj->post("/{$this->twitterUsername}/lists.json", array('name' => $name, 'mode' => 'public', 'description' => "List {$name}"));
$this->assertEquals($resp->name, $name, "List name is not {$name} but rather {$resp->list}");
// delete the list
$respDel = $this->twitterObj->delete("/{$this->twitterUsername}/lists/{$resp->id}.json");
$this->assertEquals($respDel->id, $resp->id, "Deleted list id doesn't match the id of the list we just created");
// verify the delete worked
$respGet = $this->twitterObj->get("/{$this->twitterUsername}/lists/{$resp->id}.json");
$this->assertEquals($respGet->code, '404', "Getting the previously deleted list should return 404 and not {$respGet->code}");
}
function testDestructor()
{
$status = 'Testing destructor ' . time();
$resp1 = $this->twitterObj->post_statusesUpdate(array('status' => $status));
unset($resp1);
$resp2 = $this->twitterObj->get_accountVerify_credentials();
$this->assertEquals($status, $resp2->status->text, 'The destructor did not ensure that the status was updated');
}
function testHeaders()
{
$resp = $this->twitterObj->get_statusesFollowers();
$this->assertTrue(!empty($resp->headers['Status']), 'header status response should not be empty');
}
/**
* @expectedException EpiTwitterForbiddenException
*/
function testNoRequiredParameter()
{
$resp = $this->twitterObj->post_direct_messagesNew( array ( 'user' => $this->screenName, 'text' => ''));
$resp->response;
}
/**
* @expectedException EpiTwitterNotAuthorizedException
*/
function testBadCredentials()
{
$resp = $this->twitterObjBadAuth->post_direct_messagesNew( array ( 'user' => $this->screenName, 'text' => 'hello world'));
$resp->response;
}
/**
* @expectedException EpiTwitterNotFoundException
*/
function testNonExistantUser()
{
$resp = $this->twitterObj->post_direct_messagesNew( array ( 'user' => 'jaisen_does_not_exist_and_dont_create_or_this_will_break', 'text' => 'seriously'));
$resp->response;
}
}