public function testLoadPhpFileByPageName()
 {
     // -- bad route -> exception --
     $caught = false;
     try {
         loadPhpFileByPageName('unknowPage');
     } catch (\Exception $e) {
         $caught = true;
     }
     $this->assertTrue($caught);
     // -- bad file -> exception
     $caught = false;
     try {
         loadPhpFileByPageName('testLoadFile_badFile');
     } catch (\Exception $e) {
         $caught = true;
     }
     $this->assertTrue($caught);
     // --- good routename -> should work --
     global $app;
     // use a global var to see if file is included
     $app['testVar'] = false;
     // default
     $caught = false;
     try {
         // try to load file associated to name "testLoadFile_goodFile"
         loadPhpFileByPageName('testLoadFile_goodFile');
         // if it works, it will overwrite $app['testVar'] -> true
     } catch (\Exception $e) {
         $caught = true;
     }
     $this->assertFalse($caught);
     $this->assertTrue($app['testVar']);
 }
Beispiel #2
0
<?php

// init session
if (!isset($_SESSION)) {
    session_start();
}
// init functions
include_once 'includes/autoload.php';
// init vars
$app['param'] = getConfig("prod");
$app['users'] = loadJson($app['param']['db_path_users']);
$app['pages'] = loadJson($app['param']['db_path_pages']);
$app['tasks'] = loadJson($app['param']['db_path_tasks']);
$app['trans'] = loadTranslation(getLang());
// get page
$page = getActualRoute();
// secure all pages
if ($page != 'login' && !isConnected()) {
    redirect('login');
}
// load header
include_once 'views/header.php';
// load content of page
try {
    loadPhpFileByPageName($page);
} catch (\Exception $e) {
    loadPhpFileByPageName("erreur");
}
// load footer
include_once 'views/footer.php';