Tests unitaires de tous les fichiers de configuration

This commit is contained in:
xdrm-brackets 2016-04-18 08:42:26 +02:00
parent 8012f68f6b
commit 81fcbde794
18 changed files with 171 additions and 72 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.ftpconfig
sftp-config.json
phpunit/coverage/

View File

@ -74,10 +74,10 @@
debug();
/* () Test du client de l'API generique */
// $api = new client();
// $response = $api->send('testmethod', array(
// $response = $api->send('generate-network-chart-data', array(
// '@token'=> '52945efbed43b50c12413f2f0e9519bfd9e98ce8'
// ));

View File

@ -60,4 +60,4 @@
"attributes": { "data-sublink": "users" } }
]
}
]
]

View File

@ -16,7 +16,7 @@
"parameters": {}
},
"getById": {
"description": "Retourne les informations d'un utilisateur.",
"permissions": ["admin"],
@ -25,14 +25,14 @@
}
},
"getAll": {
"description": "Retourne les informations de tous les utilisateurs.",
"permissions": ["admin"],
"parameters": {}
},
"create": {
"description": "Creation d'un nouvel utilisateur.",
"permissions": ["admin"],
@ -45,7 +45,7 @@
}
},
"remove": {
"description": "Suppression d'un utilisateur.",
"permissions": ["admin"],
@ -105,4 +105,4 @@
}
}
}
}

View File

@ -23,4 +23,4 @@
"remove"
]
}
}

View File

@ -4,4 +4,4 @@
"analytics",
"charts",
"settings"
]
]

View File

