test added but not finisehd and some code refactoring followign test

This commit is contained in:
Christophe Massin 2014-07-18 10:39:17 +02:00
parent 7561595458
commit 8d274b80a6
4 changed files with 121 additions and 38 deletions

View File

@ -44,10 +44,6 @@ use common_persistence_Manager;
*/
class LdapAdapter implements LoginAdapter
{
/** Key used to retrieve the persistence information */
CONST LDAP_PERSISTENCE_ID = 'authLdap';
/** @var $username string */
private $username;
@ -178,6 +174,4 @@ class LdapAdapter implements LoginAdapter
}
}

View File

@ -72,22 +72,6 @@ class LdapUser extends common_user_User {
*/
protected $languageDefLg = array(DEFAULT_LANG);
/**
* @param array $configuration
*/
public function setConfiguration($configuration)
{
$this->configuration = $configuration;
}
/**
* @return array
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* Sets the language URI
@ -111,22 +95,6 @@ class LdapUser extends common_user_User {
return $this->languageDefLg;
}
/**
* @param array $userExtraParameters
*/
public function setUserExtraParameters(array $userExtraParameters)
{
$this->userExtraParameters = $userExtraParameters;
}
/**
* @return array
*/
public function getUserExtraParameters()
{
return $this->userExtraParameters;
}
/**
* @param $property string
* @param $value string

View File

@ -0,0 +1,121 @@
<?php
/**
* Created by PhpStorm.
* User: christophemassin
* Date: 4/07/14
* Time: 10:49
*/
namespace oat\authLdap\test;
use oat\authLdap\model\LdapUser;
use GenerisPhpUnitTestRunner;
require_once dirname(__FILE__) . '/../../generis/test/GenerisPhpUnitTestRunner.php';
class AuthKeyValueUserTest extends GenerisPhpUnitTestRunner {
/** @var $user AuthKeyValueUser */
protected $user;
public function setUp() {
$this->user = new LdapUser();
$this->user->setUserRawParameters(
array(
'preferredlanguage' => 'en',
'mail' => 'mail@user.test',
'displayname' => 'toto is back'
)
);
}
public function tearDown(){
$this->user = null;
}
/**
* @cover AuthKeyValueUser::setLanguageUi
* @cover AuthKeyValueUser::getLanguageUi
* @cover AuthKeyValueUser::setLanguageDefLg
* @cover AuthKeyValueUser::getLanguageDefLg
*/
public function testLanguage()
{
$languageProperty = 'en';
$this->user->setLanguageUi($languageProperty);
$this->user->setLanguageDefLg($languageProperty);
$langUi = $this->user->getLanguageUi();
$langDefLg = $this->user->getLanguageDefLg();
$this->assertNotEmpty($langUi);
$this->assertNotEmpty($langDefLg);
$this->assertInternalType('array', $langUi);
$this->assertInternalType('array', $langDefLg);
$this->assertEquals(array('en-US'), $this->user->getLanguageUi());
$this->assertEquals(array('en-US'), $this->user->getLanguageDefLg());
}
/**
* @cover AuthKeyValueUser::getPropertyValues
*/
public function testPropertyValue(){
$this->assertEquals(array(0 => 'en-US'), $this->user->getPropertyValues(PROPERTY_USER_DEFLG));
$this->assertEquals(array(0 => 'en-US'), $this->user->getPropertyValues(PROPERTY_USER_UILG));
}
/**
* @cover AuthKeyValueUser::setRoles
* @cover AuthKeyValueUser::getRoles
*/
public function testRoles()
{
$this->user->setRoles(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'));
$this->assertEquals(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'), $this->user->getRoles());
$this->assertEquals(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'), $this->user->getPropertyValues(PROPERTY_USER_ROLES));
}
/**
* @cover AuthKeyValueUser::getPropertyValues
*/
public function testLazyLoadForMail(){
$array = $this->user->getUserExtraParameters();
// check array is currently empty
$this->assertEmpty($array);
$mail = $this->user->getPropertyValues(PROPERTY_USER_MAIL);
$this->assertNotEmpty($this->user->getUserExtraParameters());
$this->assertArrayHasKey(PROPERTY_USER_MAIL,$this->user->getUserExtraParameters());
}
/**
* @cover AuthKeyValueUser::getPropertyValues
*/
public function testLazyLoadForMultiParams(){
$array = $this->user->getUserExtraParameters();
// check array is currently empty
$this->assertEmpty($array);
$this->user->setUserExtraParameters(array('property' => array('property1', 'property2', 'property3')));
$this->assertNotEmpty($this->user->getUserExtraParameters());
$this->assertArrayHasKey('property',$this->user->getUserExtraParameters());
$this->assertEquals( array('property1', 'property2', 'property3') ,$this->user->getPropertyValues('property'));
}
}