test Service_User::getUserByPrivateKey and explicitely make it publci

This commit is contained in:
Christian Weiske 2011-04-08 19:16:19 +02:00
parent b4f6b0449b
commit 3ef5813f97
2 changed files with 39 additions and 5 deletions

View File

@ -242,9 +242,9 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
*
* @param string $username User Name
*
* @return array User array from database
* @return array User array from database, false if no user was found
*/
function getUserByUsername($username)
public function getUserByUsername($username)
{
return $this->_getuser($this->getFieldName('username'), $username);
}
@ -254,9 +254,9 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
*
* @param string $privatekey Private Key
*
* @return array User array from database
* @return array User array from database, false if no user was found
*/
function getUserByPrivateKey($privatekey)
public function getUserByPrivateKey($privatekey)
{
return $this->_getuser($this->getFieldName('privatekey'), $privatekey);
}
@ -821,7 +821,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* @return mixed Integer user ID if all is well,
* boolean false if an error occured
*/
public function addUser($username, $password, $email, $privateKey=null)
public function addUser($username, $password, $email, $privateKey = null)
{
// Set up the SQL UPDATE statement.
$datetime = gmdate('Y-m-d H:i:s', time());

View File

@ -201,6 +201,40 @@ class UserTest extends TestBase
public function testGetUserByPrivateKeyEmptyKey()
{
$arUser = $this->us->getUserByPrivateKey(null);
$this->assertFalse($arUser);
}
public function testGetUserByPrivateKeyInvalid()
{
$arUser = $this->us->getUserByPrivateKey('foobar');
$this->assertFalse($arUser);
$arUser = $this->us->getUserByPrivateKey('%');
$this->assertFalse($arUser);
}
public function testGetUserByPrivateKeyValidKey()
{
$pkey = $this->us->getNewPrivateKey();
$uId = $this->addUser(null, null, $pkey);
$arUser = $this->us->getUserByPrivateKey($pkey);
$this->assertInternalType('array', $arUser);
$this->assertArrayHasKey('uId', $arUser);
$this->assertArrayHasKey('username', $arUser);
$this->assertEquals($uId, $arUser['uId']);
}
/**
* Check if privateKeyExists() returns right
*