@ -1,6 +1,6 @@
@import 'constants';
body{
body{
font-family: 'Open Sans';
font-size: 15px;
@ -23,7 +23,7 @@ body{
z-index: 1;
/* [1] Header de la page
==========================================*/
& > #HEADER{
@ -42,9 +42,9 @@ body{
}
/* [2] Side-Menu de la page
==========================================*/
==========================================*/
// Gestion du menu
& > #MENU-SIDE{
display: block;
@ -62,7 +62,7 @@ body{
z-index: 10;
}
/* [3] Container de la page
==========================================*/
@ -101,7 +101,7 @@ body{
&.active{
left: 0;
}
// flex properties
flex-direction: row;
flex-wrap: nowrap;
@ -131,7 +131,7 @@ body{
/* (2) Formulaire de connexion */
& > #login-form{
display: block;
/* (2.1) Champs de texte (login/password) */
& > input[type='text'],
@ -149,7 +149,7 @@ body{
flex-wrap: nowrap;
align-items: middle;
border-radius: 5px;
border: 1px solid lighten($theme-fg, 10);
@ -158,7 +158,7 @@ body{
color: $dark-fg-primary;
font-weight: bold;
letter-spacing: .07em;
transition: border .2s ease-in-out;
cursor: default;
@ -176,7 +176,7 @@ body{
& > input[type='submit']{
width: 100%;
margin: 2em 0;
border: 0;
background-color: $theme-fg-primary;
@ -233,4 +233,4 @@ body{
cursor: pointer;
}
}
}

View File

@ -1,5 +1,5 @@
<?php define('__ROOT__', dirname(__FILE__) );
require_once __ROOT__.'/manager/autoloader.php';
use \router\Router;
@ -44,7 +44,7 @@
$login = new ModuleRequest('user/login', array( 'login' => $_POST['login'], 'password' => $_POST['password'] ));
$login_ans = $login->dispatch();
// Si aucune erreur, on dit qu'on vient de se connecter
// Si aucune erreur, on dit qu'on vient de se connecter
if( $login_ans->error == ManagerError::Success )
$_SESSION['login_status'] = 'logged';
else // Si on n'a pas les bonnes donnees
@ -55,7 +55,7 @@
/* (3) Gestion de le deconnexion */
$logout_vars = isset($_POST['logout-sub']);
// Si on se deconnecte
// Si on se deconnecte
if( $logout_vars ){
$logout = new ModuleRequest('user/logout');
$logout_ans = $logout->dispatch();
@ -99,7 +99,7 @@
$R->post('api/?', function(){
$request = ModuleRequest::fromPost($_POST);
$answer = $request->dispatch();
echo $answer->serialize();
});
@ -107,7 +107,7 @@
// N'importe -> page d'accueil
$R->get('.+', function(){ header('Location: /dashboard/'); });
$R->post('.+', function(){ header('Location: /dashboard/'); });
@ -115,4 +115,4 @@
===================================================*/
$R->run();
?>
?>

View File

@ -5,25 +5,24 @@ APIClass.prototype = {
xhr: [], // tableau d'objets pour les requêtes ajax
/* transaction avec le serveur (http://host/api/)
*
* @param pRequest<Object> l'objet passé en JSON à http://host/api/
* @param pHandler<Function> fonction qui s'éxécutera lors de la réponse (1 argument -> réponse<Object>)
* @param pToken<String> si donne, token d'auth pour l'api
*
* @return answer<Object> l'objet retourné par http://host/api/ via pHandler (1er argument)
* @return answer<Object> l'objet retourné par http://host/api/ via pHandler (1er argument)
*
***************************************************************************************************
*
* @usecase
* 1. var answerObject = sendRequest(
* 2. { var1: "exemple", var2: 198294 },
* 3. function(rep){ alert(rep); }
* 2. { var1: "exemple", var2: 198294 },
* 3. function(rep){ alert(rep); }
* 4. );
* @explain
* 1. on appelle la fonction <=> on créé la requête
* 2. on passe l'objet qui sera envoyé
* 1. on appelle la fonction <=> on créé la requête
* 2. on passe l'objet qui sera envoyé
* 3. on passe une fonction qui utilise un argument (sera la réponse de http://host/api/) (sous forme d'objet)
*
*/
@ -46,7 +45,7 @@ APIClass.prototype = {
// création de l'objet AJAX
if(window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
this.xhr[i] = new XMLHttpRequest();
else // IE5, IE6
else // IE5, IE6
this.xhr[i] = new ActiveXObject('Microsoft.XMLHttpRequest');
console.log(pRequest);
@ -85,7 +84,7 @@ APIClass.prototype = {
// Gestion du token optionnel
if( pToken != null ) this.xhr[i].setRequestHeader('Authorization', 'Digest '+pToken);
this.xhr[i].send( form );

View File

@ -499,8 +499,8 @@
<tr class="warning"><td><div align="right"><a name="247"></a><a href="#247">247</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">break</span><span class="keyword">;</span></td></tr>
<tr><td><div align="right"><a name="248"></a><a href="#248">248</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr>
<tr class="covered-by-large-tests popin" data-title="1 test covers line 249" data-content="&lt;ul&gt;&lt;li class=&quot;covered-by-large-tests&quot;&gt;phpunit\Database_check::testArrayRecursive&lt;/li&gt;&lt;/ul&gt;" data-placement="bottom" data-html="true"><td><div align="right"><a name="249"></a><a href="#249">249</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">default</span><span class="keyword">:</span></td></tr>
<tr class="covered-by-large-tests popin" data-title="1 test covers line 250" data-content="&lt;ul&gt;&lt;li class=&quot;covered-by-large-tests&quot;&gt;phpunit\Database_check::testArrayRecursive&lt;/li&gt;&lt;/ul&gt;" data-placement="bottom" data-html="true"><td><div align="right"><a name="250"></a><a href="#250">250</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span class="default">&nbsp;</span><span class="default">false</span><span class="keyword">;</span></td></tr>
<tr><td><div align="right"><a name="251"></a><a href="#251">251</a></div></td><td class="codeLine"></td></tr>
<tr class="covered-by-large-tests popin" data-title="1 test covers line 250" data-content="&lt;ul&gt;&lt;li class=&quot;covered-by-large-tests&quot;&gt;phpunit\Database_check::testArrayRecursive&lt;/li&gt;&lt;/ul&gt;" data-placement="bottom" data-html="true"><td><div align="right"><a name="250"></a><a href="#250">250</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span class="default">&nbsp;</span><span class="default">false</span><span class="keyword">;</span></td></tr>
<tr class="warning"><td><div align="right"><a name="251"></a><a href="#251">251</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">break</span><span class="keyword">;</span></td></tr>
<tr class="covered-by-large-tests popin" data-title="1 test covers line 252" data-content="&lt;ul&gt;&lt;li class=&quot;covered-by-large-tests&quot;&gt;phpunit\Database_check::testArrayRecursive&lt;/li&gt;&lt;/ul&gt;" data-placement="bottom" data-html="true"><td><div align="right"><a name="252"></a><a href="#252">252</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">}</span></td></tr>
<tr><td><div align="right"><a name="253"></a><a href="#253">253</a></div></td><td class="codeLine"></td></tr>
<tr class="warning"><td><div align="right"><a name="254"></a><a href="#254">254</a></div></td><td class="codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span class="default">&nbsp;</span><span class="default">$checker</span><span class="keyword">;</span></td></tr>
@ -559,7 +559,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -247,7 +247,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -517,7 +517,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -214,7 +214,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -210,7 +210,7 @@
<span class="success"><strong>High</strong>: 90% to 100%</span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
</footer>
</div>

View File

@ -315,7 +315,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Sun Apr 17 15:49:45 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 6:41:06 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -23,16 +23,16 @@
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['database-local'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu */
$this->assertArrayHasKey('host', $json_content);
$this->assertArrayHasKey('dbname', $json_content);
$this->assertArrayHasKey('user', $json_content);
$this->assertArrayHasKey('password', $json_content);
$this->assertArrayHasKey('host',$json_content);
$this->assertArrayHasKey('dbname',$json_content);
$this->assertArrayHasKey('user',$json_content);
$this->assertArrayHasKey('password',$json_content);
}
@ -43,7 +43,7 @@
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['database'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
@ -63,7 +63,7 @@
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['dispatcher-extensions'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
@ -81,14 +81,13 @@
}
/* [3] config/dispatcher-tree.json
=========================================================*/
public function testDispatcherTree(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['dispatcher-tree'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
@ -106,28 +105,128 @@
}
/* [3] config/menu.json
=========================================================*/
public function testMenu(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['menu'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu */
/* (3) Contenu de chaque catégorie */
foreach($json_content as $category){
continue;
$this->assertArrayHasKey( 'icon', $category );
$this->assertTrue( is_string($category['icon']) );
$this->assertArrayHasKey( 'text', $category );
$this->assertTrue( is_string($category['text']) );
$this->assertArrayHasKey( 'attributes', $category );
$this->assertTrue( is_array($category['attributes']) );
$this->assertArrayHasKey( 'children', $category );
$this->assertTrue( is_array($category['children']) );
/* (4) Contenu de chaque sous-catégorie */
foreach($category['children'] as $children){
$this->assertArrayHasKey( 'permissions', $children );
$this->assertTrue( is_array($children['permissions']) );
$this->assertArrayHasKey( 'text', $children );
$this->assertTrue( is_string($children['text']) );
$this->assertArrayHasKey( 'attributes', $children );
$this->assertTrue( is_array($children['attributes']) );
}
}
}
/* [4] config/modules.json
=========================================================*/
public function testModules(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['modules'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu de chaque module */
foreach($json_content as $moduleName=>$methods){
$this->assertTrue( is_string($moduleName) );
/* (4) Liste des méthodes du module */
foreach($methods as $methodName=>$method){
$this->assertTrue( is_string($methodName) );
$this->assertArrayHasKey( 'description', $method );
$this->assertTrue( is_string($method['description']) );
$this->assertArrayHasKey( 'permissions', $method );
$this->assertTrue( is_array($method['permissions']) );
$this->assertArrayHasKey( 'parameters', $method );
$this->assertTrue( is_array($method['parameters']) );
/* (5) Pour chaque paramètre */
foreach($method['parameters'] as $parameterName=>$parameter){
$this->assertTrue( is_string($parameterName) );
$this->assertArrayHasKey( 'description', $parameter );
$this->assertTrue( is_string($parameter['description']) );
$typeIsDefined = isset($parameter['type']);
if( $typeIsDefined )
$this->assertTrue( is_string($parameter['type']) );
}
}
}
}
/* [5] config/repositories.json
=========================================================*/
public function testRepositories(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['repositories'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu de chaque repository */
foreach($json_content as $repoName=>$methods){
$this->assertTrue( is_string($repoName) );
/* (4) Liste des méthodes du repository */
foreach($methods as $methodName)
$this->assertTrue( is_string($methodName) );
}
}
/* [6] config/views.json
=========================================================*/
public function testViews(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['views'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu de chaque repository */
foreach($json_content as $viewName)
$this->assertTrue( is_string($viewName) );
}
}
?>
?>

View File

@ -1,4 +1,4 @@
<?php define('__ROOT__', dirname(__FILE__) );
?>
?>

View File

@ -35,17 +35,17 @@
<!-- <script type='text/javascript' src='/f/js/sigma-plugins-animate-min/sigma/plugins' ></script> for animations -->
</head>
<body>
<!-- LOGIN -->
<?php if( connected() ) echo "<div id='LOGIN'>";
else echo "<div id='LOGIN' class='active'>"; ?>
else echo "<div id='LOGIN' class='active'>"; ?>
<?php //var_dump(session_id()); ?>
<div id='login-icon'></div>
<div id='login-close'>Accéder à la plateforme</div>
<form method='POST' action='' id='login-form'>
<!-- SI ON EST PAS CONNECTE -> FORMULAIRE DE LOGIN -->
<?php if( !connected() ){ ?>
<input type='text' placeholder='Identifiant ou adresse mail' name='login' id='login-login'>
@ -58,7 +58,7 @@
<?php }else{ ?>
<input type='submit' value='Déconnexion' name='logout-sub'>
<?php } ?>
</form>
</div>
@ -66,7 +66,7 @@
<!-- CORPS DE LA PAGE -->
<div id='WRAPPER'>
<!-- HEADER DE LA PAGE -->
<div id='HEADER'>
@ -83,7 +83,7 @@
echo "<span id='user-picture'></span>";
}?>
</div>
</div>
@ -93,7 +93,7 @@
<?php
$menuInflater = new MenuManager();
echo $menuInflater->inflate();
?>
?>
</nav>
@ -101,11 +101,11 @@
<div id='CONTAINER'></div>
</div>
<!-- Dépendences Javascript après chargement des éléments -->
<script type='text/javascript' src='/f/js/action-script/js'></script>
</body>
</html>
</html>