From e8bc1a72bf298d9cb88f216495fff15b3f58d242 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 9 Jul 2016 15:06:59 +0200 Subject: [PATCH] Corrections des modules+repos et TESTS 'user' 'cluster' 'machine' 'userDefault/create' 'machineDefault/create' --- manager/module/machineDefault.php | 2 +- manager/module/userDefault.php | 18 ++++++++---------- manager/repo/cluster.php | 31 ++++++++++++------------------- manager/repo/machine.php | 3 ++- manager/repo/user.php | 4 ++-- test/automate.php | 29 ++++++++++++++++------------- view/users.php | 1 + 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 7c1d9eb..90713c0 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -33,6 +33,7 @@ return ['ModuleError' => ManagerError::ModuleError]; + /* [2] Creation du groupe de meme nom que la machine =========================================================*/ $create_group = new Repo('cluster/create', [ @@ -46,7 +47,6 @@ if( $id_group === false ) return ['ModuleError' => ManagerError::ModuleError]; - /* [3] Association au groupe =========================================================*/ $assoc_goup = new Repo('cluster/link', [ diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php index 217304d..04f3a08 100755 --- a/manager/module/userDefault.php +++ b/manager/module/userDefault.php @@ -44,8 +44,6 @@ ]); $id_user = $create_user->answer(); - var_dump($create_user); - // Si une erreur est retournee, on retourne une erreur if( $id_user === false ) return ['ModuleError' => ManagerError::ModuleError]; @@ -54,15 +52,15 @@ /* [3] Creation du groupe de meme nom que l'username =========================================================*/ - $create_group = new Repo('cluster/create', [ + $create_cluster = new Repo('cluster/create', [ $_SESSION['WAREHOUSE']['id'], $username, clusterRepo::USER_CLASS ]); - $id_group = $create_group->answer(); + $id_cluster = $create_cluster->answer(); // Si une erreur est retournee, on retourne une erreur - if( $id_group === false ) + if( $id_cluster === false ) return ['ModuleError' => ManagerError::ModuleError]; @@ -72,15 +70,15 @@ =========================================================*/ $assoc_goup = new Repo('cluster/link', [ $_SESSION['WAREHOUSE']['id'], - $id_group, + $id_cluster, $id_user, clusterRepo::USER_CLASS ]); - $id_assoc = $assoc_goup->answer(); + $assoc_err = $assoc_goup->answer(); // Si une erreur est retournee, on retourne une erreur - if( $id_assoc === false ) - return ['ModuleError' => ManagerError::ModuleError]; + if( $assoc_err != ManagerError::Success ) + return ['ModuleError' => $assoc_err]; @@ -88,7 +86,7 @@ =========================================================*/ return [ 'id_user' => $id_user, - 'id_cluster' => $id_group + 'id_cluster' => $id_cluster ]; } diff --git a/manager/repo/cluster.php b/manager/repo/cluster.php index 3b9500a..3bd81c2 100755 --- a/manager/repo/cluster.php +++ b/manager/repo/cluster.php @@ -68,8 +68,7 @@ * @id_entity UID de la machine ou de l'utilisateur * @class Spefication du type d'entite (0=user;1=machine) * - * @return association Renvoie l'UID de l'association cree - * Renvoie FALSE si une erreur occure + * @return error Renvoie le code 'ManagerError' * */ public static function link($id_warehouse, $id_cluster, $id_entity, $class){ @@ -130,7 +129,7 @@ // Si n'existe pas on retourne FALSE if( !is_array($check_cluster_merge) ) - return ManagerError::ModuleError; + return ManagerError::RepoError; // Sinon, on retourne son id return ManagerError::Success; @@ -150,7 +149,7 @@ * @id_entity UID de la machine ou de l'utilisateur * @class Spefication du type d'entite (0=user;1=machine) * - * @return status Retourne si oui ou non l'association a bien ete supprimee + * @return error Renvoie le code 'ManagerError' * */ public static function unlink($id_warehouse, $id_cluster, $id_entity, $class){ @@ -245,11 +244,9 @@ */ public static function getAll($id_warehouse){ // On ecrit la requete - $request = Database::getPDO()->prepare("SELECT c.*, count(cm.id_cluster_merge) as count - FROM cluster as c, cluster_merge as cm - WHERE cm.id_cluster = c.id_cluster - AND c.id_warehouse = :id_warehouse - GROUP BY c.id_cluster + $request = Database::getPDO()->prepare("SELECT * + FROM cluster as c + WHERE c.id_warehouse = :id_warehouse ORDER BY c.name ASC"); // On execute la requete @@ -279,11 +276,9 @@ public static function getById($id_warehouse, $id){ // On ecrit la requete $request = Database::getPDO()->prepare("SELECT c.* - FROM cluster as c, cluster_merge as cm - WHERE cm.id_cluster = c.id_cluster - AND c.id_warehouse = :id_warehouse - AND c.id_cluster = :id - ORDER BY c.id ASC"); + FROM cluster as c + WHERE c.id_warehouse = :id_warehouse + AND c.id_cluster = :id"); // On execute la requete $request->execute([ @@ -319,11 +314,9 @@ public static function getByName($id_warehouse, $name){ // On ecrit la requete $request = Database::getPDO()->prepare("SELECT c.* - FROM cluster as c, cluster_merge as cm - WHERE cm.id_cluster = c.id_cluster - AND c.id_warehouse = :id_warehouse - AND c.name = :name - ORDER BY c.name ASC"); + FROM cluster as c + WHERE c.id_warehouse = :id_warehouse + AND c.name = :name"); // On execute la requete $request->execute([ diff --git a/manager/repo/machine.php b/manager/repo/machine.php index b6d4320..61c45fb 100755 --- a/manager/repo/machine.php +++ b/manager/repo/machine.php @@ -24,8 +24,9 @@ $check_unique = self::getByName($id_warehouse, $name) === false; // Si une machine a deja ce nom, on renvoie une erreur - if( !$check_unique ) + if( !$check_unique ){ return false; + } /* [2] Creation de la machine diff --git a/manager/repo/user.php b/manager/repo/user.php index c057858..b9fc6b1 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -50,7 +50,7 @@ /* [3] On retourne l'id_user ou FALSE si erreur =========================================================*/ - $check_user = self::getByCode($code); + $check_user = self::getByCode($id_warehouse, $code); // Si n'existe pas on retourne FALSE if( $check_user === false ) @@ -238,7 +238,7 @@ /* [2] On verifie que l'utilisateur n'existe plus =========================================================*/ - return ( self::getById($id_user) === false ); + return ( self::getById($id_warehouse, $id_user) === false ); } diff --git a/test/automate.php b/test/automate.php index 43a2f54..91783dd 100755 --- a/test/automate.php +++ b/test/automate.php @@ -21,7 +21,7 @@ * */ function insertUsersFromJSON(){ - $json = ResourceDispatcher::getResource('f/json/generated_users/conf'); + $json = file_get_contents(__ROOT__.'/config/generated_users.json'); $json = json_decode( $json, true ); // Pour chaque entree @@ -29,17 +29,19 @@ // Creation de la requete $request = new ModuleRequest('userDefault/create', [ - $user['code'], - $user['username'], - $user['firstname'], - $user['lastname'], - $user['email'], - $user['password'], - $user['status'] + 'code' => $user['code'], + 'username' => $user['username'], + 'firstname' => $user['firstname'], + 'lastname' => $user['lastname'], + 'mail' => $user['email'], + 'password' => $user['password'], + 'status' => $user['status'] ]); $answer = $request->dispatch(); + // Debug error - var_dump( $answer->error == ManagerError::Success ); + if( $answer->error != ManagerError::Success ) + var_dump( $answer->error ); } return true; @@ -56,7 +58,7 @@ * */ function insertMachinesFromJSON(){ - $json = ResourceDispatcher::getResource('f/json/generated_machines/conf'); + $json = file_get_contents(__ROOT__.'/config/generated_machines.json'); $json = json_decode( $json, true ); // Pour chaque entree @@ -64,12 +66,13 @@ // Creation de la requete $request = new ModuleRequest('machineDefault/create', [ - $machine['code'], - $machine['name'] + 'name' => $machine['name'] ]); $answer = $request->dispatch(); + // Debug error - var_dump( $answer->error == ManagerError::Success ); + if( $answer->error != ManagerError::Success ) + var_dump( $answer->error ); } return true; diff --git a/view/users.php b/view/users.php index ae0a372..cae2f9e 100755 --- a/view/users.php +++ b/view/users.php @@ -127,6 +127,7 @@ foreach($clusters as $cluster) if( $cluster['name'] != $user['username'] ) // Si c'est le groupe personnel, on ne l'affiche pas echo "".$cluster['name'].""; + echo "+"; echo"";