@ -7,332 +7,332 @@
class TestMainApi extends UnitTestCase {
class TestMainApi extends UnitTestCase {
function TestMainApi() {
function TestMainApi() {
$this->UnitTestCase('Main API tests');
$this->UnitTestCase('Main API tests');
}
}
public function testApiGetPath() {
public function testApiGetPath() {
$common_paths = array(
$common_paths = array(
WEB_PATH,
WEB_PATH,
SYS_PATH,
SYS_PATH,
REL_PATH,
REL_PATH,
WEB_SERVER_ROOT_PATH,
WEB_SERVER_ROOT_PATH,
SYS_SERVER_ROOT_PATH,
SYS_SERVER_ROOT_PATH,
WEB_COURSE_PATH,
WEB_COURSE_PATH,
SYS_COURSE_PATH,
SYS_COURSE_PATH,
REL_COURSE_PATH,
REL_COURSE_PATH,
REL_CODE_PATH,
REL_CODE_PATH,
WEB_CODE_PATH,
WEB_CODE_PATH,
SYS_CODE_PATH,
SYS_CODE_PATH,
SYS_LANG_PATH,
SYS_LANG_PATH,
WEB_IMG_PATH,
WEB_IMG_PATH,
WEB_CSS_PATH,
WEB_CSS_PATH,
SYS_PLUGIN_PATH,
SYS_PLUGIN_PATH,
WEB_PLUGIN_PATH,
WEB_PLUGIN_PATH,
SYS_ARCHIVE_PATH,
SYS_ARCHIVE_PATH,
WEB_ARCHIVE_PATH,
WEB_ARCHIVE_PATH,
INCLUDE_PATH,
INCLUDE_PATH,
LIBRARY_PATH,
LIBRARY_PATH,
CONFIGURATION_PATH,
CONFIGURATION_PATH,
WEB_LIBRARY_PATH
WEB_LIBRARY_PATH
);
);
$specific_paths = array(
$specific_paths = array(
FLASH_PLAYER_AUDIO,
FLASH_PLAYER_AUDIO,
FLASH_PLAYER_VIDEO,
FLASH_PLAYER_VIDEO,
SCRIPT_SWFOBJECT,
SCRIPT_SWFOBJECT,
SCRIPT_ASCIIMATHML
SCRIPT_ASCIIMATHML
);
);
$res = array();
$res = array();
$is_ok = array();
$is_ok = array();
$message = array();
$message = array();
$paths = array();
$paths = array();
$message[] = '';
$message[] = '';
$message[] = '< strong > A test about api_get_path()< / strong > ';
$message[] = '< strong > A test about api_get_path()< / strong > ';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = 'Changed behaviour of the function api_get_path() after Dokeos 1.8.6.1, i.e. as of Chamilo 1.8.6.2.';
$message[] = 'Changed behaviour of the function api_get_path() after Dokeos 1.8.6.1, i.e. as of Chamilo 1.8.6.2.';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
$message[] = 'Old behaviour (1.8.6.1) api_get_path(INCLUDE_PATH) = '.api_get_path_1_8_6_1(INCLUDE_PATH).' | '.'New behaviour (1.8.6.2) api_get_path(INCLUDE_PATH) = '.api_get_path(INCLUDE_PATH);
$message[] = 'Old behaviour (1.8.6.1) api_get_path(INCLUDE_PATH) = '.api_get_path_1_8_6_1(INCLUDE_PATH).' | '.'New behaviour (1.8.6.2) api_get_path(INCLUDE_PATH) = '.api_get_path(INCLUDE_PATH);
$message[] = '* Reason for this change: Difference here is due to the fact that the etalonic old function api_get_path() has ben moved in this file ( see api_get_path_1_8_6_1() ). Even for such rare, hypothetical cases, this widely used function should be stable. Now, after installation, the function returns results based on configuration settings only, as it should be.';
$message[] = '* Reason for this change: Difference here is due to the fact that the etalonic old function api_get_path() has ben moved in this file ( see api_get_path_1_8_6_1() ). Even for such rare, hypothetical cases, this widely used function should be stable. Now, after installation, the function returns results based on configuration settings only, as it should be.';
$message[] = '';
$message[] = '';
$message[] = 'Old behaviour (1.8.6.1) api_get_path(WEB_CSS_PATH) = '.api_get_path_1_8_6_1(WEB_CSS_PATH).' | '.'New behaviour (1.8.6.2) api_get_path(WEB_CSS_PATH) = '.api_get_path(WEB_CSS_PATH);
$message[] = 'Old behaviour (1.8.6.1) api_get_path(WEB_CSS_PATH) = '.api_get_path_1_8_6_1(WEB_CSS_PATH).' | '.'New behaviour (1.8.6.2) api_get_path(WEB_CSS_PATH) = '.api_get_path(WEB_CSS_PATH);
$message[] = '* This is a proposed implementation. Retrieving css paths through user\'s configuration options has not been implemented yet.';
$message[] = '* This is a proposed implementation. Retrieving css paths through user\'s configuration options has not been implemented yet.';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = 'Reading common purpose paths';
$message[] = 'Reading common purpose paths';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
foreach ($common_paths as $path) {
foreach ($common_paths as $path) {
$test_case = "api_get_path($path)";
$test_case = "api_get_path($path)";
$res[$test_case] = api_get_path($path);
$res[$test_case] = api_get_path($path);
switch ($path) {
switch ($path) {
case INCLUDE_PATH:
case INCLUDE_PATH:
case WEB_CSS_PATH:
case WEB_CSS_PATH:
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
break;
break;
default:
default:
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]) & & $res[$test_case] == api_get_path_1_8_6_1($path);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]) & & $res[$test_case] == api_get_path_1_8_6_1($path);
}
}
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
}
}
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = 'Reading specific purpose paths';
$message[] = 'Reading specific purpose paths';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
foreach ($specific_paths as $path) {
foreach ($specific_paths as $path) {
$test_case = "api_get_path(TO_WEB, $path)";
$test_case = "api_get_path(TO_WEB, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_WEB, $path);
$res[$test_case] = api_get_path(TO_WEB, $path);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
$test_case = "api_get_path(TO_SYS, $path)";
$test_case = "api_get_path(TO_SYS, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_SYS, $path);
$res[$test_case] = api_get_path(TO_SYS, $path);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
$test_case = "api_get_path(TO_REL, $path)";
$test_case = "api_get_path(TO_REL, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_REL, $path);
$res[$test_case] = api_get_path(TO_REL, $path);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$is_ok[$test_case] = is_string($res[$test_case]) & & !empty($res[$test_case]);
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : '.$test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
}
}
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = 'Testing path conversions';
$message[] = 'Testing path conversions';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
$paths = array();
$paths = array();
foreach ($common_paths as $path) {
foreach ($common_paths as $path) {
$paths[] = array($path, api_get_path($path));
$paths[] = array($path, api_get_path($path));
}
}
foreach ($specific_paths as $path) {
foreach ($specific_paths as $path) {
$paths[] = array($path, api_get_path(TO_WEB, $path));
$paths[] = array($path, api_get_path(TO_WEB, $path));
$paths[] = array($path, api_get_path(TO_SYS, $path));
$paths[] = array($path, api_get_path(TO_SYS, $path));
$paths[] = array($path, api_get_path(TO_REL, $path));
$paths[] = array($path, api_get_path(TO_REL, $path));
}
}
foreach ($paths as $path) {
foreach ($paths as $path) {
$test_case = 'api_get_path(TO_WEB, '.$path[0].')';
$test_case = 'api_get_path(TO_WEB, '.$path[0].')';
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_WEB, $path[0]);
$res[$test_case] = api_get_path(TO_WEB, $path[0]);
$test_case_1 = 'api_get_path(TO_WEB, \''.$path[1].'\')';
$test_case_1 = 'api_get_path(TO_WEB, \''.$path[1].'\')';
$res[$test_case_1] = api_get_path(TO_WEB, $path[1]);
$res[$test_case_1] = api_get_path(TO_WEB, $path[1]);
$is_ok[$test_case] =
$is_ok[$test_case] =
is_string($res[$test_case]) & & !empty($res[$test_case])
is_string($res[$test_case]) & & !empty($res[$test_case])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & $res[$test_case] == $res[$test_case_1];
& & $res[$test_case] == $res[$test_case_1];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = '';
$message[] = '';
$test_case = 'api_get_path(TO_SYS, '.$path[0].')';
$test_case = 'api_get_path(TO_SYS, '.$path[0].')';
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_SYS, $path[0]);
$res[$test_case] = api_get_path(TO_SYS, $path[0]);
$test_case_1 = 'api_get_path(TO_SYS, \''.$path[1].'\')';
$test_case_1 = 'api_get_path(TO_SYS, \''.$path[1].'\')';
$res[$test_case_1] = api_get_path(TO_SYS, $path[1]);
$res[$test_case_1] = api_get_path(TO_SYS, $path[1]);
$is_ok[$test_case] =
$is_ok[$test_case] =
is_string($res[$test_case]) & & !empty($res[$test_case])
is_string($res[$test_case]) & & !empty($res[$test_case])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & $res[$test_case] == $res[$test_case_1];
& & $res[$test_case] == $res[$test_case_1];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = '';
$message[] = '';
$test_case = 'api_get_path(TO_REL, '.$path[0].')';
$test_case = 'api_get_path(TO_REL, '.$path[0].')';
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_REL, $path[0]);
$res[$test_case] = api_get_path(TO_REL, $path[0]);
$test_case_1 = 'api_get_path(TO_REL, \''.$path[1].'\')';
$test_case_1 = 'api_get_path(TO_REL, \''.$path[1].'\')';
$res[$test_case_1] = api_get_path(TO_REL, $path[1]);
$res[$test_case_1] = api_get_path(TO_REL, $path[1]);
$is_ok[$test_case] =
$is_ok[$test_case] =
is_string($res[$test_case]) & & !empty($res[$test_case])
is_string($res[$test_case]) & & !empty($res[$test_case])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & is_string($res[$test_case_1]) & & !empty($res[$test_case_1])
& & $res[$test_case] == $res[$test_case_1];
& & $res[$test_case] == $res[$test_case_1];
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = ($is_ok[$test_case] ? '< span style = "color: green; font-weight: bold;" > Ok< / span > ' : '< span style = "color: red; font-weight: bold;" > Failed< / span > ').' : ';
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = $test_case_1.' => '.$res[$test_case_1];
$message[] = '';
$message[] = '';
}
}
$message[] = '';
$message[] = '';
$message[] = 'Random examples, check them visually';
$message[] = 'Random examples, check them visually';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
$message[] = '$_SERVER[\'REQUEST_URI\'] => '.$_SERVER['REQUEST_URI'];
$message[] = '$_SERVER[\'REQUEST_URI\'] => '.$_SERVER['REQUEST_URI'];
$message[] = '< strong > Note:< / strong > Try some query strings. They should be removed from the results.';
$message[] = '< strong > Note:< / strong > Try some query strings. They should be removed from the results.';
$message[] = 'api_get_path(TO_WEB, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_WEB, $_SERVER['REQUEST_URI']);
$message[] = 'api_get_path(TO_WEB, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_WEB, $_SERVER['REQUEST_URI']);
$message[] = 'api_get_path(TO_SYS, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_SYS, $_SERVER['REQUEST_URI']);
$message[] = 'api_get_path(TO_SYS, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_SYS, $_SERVER['REQUEST_URI']);
$message[] = 'api_get_path(TO_REL, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_REL, $_SERVER['REQUEST_URI']);
$message[] = 'api_get_path(TO_REL, $_SERVER[\'REQUEST_URI\']) => '.api_get_path(TO_REL, $_SERVER['REQUEST_URI']);
$message[] = '';
$message[] = '';
$message[] = '__FILE__ => '.__FILE__;
$message[] = '__FILE__ => '.__FILE__;
$message[] = 'api_get_path(TO_WEB, __FILE__) => '.api_get_path(TO_WEB, __FILE__);
$message[] = 'api_get_path(TO_WEB, __FILE__) => '.api_get_path(TO_WEB, __FILE__);
$message[] = 'api_get_path(TO_SYS, __FILE__) => '.api_get_path(TO_SYS, __FILE__);
$message[] = 'api_get_path(TO_SYS, __FILE__) => '.api_get_path(TO_SYS, __FILE__);
$message[] = 'api_get_path(TO_REL, __FILE__) => '.api_get_path(TO_REL, __FILE__);
$message[] = 'api_get_path(TO_REL, __FILE__) => '.api_get_path(TO_REL, __FILE__);
$message[] = '';
$message[] = '';
$message[] = '$_SERVER[\'PHP_SELF\'] => '.$_SERVER['PHP_SELF'];
$message[] = '$_SERVER[\'PHP_SELF\'] => '.$_SERVER['PHP_SELF'];
$message[] = 'api_get_path(TO_WEB, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_WEB, $_SERVER['PHP_SELF']);
$message[] = 'api_get_path(TO_WEB, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_WEB, $_SERVER['PHP_SELF']);
$message[] = 'api_get_path(TO_SYS, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_SYS, $_SERVER['PHP_SELF']);
$message[] = 'api_get_path(TO_SYS, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_SYS, $_SERVER['PHP_SELF']);
$message[] = 'api_get_path(TO_REL, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_REL, $_SERVER['PHP_SELF']);
$message[] = 'api_get_path(TO_REL, $_SERVER[\'PHP_SELF\']) => '.api_get_path(TO_REL, $_SERVER['PHP_SELF']);
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = 'This test and changes of behaviour of api_get_path() have been done by Ivan Tcholakov, September 22, 2009.';
$message[] = 'This test and changes of behaviour of api_get_path() have been done by Ivan Tcholakov, September 22, 2009.';
$message[] = '';
$message[] = '';
$result = !in_array(false, $is_ok);
$result = !in_array(false, $is_ok);
$this->assertTrue($result);
$this->assertTrue($result);
//var_dump($res);
//var_dump($res);
foreach ($message as $line) { echo $line.'< br / > '; }
foreach ($message as $line) { echo $line.'< br / > '; }
// Sample code for showing results in different context.
// Sample code for showing results in different context.
/*
/*
$common_paths = array(
$common_paths = array(
WEB_PATH,
WEB_PATH,
SYS_PATH,
SYS_PATH,
REL_PATH,
REL_PATH,
WEB_SERVER_ROOT_PATH,
WEB_SERVER_ROOT_PATH,
SYS_SERVER_ROOT_PATH,
SYS_SERVER_ROOT_PATH,
WEB_COURSE_PATH,
WEB_COURSE_PATH,
SYS_COURSE_PATH,
SYS_COURSE_PATH,
REL_COURSE_PATH,
REL_COURSE_PATH,
REL_CODE_PATH,
REL_CODE_PATH,
WEB_CODE_PATH,
WEB_CODE_PATH,
SYS_CODE_PATH,
SYS_CODE_PATH,
SYS_LANG_PATH,
SYS_LANG_PATH,
WEB_IMG_PATH,
WEB_IMG_PATH,
WEB_CSS_PATH,
WEB_CSS_PATH,
SYS_PLUGIN_PATH,
SYS_PLUGIN_PATH,
WEB_PLUGIN_PATH,
WEB_PLUGIN_PATH,
SYS_ARCHIVE_PATH,
SYS_ARCHIVE_PATH,
WEB_ARCHIVE_PATH,
WEB_ARCHIVE_PATH,
INCLUDE_PATH,
INCLUDE_PATH,
LIBRARY_PATH,
LIBRARY_PATH,
CONFIGURATION_PATH,
CONFIGURATION_PATH,
WEB_LIBRARY_PATH
WEB_LIBRARY_PATH
);
);
$specific_paths = array(
$specific_paths = array(
FLASH_PLAYER_AUDIO,
FLASH_PLAYER_AUDIO,
FLASH_PLAYER_VIDEO,
FLASH_PLAYER_VIDEO,
SCRIPT_SWFOBJECT,
SCRIPT_SWFOBJECT,
SCRIPT_ASCIIMATHML
SCRIPT_ASCIIMATHML
);
);
$res = array();
$res = array();
$is_ok = array();
$is_ok = array();
$message = array();
$message = array();
$paths = array();
$paths = array();
$message[] = '';
$message[] = '';
$message[] = 'Reading common purpose paths';
$message[] = 'Reading common purpose paths';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
foreach ($common_paths as $path) {
foreach ($common_paths as $path) {
$test_case = "api_get_path($path)";
$test_case = "api_get_path($path)";
$res[$test_case] = api_get_path($path);
$res[$test_case] = api_get_path($path);
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
}
}
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = '';
$message[] = 'Reading specific purpose paths';
$message[] = 'Reading specific purpose paths';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '---------------------------------------------------------------------------------------------------------------';
$message[] = '';
$message[] = '';
foreach ($specific_paths as $path) {
foreach ($specific_paths as $path) {
$test_case = "api_get_path(TO_WEB, $path)";
$test_case = "api_get_path(TO_WEB, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_WEB, $path);
$res[$test_case] = api_get_path(TO_WEB, $path);
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
$test_case = "api_get_path(TO_SYS, $path)";
$test_case = "api_get_path(TO_SYS, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_SYS, $path);
$res[$test_case] = api_get_path(TO_SYS, $path);
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
$test_case = "api_get_path(TO_REL, $path)";
$test_case = "api_get_path(TO_REL, $path)";
$test_case = str_replace(array('{', '}'), '', $test_case);
$test_case = str_replace(array('{', '}'), '', $test_case);
$res[$test_case] = api_get_path(TO_REL, $path);
$res[$test_case] = api_get_path(TO_REL, $path);
$message[] = $test_case.' => '.$res[$test_case];
$message[] = $test_case.' => '.$res[$test_case];
$paths[] = $path;
$paths[] = $path;
}
}
foreach ($message as $line) { echo $line.'< br / > '; }
foreach ($message as $line) { echo $line.'< br / > '; }
*/
*/
}
}
public function testApiIsInternalPath() {
public function testApiIsInternalPath() {
$path1 = api_get_path(WEB_IMG_PATH);
$path1 = api_get_path(WEB_IMG_PATH);
$path2 = 'http://kdflskfsenfnmzsdn/fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$path2 = 'http://kdflskfsenfnmzsdn/fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$path3 = api_get_path(TO_SYS, WEB_IMG_PATH);
$path3 = api_get_path(TO_SYS, WEB_IMG_PATH);
$path4 = 'C:\Inetpub\wwwroot\fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$path4 = 'C:\Inetpub\wwwroot\fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$path5 = api_get_path(TO_REL, WEB_IMG_PATH);
$path5 = api_get_path(TO_REL, WEB_IMG_PATH);
$path6 = '/fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$path6 = '/fnefsdsmdsdmsdfsdcmxaddfdafada/index.html';
$res1 = api_is_internal_path($path1);
$res1 = api_is_internal_path($path1);
$res2 = api_is_internal_path($path2);
$res2 = api_is_internal_path($path2);
$res3 = api_is_internal_path($path3);
$res3 = api_is_internal_path($path3);
$res4 = api_is_internal_path($path4);
$res4 = api_is_internal_path($path4);
$res5 = api_is_internal_path($path5);
$res5 = api_is_internal_path($path5);
$res6 = api_is_internal_path($path6);
$res6 = api_is_internal_path($path6);
$this->assertTrue(is_bool($res1) & & is_bool($res2) & & is_bool($res3) & & is_bool($res4) & & is_bool($res5) & & is_bool($res6)
$this->assertTrue(is_bool($res1) & & is_bool($res2) & & is_bool($res3) & & is_bool($res4) & & is_bool($res5) & & is_bool($res6)
& & $res1 & & !$res2 & & $res3 & & !$res4 & & $res5 & & !$res6);
& & $res1 & & !$res2 & & $res3 & & !$res4 & & $res5 & & !$res6);
//var_dump($res1);
//var_dump($res1);
//var_dump($res2);
//var_dump($res2);
//var_dump($res1);
//var_dump($res1);
//var_dump($res2);
//var_dump($res2);
//var_dump($res1);
//var_dump($res1);
//var_dump($res2);
//var_dump($res2);
}
}
public function testApiAddTrailingSlash() {
public function testApiAddTrailingSlash() {
$string1 = 'path';
$string1 = 'path';
$string2 = 'path/';
$string2 = 'path/';
$res1 = api_add_trailing_slash($string1);
$res1 = api_add_trailing_slash($string1);
$res2 = api_add_trailing_slash($string2);
$res2 = api_add_trailing_slash($string2);
$this->assertTrue(is_string($res1) & & is_string($res2) & & $res1 == $res2);
$this->assertTrue(is_string($res1) & & is_string($res2) & & $res1 == $res2);
//var_dump($res1);
//var_dump($res1);
//var_dump($res2);
//var_dump($res2);
}
}
public function testRemoveAddTrailingSlash() {
public function testRemoveAddTrailingSlash() {
$string1 = 'path';
$string1 = 'path';
$string2 = 'path/';
$string2 = 'path/';
$res1 = api_remove_trailing_slash($string1);
$res1 = api_remove_trailing_slash($string1);
$res2 = api_remove_trailing_slash($string2);
$res2 = api_remove_trailing_slash($string2);
$this->assertTrue(is_string($res1) & & is_string($res2) & & $res1 == $res2);
$this->assertTrue(is_string($res1) & & is_string($res2) & & $res1 == $res2);
//var_dump($res1);
//var_dump($res1);
//var_dump($res2);
//var_dump($res2);
}
}
}
}
/**
/**
@ -377,161 +377,161 @@ class TestMainApi extends UnitTestCase {
*/
*/
function api_get_path_1_8_6_1($path_type) {
function api_get_path_1_8_6_1($path_type) {
global $_configuration;
global $_configuration;
if (!isset($_configuration['access_url']) || $_configuration['access_url']==1 || $_configuration['access_url']=='') {
if (!isset($_configuration['access_url']) || $_configuration['access_url']==1 || $_configuration['access_url']=='') {
//by default we call the $_configuration['root_web'] we don't query to the DB
//by default we call the $_configuration['root_web'] we don't query to the DB
//$url_info= api_get_access_url(1);
//$url_info= api_get_access_url(1);
//$root_web = $url_info['url'];
//$root_web = $url_info['url'];
if(isset($_configuration['root_web']))
if(isset($_configuration['root_web']))
$root_web = $_configuration['root_web'];
$root_web = $_configuration['root_web'];
} else {
} else {
//we look into the DB the function api_get_access_url
//we look into the DB the function api_get_access_url
//this funcion have a problem because we can't called to the Database:: functions
//this funcion have a problem because we can't called to the Database:: functions
$url_info= api_get_access_url($_configuration['access_url']);
$url_info= api_get_access_url($_configuration['access_url']);
if ($url_info['active']==1) {
if ($url_info['active']==1) {
$root_web = $url_info['url'];
$root_web = $url_info['url'];
} else {
} else {
$root_web = $_configuration['root_web'];
$root_web = $_configuration['root_web'];
}
}
}
}
switch ($path_type) {
switch ($path_type) {
case WEB_SERVER_ROOT_PATH:
case WEB_SERVER_ROOT_PATH:
// example: http://www.mydokeos.com/
// example: http://www.mydokeos.com/
$result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(WEB_PATH));
$result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(WEB_PATH));
if (substr($result, -1) == '/') {
if (substr($result, -1) == '/') {
return $result;
return $result;
} else {
} else {
return $result.'/';
return $result.'/';
}
}
break;
break;
case SYS_SERVER_ROOT_PATH:
case SYS_SERVER_ROOT_PATH:
$result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(SYS_PATH));
$result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(SYS_PATH));
if (substr($result, -1) == '/') {
if (substr($result, -1) == '/') {
return $result;
return $result;
} else {
} else {
return $result.'/';
return $result.'/';
}
}
break;
break;
case WEB_PATH :
case WEB_PATH :
// example: http://www.mydokeos.com/ or http://www.mydokeos.com/dokeos/ if you're using
// example: http://www.mydokeos.com/ or http://www.mydokeos.com/dokeos/ if you're using
// a subdirectory of your document root for Dokeos
// a subdirectory of your document root for Dokeos
if (substr($root_web,-1) == '/') {
if (substr($root_web,-1) == '/') {
return $root_web;
return $root_web;
} else {
} else {
return $root_web.'/';
return $root_web.'/';
}
}
break;
break;
case SYS_PATH :
case SYS_PATH :
// example: /var/www/dokeos/
// example: /var/www/dokeos/
if (substr($_configuration['root_sys'],-1) == '/') {
if (substr($_configuration['root_sys'],-1) == '/') {
return $_configuration['root_sys'];
return $_configuration['root_sys'];
} else {
} else {
return $_configuration['root_sys'].'/';
return $_configuration['root_sys'].'/';
}
}
break;
break;
case REL_PATH :
case REL_PATH :
// example: dokeos/
// example: dokeos/
if (substr($_configuration['url_append'], -1) === '/') {
if (substr($_configuration['url_append'], -1) === '/') {
return $_configuration['url_append'];
return $_configuration['url_append'];
} else {
} else {
return $_configuration['url_append'].'/';
return $_configuration['url_append'].'/';
}
}
break;
break;
case WEB_COURSE_PATH :
case WEB_COURSE_PATH :
// example: http://www.mydokeos.com/courses/
// example: http://www.mydokeos.com/courses/
return $root_web.$_configuration['course_folder'];
return $root_web.$_configuration['course_folder'];
break;
break;
case SYS_COURSE_PATH :
case SYS_COURSE_PATH :
// example: /var/www/dokeos/courses/
// example: /var/www/dokeos/courses/
return $_configuration['root_sys'].$_configuration['course_folder'];
return $_configuration['root_sys'].$_configuration['course_folder'];
break;
break;
case REL_COURSE_PATH :
case REL_COURSE_PATH :
// example: courses/ or dokeos/courses/
// example: courses/ or dokeos/courses/
return api_get_path(REL_PATH).$_configuration['course_folder'];
return api_get_path(REL_PATH).$_configuration['course_folder'];
break;
break;
case REL_CODE_PATH :
case REL_CODE_PATH :
// example: main/ or dokeos/main/
// example: main/ or dokeos/main/
return api_get_path(REL_PATH).$_configuration['code_append'];
return api_get_path(REL_PATH).$_configuration['code_append'];
break;
break;
case WEB_CODE_PATH :
case WEB_CODE_PATH :
// example: http://www.mydokeos.com/main/
// example: http://www.mydokeos.com/main/
//return $GLOBALS['clarolineRepositoryWeb']; // this was changed
//return $GLOBALS['clarolineRepositoryWeb']; // this was changed
return $root_web.$_configuration['code_append'];
return $root_web.$_configuration['code_append'];
break;
break;
case SYS_CODE_PATH :
case SYS_CODE_PATH :
// example: /var/www/dokeos/main/
// example: /var/www/dokeos/main/
return $GLOBALS['clarolineRepositorySys'];
return $GLOBALS['clarolineRepositorySys'];
break;
break;
case SYS_LANG_PATH :
case SYS_LANG_PATH :
// example: /var/www/dokeos/main/lang/
// example: /var/www/dokeos/main/lang/
return api_get_path(SYS_CODE_PATH).'lang/';
return api_get_path(SYS_CODE_PATH).'lang/';
break;
break;
case WEB_IMG_PATH :
case WEB_IMG_PATH :
// example: http://www.mydokeos.com/main/img/
// example: http://www.mydokeos.com/main/img/
return api_get_path(WEB_CODE_PATH).'img/';
return api_get_path(WEB_CODE_PATH).'img/';
break;
break;
case SYS_PLUGIN_PATH :
case SYS_PLUGIN_PATH :
// example: /var/www/dokeos/plugin/
// example: /var/www/dokeos/plugin/
return api_get_path(SYS_PATH).'plugin/';
return api_get_path(SYS_PATH).'plugin/';
break;
break;
case WEB_PLUGIN_PATH :
case WEB_PLUGIN_PATH :
// example: http://www.mydokeos.com/plugin/
// example: http://www.mydokeos.com/plugin/
return api_get_path(WEB_PATH).'plugin/';
return api_get_path(WEB_PATH).'plugin/';
break;
break;
case GARBAGE_PATH : //now set to be same as archive
case GARBAGE_PATH : //now set to be same as archive
case SYS_ARCHIVE_PATH :
case SYS_ARCHIVE_PATH :
// example: /var/www/dokeos/archive/
// example: /var/www/dokeos/archive/
return api_get_path(SYS_PATH).'archive/';
return api_get_path(SYS_PATH).'archive/';
break;
break;
case WEB_ARCHIVE_PATH :
case WEB_ARCHIVE_PATH :
// example: http://www.mydokeos.com/archive/
// example: http://www.mydokeos.com/archive/
return api_get_path(WEB_PATH).'archive/';
return api_get_path(WEB_PATH).'archive/';
break;
break;
case INCLUDE_PATH :
case INCLUDE_PATH :
// Generated by main/inc/global.inc.php
// Generated by main/inc/global.inc.php
// example: /var/www/dokeos/main/inc/
// example: /var/www/dokeos/main/inc/
$incpath = realpath(dirname(__FILE__).'/../');
$incpath = realpath(dirname(__FILE__).'/../');
return str_replace('\\', '/', $incpath).'/';
return str_replace('\\', '/', $incpath).'/';
break;
break;
case LIBRARY_PATH :
case LIBRARY_PATH :
// example: /var/www/dokeos/main/inc/lib/
// example: /var/www/dokeos/main/inc/lib/
return api_get_path(INCLUDE_PATH).'lib/';
return api_get_path(INCLUDE_PATH).'lib/';
break;
break;
case WEB_LIBRARY_PATH :
case WEB_LIBRARY_PATH :
// example: http://www.mydokeos.com/main/inc/lib/
// example: http://www.mydokeos.com/main/inc/lib/
return api_get_path(WEB_CODE_PATH).'inc/lib/';
return api_get_path(WEB_CODE_PATH).'inc/lib/';
break;
break;
case CONFIGURATION_PATH :
case CONFIGURATION_PATH :
// example: /var/www/dokeos/main/inc/conf/
// example: /var/www/dokeos/main/inc/conf/
return api_get_path(INCLUDE_PATH).'conf/';
return api_get_path(INCLUDE_PATH).'conf/';
break;
break;
default :
default :
return;
return;
break;
break;
}
}
}
}
?>
?>