text.lib.test.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  3. class TestText extends UnitTestCase {
  4. public function test_api_html_to_text() {
  5. $filename = api_get_path(SYS_PATH).'documentation/installation_guide.html';
  6. $res = @file_get_contents($filename);
  7. if ($res !== false) {
  8. $res = api_html_to_text($res);
  9. $this->assertTrue(is_string($res));
  10. } else {
  11. $this->assertTrue(true); // The file is missing, skip this test.
  12. }
  13. //var_dump('<pre>'.$res.'</pre>');
  14. }
  15. public function test_api_str_getcsv() {
  16. $strings = array('FirstName;LastName;Email', 'John;Doe;john.doe@mail.com', '"Иван";\\Чолаков;ivan@mail.com');
  17. $expected_results = array(array('FirstName', 'LastName', 'Email'), array('John', 'Doe', 'john.doe@mail.com'), array('Иван', 'Чолаков', 'ivan@mail.com'));
  18. $res = array();
  19. foreach ($strings as $string) {
  20. $res[] = api_str_getcsv($string, ';');
  21. }
  22. $this->assertTrue($res === $expected_results);
  23. //var_dump($res);
  24. }
  25. public function test_api_fgetcsv() {
  26. $filename = api_get_path(SYS_CODE_PATH).'admin/exemple.csv';
  27. $res = array();
  28. $handle = @fopen($filename, 'r');
  29. if ($handle !== false) {
  30. while (($line = @api_fgetcsv($handle, null, ';')) !== false) {
  31. $res[] = $line;
  32. }
  33. @fclose($handle);
  34. $this->assertTrue(is_array($res) && count($res) > 0);
  35. } else {
  36. $this->assertTrue(true); // The file is missing, skip this test.
  37. }
  38. //var_dump($res);
  39. }
  40. public function test_api_camel_case_to_underscore() {
  41. $input_strings = array('myDocuments', 'MyProfile', 'CreateNewCourse', 'Create_New_course');
  42. $expected_results = array('my_documents', 'my_profile', 'create_new_course', 'create_new_course');
  43. $results = array_map('api_camel_case_to_underscore', $input_strings);
  44. $this->assertTrue($results == $expected_results);
  45. //var_dump($results);
  46. }
  47. function test_api_underscore_to_camel_case() {
  48. $input_strings = array('my_documents', 'My_profile', 'create_new_course');
  49. $expected_results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  50. $expected_results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  51. $func = create_function('$param', 'return api_underscore_to_camel_case($param, false);');
  52. $results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  53. $results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  54. $results1 = array_map('api_underscore_to_camel_case', $input_strings);
  55. $results2 = array_map($func, $input_strings);
  56. $this->assertTrue($results1 == $expected_results1 && $results2 == $expected_results2);
  57. //var_dump($results1);
  58. //var_dump($results2);
  59. }
  60. function test_text_parse_glossary() {
  61. $input='';
  62. $res=_text_parse_glossary($input);
  63. $this->assertTrue(is_string($res));
  64. //var_dump($res);
  65. }
  66. function test_text_parse_tex() {
  67. $textext='';
  68. $res=_text_parse_tex($textext);
  69. $this->assertTrue(is_string($res));
  70. //var_dump($res);
  71. }
  72. function test_text_parse_texexplorer() {
  73. $textext='';
  74. $res=_text_parse_texexplorer($textext);
  75. $this->assertTrue(is_string($res));
  76. //var_dump($res);
  77. }
  78. function test_text_parse_tool() {
  79. $input='';
  80. $res=_text_parse_tool($input);
  81. $this->assertTrue(is_null($res));
  82. //var_dump($res);
  83. }
  84. function testcut() {
  85. $text='';
  86. $maxchar='';
  87. $res=cut($text,$maxchar,$embed=false);
  88. $this->assertTrue(is_string($res));
  89. //var_dump($res);
  90. }
  91. function testdate_to_str_ago() {
  92. $date='';
  93. $res=date_to_str_ago($date);
  94. $this->assertTrue(is_string($res));
  95. //var_dump($res);
  96. }
  97. function testfloat_format() {
  98. $number='';
  99. $res=float_format($number, $flag = 1);
  100. if(!is_numeric($res) or !is_float($res)) {
  101. $this->assertTrue(is_null($res));
  102. }
  103. //var_dump($res);
  104. }
  105. function testlatex_gif_renderer() {
  106. ob_start();
  107. $latex_code="";
  108. global $_course;
  109. $res=latex_gif_renderer($latex_code);
  110. ob_end_clean();
  111. $this->assertTrue(is_string($res));
  112. //var_dump($res);
  113. }
  114. function testmake_clickable() {
  115. $string='';
  116. $res=make_clickable($string);
  117. $this->assertTrue(is_string($res));
  118. //var_dump($res);
  119. }
  120. function testtext_filter() {
  121. $input='';
  122. $res=text_filter($input, $filter=true);
  123. $this->assertTrue(is_string($res));
  124. //var_dump($res);
  125. }
  126. function testApiParseTex(){
  127. $textext = 'abc';
  128. $res = api_parse_tex($textext); //this function is practically deprecated now, it doesn't do anything
  129. $this->assertEqual($textext,$res);
  130. }
  131. }
  132. ?>