public static function test_strings() { //-- $unicode_text = '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド'; //-- $idn_domain_unicode = 'jösefsson.tßst123.org'; $idn_domain_iso = 'xn--jsefsson-n4a.xn--tst123-bta.org'; $idn_email_unicode = 'räksmörgås@jösefsson.tßst123.org'; $idn_email_iso = '*****@*****.**'; //-- //-- $err = ''; //-- //-- $tests[] = '##### Unicode STRING / TESTS: #####'; //-- //-- $regex_positive = '/^[\\w"\\:\\?]+$/'; $regex_negative = '/[^\\w"\\:\\?]/'; //-- //-- if (defined('SMART_FRAMEWORK_SECURITY_FILTER_INPUT')) { if ((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT != '') { if ((string) $err == '') { $the_test = 'Smart.Framework Security Input Filter Regex - test over a full Unicode String'; $tests[] = $the_test; if (preg_match((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT, 'Platform クラウドアプリケーションプラットフォーム \'áâãäåāăąÁÂÃÄÅĀĂĄćĉčçĆĈČÇďĎèéêëēĕėěęÈÉÊËĒĔĖĚĘĝģĜĢĥħĤĦìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮijĵIJĴķĶĺļľłĹĻĽŁñńņňÑŃŅŇòóôõöōŏőøœÒÓÔÕÖŌŎŐØŒŕŗřŔŖŘșşšśŝßȘŞŠŚŜțţťȚŢŤùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲŵŴẏỳŷÿýẎỲŶŸÝźżžŹŻŽ " <p></p> ? & * ^ $ @ ! ` ~ % () [] {} | \\ / + - _ : ; , . #\'0.51085600 1454529112#' . "\r\n\t" . '`~@#$%^&*()-_=+[{]}|;:"<>,.?/\\')) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Regex Test Positive'; $tests[] = $the_test; if (!preg_match((string) $regex_positive . 'u', (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (1) ...'; } elseif (preg_match((string) $regex_positive, (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (2) ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Regex Test Negative'; $tests[] = $the_test; if (preg_match((string) $regex_negative . 'u', (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (1) ...'; } elseif (!preg_match((string) $regex_negative, (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (2) ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Deaccented ISO Regex Test Positive'; $tests[] = $the_test; if (!preg_match((string) $regex_positive, (string) SmartUnicode::deaccent_str($unicode_text))) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Deaccented ISO Regex Test Negative'; $tests[] = $the_test; if (preg_match((string) $regex_negative, (string) SmartUnicode::deaccent_str($unicode_text))) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Strlen Test'; $tests[] = $the_test; if (SmartUnicode::str_len($unicode_text) !== 30) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { // this tests also SmartUnicode::str_ipos $the_test = 'Unicode Find Substring (Case Insensitive), Positive'; $tests[] = $the_test; if (SmartUnicode::str_icontains($unicode_text, 'șș') !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { // this tests also SmartUnicode::str_ipos $the_test = 'Unicode Find Substring (Case Insensitive), Negative'; $tests[] = $the_test; if (SmartUnicode::str_icontains($unicode_text, 'șş') !== false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { // this tests also SmartUnicode::str_pos $the_test = 'Unicode Find Substring (Case Sensitive), Positive'; $tests[] = $the_test; if (SmartUnicode::str_contains($unicode_text, 'țȚ') !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { // this tests also SmartUnicode::str_pos $the_test = 'Unicode Find Substring (Case Sensitive), Negative'; $tests[] = $the_test; if (SmartUnicode::str_contains($unicode_text, 'țŢ') !== false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Find Substring (Case Insensitive), Reverse'; $tests[] = $the_test; if (SmartUnicode::str_ripos($unicode_text, 'ţţグ') === false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Find Substring (Case Sensitive), Reverse'; $tests[] = $the_test; if (SmartUnicode::str_rpos($unicode_text, 'ţŢグ') === false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Return Substring (Case Insensitive)'; $tests[] = $the_test; if (SmartUnicode::stri_str($unicode_text, 'âȘșȚ') !== 'ÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Return Substring (Case Sensitive)'; $tests[] = $the_test; if (SmartUnicode::str_str($unicode_text, 'ÂșȘț') !== 'ÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode String to LowerCase'; $tests[] = $the_test; if (SmartUnicode::str_tolower($unicode_text) !== '"unicode78źź:ăăîîââșșțțşşţţグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode String to UpperCase'; $tests[] = $the_test; if (SmartUnicode::str_toupper($unicode_text) !== '"UNICODE78ŹŹ:ĂĂÎÎÂÂȘȘȚȚŞŞŢŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode SubString function (without last param)'; $tests[] = $the_test; if (SmartUnicode::sub_str($unicode_text, 25) !== 'ţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode SubString function (with last param)'; $tests[] = $the_test; if (SmartUnicode::sub_str($unicode_text, 25, 3) !== 'ţŢグ') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode SubString Count function'; $tests[] = $the_test; if (SmartUnicode::substr_count($unicode_text, 'ţ') !== 1) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode String Replace with Limit (Case Sensitive)'; $tests[] = $the_test; if (SmartUnicode::str_limit_replace('ź', '@', $unicode_text, 1) !== '"Unicode78@ź:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'String Replace without Limit (Case Sensitive)'; $tests[] = $the_test; if (str_replace('ź', '@', $unicode_text) !== '"Unicode78@@:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { /* This test fails if the replacements accented characters are different case than one find in string (upper/lower) ... */ $the_test = 'String Replace without Limit (Case Insensitive) *** Only with unaccented replacements !!'; $tests[] = $the_test; if (str_ireplace('E7', '@', $unicode_text) !== '"Unicod@8źź:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Deaccent String'; $tests[] = $the_test; if (SmartUnicode::deaccent_str($unicode_text) !== '"Unicode78zz:aAiIaAsStTsStT???') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'YAML Unicode Test: Compose from Array / Parse from YAML'; $tests[] = $the_test; $test_arr = array('@test' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, $unicode_text => 'Unicode as Key', 'line3' => ['A' => 'b', 100, 'Thousand'], 'line4' => [1, 0.2, 3.0001], 'line5' => date('Y-m-d H:i:s')); $test_yaml = (string) '# start YAML (to test also comments)' . "\n" . (new SmartYamlConverter())->compose($test_arr) . "\n" . '# end YAML'; $test_parr = (new SmartYamlConverter())->parse($test_yaml); if ($test_arr !== $test_parr) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#YAML Array (from YAML String): ' . print_r($test_parr, 1) . "\n\n" . '#YAML String (from ORIGINAL Array): ' . "\n" . $test_yaml; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'XML Unicode Test: Compose from Array / Parse from XML'; $tests[] = $the_test; $test_arr = array('TEST' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, 'line3' => ['A' => 'b', 'c' => 'D'], 'line4' => '', 'line5' => date('Y-m-d H:i:s')); $test_xml = (string) (new SmartXmlComposer())->transform($test_arr); $test_parr = (new SmartXmlParser())->transform($test_xml); if ($test_arr !== $test_parr) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#XML Array (from XML String): ' . print_r($test_parr, 1) . "\n\n" . '#XML String (from ORIGINAL Array): ' . "\n" . $test_xml; } //end if } //end if //-- $the_random_unicode_text = sha1($unicode_text . Smart::random_number(1000, 9999)) . '-' . $unicode_text . " \r\n\t" . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str() . '-' . Smart::uuid_10_seq(); //-- if ((string) $err == '') { $the_test = 'Data: Archive / Unarchive'; $tests[] = $the_test; if (SmartUtils::data_unarchive(SmartUtils::data_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Cache: Archive / Unarchive'; $tests[] = $the_test; if (SmartUtils::cache_variable_unarchive(SmartUtils::cache_variable_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']'; } //end if } //end if //-- //-- if ((string) $err == '') { $the_test = 'IDN: Domain Punycode Encode UTF-8 to ISO'; $tests[] = $the_test; if ((string) (new SmartPunycode())->encode($idn_domain_unicode) != (string) $idn_domain_iso) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_unicode . ' -> ' . $idn_domain_iso . ']'; } //end if } //end if if ((string) $err == '') { $the_test = 'IDN: Domain Punycode Decode ISO to UTF-8'; $tests[] = $the_test; if ((string) (new SmartPunycode())->decode($idn_domain_iso) != (string) $idn_domain_unicode) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_iso . ' -> ' . $idn_domain_unicode . ']'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'IDN: Email Punycode Encode UTF-8 to ISO'; $tests[] = $the_test; if ((string) (new SmartPunycode())->encode($idn_email_unicode) != (string) $idn_email_iso) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_unicode . ' -> ' . $idn_email_iso . ']'; } //end if } //end if if ((string) $err == '') { $the_test = 'IDN: Email Punycode Decode ISO to UTF-8'; $tests[] = $the_test; if ((string) (new SmartPunycode())->decode($idn_email_iso) != (string) $idn_email_unicode) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_iso . ' -> ' . $idn_email_unicode . ']'; } //end if } //end if //-- //-- regex positive tests $arr_regex = ['number-integer' => [0, '75', '-101'], 'number-decimal' => [0, '0.0', '0.1', '75', '75.0', '75.1', '-555', '-555.0', '-555.1'], 'number-list-integer' => '1;2;30', 'number-list-decimal' => '1.0;2;30.44', 'url' => ['https://192.168.1.0', 'http://localhost', 'https://www.dom.ext', 'http://dom.ext/path?a=b&c=d%20#s'], 'domain' => ['domain.com', 'sdom.domain.org'], 'email' => ['root@localhost', '*****@*****.**', '*****@*****.**'], 'fax' => ['~+99-(0)999-123.456.78~'], 'macaddr' => ['00:0A:95:9d:68:16', '00-0a-95-9D-68-16'], 'ipv4' => ['192.168.0.1', '169.254.1.0', '1.0.0.1'], 'ipv6' => ['::1', '0000:0000:0000:0000:0000:0000:0000:0001', '2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:dB8::2:1', '2001:db8::1', '3731:54:65fe:2::a7']]; //-- foreach ((array) $arr_regex as $key => $val) { //-- if (is_array($val)) { for ($i = 0; $i < Smart::array_size($val); $i++) { $the_test = 'Regex Validate Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val[$i], $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) { $the_test = 'Regex Validate Numeric Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_numeric_integer_or_decimal_values($val[$i], $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if } //end if } //end for } else { $the_test = 'Regex Validate Positive: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val, $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) { $the_test = 'Regex Validate Numeric Positive: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_numeric_integer_or_decimal_values($val, $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if } //end if else //-- if ((string) $err != '') { break; } //end if //-- } //end foreach //-- //-- regex negative tests $arr_regex = ['number-integer' => ['', '.', 'a9', '7B', '-9 ', ' -7'], 'number-decimal' => ['', '.0', '.1', '-.10', ' -7', '-9.0 '], 'number-list-integer' => '1;2.3;30', 'number-list-decimal' => '1.0;2;30.44a', 'url' => ['http:://192.168.1.0', 'https://local host', 'http:/www.dom.ext', 'https:dom.ext/path?a=b&c=d%20#s'], 'domain' => ['doMain.com', 's dom.domain.org', '.dom.ext', 'dom..ext', 'localhost', 'loc', 'dom.ext.'], 'email' => ['rooT@localhost', 'root@local host.loc', 'sometest-name.extra@do_m.ext'], 'fax' => ['~ +99-(0)999-123.456.78 ~'], 'macaddr' => ['00:0A:95:9z:68:16', '00-0Z-95-9D-68-16'], 'ipv4' => ['192.168.0.', '169..1.0', '1.0.1'], 'ipv6' => ['::x', '00z0:0000:0000:0000:0000:0000:0000:0001', '2001:0dx8:0000:0000:0000:ff00:0042:8329', '2001:WB8::2:1', '2001:@db8::1', '3731:54:65Qe:2::a7']]; //-- foreach ((array) $arr_regex as $key => $val) { //-- if (is_array($val)) { for ($i = 0; $i < Smart::array_size($val); $i++) { $the_test = 'Regex Validate Negative (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val[$i], $key) === true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if } //end for } else { $the_test = 'Regex Validate Negative: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val, $key) === true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if else //-- if ((string) $err != '') { break; } //end if //-- } //end foreach //-- //-- $endtest = '##### END TESTS ... #####'; //-- //-- if ((string) $err == '') { $img_sign = 'lib/core/img/sign_info.png'; $img_check = 'lib/core/img/q_completed.png'; $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect :: グッド ... パーフェクト</span>'); $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Unicode String <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $endtest)) . '</span>'); } else { $img_sign = 'lib/core/img/sign_error.png'; $img_check = 'lib/core/img/q_warning.png'; $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... :: エラーが発生しました ...</span>'); $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Unicode String Tests.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>'); } //end if else //-- //-- $html = <<<HTML <h1>SmartFramework Unicode Strings Tests: DONE ...</h1> <script type="text/javascript"> \tSmartJS_BrowserUtils.alert_Dialog( \t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>', \t\t'', \t\t'Unicode String Test Suite for SmartFramework: PHP', \t\t'725', \t\t'425' \t); </script> HTML; //-- //-- return $html; //-- }