Remove inexistant user
This commit is contained in:
parent
81fd85eae3
commit
9536b7901e
5 changed files with 78 additions and 33 deletions
|
|
@ -1315,6 +1315,24 @@ class User
|
|||
|
||||
|
||||
}
|
||||
static function remove_inexistant_user($p_dossier)
|
||||
{
|
||||
$cnx_repo=new Database();
|
||||
$cnx_dossier=new Database($p_dossier);
|
||||
|
||||
$a_user=$cnx_dossier->get_array('select user_name from profile_user');
|
||||
if ( ! $a_user ) return;
|
||||
$nb=count($a_user);
|
||||
for ($i=0;$i < $nb;$i++) {
|
||||
if ( $cnx_repo->get_value('select count(*) from ac_users where use_login=$1',
|
||||
array($a_user[$i]['user_name'])) == 0) {
|
||||
$cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1",array($a_user[$i]['user_name']));
|
||||
$cnx_dossier->exec_sql("delete from profile_user where user_name=$1",array($a_user[$i]['user_name']));
|
||||
$cnx_dossier->exec_sql("delete from user_sec_act where ua_login=$1",array($a_user[$i]['user_name']));
|
||||
$cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1",array($a_user[$i]['user_name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ if ( isset ($_POST["DATABASE"]) )
|
|||
$Res=$cn->exec_sql($sql);
|
||||
|
||||
Dossier::synchro_admin($l_id);
|
||||
User::remove_inexistant_user($l_id);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ if ( isset ($_REQUEST['sa'] ))
|
|||
$new_cn->apply_patch($name,0);
|
||||
echo '<span class="error">'._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'</span>';
|
||||
Dossier::synchro_admin($id);
|
||||
User::remove_inexistant_user($id);
|
||||
echo $retour;
|
||||
|
||||
echo '</div>';
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ if ($sb === "upg_all" && (!defined('MULTI')||(defined('MULTI')&&MULTI==1)))
|
|||
$db=new Database($db_row['dos_id'], 'dos');
|
||||
$db->apply_patch($db_row['dos_name']);
|
||||
Dossier::synchro_admin($db_row['dos_id']);
|
||||
User::remove_inexistant_user($db_row['dos_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
define ('USE_ID',999999);
|
||||
define ('USE_FIRST_NAME','Unit test');
|
||||
define ('USE_NAME','UNIT');
|
||||
define ('USE_LOGIN','unit-test');
|
||||
define ('USE_ACTIVE',1);
|
||||
define ('USE_PASS','passord');
|
||||
define ('USE_ADMIN',0);
|
||||
define ('USE_EMAIL','none@dev.null.eu');
|
||||
|
||||
define('USE_ID', 999999);
|
||||
define('USE_FIRST_NAME', 'Unit test');
|
||||
define('USE_NAME', 'UNIT');
|
||||
define('USE_LOGIN', 'unit-test');
|
||||
define('USE_ACTIVE', 1);
|
||||
define('USE_PASS', 'passord');
|
||||
define('USE_ADMIN', 0);
|
||||
define('USE_EMAIL', 'none@dev.null.eu');
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2016-02-10 at 22:48:23.
|
||||
*/
|
||||
|
|
@ -27,12 +29,15 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
// create database connx :
|
||||
$this->cn=new Database();
|
||||
// create a user
|
||||
$this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',array(USE_ID));
|
||||
$this->cn->exec_sql('delete from ac_users where use_id=$1',array(USE_ID));
|
||||
$this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',
|
||||
array(USE_ID));
|
||||
$this->cn->exec_sql('delete from ac_users where use_id=$1',
|
||||
array(USE_ID));
|
||||
$this->cn->exec_sql('insert into ac_users (use_id,use_first_name,use_name,use_login,use_active,use_pass,use_admin,use_email) values ($1,$2,$3,$4,$5,$6,$7,$8)',
|
||||
array(USE_ID,USE_FIRST_NAME,USE_NAME,USE_LOGIN,USE_ACTIVE,USE_PASS,USE_ADMIN,USE_EMAIL));
|
||||
|
||||
$this->object=new User($cn,USE_ID);
|
||||
array(USE_ID, USE_FIRST_NAME, USE_NAME, USE_LOGIN, USE_ACTIVE, USE_PASS,
|
||||
USE_ADMIN, USE_EMAIL));
|
||||
|
||||
$this->object=new User($cn, USE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,8 +47,10 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
protected function tearDown()
|
||||
{
|
||||
//drop user
|
||||
$this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',array(USE_ID));
|
||||
$this->cn->exec_sql('delete from ac_users where use_id = $1',array(USE_ID));
|
||||
$this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',
|
||||
array(USE_ID));
|
||||
$this->cn->exec_sql('delete from ac_users where use_id = $1',
|
||||
array(USE_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,18 +59,16 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
|
||||
|
||||
$this->object->load();
|
||||
$this->assertEquals($this->object->id , USE_ID) ;
|
||||
$this->assertEquals($this->object->name , USE_NAME) ;
|
||||
$this->assertEquals($this->object->first_name , USE_FIRST_NAME );
|
||||
$this->assertEquals($this->object->login , USE_LOGIN) ;
|
||||
$this->assertEquals($this->object->active , USE_ACTIVE) ;
|
||||
$this->assertEquals($this->object->password, USE_PASS) ;
|
||||
$this->assertEquals($this->object->admin , USE_ADMIN) ;
|
||||
$this->assertEquals($this->object->email , USE_EMAIL) ;
|
||||
|
||||
|
||||
$this->assertEquals($this->object->id, USE_ID);
|
||||
$this->assertEquals($this->object->name, USE_NAME);
|
||||
$this->assertEquals($this->object->first_name, USE_FIRST_NAME);
|
||||
$this->assertEquals($this->object->login, USE_LOGIN);
|
||||
$this->assertEquals($this->object->active, USE_ACTIVE);
|
||||
$this->assertEquals($this->object->password, USE_PASS);
|
||||
$this->assertEquals($this->object->admin, USE_ADMIN);
|
||||
$this->assertEquals($this->object->email, USE_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -601,8 +606,9 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
public function testRevoke_access()
|
||||
{
|
||||
$cn_dossier=new Database(DOSSIER);
|
||||
User::revoke_access(USE_LOGIN, DOSSIER);
|
||||
$this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',array(USE_LOGIN)),0);
|
||||
User::revoke_access(USE_LOGIN, DOSSIER);
|
||||
$this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',
|
||||
array(USE_LOGIN)), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -611,10 +617,28 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGrant_admin_access()
|
||||
{
|
||||
$cn_dossier=new Database(TARGET);
|
||||
User::grant_admin_access(USE_LOGIN, DOSSIER);
|
||||
|
||||
$this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',array(USE_LOGIN)),1);
|
||||
}
|
||||
$cn_dossier=new Database(DOSSIER);
|
||||
User::grant_admin_access(USE_LOGIN, DOSSIER);
|
||||
|
||||
$this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',
|
||||
array(USE_LOGIN)), 1);
|
||||
}
|
||||
/**
|
||||
* @covers User::remove_inexistant_user
|
||||
*/
|
||||
public function testRemove_inexistant_user() {
|
||||
// insert inexisting user
|
||||
$cn=new Database (DOSSIER);
|
||||
$cn->exec_sql('insert into profile_user (user_name,p_id) values ($1,$2)',
|
||||
array('unknown/user',1));
|
||||
|
||||
//verify presence of it in DOSSIER
|
||||
$this->assertEquals($cn->get_value('select count(*) from profile_user where user_name=$1',array('unknown/user')),1);
|
||||
|
||||
//remove him
|
||||
User::remove_inexistant_user(DOSSIER);
|
||||
|
||||
// check his removal
|
||||
$this->assertEquals($cn->get_value('select count(*) from profile_user where user_name=$1',array('unknown/user')),0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue