Esempio n. 1
0
bool TestExtDatetime::test_localtime() {
  int d = f_strtotime("2008-09-10 12:34:56");

  Array localtime = f_localtime(d);
  Array localtime_assoc = f_localtime(d, true);
  VS(f_print_r(localtime, true),
     "Array\n"
     "(\n"
     "    [0] => 56\n"
     "    [1] => 34\n"
     "    [2] => 12\n"
     "    [3] => 10\n"
     "    [4] => 8\n"
     "    [5] => 108\n"
     "    [6] => 3\n"
     "    [7] => 253\n"
     "    [8] => 1\n"
     ")\n");

  VS(f_print_r(localtime_assoc, true),
     "Array\n"
     "(\n"
     "    [tm_sec] => 56\n"
     "    [tm_min] => 34\n"
     "    [tm_hour] => 12\n"
     "    [tm_mday] => 10\n"
     "    [tm_mon] => 8\n"
     "    [tm_year] => 108\n"
     "    [tm_wday] => 3\n"
     "    [tm_yday] => 253\n"
     "    [tm_isdst] => 1\n"
     ")\n");

  return Count(true);
}
Esempio n. 2
0
bool TestExtMysql::test_mysql_unbuffered_query() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_unbuffered_query("select * from test");
  Variant row = f_mysql_fetch_assoc(res);
  VS(f_print_r(row, true),
     "Array\n"
     "(\n"
     "    [id] => 1\n"
     "    [name] => test\n"
     ")\n");

  row = f_mysql_fetch_assoc(res);
  VS(f_print_r(row, true),
     "Array\n"
     "(\n"
     "    [id] => 2\n"
     "    [name] => test2\n"
     ")\n");

  row = f_mysql_fetch_assoc(res);
  VS(row, false);
  return Count(true);
}
Esempio n. 3
0
bool TestExtPreg::test_preg_match() {
  // The "i" after the pattern delimiter indicates a case-insensitive search
  VERIFY(f_preg_match("/php/i", "PHP is a scripting language."));

  // The \b in the pattern indicates a word boundary, so only the distinct
  // word "web" is matched, and not a word partial like "webbing" or "cobweb"
  VERIFY(f_preg_match("/\\bweb\\b/i", "is the web scripting"));

  // get host name from URL
  Variant matches;
  f_preg_match("@^(?:http://)?([^/]+)@i",
               "http://www.php.net/index.html", ref(matches));
  String host = matches[1];
  VS(host, "www.php.net");

  // get last two segments of host name
  f_preg_match("/[^.]+\\.[^.]+$/", host, ref(matches));
  VS(matches[0], "php.net");

  String str = "foobar: 2008";
  f_preg_match("/(?<name>\\w+): (?<digit>\\d+)/", str, ref(matches));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => foobar: 2008\n"
     "    [name] => foobar\n"
     "    [1] => foobar\n"
     "    [digit] => 2008\n"
     "    [2] => 2008\n"
     ")\n");

  return Count(true);
}
Esempio n. 4
0
bool TestExtDatetime::test_date_parse() {
  VS(f_print_r(f_date_parse("2006-12-12 10:00:00.5"), true),
     "Array\n"
     "(\n"
     "    [year] => 2006\n"
     "    [month] => 12\n"
     "    [day] => 12\n"
     "    [hour] => 10\n"
     "    [minute] => 0\n"
     "    [second] => 0\n"
     "    [fraction] => 0.5\n"
     "    [warning_count] => 0\n"
     "    [warnings] => Array\n"
     "        (\n"
     "        )\n"
     "\n"
     "    [error_count] => 0\n"
     "    [errors] => Array\n"
     "        (\n"
     "        )\n"
     "\n"
     "    [is_localtime] => \n"
     ")\n");
  return Count(true);
}
Esempio n. 5
0
bool TestExtMysql::test_mysql_fetch_lengths() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  Variant row = f_mysql_fetch_row(res);
  Variant lengths = f_mysql_fetch_lengths(res);
  VS(f_print_r(lengths, true),
     "Array\n"
     "(\n"
     "    [0] => 1\n"
     "    [1] => 4\n"
     ")\n");

  // A much more intense test on lengths
  f_mysql_query("drop table testlen");
  VS(f_mysql_query("create table testlen (id int not null auto_increment, "
                   "d decimal(10,5), t tinyint, i int, b bigint, f float, "
                   "db double, y2 year(2), y4 year(4), primary key (id)) "
                   "engine=innodb"), true);
  VS(f_mysql_query("insert into testlen(d, t, i, b, f, db, y2, y4) values"
                   "(.343, null, 384, -1, 03.44, -03.43892874e101, 00, 0000)"),
     true);
  res = f_mysql_query("select * from testlen");
  row = f_mysql_fetch_row(res);
  lengths = f_mysql_fetch_lengths(res);
  VS(f_print_r(lengths, true),
     "Array\n"
     "(\n"
     "    [0] => 1\n"
     "    [1] => 7\n"
     "    [2] => 0\n"
     "    [3] => 3\n"
     "    [4] => 2\n"
     "    [5] => 4\n"
     "    [6] => 16\n"
     "    [7] => 2\n"
     "    [8] => 4\n"
     ")\n");

  return Count(true);
}
bool TestExtFile::test_pathinfo() {
  VS(f_print_r(f_pathinfo("test/test_ext_file.txt"), true),
     "Array\n"
     "(\n"
     "    [dirname] => test\n"
     "    [basename] => test_ext_file.txt\n"
     "    [extension] => txt\n"
     "    [filename] => test_ext_file\n"
     ")\n");
  return Count(true);
}
Esempio n. 7
0
bool TestExtXml::test_xml_parse_into_struct() {
  //VCB("<?php ");
  String simple = "<para><note attrib1='foo'>simple&amp;note</note></para>";
  Variant p = f_xml_parser_create();
  Variant vals, index;
  f_xml_parse_into_struct(p, simple, ref(vals), ref(index));
  f_xml_parser_free(p);
  VS(f_print_r(index.rvalAt(String("PARA")),1),
    "Array\n(\n    [0] => 0\n    [1] => 2\n)\n");
  VS(f_print_r(index.rvalAt(String("NOTE")),1),
    "Array\n(\n    [0] => 1\n)\n");
  VS(f_print_r(vals.rvalAt(0),1),
    "Array\n(\n    [tag] => PARA\n    [type] => open\n    [level] => 1\n)\n");
  VS(f_print_r(vals.rvalAt(1),1),
    "Array\n(\n    [tag] => NOTE\n    [type] => complete\n    [level] => 2\n"
    "    [attributes] => Array\n        (\n            [ATTRIB1] => foo\n"
    "        )\n\n    [value] => simple&note\n)\n");
  VS(f_print_r(vals.rvalAt(2),1),
    "Array\n(\n    [tag] => PARA\n    [type] => close\n    [level] => 1\n)\n");
  return true;
}
Esempio n. 8
0
bool TestExtPreg::test_preg_split() {
  // split the phrase by any number of commas or space characters,
  // which include " ", \r, \t, \n and \f
  {
    Array keywords = f_preg_split("/[\\s,]+/",
                                  "hypertext language, programming");
    VS(keywords.size(), 3);
    VS(keywords[0], "hypertext");
    VS(keywords[1], "language");
    VS(keywords[2], "programming");
  }
  {
    String str = "string";
    Array chars = f_preg_split("//", str, -1, k_PREG_SPLIT_NO_EMPTY);
    VS(chars.size(), 6);
    VS(chars[0], "s");
    VS(chars[1], "t");
    VS(chars[2], "r");
    VS(chars[3], "i");
    VS(chars[4], "n");
    VS(chars[5], "g");
  }
  {
    String str = "hypertext language programming";
    Array chars = f_preg_split("/ /", str, -1, k_PREG_SPLIT_OFFSET_CAPTURE);
    VS(f_print_r(chars, true),
       "Array\n"
       "(\n"
       "    [0] => Array\n"
       "        (\n"
       "            [0] => hypertext\n"
       "            [1] => 0\n"
       "        )\n"
       "\n"
       "    [1] => Array\n"
       "        (\n"
       "            [0] => language\n"
       "            [1] => 10\n"
       "        )\n"
       "\n"
       "    [2] => Array\n"
       "        (\n"
       "            [0] => programming\n"
       "            [1] => 19\n"
       "        )\n"
       "\n"
       ")\n");
  }
  return Count(true);
}
Esempio n. 9
0
bool TestExtUrl::test_parse_url() {
  String url = "http://*****:*****@hostname/path?arg=value#anchor";
  VS(f_print_r(f_parse_url(url), true),
     "Array\n"
     "(\n"
     "    [scheme] => http\n"
     "    [host] => hostname\n"
     "    [user] => username\n"
     "    [pass] => password\n"
     "    [path] => /path\n"
     "    [query] => arg=value\n"
     "    [fragment] => anchor\n"
     ")\n");
  return Count(true);
}
bool TestExtVariable::test_print_r() {
  Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
  VS(f_print_r(v, true),
     "Array\n"
     "(\n"
     "    [a] => apple\n"
     "    [b] => 2\n"
     "    [c] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => y\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     ")\n");
  return Count(true);
}
Esempio n. 11
0
bool TestExtDatetime::test_date_sun_info() {
  VS(f_print_r(f_date_sun_info(f_strtotime("2006-12-12"), 31.7667, 35.2333),
               true),
     "Array\n"
     "(\n"
     "    [sunrise] => 1165897795\n"
     "    [sunset] => 1165934173\n"
     "    [transit] => 1165915984\n"
     "    [civil_twilight_begin] => 1165896189\n"
     "    [civil_twilight_end] => 1165935779\n"
     "    [nautical_twilight_begin] => 1165894366\n"
     "    [nautical_twilight_end] => 1165937603\n"
     "    [astronomical_twilight_begin] => 1165892582\n"
     "    [astronomical_twilight_end] => 1165939386\n"
     ")\n");
  return Count(true);
}
Esempio n. 12
0
bool TestExtDatetime::test_strptime() {
  String format = "%d/%m/%Y %H:%M:%S";
  String strf = f_strftime(format, f_strtotime("10/03/2004 15:54:19"));
  VS(strf, "03/10/2004 15:54:19");
  VS(f_print_r(f_strptime(strf, format), true),
     "Array\n"
     "(\n"
     "    [tm_sec] => 19\n"
     "    [tm_min] => 54\n"
     "    [tm_hour] => 15\n"
     "    [tm_mday] => 3\n"
     "    [tm_mon] => 9\n"
     "    [tm_year] => 104\n"
     "    [tm_wday] => 0\n"
     "    [tm_yday] => 276\n"
     "    [unparsed] => \n"
     ")\n");

  return Count(true);
}
Esempio n. 13
0
bool TestExtDatetime::test_getdate() {
  int d = f_strtotime("2008-09-10 12:34:56");

  Array today = f_getdate(d);
  VS(f_print_r(today, true),
     "Array\n"
     "(\n"
     "    [seconds] => 56\n"
     "    [minutes] => 34\n"
     "    [hours] => 12\n"
     "    [mday] => 10\n"
     "    [wday] => 3\n"
     "    [mon] => 9\n"
     "    [year] => 2008\n"
     "    [yday] => 253\n"
     "    [weekday] => Wednesday\n"
     "    [month] => September\n"
     "    [0] => 1221075296\n"
     ")\n");

  return Count(true);
}
Esempio n. 14
0
bool TestExtPreg::test_preg_match_all() {
  Variant matches;

  f_preg_match_all("/\\(?  (\\d{3})?  \\)?  (?(1)  [\\-\\s] ) \\d{3}-\\d{4}/x",
                   "Call 555-1212 or 1-800-555-1212", ref(matches));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => 555-1212\n"
     "            [1] => 800-555-1212\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => \n"
     "            [1] => 800\n"
     "        )\n"
     "\n"
     ")\n");

  // The \\2 is an example of backreferencing. This tells pcre that
  // it must match the second set of parentheses in the regular expression
  // itself, which would be the ([\w]+) in this case. The extra backslash is
  // required because the string is in double quotes.
  String html = "<b>bold text</b><a href=howdy.html>click me</a>";
  f_preg_match_all("/(<([\\w]+)[^>]*>)(.*)(<\\/\\2>)/", html, ref(matches),
                   k_PREG_SET_ORDER);
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => <b>bold text</b>\n"
     "            [1] => <b>\n"
     "            [2] => b\n"
     "            [3] => bold text\n"
     "            [4] => </b>\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => <a href=howdy.html>click me</a>\n"
     "            [1] => <a href=howdy.html>\n"
     "            [2] => a\n"
     "            [3] => click me\n"
     "            [4] => </a>\n"
     "        )\n"
     "\n"
     ")\n");

  String str = "a: 1\nb: 2\nc: 3\n";
  f_preg_match_all("/(?<name>\\w+): (?<digit>\\d+)/", str, ref(matches));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => a: 1\n"
     "            [1] => b: 2\n"
     "            [2] => c: 3\n"
     "        )\n"
     "\n"
     "    [name] => Array\n"
     "        (\n"
     "            [0] => a\n"
     "            [1] => b\n"
     "            [2] => c\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => a\n"
     "            [1] => b\n"
     "            [2] => c\n"
     "        )\n"
     "\n"
     "    [digit] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => 2\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     "    [2] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => 2\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     ")\n");

  return Count(true);
}
Esempio n. 15
0
bool TestExtIcu::test_icu_match() {
  // Test subject strings.
  String subject = String(
    "\u05d6\U00010905 PHP is a scripting language. \ufeb0\ufef3",
    CopyString);
  String subject_32 = String(
    "\U00010905\U00010905\U00010905\U00010905\U00010905\U00010905",
    CopyString);
  String subject_en = String("this is an english string", CopyString);
  // "this is a hebrew string"
  String subject_he = String(
    "\u05d6\u05d4 \u05d4\u05d5\u05d0 \u05de\u05d7\u05e8\u05d5\u05d6\u05ea "
    "\u05e2\u05d1\u05e8\u05d9\u05ea",
    CopyString);
  // "this is an arabic string"
  String subject_ar = String(
    "\ufee9\ufeab\ufe8d \ufee9\ufeed \ufe8e\ufee0\ufee8\ufebb "
    "\ufe8d\ufefa\ufee8\ufea0\ufee0\ufef3\ufeb0\ufef3",
    CopyString);
  // "this is a hebrew string"
  String subject_mixed = String(
    "this is a \u05e2\u05d1\u05e8\u05d9\u05ea string",
    CopyString);

  // Test basic regex parsing functionality.
  VERIFY(f_icu_match("scripting", subject));
  VERIFY(!f_icu_match("php", subject));
  VERIFY(f_icu_match("(\\bPHP\\b)", subject));
  VERIFY(!f_icu_match("(\\bPHP\\b))", subject));

  // Test returning matches functionality.
  Variant matches;
  VERIFY(f_icu_match("(PHP) is", subject, ref(matches)));
  VS(f_print_r(matches, true),
    "Array\n"
    "(\n"
    "    [0] => PHP is\n"
    "    [1] => PHP\n"
    ")\n");
  VERIFY(f_icu_match("is (a)", subject, ref(matches),
                     k_UREGEX_OFFSET_CAPTURE));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => is a\n"
     "            [1] => 7\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => a\n"
     "            [1] => 10\n"
     "        )\n"
     "\n"
     ")\n");
  VERIFY(f_icu_match("\\. \ufeb0", subject, ref(matches),
                     k_UREGEX_OFFSET_CAPTURE));
  VS(f_print_r(matches, true),
    "Array\n"
    "(\n"
    "    [0] => Array\n"
    "        (\n"
    "            [0] => . \ufeb0\n"
    "            [1] => 30\n"
    "        )\n"
    "\n"
    ")\n");
  VERIFY(f_icu_match("\ufee9\ufeed (\ufe8e\ufee0\ufee8\ufebb)",
                     subject_ar, ref(matches), k_UREGEX_OFFSET_CAPTURE));
  VS(f_print_r(matches, true),
    "Array\n"
    "(\n"
    "    [0] => Array\n"
    "        (\n"
    "            [0] => \ufee9\ufeed \ufe8e\ufee0\ufee8\ufebb\n"
    "            [1] => 4\n"
    "        )\n"
    "\n"
    "    [1] => Array\n"
    "        (\n"
    "            [0] => \ufe8e\ufee0\ufee8\ufebb\n"
    "            [1] => 7\n"
    "        )\n"
    "\n"
    ")\n");

  // Test match for 32-bit code points.
  VERIFY(f_icu_match(".*", subject_32, ref(matches)));
  VS(f_print_r(matches, true),
    "Array\n"
    "(\n"
    "    [0] => \U00010905\U00010905\U00010905\U00010905\U00010905\U00010905\n"
    ")\n");

  // Test regex caching functionality.
  VERIFY(f_icu_match("(php)", subject, uninit_null(), k_UREGEX_CASE_INSENSITIVE));
  VERIFY(!f_icu_match("(php)", subject));

  // Test ICU specific (ie bidi) functionality.
  String pattern_ltr = String("\\p{Bidi_Class=Left_To_Right}", CopyString);
  String pattern_rtl = String("\\p{Bidi_Class=Right_To_Left}", CopyString);
  String pattern_arl = String("\\p{Bidi_Class=Arabic_Letter}", CopyString);

 VERIFY(f_icu_match(pattern_ltr, subject_en));
  VERIFY(!f_icu_match(pattern_rtl, subject_en));

  VERIFY(!f_icu_match(pattern_ltr, subject_he));
  VERIFY(f_icu_match(pattern_rtl, subject_he));
  VERIFY(!f_icu_match(pattern_arl, subject_he));

  VERIFY(!f_icu_match(pattern_ltr, subject_ar));
  VERIFY(!f_icu_match(pattern_rtl, subject_ar));
  VERIFY(f_icu_match(pattern_arl, subject_ar));

  VERIFY(f_icu_match(pattern_ltr, subject_mixed));
  VERIFY(f_icu_match(pattern_rtl, subject_mixed));

  return Count(true);
}
Esempio n. 16
0
bool TestExtIcu::test_icu_tokenize() {


  String input_eng = String("Hello World");
  Array output_eng = f_icu_tokenize(input_eng);

  VS(f_print_r(output_eng, true),
     "Array\n"
     "(\n"
     "    [0] => _B_\n"
     "    [1] => hello\n"
     "    [2] => world\n"
     "    [3] => _E_\n"
     ")\n"
    );
  String input_long = String("Hello! You are visitor #1234 to "
                            "http://www.facebook.com! "
                            "<3 How are you today (6/14/2011),"
                            " [email protected]?");

  Array output_long = f_icu_tokenize(input_long);

  VS(f_print_r(output_long, true),
     "Array\n"
     "(\n"
     "    [0] => _B_\n"
     "    [1] => hello\n"
     "    [2] => !\n"
     "    [3] => you\n"
     "    [4] => are\n"
     "    [5] => visitor\n"
     "    [6] => #\n"
     "    [7] => XXXX\n"
     "    [8] => to\n"
     "    [9] => TOKEN_URL\n"
     "    [10] => !\n"
     "    [11] => TOKEN_HEART\n"
     "    [12] => how\n"
     "    [13] => are\n"
     "    [14] => you\n"
     "    [15] => today\n"
     "    [16] => (\n"
     "    [17] => TOKEN_DATE\n"
     "    [18] => )\n"
     "    [19] => ,\n"
     "    [20] => TOKEN_EMAIL\n"
     "    [21] => ?\n"
     "    [22] => _E_\n"
     ")\n"
    );

  String input_de = String("Ich möchte überzeugend oder ähnliche sein");
  Array output_de = f_icu_tokenize(input_de);

  VS(f_print_r(output_de, true),
     "Array\n"
     "(\n"
     "    [0] => _B_\n"
     "    [1] => ich\n"
     "    [2] => mã\n"
     "    [3] => ¶\n"
     "    [4] => chte\n"
     "    [5] => ã\n"
     "    [6] => ¼\n"
     "    [7] => berzeugend\n"
     "    [8] => oder\n"
     "    [9] => ã\n"
     "    [10] => ¤\n"
     "    [11] => hnliche\n"
     "    [12] => sein\n"
     "    [13] => _E_\n"
     ")\n");


  return Count(true);
}