Skip to content

Commit

Permalink
Track event was outside of the test for a valid tracker which caused …
Browse files Browse the repository at this point in the history
…it to throw an error if the hash was invalid.
  • Loading branch information
Jon Baker committed May 9, 2016
1 parent 7ac1708 commit 7defd42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/MailTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ protected function inject_link_callback($matches)

return $matches[1].action('\jdavidbakr\MailTracker\MailTrackerController@getL',
[
str_replace("/","$",base64_encode($url)), // Replace slash with dollar sign
MailTracker::hash_url($url),
$this->hash
]);
}

static public function hash_url($url)
{
// Replace "/" with "$"
return str_replace("/","$",base64_encode($url));
}
}
4 changes: 2 additions & 2 deletions src/MailTrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function getT($hash)
if($tracker) {
$tracker->opens++;
$tracker->save();
Event::fire(new ViewEmailEvent($tracker));
}
Event::fire(new ViewEmailEvent($tracker));

return $response;
}
Expand All @@ -45,8 +45,8 @@ public function getL($url, $hash)
if($tracker) {
$tracker->clicks++;
$tracker->save();
Event::fire(new LinkClickedEvent($tracker));
}
Event::fire(new LinkClickedEvent($tracker));

return redirect($url);
}
Expand Down
10 changes: 9 additions & 1 deletion tests/MailTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@ public function testLink()
$redirect = 'http://mfn1.myfootballnow.com/community/thread/2/1636?page=4&x=tRnYCfp9mT#10111';

$url = action('\jdavidbakr\MailTracker\MailTrackerController@getL',[
str_replace("/","$",base64_encode($redirect)), // Replace slash with dollar sign
\jdavidbakr\MailTracker\MailTracker::hash_url($redirect), // Replace slash with dollar sign
$track->hash
]);
$this->call('GET',$url);
$this->assertRedirectedTo($redirect);

$track = $track->fresh();
$this->assertEquals($clicks, $track->clicks);

// Do it with an invalid hash
$url = action('\jdavidbakr\MailTracker\MailTrackerController@getL',[
\jdavidbakr\MailTracker\MailTracker::hash_url($redirect), // Replace slash with dollar sign
'bad-hash'
]);
$this->call('GET',$url);
$this->assertRedirectedTo($redirect);
}
}

0 comments on commit 7defd42

Please sign in to comment.