Skip to content

Commit

Permalink
Expand URLs plugin: Set error when short URL expands to empty string, c…
Browse files Browse the repository at this point in the history
…loses #1280
  • Loading branch information
ginatrapani committed Mar 23, 2012
1 parent f909861 commit 850abd2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
17 changes: 11 additions & 6 deletions webapp/plugins/expandurls/model/class.ExpandURLsPlugin.php
Expand Up @@ -146,12 +146,17 @@ public function expandOriginalURLs($flickr_api_key=null) {
}
$short_link = $expanded_url;
}
if ($expanded_url != '' && !$has_expanded_flickr_link) {
$image_src = URLProcessor::getImageSource($expanded_url);
$this->link_dao->saveExpandedUrl($link->url, $expanded_url, '', $image_src);
$total_expanded = $total_expanded + 1;
} else {
$total_errors = $total_errors + 1;
if (!$has_expanded_flickr_link) {
if ($expanded_url != '' ) {
$image_src = URLProcessor::getImageSource($expanded_url);
$this->link_dao->saveExpandedUrl($link->url, $expanded_url, '', $image_src);
$total_expanded = $total_expanded + 1;
} else {
$this->logger->logError($link->url." not a valid URL - relocates to nowhere",
__METHOD__.','.__LINE__);
$this->link_dao->saveExpansionError($link->url, "Invalid URL - relocates to nowhere");
$total_errors = $total_errors + 1;
}
}
} else {
$total_errors = $total_errors + 1;
Expand Down
23 changes: 23 additions & 0 deletions webapp/plugins/expandurls/tests/TestOfExpandURLsPlugin.php
Expand Up @@ -125,6 +125,13 @@ public function testExpandURLsCrawl() {
$this->assertEqual($link->image_src, 'http://yfrog.com/gz2inwrj.th.jpg');
$this->assertEqual($link->error, '');

$link = $link_dao->getLinkById(11);
$this->debug($link->url);
$this->assertEqual($link->url, 'http://wp.me/p1fxNB-2F');
$this->assertEqual($link->expanded_url, '');
$this->assertEqual($link->image_src, '');
$this->assertEqual($link->error, 'Invalid URL - relocates to nowhere');

//check that short URLs were saved
$sql = "SELECT * FROM " . $this->table_prefix . 'links_short';
$stmt = ShortLinkMySQLDAO::$PDO->query($sql);
Expand Down Expand Up @@ -268,6 +275,19 @@ private function buildData() {
'image_src' => '',
'error' => null
));

// Expanded URL is empty
$builders[] = FixtureBuilder::build('links', array(
'id' => 11,
'url' => 'http://wp.me/p1fxNB-2F',
'expanded_url' => null,
'title' => '',
'clicks' => 0,
'post_id' => 1,
'image_src' => '',
'error' => null
));

return $builders;
}

Expand Down Expand Up @@ -471,6 +491,7 @@ public function testExpandInstagramImageURLs() {
$link_dao = DAOFactory::getDAO('LinkDAO');

$link = $link_dao->getLinkById(43);
$this->debug(Utils::varDumpToString($link));
//Instagr.am constantly changes the location of their images so it's an unpredictable assertion
// $this->assertEqual($link->expanded_url,
// 'http://images.instagram.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg');
Expand All @@ -479,10 +500,12 @@ public function testExpandInstagramImageURLs() {
$link = $link_dao->getLinkById(42);
$this->assertEqual($link->expanded_url, 'http://instagr.am/41');
$this->assertEqual($link->image_src, 'http://instagr.am/41/media/');
$this->assertEqual($link->error, '');

$link = $link_dao->getLinkById(41);
$this->assertEqual($link->expanded_url, 'http://instagr.am/40');
$this->assertEqual($link->image_src, 'http://instagr.am/40/media/');
$this->assertEqual($link->error, '');
}

public function testBitlyCrawl() {
Expand Down
6 changes: 6 additions & 0 deletions webapp/plugins/expandurls/tests/classes/mock.URLExpander.php
Expand Up @@ -101,6 +101,12 @@ public static function expandURL($tinyurl, $original_link, $current_number, $tot
case "http://thinkupapp.com/":
$exp_url = "http://thinkupapp.com/";
break;
case "http://wp.me/p1fxNB-2F":
$exp_url = "";
break;
case "http://instagr.am/p/oyQ6/":
$exp_url = "http://instagr.am/p/oyQ6/";
break;
default:
$exp_url = '';
}
Expand Down

0 comments on commit 850abd2

Please sign in to comment.