Skip to content

Commit

Permalink
Fix PHP equality test in error case.
Browse files Browse the repository at this point in the history
As described in <https://groups.google.com/forum/?fromgroups#!topic/thinkupapp/xJZ7wAyo-xg>

In PHP, != and !== are two different operators, correct flaw in parsing error message.

Add test for parseError function
Closes #1265
  • Loading branch information
BrianEnigma authored and ginatrapani committed Mar 13, 2012
1 parent 773e5aa commit 150a90a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Expand Up @@ -214,7 +214,7 @@ public function parseError($data) {
$parsed_payload = array();
try {
$xml = $this->createParserFromString(utf8_encode($data));
if ($xml != false) {
if ($xml !== false) {
$root = $xml->getName();
switch ($root) {
case 'hash':
Expand Down Expand Up @@ -250,7 +250,7 @@ public function parseXML($data) {
$parsed_payload = array();
try {
$xml = $this->createParserFromString(utf8_encode($data));
if ($xml != false) {
if ($xml !== false) {
$root = $xml->getName();
switch ($root) {
case 'user':
Expand Down Expand Up @@ -451,7 +451,7 @@ private function parsePostXML($post) {
// do this only for the original post (rt will have rt count too)
$retweet_count_api = $post->retweet_count;
$pos = strrpos($post->retweet_count, '+');
if ($pos != false) {
if ($pos !== false) {
// remove '+', e.g. '100+' -- currently 100 is the max count that will be reported
$retweet_count_api = substr($post->retweet_count, 0, $pos) ;
}
Expand Down
17 changes: 16 additions & 1 deletion webapp/plugins/twitter/tests/TestOfTwitterAPIAccessorOAuth.php
Expand Up @@ -68,7 +68,7 @@ public function testSearchResults() {

public function testCreateParserFromStringMalformedMarkup() {
$data = <<<XML
<?xml version='1.0'?>
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
Expand Down Expand Up @@ -131,4 +131,19 @@ public function testParseXMLStatusesPublic() {
$this->assertEqual($results[0]['is_protected'], 0);
}

public function testParseError() {
$to = new TwitterOAuth('', '', '', '');
//Public statuses
$twitter_data = $to->http(
'https://twitter.com/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100');

$api = new CrawlerTwitterAPIAccessorOAuth('111', '222', 1234, 1234, 5, 3200, 5, 350);

$results = $api->parseError($twitter_data);

$this->debug(Utils::varDumpToString($results));

$this->assertEqual($results['error'], 'Not found');
$this->assertEqual($results['request'], '/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100');
}
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Not found</error>
<request>/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100</request>
</hash>

0 comments on commit 150a90a

Please sign in to comment.