123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?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);
- }
-
- }
- public function test_api_str_getcsv() {
- $strings = array('FirstName;LastName;Email', 'John;Doe;john.doe@mail.com', '"Иван";\\Чолаков;ivan@mail.com');
- $expected_results = array(array('FirstName', 'LastName', 'Email'), array('John', 'Doe', 'john.doe@mail.com'), array('Иван', 'Чолаков', 'ivan@mail.com'));
- $res = array();
- foreach ($strings as $string) {
- $res[] = api_str_getcsv($string, ';');
- }
- $this->assertTrue($res === $expected_results);
-
- }
- public function test_api_fgetcsv() {
- $filename = api_get_path(SYS_CODE_PATH).'admin/exemple.csv';
- $res = array();
- $handle = @fopen($filename, 'r');
- if ($handle !== false) {
- while (($line = @api_fgetcsv($handle, null, ';')) !== false) {
- $res[] = $line;
- }
- @fclose($handle);
- $this->assertTrue(is_array($res) && count($res) > 0);
- } else {
- $this->assertTrue(true);
- }
-
- }
- 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);
-
- }
- 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);
-
-
- }
- function test_text_parse_glossary() {
- $input='';
- $res=_text_parse_glossary($input);
- $this->assertTrue(is_string($res));
-
- }
- function test_text_parse_tex() {
- $textext='';
- $res=_text_parse_tex($textext);
- $this->assertTrue(is_string($res));
-
- }
- function test_text_parse_texexplorer() {
- $textext='';
- $res=_text_parse_texexplorer($textext);
- $this->assertTrue(is_string($res));
-
- }
- function test_text_parse_tool() {
- $input='';
- $res=_text_parse_tool($input);
- $this->assertTrue(is_null($res));
-
- }
- function testcut() {
- $text='';
- $maxchar='';
- $res=cut($text,$maxchar,$embed=false);
- $this->assertTrue(is_string($res));
-
- }
- function testdate_to_str_ago() {
- $date='';
- $res=date_to_str_ago($date);
- $this->assertTrue(is_string($res));
-
- }
- function testfloat_format() {
- $number='';
- $res=float_format($number, $flag = 1);
- if(!is_numeric($res) or !is_float($res)) {
- $this->assertTrue(is_null($res));
- }
-
- }
- function testlatex_gif_renderer() {
- ob_start();
- $latex_code="";
- global $_course;
- $res=latex_gif_renderer($latex_code);
- ob_end_clean();
- $this->assertTrue(is_string($res));
-
- }
- function testmake_clickable() {
- $string='';
- $res=make_clickable($string);
- $this->assertTrue(is_string($res));
-
- }
- function testtext_filter() {
- $input='';
- $res=text_filter($input, $filter=true);
- $this->assertTrue(is_string($res));
-
- }
- function testApiParseTex(){
- $textext = 'abc';
- $res = api_parse_tex($textext);
- $this->assertEqual($textext,$res);
- }
- }
- ?>
|