sub_language.class.test.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. require_once (api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php');
  3. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  4. class TestSubLanguageManager extends UnitTestCase {
  5. public $clean = array();
  6. public function __construct() {
  7. $this->UnitTestCase('Sublanguage Manager library - main/admin/sub_language.class.test.php');
  8. }
  9. /**
  10. * Testing who get all data of lang folder
  11. * @param String to url path folder
  12. * @param bool true if we only want the subname
  13. * @return Array All file of lang folder
  14. */
  15. public function testget_lang_folder_files_list(){
  16. $path = api_get_path(SYS_LANG_PATH).'english';
  17. $res = SubLanguageManager::get_lang_folder_files_list($path, $only_main_name = false);
  18. $this->assertTrue(is_array($res));
  19. $this->assertTrue(count($res)>0);
  20. }
  21. /**
  22. *
  23. *
  24. */
  25. public function testget_all_information_of_sub_language(){
  26. $parent_id = 13;
  27. $language_id = 10;
  28. $res = SubLanguageManager::get_all_information_of_sub_language($parent_id, $language_id);
  29. // under normal circumstances, there is no language 10 child of language 13
  30. $this->assertFalse($res);
  31. }
  32. /**
  33. *
  34. */
  35. public function testget_all_information_of_language(){
  36. $parent_id = 11;
  37. $res = SubLanguageManager::get_all_information_of_language($parent_id);
  38. $this->assertTrue(is_array($res));
  39. }
  40. /**
  41. * Get variables within a language file
  42. */
  43. public function testget_all_language_variable_in_file(){
  44. $system_path_folder = api_get_path(SYS_LANG_PATH);
  45. $system_path_file = $system_path_folder.'spanish/link.inc.php';
  46. $res = SubLanguageManager::get_all_language_variable_in_file($system_path_file);
  47. $this->assertTrue(is_array($res));
  48. }
  49. /**
  50. * Add directory for sub-language
  51. * @param String The sub-language path directory ( /var/www/my_lms/main/lang/spanish_corporate )
  52. * @return boolean
  53. */
  54. public function testadd_language_directory() {
  55. $res = SubLanguageManager :: add_language_directory('test');
  56. $this->assertTrue($res);
  57. $res = SubLanguageManager :: remove_language_directory('test');
  58. }
  59. /**
  60. *
  61. */
  62. public function testadd_file_in_language_directory(){
  63. $res = SubLanguageManager :: add_language_directory('test');
  64. $this->assertTrue($res);
  65. $system_path_file = api_get_path(SYS_LANG_PATH).'test/spanish.inc.php';
  66. $res = SubLanguageManager::add_file_in_language_directory($system_path_file);
  67. $this->assertTrue($res);
  68. $res = SubLanguageManager :: remove_language_directory('test');
  69. }
  70. public function testwrite_data_in_file(){
  71. $dirname = api_get_path(SYS_LANG_PATH);
  72. $file = $dirname.'spanish.inc.php';
  73. $path_file = $file;
  74. $new_sub_language='spanishtest';
  75. $variable_sub_language='test';
  76. $res = SubLanguageManager::write_data_in_file($path_file,$new_sub_language,$variable_sub_language);
  77. $this->assertTrue($res);
  78. }
  79. /**
  80. * Delete sub language of database
  81. * @param Integer id's.
  82. * @return null
  83. */
  84. public function Testremove_sub_language() {
  85. $parent_id = '';
  86. $sub_language_id = 1;
  87. $res = SubLanguageManager :: remove_sub_language($parent_id, $sub_language_id);
  88. $this->assertFalse($res);
  89. // var_dump($res);
  90. }
  91. /**
  92. * Test of Check if language exist by id
  93. * @param Integer
  94. * @return Boolean
  95. */
  96. public function Testcheck_if_exist_language_by_id() {
  97. $language_id = 14;
  98. $res = SubLanguageManager :: check_if_exist_language_by_id($language_id);
  99. $this->assertTrue($res);
  100. // var_dump($res);
  101. }
  102. /**
  103. * Show the name of language by id
  104. * @param Integer id
  105. * @return String the name of language
  106. */
  107. public function Testget_name_of_language_by_id() {
  108. $language_id = 13;
  109. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  110. $sql='SELECT original_name FROM '.$tbl_admin_languages.' WHERE id=13';
  111. $rs=Database::query($sql);
  112. $name ='';
  113. if (Database::num_rows($rs)>0) {
  114. $name = Database::result($rs,0,'original_name');
  115. }
  116. $res = SubLanguageManager :: get_name_of_language_by_id($language_id);
  117. $this->assertEqual($res,$name,'The language name from function does not match the database value');
  118. }
  119. /**
  120. * Verified if language is an sub-language
  121. * @param Integer
  122. * @return Boolean
  123. */
  124. public function Testcheck_if_language_is_sub_language_for_non_existing_sublanguage() {
  125. $language_id = 112;
  126. $res = SubLanguageManager :: check_if_language_is_sub_language($language_id);
  127. $this->assertFalse($res);
  128. // var_dump($res);
  129. }
  130. /**
  131. *
  132. */
  133. public function Testcheck_if_language_is_father() {
  134. $language_id = 12;
  135. $res = SubLanguageManager :: check_if_language_is_father($language_id);
  136. $this->assertFalse($res);
  137. // var_dump($res);
  138. }
  139. /**
  140. *
  141. */
  142. public function Testmake_language_unavailable_and_back() {
  143. $language_id = 11;
  144. $res = SubLanguageManager :: make_unavailable_language($language_id);
  145. $this->assertTrue($res,'Language could not be made unavailable');
  146. $res = SubLanguageManager :: make_available_language($language_id);
  147. // var_dump($res);
  148. }
  149. /**
  150. *
  151. */
  152. public function Testmake_available_language() {
  153. $language_id= 11;
  154. $res = SubLanguageManager :: make_unavailable_language($language_id);
  155. $res = SubLanguageManager :: make_available_language ($language_id);
  156. $this->assertTrue($res,'Language could not be made available');
  157. // var_dump($res);
  158. }
  159. /**
  160. *
  161. *
  162. */
  163. public function Testset_platform_language_empty(){
  164. $backup = SubLanguageManager :: get_platform_language_id();
  165. $language_id = '';
  166. $res = SubLanguageManager :: set_platform_language($language_id);
  167. $this->assertFalse($res);
  168. $res = SubLanguageManager :: set_platform_language($backup);
  169. // var_dump($res);
  170. }
  171. public function Testset_platform_language_2(){
  172. $backup = SubLanguageManager :: get_platform_language_id();
  173. $language_id = 2;
  174. $res = SubLanguageManager :: set_platform_language($language_id);
  175. $this->assertTrue($res);
  176. $res = SubLanguageManager :: set_platform_language($backup);
  177. // var_dump($res);
  178. }
  179. /**
  180. *
  181. *
  182. */
  183. public function Testremove_directory_of_sub_language(){
  184. $res = SubLanguageManager :: remove_language_directory('test');
  185. // create a directory of sub language
  186. $res = SubLanguageManager :: add_language_directory('test');
  187. $this->assertTrue($res);
  188. $res = SubLanguageManager :: remove_language_directory('test');
  189. // var_dump($res);
  190. }
  191. }
  192. ?>