Merge branch 'master' of github.com:jpkrohling/frontend into jpkrohling-master
Adding unit tests and making corresponding changes. Conflicts: src/libraries/models/User.php
This commit is contained in:
commit
5bd1a180ce
5 changed files with 48 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
|||
*.swp
|
||||
*.graffle
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# Useful files which should never be committed
|
||||
src/configs/override.ini
|
||||
|
|
|
@ -20,6 +20,7 @@ assetProtocol=""
|
|||
displaySignupLink=""
|
||||
displaySignupUrl=""
|
||||
enableBetaFeatures="0"
|
||||
useGravatar=1
|
||||
|
||||
[secrets]
|
||||
passwordSalt="salt_for_passwords"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
AddOutputFilterByType DEFLATE text/html
|
||||
AddOutputFilterByType DEFLATE text/css
|
||||
AddOutputFilterByType DEFLATE application/x-javascript
|
||||
AddOutputFilterByType DEFLATE text/javascript
|
||||
BrowserMatch ^Mozilla/4 gzip-only-text/html
|
||||
BrowserMatch ^Mozilla/4\.0[678] no-gzip
|
||||
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
|
||||
|
|
|
@ -101,10 +101,6 @@ class User extends BaseModel
|
|||
if(empty($email))
|
||||
return;
|
||||
|
||||
$user = $this->getUserByEmail($email);
|
||||
if(isset($user['attrprofilePhoto']) && !empty($user['attrprofilePhoto']))
|
||||
return $user['attrprofilePhoto'];
|
||||
|
||||
$utilityObj = new Utility;
|
||||
$protocol = $utilityObj->getProtocol(false);
|
||||
if(empty($this->config->site->cdnPrefix))
|
||||
|
@ -117,6 +113,14 @@ class User extends BaseModel
|
|||
|
||||
$defaultUrl = sprintf('%s%s', $hostAndProtocol, $this->themeObj->asset('image', 'profile-default.png', false));
|
||||
|
||||
$user = $this->getUserByEmail($email);
|
||||
if(isset($user['attrprofilePhoto']) && !empty($user['attrprofilePhoto']))
|
||||
return $user['attrprofilePhoto'];
|
||||
|
||||
// if gravatar support is disabled and no profile photo exists then we immediately return the default url
|
||||
if ($this->config->site->useGravatar == 0)
|
||||
return $defaultUrl;
|
||||
|
||||
if($protocol === 'https')
|
||||
$gravatarUrl = 'https://secure.gravatar.com/avatar/';
|
||||
else
|
||||
|
|
|
@ -19,7 +19,15 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
$db->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'attrprofilePhoto' => 'http://foo/bar')));
|
||||
$themeObj = $this->getMock('ThemeObj', array('asset'));
|
||||
$themeObj->expects($this->any())
|
||||
->method('asset')
|
||||
->will($this->returnValue('/path/to/asset'));
|
||||
$this->user->inject('db', $db);
|
||||
$this->user->inject('themeObj', $themeObj);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'foo';
|
||||
|
||||
$res = $this->user->getAvatarFromEmail(50, 'test@example.com');
|
||||
$this->assertEquals('http://foo/bar', $res);
|
||||
}
|
||||
|
@ -34,8 +42,13 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
$themeObj->expects($this->any())
|
||||
->method('asset')
|
||||
->will($this->returnValue('/path/to/asset'));
|
||||
$config = new stdClass;
|
||||
$config->site = new stdClass;
|
||||
$config->site->useGravatar = 1;
|
||||
|
||||
$this->user->inject('themeObj', $themeObj);
|
||||
$this->user->inject('db', $db);
|
||||
$this->user->inject('config', $config);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'foo';
|
||||
|
||||
|
@ -43,6 +56,30 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=50&d=http%3A%2F%2Ffoo%2Fpath%2Fto%2Fasset', $res);
|
||||
}
|
||||
|
||||
public function testGetAvatarFromEmailNoGravatar()
|
||||
{
|
||||
$db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
|
||||
$db->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc')));
|
||||
$themeObj = $this->getMock('ThemeObj', array('asset'));
|
||||
$themeObj->expects($this->any())
|
||||
->method('asset')
|
||||
->will($this->returnValue('/path/to/asset'));
|
||||
$config = new stdClass;
|
||||
$config->site = new stdClass;
|
||||
$config->site->useGravatar = 0;
|
||||
|
||||
$this->user->inject('themeObj', $themeObj);
|
||||
$this->user->inject('db', $db);
|
||||
$this->user->inject('config', $config);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'foo';
|
||||
|
||||
$res = $this->user->getAvatarFromEmail(50, 'test@example.com');
|
||||
$this->assertEquals('http://foo/path/to/asset', $res);
|
||||
}
|
||||
|
||||
public function testGetEmailAddressNonOAuth()
|
||||
{
|
||||
$session = $this->getMock('session', array('get'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue