text.lib.test.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  3. class TestText extends UnitTestCase
  4. {
  5. public function test_api_html_to_text() {
  6. $filename = api_get_path(SYS_PATH).'documentation/installation_guide.html';
  7. $res = @file_get_contents($filename);
  8. if ($res !== false) {
  9. $res = api_html_to_text($res);
  10. $this->assertTrue(is_string($res));
  11. } else {
  12. $this->assertTrue(true); // The file is missing, skip this test.
  13. }
  14. //var_dump('<pre>'.$res.'</pre>');
  15. }
  16. public function test_api_camel_case_to_underscore() {
  17. $input_strings = array('myDocuments', 'MyProfile', 'CreateNewCourse', 'Create_New_course');
  18. $expected_results = array('my_documents', 'my_profile', 'create_new_course', 'create_new_course');
  19. $results = array_map('api_camel_case_to_underscore', $input_strings);
  20. $this->assertTrue($results == $expected_results);
  21. //var_dump($results);
  22. }
  23. function test_api_underscore_to_camel_case() {
  24. $input_strings = array('my_documents', 'My_profile', 'create_new_course');
  25. $expected_results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  26. $expected_results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  27. $func = create_function('$param', 'return api_underscore_to_camel_case($param, false);');
  28. $results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
  29. $results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
  30. $results1 = array_map('api_underscore_to_camel_case', $input_strings);
  31. $results2 = array_map($func, $input_strings);
  32. $this->assertTrue($results1 == $expected_results1 && $results2 == $expected_results2);
  33. //var_dump($results1);
  34. //var_dump($results2);
  35. }
  36. function testcut() {
  37. $text='';
  38. $maxchar='';
  39. $res=cut($text,$maxchar,$embed=false);
  40. $this->assertTrue(is_string($res));
  41. //var_dump($res);
  42. }
  43. function testdate_to_str_ago() {
  44. $date='';
  45. $res=date_to_str_ago($date);
  46. $this->assertTrue(is_string($res));
  47. //var_dump($res);
  48. }
  49. function testfloat_format() {
  50. $number='';
  51. $res=float_format($number, $flag = 1);
  52. if(!is_numeric($res) or !is_float($res)) {
  53. $this->assertTrue(is_null($res));
  54. }
  55. //var_dump($res);
  56. }
  57. function testmake_clickable() {
  58. $string='';
  59. $res=make_clickable($string);
  60. $this->assertTrue(is_string($res));
  61. //var_dump($res);
  62. }
  63. }