Permalink
Browse files

Updating about 1/2 of the unit tests for v1.1 of the API. #173 #161

  • Loading branch information...
1 parent a486656 commit 0929f87e60b2d0b286ee207d6c8b47f75f162f3d @jmathai committed May 2, 2013
Showing with 106 additions and 105 deletions.
  1. +106 −105 tests/EpiTwitterTest.php
View
@@ -58,13 +58,14 @@ function testGetRequestToken()
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');
+ $this->markTestSkipped('This endpoint no longer exists.');
+ //$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()
@@ -84,28 +85,28 @@ function testGetVerifyCredentials()
function testGetWithParameters()
{
- $resp = $this->twitterObj->get('/statuses/friends_timeline.json', array('since_id' => 1));
+ $resp = $this->twitterObj->get('/statuses/home_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));
+ $resp = $this->twitterObj->get_statusesHome_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');
+ $resp = $this->twitterObj->get('/followers/list.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($resp['users']), 'array access for resp is empty');
+ foreach($resp->users 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();
+ $resp = $this->twitterObj->get_followersList();
$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($resp['users']), 'array access for resp is empty');
+ foreach($resp->users as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
@@ -116,7 +117,7 @@ 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('&lt;','&gt;'),$statusText), 'The status was not updated correctly');
+ $this->assertEquals($resp->text, str_replace(array('&','<','>'),array('&amp;','&lt;','&gt;'),$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->twitterObj->post('/statuses/update.json', array('status' => $statusText));
@@ -125,7 +126,7 @@ function testPostStatus()
// __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('&lt;','&gt;'),$statusText), 'The status was not updated correctly for __call');
+ $this->assertEquals($resp->text, str_replace(array('&','<','>'),array('&amp;','&lt;','&gt;'),$statusText), 'The status was not updated correctly');
$statusText = 'Testing a random status (time: ' . time() . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
@@ -146,9 +147,9 @@ function testRetweet()
$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->twitterObj->get('/search.json', array('q' => $term));
- $resp = $this->twitterObj->post("/statuses/retweet/{$public->results[rand(0,5)]->id_str}.json");
- $this->assertEquals('RT', substr($resp->text, 0, 2), 'Retweet response text did not start with RT');
+ $public = $this->twitterObj->get('/search/tweets.json', array('q' => $term));
+ $resp = $this->twitterObj->post("/statuses/retweet/{$public->statuses[rand(0,5)]->id_str}.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}"));
@@ -185,19 +186,19 @@ function testPassingInTokenParams()
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)
+ $resp = $this->twitterObj->get('/followers/list.json');
+ $this->assertTrue(!empty($resp['users']), 'array access for resp is empty');
+ $this->assertEquals($resp['users'], $resp->response['users'], 'array access for resp is empty');
+ foreach($resp->users 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)
+ $resp = $this->twitterObj->get_followersList();
+ $this->assertTrue(!empty($resp['users']), 'array access for resp is empty');
+ $this->assertEquals($resp['users'], $resp->response['users'], 'array access for resp is empty');
+ foreach($resp->users as $k => $v)
{
$this->assertTrue(!empty($v->screen_name), 'screen name for one of the resp nodes is empty');
}
@@ -206,42 +207,31 @@ function testResponseAccess()
function testSearch()
{
- $resp = $this->twitterObj->get('/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->twitterObj->get('/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}");
+ $resp = $this->twitterObj->get('/search/tweets.json', array('q' => 'hello'));
+ $this->assertTrue(is_array($resp->response['statuses']));
+ $this->assertTrue(!empty($resp->statuses[0]->text), "search response is not an array {$resp->results[0]->text}");
+ $resp = $this->twitterObj->get('/search/tweets.json', array('geocode' => '40.757929,-73.985506,25km', 'rpp' => 10));
+ $this->assertTrue(is_array($resp->response['statuses']));
+ $this->assertTrue(!empty($resp->statuses[0]->text), "search response is not an array {$resp->results[0]->text}");
// __call
- $resp = $this->twitterObj->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->twitterObj->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}");
+ $resp = $this->twitterObj->get_searchTweets(array('q' => 'hello'));
+ $this->assertTrue(is_array($resp->response['statuses']));
+ $this->assertTrue(!empty($resp->statuses[0]->text), "search response is not an array {$resp->results[0]->text}");
+ $resp = $this->twitterObj->get_searchTweets(array('geocode' => '40.757929,-73.985506,25km', 'rpp' => 10));
+ $this->assertTrue(is_array($resp->response['statuses']));
+ $this->assertTrue(!empty($resp->statuses[0]->text), "search response is not an array {$resp->results[0]->text}");
}
function testTrends()
{
- $resp = $this->twitterObj->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->twitterObj->get('/trends/place.json', array('id' => '1'));
+ $this->assertTrue(is_array($resp->response[0]['trends']), "trends is empty");
+ $this->assertTrue(!empty($resp[0]['trends'][0]['name']), "current trends is not an array " . $resp->trends[0]->name);
- $resp = $this->twitterObj->get('/trends/current.json');
- $this->assertTrue(is_array($resp->response['trends']), "current trends is empty");
// __call
- $resp = $this->twitterObj->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->twitterObj->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');;
+ $resp = $this->twitterObj->get_trendsPlace(array('id' => '1'));
+ $this->assertTrue(is_array($resp->response[0]['trends']), "trends is empty");
+ $this->assertTrue(!empty($resp[0]['trends'][0]['name']), "current trends is not an array " . $resp->trends[0]->name);
}
function testSSl()
@@ -261,42 +251,52 @@ function testSSl()
$this->twitterObj->useSSL(false);
}
+
function testCount()
{
$screenName = ucwords(strtolower($this->screenName));
- $resp = $this->twitterObj->get("/statuses/followers/{$screenName}.json");
+ $resp = $this->twitterObj->get("/followers/ids.json");
$this->assertTrue(count($resp) > 0, "Count for followers was not larger than 0");
// __call
- $method = "get_statusesFollowers{$screenName}";
- $resp = $this->twitterObj->$method();
+ $resp = $this->twitterObj->get_followersIds();
$this->assertTrue(count($resp) > 0, "Count for followers was not larger than 0");
}
- function testFavorites()
+ /*function testFavorites()
{
+ // clean up
+ $resp = $this->twitterObj->get("/favorites/list.json");
+
+ foreach($resp as $r)
+ {
+ $del = $this->twitterObj->post('/favorites/destroy.json', array('id' => $r->id_str));
+ $del->response;
+ }
+
// get favs
- $resp = $this->twitterObj->get("/favorites/{$this->screenName}.json");
+ $resp = $this->twitterObj->get("/favorites/list.json");
$this->assertEquals(count($resp), 0, "Favorites should be length 0");
// create fav
- $public = $this->twitterObj->get('/search.json', array('q' => 'hello'));
- $resp = $this->twitterObj->post("/favorites/create/{$public->results[0]->id_str}.json");
- $this->assertEquals($resp->id_str, $public->results[0]->id_str, "Created fav should have same id");
+ $public = $this->twitterObj->get('/search/tweets.json', array('q' => 'hello'));
+ $resp = $this->twitterObj->post('/favorites/create.json', array('id' => $public->response['statuses'][0]->id_str));
+ $this->assertEquals($resp->id_str, $public->response['statuses'][0]->id_str, "Created fav should have same id");
// destroy fav
- $resp = $this->twitterObj->post("/favorites/destroy/{$public->results[0]->id_str}.json");
- $this->assertEquals($resp->id_str, $public->results[0]->id_str, "Destroy fav should have same id");
- $resp = $this->twitterObj->get("/favorites/{$this->screenName}.json");
+ $resp = $this->twitterObj->post('/favorites/destroy.json', array('id' => $public->response['statuses'][0]->id_str));
+ $this->assertEquals($resp->id_str, $public->response['statuses'][0]->id_str, "Destroy fav should have same id");
+ $resp = $this->twitterObj->get("/favorites/list.json");
$this->assertEquals(count($resp), 0, "Favorites should be length 0 after destroying");
// clean up
- $resp = $this->twitterObj->get("/favorites/{$this->screenName}.json");
+ $resp = $this->twitterObj->get("/favorites/list.json");
+
foreach($resp as $r)
{
- $del = $this->twitterObj->post("/favorites/destroy/{$r->id_str}.json");
+ $del = $this->twitterObj->post('/favorites/destroy.json', array('id' => $r->id_str));
$del->response;
}
}
- function testUpdateAvatar()
+ /*function testUpdateAvatar()
{
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post('/account/update_profile_image.json', array('@image' => "@{$file}"));
@@ -428,19 +428,20 @@ function testGetStatusesFriends()
$this->assertTrue(!empty($twitterFriends[0]), 'First result in get statuses friends is empty');;
}
- /*function testCreateAndDeleteList()
+ function testCreateAndDeleteList()
{
+ $this->markTestSkipped('Skipping test.');
// 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}");
- }*/
+ //$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()
{
@@ -460,27 +461,27 @@ function testHeaders()
/**
* @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;
- }
+//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;
+//}
}

0 comments on commit 0929f87

Please sign in to comment.