1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
- class TestText extends UnitTestCase
- {
- public function test_api_html_to_text() {
- $filename = api_get_path(SYS_PATH).'documentation/installation_guide.html';
- $res = @file_get_contents($filename);
- if ($res !== false) {
- $res = api_html_to_text($res);
- $this->assertTrue(is_string($res));
- } else {
- $this->assertTrue(true); // The file is missing, skip this test.
- }
- //var_dump('<pre>'.$res.'</pre>');
- }
- public function test_api_camel_case_to_underscore() {
- $input_strings = array('myDocuments', 'MyProfile', 'CreateNewCourse', 'Create_New_course');
- $expected_results = array('my_documents', 'my_profile', 'create_new_course', 'create_new_course');
- $results = array_map('api_camel_case_to_underscore', $input_strings);
- $this->assertTrue($results == $expected_results);
- //var_dump($results);
- }
- function test_api_underscore_to_camel_case() {
- $input_strings = array('my_documents', 'My_profile', 'create_new_course');
- $expected_results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
- $expected_results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
- $func = create_function('$param', 'return api_underscore_to_camel_case($param, false);');
- $results1 = array('MyDocuments', 'MyProfile', 'CreateNewCourse');
- $results2 = array('myDocuments', 'MyProfile', 'createNewCourse');
- $results1 = array_map('api_underscore_to_camel_case', $input_strings);
- $results2 = array_map($func, $input_strings);
- $this->assertTrue($results1 == $expected_results1 && $results2 == $expected_results2);
- //var_dump($results1);
- //var_dump($results2);
- }
- function testcut() {
- $text='';
- $maxchar='';
- $res=cut($text,$maxchar,$embed=false);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- function testdate_to_str_ago() {
- $date='';
- $res=date_to_str_ago($date);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- function testfloat_format() {
- $number='';
- $res=float_format($number, $flag = 1);
- if(!is_numeric($res) or !is_float($res)) {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- function testmake_clickable() {
- $string='';
- $res=make_clickable($string);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- }
|