Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #48 from alister/master
Browse files Browse the repository at this point in the history
Default all URLs to https:// by default  #44
  • Loading branch information
henrikbjorn authored Oct 25, 2017
2 parents 1a35eef + f3eb2df commit 6c667d6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
12 changes: 6 additions & 6 deletions GravatarApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GravatarApi
'size' => 80,
'rating' => 'g',
'default' => null,
'secure' => false,
'secure' => true,
);

/**
Expand All @@ -45,7 +45,7 @@ public function __construct(array $options = array())
*
* @return string
*/
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = null)
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true)
{
$hash = md5(strtolower(trim($email)));

Expand All @@ -63,15 +63,15 @@ public function getUrl($email, $size = null, $rating = null, $default = null, $s
*
* @return string
*/
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = null)
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true)
{
$map = array(
's' => $size ?: $this->defaults['size'],
'r' => $rating ?: $this->defaults['rating'],
'd' => $default ?: $this->defaults['default'],
);

$secure = $secure ?: $this->defaults['secure'];
$secure = isset($secure) ? $secure : $this->defaults['secure'];

return ($secure ? 'https://secure' : 'http://www').'.gravatar.com/avatar/'.$hash.'?'.http_build_query(array_filter($map));
}
Expand All @@ -84,7 +84,7 @@ public function getUrlForHash($hash, $size = null, $rating = null, $default = nu
*
* @return string
*/
public function getProfileUrl($email, $secure = null)
public function getProfileUrl($email, $secure = true)
{
$hash = md5(strtolower(trim($email)));

Expand All @@ -99,7 +99,7 @@ public function getProfileUrl($email, $secure = null)
*
* @return string
*/
public function getProfileUrlForHash($hash, $secure = null)
public function getProfileUrlForHash($hash, $secure = true)
{
$secure = $secure ?: $this->defaults['secure'];

Expand Down
10 changes: 5 additions & 5 deletions Templating/Helper/GravatarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ public function __construct(GravatarApi $api, ContainerInterface $container = nu
/**
* {@inheritdoc}
*/
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = null)
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true)
{
return $this->api->getUrl($email, $size, $rating, $default, $this->isSecure($secure));
}

/**
* {@inheritdoc}
*/
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = null)
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true)
{
return $this->api->getUrlForHash($hash, $size, $rating, $default, $this->isSecure($secure));
}

/**
* {@inheritdoc}
*/
public function getProfileUrl($email, $secure = null)
public function getProfileUrl($email, $secure = true)
{
return $this->api->getProfileUrl($email, $this->isSecure($secure));
}

/**
* {@inheritdoc}
*/
public function getProfileUrlForHash($hash, $secure = null)
public function getProfileUrlForHash($hash, $secure = true)
{
return $this->api->getProfileUrlForHash($hash, $this->isSecure($secure));
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public function exists($email)
*
* @return Boolean
*/
protected function isSecure($preset = null)
protected function isSecure($preset = true)
{
if (null !== $preset) {
return !!$preset;
Expand Down
8 changes: 4 additions & 4 deletions Templating/Helper/GravatarHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface GravatarHelperInterface
*
* @return string
*/
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = null);
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true);

/**
* Returns a url for a gravatar for a given hash.
Expand All @@ -28,7 +28,7 @@ public function getUrl($email, $size = null, $rating = null, $default = null, $s
*
* @return string
*/
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = null);
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true);

/**
* Returns a url for a gravatar profile.
Expand All @@ -38,7 +38,7 @@ public function getUrlForHash($hash, $size = null, $rating = null, $default = nu
*
* @return string
*/
public function getProfileUrl($email, $secure = null);
public function getProfileUrl($email, $secure = true);

/**
* Returns a url for a gravatar profile, for the given hash.
Expand All @@ -48,7 +48,7 @@ public function getProfileUrl($email, $secure = null);
*
* @return string
*/
public function getProfileUrlForHash($hash, $secure = null);
public function getProfileUrlForHash($hash, $secure = true);

