sub_language.class.test.php 6.2 KB

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