From 8b39730e8904fe0639b1155e526c1f3c149ca2f6 Mon Sep 17 00:00:00 2001
From: xdrm-brackets
Date: Mon, 18 Apr 2016 10:30:40 +0200
Subject: [PATCH] Tests et opti de ModuleRequest
---
config/dispatcher-tree.json | 9 +-
config/modules.json | 22 ++++
js/action-script.js | 34 +++---
js/includes/test.js | 1 +
js/lib/reset.js | 14 ++-
manager/ManagerError.php | 6 +-
manager/ModuleRequest.php | 35 +++---
manager/module/module.php | 25 +++++
phpunit/bootstrap.php | 6 +-
phpunit/coverage/Database.php.html | 28 ++---
phpunit/coverage/ManagerError.php.html | 6 +-
phpunit/coverage/ResourceDispatcher.php.html | 94 ++++++++--------
phpunit/coverage/autoloader.php.html | 14 +--
phpunit/coverage/index.html | 110 ++++++++++++++++---
phpunit/coverage/sessionManager.php.html | 2 +-
phpunit/phpunit.xml | 12 +-
phpunit/tests/ModuleRequest.php | 98 +++++++++++++++++
phpunit/tests/sessionManager.php | 4 +-
18 files changed, 384 insertions(+), 136 deletions(-)
create mode 100644 js/includes/test.js
create mode 100644 manager/module/module.php
create mode 100644 phpunit/tests/ModuleRequest.php
diff --git a/config/dispatcher-tree.json b/config/dispatcher-tree.json
index a99e550..6e7558d 100755
--- a/config/dispatcher-tree.json
+++ b/config/dispatcher-tree.json
@@ -9,9 +9,6 @@
"css" : "/css",
"js" : "/js",
- "highcharts": "/js/lib/highcharts",
- "sigma": "/js/lib/sigma",
-
- "cssview" : "/view/css",
- "jsview" : "/view/js"
-}
\ No newline at end of file
+ "highcharts": "/js/lib/highcharts",
+ "sigma": "/js/lib/sigma"
+}
diff --git a/config/modules.json b/config/modules.json
index 6c390b0..c341857 100755
--- a/config/modules.json
+++ b/config/modules.json
@@ -1,4 +1,26 @@
{
+ "module": {
+ "method": {
+ "description": "Test de l'API",
+ "permissions": [],
+ "parameters": {}
+ },
+
+ "phpunitParams": {
+ "description": "Méthode utile à phpunit pour le test des paramètres.",
+ "permissions": [],
+ "parameters": {
+ "p1": { "description": "Texte", "type": "text" },
+ "p2": { "description": "Entier positif", "type": "id" }
+ }
+ },
+
+ "phpunitPermissions": {
+ "description": "Méthode utile à phpunit pour le test des permissions.",
+ "permissions": ["a", "b"],
+ "parameters": {}
+ }
+ },
"user": {
"login": {
diff --git a/js/action-script.js b/js/action-script.js
index 9f038b3..c12ba0f 100755
--- a/js/action-script.js
+++ b/js/action-script.js
@@ -28,7 +28,7 @@ function navSubMenu(subsection){
var target = null;
// si @subsection est un element, on le prends
- target = (subsection instanceof Element) ? subsection : null;
+ target = (subsection instanceof Element) ? subsection : null;
// Si string, on trouve l'element correspondant
target = (typeof subsection == 'string') ? document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub > span[data-sublink="'+subsection+'"]') : target;
@@ -44,7 +44,7 @@ function navSubMenu(subsection){
// On desactive l'element courant
if( current != null )
current.remClass('active');
-
+
// On cache les sections visibles
var visibleSections = document.querySelectorAll('#CONTAINER > section[data-sublink].active');
for( var i = 0 ; i < visibleSections.length ; i++ )
@@ -84,7 +84,7 @@ function navSubMenu(subsection){
/* [4 Toggle du side-menu <-> navigation
===========================================*/
function navMenu(section){
-
+
/* [1] Format du param
------------------------------------------------*/
// Contient l'element courant
@@ -94,7 +94,7 @@ function navMenu(section){
var target = null;
// si @section est un element, on le prends
- target = (section instanceof Element) ? section : null;
+ target = (section instanceof Element) ? section : null;
// Si string, on trouve l'element correspondant
target = (typeof section == 'string') ? document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+section+'"]') : target;
@@ -190,22 +190,22 @@ DOM.MENUSIDE.addEventListener('click', function(e){
/* [6] Gestion du rechargement de page
-=========================================================*/
+=========================================================*/
function reload(){ navMenu( pageManager.page ); }
-/* [7] Gestion du toggle de la page de login
-=========================================================*/
-var LOGIN = {
- show: document.getElementById('user-data'),
- hide: document.getElementById('login-close'),
- page: document.getElementById('LOGIN')
-};
+/* [7] Gestion du toggle de la page de login
+=========================================================*/
+var LOGIN = {
+ show: document.getElementById('user-data'),
+ hide: document.getElementById('login-close'),
+ page: document.getElementById('LOGIN')
+};
-/* (1) Gestion de l'affichage de la page de login */
-LOGIN.show.addEventListener('click', function(e){ LOGIN.page.className = 'active'; }, false);
+/* (1) Gestion de l'affichage de la page de login */
+LOGIN.show.addEventListener('click', function(e){ LOGIN.page.className = 'active'; }, false);
-/* (2) Gestion de la fermeture de la page de login */
-LOGIN.hide.addEventListener('click', function(e){ LOGIN.page.className = ''; }, false);
+/* (2) Gestion de la fermeture de la page de login */
+LOGIN.hide.addEventListener('click', function(e){ LOGIN.page.className = ''; }, false);
@@ -229,4 +229,4 @@ pageManagerClass.prototype.ajax('/f/json/menu/conf', function(pagelistSerialized
/* (2) On charge la premiere page */
navMenu(pageManager.page);
-}, 'GET');
\ No newline at end of file
+}, 'GET');
diff --git a/js/includes/test.js b/js/includes/test.js
new file mode 100644
index 0000000..84d02ea
--- /dev/null
+++ b/js/includes/test.js
@@ -0,0 +1 @@
+var a = 'Hello World!';
diff --git a/js/lib/reset.js b/js/lib/reset.js
index b3c32a4..25be8eb 100755
--- a/js/lib/reset.js
+++ b/js/lib/reset.js
@@ -105,9 +105,21 @@ Element.prototype.anim = function(className, timeout){
}
+// INCLUSION D'UN SCRIPT JAVASCRIPT
+function include(jsResource, callback){
+ var tag = document.createElement('script');
+ tag.type = 'text/javascript';
+ tag.src = jsResource;
+
+ document.head.appendChild( tag );
+
+ tag.onload = callback;
+}
+
+
/* DEFINITION DES FORMATS UTILES POUR INPUT-CHECKER
*
*/
-var format_code = new formatChecker(null, 'HH-HH-HH-HH', { 'H' : '[0-9A-F]'} )
\ No newline at end of file
+var format_code = new formatChecker(null, 'HH-HH-HH-HH', { 'H' : '[0-9A-F]'} )
diff --git a/manager/ManagerError.php b/manager/ManagerError.php
index d724603..509fa59 100755
--- a/manager/ManagerError.php
+++ b/manager/ManagerError.php
@@ -1,6 +1,6 @@
\ No newline at end of file
+?>
diff --git a/manager/ModuleRequest.php b/manager/ModuleRequest.php
index d7e38fd..9a93ed4 100755
--- a/manager/ModuleRequest.php
+++ b/manager/ModuleRequest.php
@@ -1,4 +1,4 @@
-modules = json_decode( ResourceDispatcher::getResource(self::$config_path), true );
-
+
// Gestion de l'erreur de parsage
if( $this->modules == null ){
$this->error = ManagerError::ParsingFailed;
@@ -63,7 +62,7 @@
}
// Type de @data (optionnel)
- $params = (is_array($params)) ? $params : array();
+ $params = (is_array($params)) ? $params : array();
/* [2] Verification du chemin (existence module+methode)
@@ -72,14 +71,11 @@
return false;
+
/* [3] Verification des droits
=========================================================*/
- if( !$this->checkPermission($token) ){ // Si on a pas les droits
-
- // Si on a un token -> erreur de token, sinon erreur de permission
- $this->error = ($token===null) ? ManagerError::PermissionError : ManagerError::TokenError;
+ if( !$this->checkPermission($token) ) // Si on a pas les droits
return false;
- }
/* [4] Verification des parametres (si @type est defini)
@@ -159,7 +155,7 @@
// On definit $params au cas ou il soit vide
$params = $json;
// On retire le @path de @params
- unset($params['path']);
+ unset($params['path']);
return new ModuleRequest($json['path'], $params);
}
@@ -192,7 +188,7 @@
=========================================================*/
// Si variable n'existe pas, on cree un tableau vide
$params = $post;
-
+
// On retire le @path de @params
unset($params['path']);
@@ -226,6 +222,7 @@
$module = $matches[1];
$method = $matches[2];
+
/* [2] Verification de l'existence du module (conf)
=========================================================*/
if( !array_key_exists($module, $this->modules) ){ // Si le module n'est pas specifie dans la conf
@@ -239,7 +236,7 @@
$this->error = ManagerError::UnknownMethod;
return false; // On retourne FALSE, si erreur
}
-
+
/* [4] Enregistrement du chemin et renvoi de SUCCESS
@@ -283,9 +280,12 @@
$checkToken = new Repo('token/check', array($token) );
$token_permissions = $checkToken->answer();
- // Si le token est invalide, on retourne FAUX
- if( $token_permissions === false ) return false;
-
+ // Si le token est invalide, on retourne une erreur -> FAUX
+ if( $token_permissions === false ){
+ $this->error = ManagerError::TokenError;
+ return false;
+ }
+
$local_permissions = $token_permissions;
@@ -310,6 +310,7 @@
/* [5] On retourne FAUX si aucun droit n'a ete trouve
=========================================================*/
+ $this->error = ManagerError::PermissionError;
return false;
}
@@ -344,7 +345,7 @@
// Si le type n'est pas defini, on reboucle
if( !isset($paramsdata['type']) ) continue;
-
+
// Si la verification est fausse, on retourne faux
if( !Database::check($paramsdata['type'], $params[$name]) ) return false;
}
@@ -370,4 +371,4 @@
}
-?>
\ No newline at end of file
+?>
diff --git a/manager/module/module.php b/manager/module/module.php
new file mode 100644
index 0000000..3c2e195
--- /dev/null
+++ b/manager/module/module.php
@@ -0,0 +1,25 @@
+ ManagerError::Success,
+ 'ReceivedArguments' => $arguments
+ );
+
+ }
+
+
+
+
+ }
+
+
+?>
diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php
index bdac929..5eb0795 100755
--- a/phpunit/bootstrap.php
+++ b/phpunit/bootstrap.php
@@ -5,8 +5,12 @@
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0';
+
+ $_SESSION = array();
+ $_SESSION['permission'] = array('phpunit');
+
require_once __ROOT__.'/manager/autoloader.php';
-?>
\ No newline at end of file
+?>
diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html
index 63205f8..491f6fb 100755
--- a/phpunit/coverage/Database.php.html
+++ b/phpunit/coverage/Database.php.html
@@ -297,7 +297,7 @@
| |
| |
| public static function getInstance(){ |
- | if( self::$instance == null || self::$error != ManagerError::Success ){ |
+ | if( self::$instance == null || self::$error != ManagerError::Success ){ |
| |
| |
| if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'socioview' ) |
@@ -310,14 +310,14 @@
| |
| } |
| |
- | return self::$instance; |
+ | return self::$instance; |
| } |
| |
| |
| public static function getPDO(){ |
- | $instance = self::getInstance(); |
+ | $instance = self::getInstance(); |
| |
- | return self::$pdo; |
+ | return self::$pdo; |
| } |
| |
| |
@@ -435,17 +435,17 @@
| |
| |
| public static function check($type, $value){ |
- | $checker = true; |
+ | $checker = true; |
| |
| |
| |
- | if( is_null($value) ) return false; |
+ | if( is_null($value) ) return false; |
| |
| |
| |
| |
| |
- | if( preg_match('/^varchar\((\d+), ?(\d+)\)$/', $type, $match) ){ |
+ | if( preg_match('/^varchar\((\d+), ?(\d+)\)$/', $type, $match) ){ |
| |
| $min = (int) $match[1]; |
| |
@@ -458,7 +458,7 @@
| |
| |
| |
- | if( preg_match('/^array<(.+)>$/', $type, $match) ){ |
+ | if( preg_match('/^array<(.+)>$/', $type, $match) ){ |
| |
| if( !is_array($value) ) |
| return false; |
@@ -480,22 +480,22 @@
| |
| switch($type){ |
| |
- | case 'id': |
+ | case 'id': |
| return $checker && is_numeric($value) && $value <= 2147483647 && $value >= 0; |
| break; |
| |
| |
- | case 'text': |
+ | case 'text': |
| return $checker && is_string($value); |
| |
| |
- | case 'mail': |
+ | case 'mail': |
| return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value); |
| break; |
| |
| |
- | case 'sha1': |
- | return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); |
+ | case 'sha1': |
+ | return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); |
| break; |
| |
| default: |
@@ -559,7 +559,7 @@
Dead Code
| <?php |
| |
- | |
+ | |
| namespace manager; |
| |
| |
@@ -205,7 +205,7 @@
| case self::Success: return "Tout s'est bien deroule"; break; |
| |
| case self::ParsingFailed: return "La lecture du fichier JSON ou XML a echoue"; break; |
- | |
+ | |
| case self::InvalidFlags: return "Les specifications (drapeaux) sont incorrects"; break; |
| case self::UnreachableResource: return "La ressource n'existe pas (404)"; break; |
| case self::MissingPath: return "Le chemin de delegation n'a pas ete renseigne"; break; |
@@ -247,7 +247,7 @@
Dead Code
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016.
+ Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html
index 0fd0aff..03af216 100755
--- a/phpunit/coverage/ResourceDispatcher.php.html
+++ b/phpunit/coverage/ResourceDispatcher.php.html
@@ -262,49 +262,49 @@
| |
| |
| public function __construct($url, $view=false){ |
- | $this->error = ManagerError::Success; |
+ | $this->error = ManagerError::Success; |
| |
| |
| |
| |
| |
- | $extensions_conf = json_decode( file_get_contents(__ROOT__.self::$extension_config_path), true ); |
+ | $extensions_conf = json_decode( file_get_contents(__ROOT__.self::$extension_config_path), true ); |
| |
| |
- | if( $extensions_conf == null ){ |
+ | if( $extensions_conf == null ){ |
| $this->error = ManagerError::ParsingFailed; |
| return false; |
| } |
| |
- | self::$supported_extensions = $extensions_conf; |
+ | self::$supported_extensions = $extensions_conf; |
| |
| |
- | $parents_conf = json_decode( file_get_contents(__ROOT__.self::$parents_config_path), true ); |
+ | $parents_conf = json_decode( file_get_contents(__ROOT__.self::$parents_config_path), true ); |
| |
| |
- | if( $parents_conf == null ){ |
+ | if( $parents_conf == null ){ |
| $this->error = ManagerError::ParsingFailed; |
| return false; |
| } |
| |
- | self::$supported_parents = $parents_conf; |
+ | self::$supported_parents = $parents_conf; |
| |
| |
| |
| |
| |
- | $serialFlags = array_slice( explode('/',$url), 1 ); |
+ | $serialFlags = array_slice( explode('/',$url), 1 ); |
| |
| |
| |
- | if( !$this->createFlags($serialFlags) ){ |
+ | if( !$this->createFlags($serialFlags) ){ |
| $this->error = ManagerError::InvalidFlags; |
| return false; |
| } |
| |
| |
| |
- | if( !$this->buildPath() ){ |
+ | if( !$this->buildPath() ){ |
| $this->error = ManagerError::UnreachableResource; |
| return false; |
| } |
@@ -312,10 +312,10 @@
| |
| |
| if( $view ) |
- | $this->view(); |
+ | $this->view(); |
| |
| |
- | return true; |
+ | return true; |
| |
| } |
| |
@@ -328,8 +328,8 @@
| |
| |
| public static function getResource($route){ |
- | $instance = new ResourceDispatcher($route); |
- | return $instance->getContent(); |
+ | $instance = new ResourceDispatcher($route); |
+ | return $instance->getContent(); |
| } |
| |
| |
@@ -345,51 +345,51 @@
| |
| |
| |
- | $correct = true; |
+ | $correct = true; |
| |
| |
- | $correct = $correct && count($serialFlags) >= 3; |
+ | $correct = $correct && count($serialFlags) >= 3; |
| |
| |
- | $correct = $correct && array_key_exists($serialFlags[0], self::$supported_extensions); |
+ | $correct = $correct && array_key_exists($serialFlags[0], self::$supported_extensions); |
| |
| |
- | $correct = $correct && preg_match('/^[\w_\.-]+$/i', $serialFlags[1]); |
+ | $correct = $correct && preg_match('/^[\w_\.-]+$/i', $serialFlags[1]); |
| |
| |
- | $correct = $correct && array_key_exists($serialFlags[2], self::$supported_parents); |
+ | $correct = $correct && array_key_exists($serialFlags[2], self::$supported_parents); |
| |
| |
- | $opt_subParent = count($serialFlags) >= 4; |
+ | $opt_subParent = count($serialFlags) >= 4; |
| |
| if( $opt_subParent ) |
- | $correct = $correct && preg_match('/^[\w_-]+$/i', $serialFlags[3]); |
+ | $correct = $correct && preg_match('/^[\w_-]+$/i', $serialFlags[3]); |
| |
| |
- | $opt_color = count($serialFlags) >= 5 && preg_match('/^[\da-f]{6,8}+$/i', $serialFlags[4]); |
+ | $opt_color = count($serialFlags) >= 5 && preg_match('/^[\da-f]{6,8}+$/i', $serialFlags[4]); |
| |
- | if( !$correct ) |
- | return false; |
+ | if( !$correct ) |
+ | return false; |
| |
| |
| |
| |
| |
- | $this->flags = array( |
- | 'extension' => $serialFlags[0], |
- | 'filename' => $serialFlags[1], |
- | 'parent' => $serialFlags[2] |
- | ); |
+ | $this->flags = array( |
+ | 'extension' => $serialFlags[0], |
+ | 'filename' => $serialFlags[1], |
+ | 'parent' => $serialFlags[2] |
+ | ); |
| |
| |
| if( $opt_subParent ) |
- | $this->flags['subparent'] = $serialFlags[3]; |
+ | $this->flags['subparent'] = $serialFlags[3]; |
| |
| |
| if( $opt_color ) |
- | $this->flags['color'] = '#'.$serialFlags[4]; |
+ | $this->flags['color'] = '#'.$serialFlags[4]; |
| |
- | return true; |
+ | return true; |
| |
| |
| } |
@@ -408,10 +408,10 @@
| |
| |
| |
- | if( !isset(self::$supported_extensions[$this->flags['extension']]) ) return false; |
+ | if( !isset(self::$supported_extensions[$this->flags['extension']]) ) return false; |
| |
| |
- | $header = self::$supported_extensions[$this->flags['extension']]; |
+ | $header = self::$supported_extensions[$this->flags['extension']]; |
| |
| |
| |
@@ -420,23 +420,23 @@
| |
| |
| |
- | if( !isset(self::$supported_parents[$this->flags['parent']]) ) return false; |
+ | if( !isset(self::$supported_parents[$this->flags['parent']]) ) return false; |
| |
| |
- | $parent = self::$supported_parents[$this->flags['parent']]; |
+ | $parent = self::$supported_parents[$this->flags['parent']]; |
| |
| |
| |
| |
- | $opt_subParent = (isset($this->flags['subparent'])) ? $this->flags['subparent'].'/' : ''; |
+ | $opt_subParent = (isset($this->flags['subparent'])) ? $this->flags['subparent'].'/' : ''; |
| |
| |
| |
| |
- | $this->stylesheet = ""; |
+ | $this->stylesheet = ""; |
| |
| |
- | if( isset($this->flags['color']) ){ |
+ | if( isset($this->flags['color']) ){ |
| $this->stylesheet = "\n<style type='text/css'>\n"; |
| $this->stylesheet .= "\t#stylisable{\n"; |
| $this->stylesheet .= "\t\tfill: ".$this->flags['color']." !important;\n"; |
@@ -449,15 +449,15 @@
| |
| |
| |
- | $this->header = $header; |
+ | $this->header = $header; |
| |
| |
| |
- | $this->path = __ROOT__.$parent.'/'.$opt_subParent.$this->flags['filename'].'.'.$this->flags['extension']; |
+ | $this->path = __ROOT__.$parent.'/'.$opt_subParent.$this->flags['filename'].'.'.$this->flags['extension']; |
| |
| |
| |
- | return @file_get_contents( $this->path ) != false; |
+ | return @file_get_contents( $this->path ) != false; |
| |
| } |
| |
@@ -489,15 +489,15 @@
| |
| public function getContent(){ |
| |
- | if( $this->error != ManagerError::Success ) |
- | return false; |
+ | if( $this->error != ManagerError::Success ) |
+ | return false; |
| |
| |
| |
- | $content = file_get_contents($this->path); |
+ | $content = file_get_contents($this->path); |
| |
| |
- | return str_replace( '</svg>', $this->stylesheet.'</svg>', $content ); |
+ | return str_replace( '</svg>', $this->stylesheet.'</svg>', $content ); |
| } |
| |
| |
@@ -517,7 +517,7 @@
Dead Code
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016.
+ Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html
index edb67cf..074336c 100755
--- a/phpunit/coverage/autoloader.php.html
+++ b/phpunit/coverage/autoloader.php.html
@@ -167,19 +167,19 @@
| |
| |
| function autoloader($className){ |
- | $path = ''; |
+ | $path = ''; |
| |
| |
| |
| |
- | $path = str_replace('\\', '/', $className) . '.php'; |
- | $path = __ROOT__.'/'.$path; |
+ | $path = str_replace('\\', '/', $className) . '.php'; |
+ | $path = __ROOT__.'/'.$path; |
| |
| |
- | if( file_exists($path) ) |
- | require_once $path; |
+ | if( file_exists($path) ) |
+ | require_once $path; |
| |
- | } |
+ | } |
| |
| |
| spl_autoload_register('autoloader', false, true); |
@@ -214,7 +214,7 @@
Dead Code
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016.
+ Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html
index 0c88c4e..ebe8e60 100755
--- a/phpunit/coverage/index.html
+++ b/phpunit/coverage/index.html
@@ -43,29 +43,57 @@
Total |
-
- 72.54% covered (warning)
+
+ 63.81% covered (warning)
|
- 72.54% |
- 140 / 193 |
+ 63.81% |
+ 231 / 362 |
-
- 50.00% covered (danger)
+
+ 36.11% covered (danger)
|
- 50.00% |
- 9 / 18 |
+ 36.11% |
+ 13 / 36 |
-
- 25.00% covered (danger)
+
+ 14.29% covered (danger)
|
- 25.00% |
- 1 / 4 |
+ 14.29% |
+ 1 / 7 |
+
+
+
+ repo |
+
+
+ 13.95% covered (danger)
+
+
+ |
+ 13.95% |
+ 6 / 43 |
+
+
+ 0.00% covered (danger)
+
+
+ |
+ 0.00% |
+ 0 / 5 |
+
+
+ 0.00% covered (danger)
+
+
+ |
+ 0.00% |
+ 0 / 1 |
@@ -124,6 +152,62 @@
1 / 1 |
+
+ ModuleRequest.php |
+
+
+ 68.60% covered (warning)
+
+
+ |
+ 68.60% |
+ 59 / 86 |
+
+
+ 25.00% covered (danger)
+
+
+ |
+ 25.00% |
+ 2 / 8 |
+
+
+ 0.00% covered (danger)
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ Repo.php |
+
+
+ 65.00% covered (warning)
+
+
+ |
+ 65.00% |
+ 26 / 40 |
+
+
+ 40.00% covered (danger)
+
+
+ |
+ 40.00% |
+ 2 / 5 |
+
+
+ 0.00% covered (danger)
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
ResourceDispatcher.php |
diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html
index 718c853..bceb5a7 100755
--- a/phpunit/coverage/sessionManager.php.html
+++ b/phpunit/coverage/sessionManager.php.html
@@ -315,7 +315,7 @@
Dead Code
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016.
+ Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/phpunit.xml b/phpunit/phpunit.xml
index 2b70fd8..676aac4 100755
--- a/phpunit/phpunit.xml
+++ b/phpunit/phpunit.xml
@@ -1,19 +1,23 @@
-
+
./tests/
-
+
./tests/ManagerError.php
-
+
./tests/config.php
-
+
+
+ ./tests/ModuleRequest.php
+
+
diff --git a/phpunit/tests/ModuleRequest.php b/phpunit/tests/ModuleRequest.php
new file mode 100644
index 0000000..24022bb
--- /dev/null
+++ b/phpunit/tests/ModuleRequest.php
@@ -0,0 +1,98 @@
+assertEquals( $req->error, \manager\ManagerError::Success );
+ }
+ public function testConstructNoPath(){
+ $req = new \manager\ModuleRequest();
+ $this->assertEquals( $req->error, \manager\ManagerError::MissingPath );
+ }
+ public function testConstructIncorrectPathType(){
+ $reqArray = new \manager\ModuleRequest( array(1) );
+ $this->assertEquals( $reqArray->error, \manager\ManagerError::WrongPathModule );
+
+
+ $reqNumber = new \manager\ModuleRequest( 10 );
+ $this->assertEquals( $reqNumber->error, \manager\ManagerError::WrongPathModule );
+ }
+ public function testConstructIncorrectPathSyntax(){
+ $req = new \manager\ModuleRequest('wrong.syntax');
+ $this->assertEquals( $req->error, \manager\ManagerError::WrongPathModule );
+ }
+ public function testConstructIncorrectPathModule(){
+ $req = new \manager\ModuleRequest( 'unknownModule/method' );
+ $this->assertEquals( $req->error, \manager\ManagerError::UnknownModule );
+ }
+ public function testConstructIncorrectPathMethod(){
+ $req = new \manager\ModuleRequest( 'module/unknownMethod' );
+ $this->assertEquals( $req->error, \manager\ManagerError::UnknownMethod );
+ }
+
+
+ /* (2) Tests des permissions */
+ // {1} Gestion des permissions quand l'utilisateur est connecté //
+ public function testConstructNoPermissionsRequired(){
+ $_SESSION['permission'] = array();
+
+ $req = new \manager\ModuleRequest( 'module/method' );
+ $this->assertEquals( $req->error, \manager\ManagerError::Success );
+ }
+ public function testConstructPermissionsMissing(){
+ $_SESSION['permission'] = array();
+
+ $req = new \manager\ModuleRequest( 'module/phpunitPermissions' );
+ $this->assertEquals( $req->error, \manager\ManagerError::PermissionError );
+ }
+ public function testConstructPermissionsMatch(){
+ $_SESSION['permission'] = array('a');
+
+ $req = new \manager\ModuleRequest( 'module/phpunitPermissions' );
+ $this->assertEquals( $req->error, \manager\ManagerError::Success );
+ }
+ public function testConstructPermissionsMatchOther(){
+ $_SESSION['permission'] = array('b');
+
+ $req = new \manager\ModuleRequest( 'module/phpunitPermissions' );
+ $this->assertEquals( $req->error, \manager\ManagerError::Success );
+ }
+ public function testConstructPermissionsMatchAll(){
+ $_SESSION['permission'] = array('a', 'b');
+
+ $req = new \manager\ModuleRequest( 'module/phpunitPermissions' );
+ $this->assertEquals( $req->error, \manager\ManagerError::Success );
+ }
+ public function testConstructPermissionsDontMatch(){
+ $_SESSION['permission'] = array('c');
+
+ $req = new \manager\ModuleRequest( 'module/phpunitPermissions' );
+ $this->assertEquals( $req->error, \manager\ManagerError::PermissionError );
+ }
+
+ // {2} Gestion des permissions quand un token est joint //
+ public function testConstructNoTokenAndNoConnection(){
+ // $_SESSION['permission'] = array();
+ $postdata = array( 'path' => 'module/method' );
+
+ $req = \manager\ModuleRequest::fromPost( $postdata );
+ $this->assertEquals( $req->error, \manager\ManagerError::TokenError );
+ }
+ public function testConstructInvalidToken(){
+ $_SERVER['PHP_AUTH_DIGEST'] = str_repeat('f', 40);
+ $_SESSION['permission'] = array();
+ $postdata = array( 'path' => 'module/method' );
+
+ $req = \manager\ModuleRequest::fromPost( $postdata );
+ $this->assertEquals( $req->error, \manager\ManagerError::TokenError );
+ }
+ }
+
+
+?>
diff --git a/phpunit/tests/sessionManager.php b/phpunit/tests/sessionManager.php
index fbfc251..8430ea5 100755
--- a/phpunit/tests/sessionManager.php
+++ b/phpunit/tests/sessionManager.php
@@ -243,9 +243,9 @@
$this->assertEquals( $first_token_prefix, $second_token_prefix );
}
-
+
}
-?>
\ No newline at end of file
+?>
|