/**
* Returns true if a avatar could be found for the email.
Expand Down
14 changes: 10 additions & 4 deletions Tests/GravatarApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class GravatarApiTest extends \PHPUnit_Framework_TestCase
public function testGravatarUrlWithDefaultOptions()
{
$api = new GravatarApi();
$this->assertEquals('http://www.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g', $api->getUrl('[email protected] '));
$this->assertEquals('https://secure.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g', $api->getUrl('[email protected] '));
}

public function testGravatarUrlWithDefaultOptionsNotSecure()
{
$api = new GravatarApi();
$this->assertEquals('http://www.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g', $api->getUrl('[email protected]', null, null, null, false));
}

public function testGravatarSecureUrlWithDefaultOptions()
Expand All @@ -21,7 +27,7 @@ public function testGravatarSecureUrlWithDefaultOptions()
public function testGravatarUrlWithDefaultImage()
{
$api = new GravatarApi();
$this->assertEquals('http://www.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g&d=mm', $api->getUrl('[email protected]', 80, 'g', 'mm'));
$this->assertEquals('https://secure.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g&d=mm', $api->getUrl('[email protected]', 80, 'g', 'mm'));
}

public function testGravatarSecureProfileUrlWithDefaultOptions()
Expand All @@ -33,7 +39,7 @@ public function testGravatarSecureProfileUrlWithDefaultOptions()
public function testGravatarProfileUrlWithDefaultImage()
{
$api = new GravatarApi();
$this->assertEquals('http://www.gravatar.com/0aa61df8e35327ac3b3bc666525e0bee', $api->getProfileUrl('[email protected]'));
$this->assertEquals('https://secure.gravatar.com/0aa61df8e35327ac3b3bc666525e0bee', $api->getProfileUrl('[email protected]'));
}

public function testGravatarInitializedWithOptions()
Expand All @@ -43,7 +49,7 @@ public function testGravatarInitializedWithOptions()
'default' => 'mm',
));

$this->assertEquals('http://www.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=20&r=g&d=mm', $api->getUrl('[email protected]'));
$this->assertEquals('https://secure.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=20&r=g&d=mm', $api->getUrl('[email protected]'));
}

public function testGravatarExists()
Expand Down
17 changes: 2 additions & 15 deletions Tests/Templating/Helper/GravatarHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,7 @@ public function setUp()

public function testGetUrlReturnsTheCorrectUrl()
{
$this->assertEquals('http://www.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g', $this->helper->getUrl('[email protected]'));
}

public function testGetUrlReturnsTheCorrectSecureUrl()
{
$this->assertEquals(
'https://secure.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g',
$this->helper->getUrl('[email protected]', null, null, null, true)
);
}

public function testGetProfileUrlReturnsTheCorrectUrl()
{
$this->assertEquals('http://www.gravatar.com/0aa61df8e35327ac3b3bc666525e0bee', $this->helper->getProfileUrl('[email protected]'));
$this->assertEquals('https://secure.gravatar.com/avatar/0aa61df8e35327ac3b3bc666525e0bee?s=80&r=g', $this->helper->getUrl('[email protected]'));
}

public function testGetProfileUrlReturnsTheCorrectSecureUrl()
Expand All @@ -43,7 +30,7 @@ public function testGetProfileUrlReturnsTheCorrectSecureUrl()
public function testGetProfileUrlForHashReturnsTheCorrectUrl()
{
$this->assertEquals(
'http://www.gravatar.com/0aa61df8e35327ac3b3bc666525e0bee',
'https://secure.gravatar.com/0aa61df8e35327ac3b3bc666525e0bee',
$this->helper->getProfileUrlForHash('0aa61df8e35327ac3b3bc666525e0bee')
);
}
Expand Down
8 changes: 4 additions & 4 deletions Twig/GravatarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public function getFunctions()
/**
* {@inheritdoc}
*/
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = null)
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true)
{
return $this->baseHelper->getUrl($email, $size, $rating, $default, $secure);
}

/**
* {@inheritdoc}
*/
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = null)
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true)
{
return $this->baseHelper->getUrlForHash($hash, $size, $rating, $default, $secure);
}

/*
* {@inheritdoc}
*/
public function getProfileUrl($email, $secure = null)
public function getProfileUrl($email, $secure = true)
{
return $this->baseHelper->getProfileUrl($email, $secure);
}

/**
* {@inheritdoc}
*/
public function getProfileUrlForHash($hash, $secure = null)
public function getProfileUrlForHash($hash, $secure = true)
{
return $this->baseHelper->getProfileUrlForHash($hash, $secure);
}
Expand Down

0 comments on commit 6c667d6

Please sign in to comment.