text.lib.test.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_camel_case_to_underscore() {
  16. $input_strings = array('myDocuments', 'MyProfile', 'CreateNewCourse', 'Create_New_course');
  17. $expected_results = array('my_documents', 'my_profile', 'create_new_course', 'create_new_course');
  18. $results = array_map('api_camel_case_to_underscore', $input_strings);
  19. $this->assertTrue($results == $expected_results);
  20. //var_dump($results);
  21. }
  22. function test_api_underscore_to_camel_case() {
  23. $input_strings = array('my_documents', 'My_profile', 'create_new_course');
  24. $expected_results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  25. $expected_results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  26. $func = create_function('$param', 'return api_underscore_to_camel_case($param, false);');
  27. $results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  28. $results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  29. $results1 = array_map('api_underscore_to_camel_case', $input_strings);
  30. $results2 = array_map($func, $input_strings);
  31. $this->assertTrue($results1 == $expected_results1 && $results2 == $expected_results2);
  32. //var_dump($results1);
  33. //var_dump($results2);
  34. }
  35. function test_text_parse_glossary() {
  36. $input='';
  37. $res=_text_parse_glossary($input);
  38. $this->assertTrue(is_string($res));
  39. //var_dump($res);
  40. }
  41. function test_text_parse_tex() {
  42. $textext='';
  43. $res=_text_parse_tex($textext);
  44. $this->assertTrue(is_string($res));
  45. //var_dump($res);
  46. }
  47. function test_text_parse_texexplorer() {
  48. $textext='';
  49. $res=_text_parse_texexplorer($textext);
  50. $this->assertTrue(is_string($res));
  51. //var_dump($res);
  52. }
  53. function test_text_parse_tool() {
  54. $input='';
  55. $res=_text_parse_tool($input);
  56. $this->assertTrue(is_null($res));
  57. //var_dump($res);
  58. }
  59. function testcut() {
  60. $text='';
  61. $maxchar='';
  62. $res=cut($text,$maxchar,$embed=false);
  63. $this->assertTrue(is_string($res));
  64. //var_dump($res);
  65. }
  66. function testdate_to_str_ago() {
  67. $date='';
  68. $res=date_to_str_ago($date);
  69. $this->assertTrue(is_string($res));
  70. //var_dump($res);
  71. }
  72. function testfloat_format() {
  73. $number='';
  74. $res=float_format($number, $flag = 1);
  75. if(!is_numeric($res) or !is_float($res)) {
  76. $this->assertTrue(is_null($res));
  77. }
  78. //var_dump($res);
  79. }
  80. function testlatex_gif_renderer() {
  81. ob_start();
  82. $latex_code="";
  83. global $_course;
  84. $res=latex_gif_renderer($latex_code);
  85. ob_end_clean();
  86. $this->assertTrue(is_string($res));
  87. //var_dump($res);
  88. }
  89. function testmake_clickable() {
  90. $string='';
  91. $res=make_clickable($string);
  92. $this->assertTrue(is_string($res));
  93. //var_dump($res);
  94. }
  95. function testtext_filter() {
  96. $input='';
  97. $res=text_filter($input, $filter=true);
  98. $this->assertTrue(is_string($res));
  99. //var_dump($res);
  100. }
  101. function testApiParseTex(){
  102. $textext = 'abc';
  103. $res = api_parse_tex($textext); //this function is practically deprecated now, it doesn't do anything
  104. $this->assertEqual($textext,$res);
  105. }
  106. }
  107. ?>