NxTIC/subDir/test/phpunit/tests/config.php

253 lines
8.0 KiB
PHP
Raw Normal View History

2016-04-17 15:46:34 +00:00
<?php namespace phpunit;
/* VERIFICATION DES FICHIERS DE CONFIGURATION
*
*/
class config extends \PHPUnit_Framework_TestCase{
private static $config = array(
'database-local' => '../config/database-local.json',
'database' => '../config/database.json',
'dispatcher-extensions' => '../config/dispatcher-extensions.json',
'dispatcher-tree' => '../config/dispatcher-tree.json',
'menu' => '../config/menu.json',
'modules' => '../config/modules.json',
'repositories' =>'../config/repositories.json',
'upload-auth' =>'../config/upload-auth.json',
'views' =>'../config/views.json'
2016-04-17 15:46:34 +00:00
);
/* [1] config/database-local.json
=========================================================*/
public function testDatabaseLocal(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['database-local'] );
$this->assertNotFalse( $file_content );
2016-04-17 15:46:34 +00:00
/* (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);
2016-04-17 15:46:34 +00:00
}
/* [2] config/database.json
=========================================================*/
public function testDatabaseRemote(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['database'] );
$this->assertNotFalse( $file_content );
2016-04-17 15:46:34 +00:00
/* (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);
}
/* [3] config/dispatcher-extensions.json
=========================================================*/
public function testDispatcherExtensions(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['dispatcher-extensions'] );
$this->assertNotFalse( $file_content );
2016-04-17 15:46:34 +00:00
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu */
foreach($json_content as $ext=>$mime){
// On verifie les extensions
$this->assertTrue( preg_match('/^\w+$/i', $ext) == true );
// On verifie les mime/type
$this->assertTrue( preg_match('/^\w+\/[\+\w]+$/i', $mime) == true );
}
}
/* [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 );
2016-04-17 15:46:34 +00:00
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu */
foreach($json_content as $name=>$path){
// On verifie les extensions
$this->assertTrue( preg_match('/^\w+$/i', $name) == true );
// On verifie les mime/type
$this->assertTrue( preg_match('/^[\w\/]+$/i', $path) == true );
}
}
/* [3] config/menu.json
=========================================================*/
public function testMenu(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['menu'] );
$this->assertNotFalse( $file_content );
2016-04-17 15:46:34 +00:00
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Contenu de chaque catégorie */
foreach($json_content as $category){
$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']) );
}
2016-04-17 15:46:34 +00:00
}
}
/* [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']) );
}
}
2016-04-17 15:46:34 +00:00
}
}
/* [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/upload-auth.json
=========================================================*/
public function testUploadAuth(){
/* (1) Lecture du fichier */
$file_content = file_get_contents( self::$config['upload-auth'] );
$this->assertNotFalse( $file_content );
/* (2) Parsage en JSON */
$json_content = json_decode( $file_content, true );
$this->assertNotNull( $json_content );
/* (3) Racine des uploads */
$this->assertTrue( isset($json_content['root']) );
/* (4) Liste des répertoires autorisés */
foreach($json_content['directories'] as $dir)
$this->assertTrue( preg_match('/^[a-z0-9_-]+$/', $dir) == true );
}
/* [7] 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) );
}
2016-04-17 15:46:34 +00:00
}
?>