Permalink
Browse files

Fix PHP equality test in error case.

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...
1 parent 773e5aa commit 150a90a6c697f1ed12ba53fe5f5bdc7d7546ad95 @BrianEnigma BrianEnigma committed with ginatrapani Mar 4, 2012
@@ -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':
@@ -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':
@@ -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) ;
}
@@ -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>
@@ -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.