133 lines
3.8 KiB
PHP
133 lines
3.8 KiB
PHP
|
<?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',
|
||
|
'views' => '../config/views.json'
|
||
|
);
|
||
|
|
||
|
/* [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 );
|
||
|
|
||
|
/* (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);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/* [2] config/database.json
|
||
|
=========================================================*/
|
||
|
public function testDatabaseRemote(){
|
||
|
/* (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 );
|
||
|
|
||
|
/* (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 );
|
||
|
|
||
|
/* (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 );
|
||
|
|
||
|
/* (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 );
|
||
|
|
||
|
/* (2) Parsage en JSON */
|
||
|
$json_content = json_decode( $file_content, true );
|
||
|
$this->assertNotNull( $json_content );
|
||
|
|
||
|
|
||
|
|
||
|
/* (3) Contenu */
|
||
|
foreach($json_content as $category){
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
?>
|