Port TestExtUrl to php

Esse commit está contido em:
Jordan DeLong
2013-06-15 01:09:02 -07:00
commit de Sara Golemon
commit 79ce492c0d
6 arquivos alterados com 157 adições e 224 exclusões
-1
Ver Arquivo
@@ -64,7 +64,6 @@
#include "hphp/test/ext/test_ext_sqlite3.h"
#include "hphp/test/ext/test_ext_stream.h"
#include "hphp/test/ext/test_ext_string.h"
#include "hphp/test/ext/test_ext_url.h"
#include "hphp/test/ext/test_ext_variable.h"
#include "hphp/test/ext/test_ext_zlib.h"
-179
Ver Arquivo
@@ -1,179 +0,0 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/test/ext/test_ext_url.h"
#include "hphp/runtime/ext/ext_url.h"
#include "hphp/system/systemlib.h"
///////////////////////////////////////////////////////////////////////////////
bool TestExtUrl::RunTests(const std::string &which) {
bool ret = true;
DECLARE_TEST_FUNCTIONS("");
RUN_TEST(test_base64_decode);
RUN_TEST(test_base64_encode);
RUN_TEST(test_get_headers);
RUN_TEST(test_get_meta_tags);
RUN_TEST(test_http_build_query);
RUN_TEST(test_parse_url);
RUN_TEST(test_rawurldecode);
RUN_TEST(test_rawurlencode);
RUN_TEST(test_urldecode);
RUN_TEST(test_urlencode);
return ret;
}
///////////////////////////////////////////////////////////////////////////////
bool TestExtUrl::test_base64_decode() {
VS(f_base64_decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw=="),
"This is an encoded string");
VERIFY(same(f_base64_decode("BgAYdjk="),
String("\006\0\030v9", 5, AttachLiteral)));
VERIFY(!same(f_base64_decode("dGVzdA=="),
f_base64_decode("dGVzdA==CORRUPT")));
return Count(true);
}
bool TestExtUrl::test_base64_encode() {
VS(f_base64_encode("This is an encoded string"),
"VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==");
VS(f_base64_encode(String("\006\0\030v9", 5, AttachLiteral)), "BgAYdjk=");
return Count(true);
}
bool TestExtUrl::test_get_headers() {
static const StaticString s_Connection("Connection");
String url = "http://www.example.com";
Array ret = f_get_headers(url);
//VS(ret[0], "HTTP/1.1 200 OK");
VERIFY(ret.size() > 0);
ret = f_get_headers(url, 1);
//VS(ret[s_Connection], "close");
VERIFY(!ret[s_Connection].toString().empty());
return Count(true);
}
bool TestExtUrl::test_get_meta_tags() {
static const StaticString
s_author("author"),
s_keywords("keywords"),
s_description("description"),
s_geo_position("geo_position");
Array ret = f_get_meta_tags("test/ext/test_get_meta_tags.html");
VS(ret.size(), 4);
VS(ret[s_author], "name");
VS(ret[s_keywords], "php documentation");
VS(ret[s_description], "a php manual");
VS(ret[s_geo_position], "49.33;-86.59");
return Count(true);
}
bool TestExtUrl::test_http_build_query() {
{
Array data = CREATE_MAP4("foo", "bar", "baz", "boom", "cow", "milk",
"php", "hypertext processor");
VS(f_http_build_query(data),
"foo=bar&baz=boom&cow=milk&php=hypertext+processor");
VS(f_http_build_query(data, "", "&"),
"foo=bar&baz=boom&cow=milk&php=hypertext+processor");
}
{
Array data = Array(ArrayInit(6).
set(String("foo")).
set(String("bar")).
set(String("baz")).
set(String("boom")).
set(String("cow"), "milk").
set(String("php"), "hypertext processor").
create());
VS(f_http_build_query(data),
"0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor");
VS(f_http_build_query(data, "myvar_"),
"myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&"
"php=hypertext+processor");
}
{
Array data = Array(ArrayInit(4).
set(String("user"),
CREATE_MAP4("name", "Bob Smith",
"age", 47,
"sex", "M",
"dob", "5/12/1956")).
set(String("pastimes"),
CREATE_VECTOR4("golf", "opera", "poker", "rap")).
set(String("children"),
CREATE_MAP2("bobby", CREATE_MAP2("age",12,"sex","M"),
"sally", CREATE_MAP2("age", 8,"sex","F"))).
set("CEO").
create());
VS(f_http_build_query(data, "flags_"),
"user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M&"
"user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&"
"pastimes%5B1%5D=opera&pastimes%5B2%5D=poker&"
"pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12&"
"children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8&"
"children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO");
}
{
Object obj(SystemLib::AllocStdClassObject());
obj->o_set("foo", "bar");
obj->o_set("baz", "boom");
VS(f_http_build_query(obj), "foo=bar&baz=boom");
}
return Count(true);
}
bool TestExtUrl::test_parse_url() {
String url = "http://username:password@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 TestExtUrl::test_rawurldecode() {
VS(f_rawurldecode("foo%20bar%40baz"), "foo bar@baz");
VS(f_rawurldecode("foo+bar%40baz"), "foo+bar@baz");
return Count(true);
}
bool TestExtUrl::test_rawurlencode() {
VS(f_rawurlencode("foo bar@baz"), "foo%20bar%40baz");
return Count(true);
}
bool TestExtUrl::test_urldecode() {
VS(f_urldecode("foo+bar%40baz"), "foo bar@baz");
return Count(true);
}
bool TestExtUrl::test_urlencode() {
VS(f_urlencode("foo bar@baz"), "foo+bar%40baz");
return Count(true);
}
-44
Ver Arquivo
@@ -1,44 +0,0 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_TEST_EXT_URL_H_
#define incl_HPHP_TEST_EXT_URL_H_
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
#include "hphp/test/ext/test_cpp_ext.h"
///////////////////////////////////////////////////////////////////////////////
class TestExtUrl : public TestCppExt {
public:
virtual bool RunTests(const std::string &which);
bool test_base64_decode();
bool test_base64_encode();
bool test_get_headers();
bool test_get_meta_tags();
bool test_http_build_query();
bool test_parse_url();
bool test_rawurldecode();
bool test_rawurlencode();
bool test_urldecode();
bool test_urlencode();
};
///////////////////////////////////////////////////////////////////////////////
#endif // incl_HPHP_TEST_EXT_URL_H_
+133
Ver Arquivo
@@ -0,0 +1,133 @@
<?php
function VS($x, $y) {
var_dump($x === $y);
if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
var_dump(debug_backtrace()); }
}
function VERIFY($x) { VS($x, true); }
//////////////////////////////////////////////////////////////////////
function test_base64_decode() {
VS(base64_decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw=="),
"This is an encoded string");
VS(base64_decode("BgAYdjk="), "\006\0\030v9");
VERIFY(base64_decode("dGVzdA==") !==
base64_decode("dGVzdA==CORRUPT"));
}
function test_base64_encode() {
VS(base64_encode("This is an encoded string"),
"VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==");
VS(base64_encode("\006\0\030v9"), "BgAYdjk=");
}
function test_get_headers() {
$url = "http://www.example.com";
$ret = get_headers($url);
//VS(ret[0], "HTTP/1.1 200 OK");
VERIFY(count($ret) > 0);
$ret = get_headers($url, 1);
//VS(ret[s_Connection], "close");
}
function test_get_meta_tags() {
$ret = get_meta_tags(__DIR__."/get_meta_tags.html");
VS(count($ret), 4);
VS($ret['author'], "name");
VS($ret['keywords'], "php documentation");
VS($ret['description'], "a php manual");
VS($ret['geo_position'], "49.33;-86.59");
}
function test_http_build_query() {
$data = array("foo" => "bar", "baz" => "boom", "cow" => "milk",
"php" => "hypertext processor");
VS(http_build_query($data),
"foo=bar&baz=boom&cow=milk&php=hypertext+processor");
VS(http_build_query($data, "", "&amp;"),
"foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor");
$data = array(
'foo',
'bar',
'baz',
'boom',
'cow' => 'milk',
'php' => 'hypertext processor'
);
VS(http_build_query($data),
"0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor");
VS(http_build_query($data, "myvar_"),
"myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&".
"php=hypertext+processor");
$data = array(
'user' => array('name' => 'Bob Smith',
'age' => 47,
'sex' => 'M',
'dob' => '5/12/1956'),
'pastimes' => array('golf', 'opera', 'poker', 'rap'),
'children' => array('bobby' => array('age' => 12,
'sex' => 'M'),
'sally' => array('age' => 8,
'sex' => 'F')),
'CEO'
);
VS(http_build_query($data, "flags_"),
"user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M&".
"user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&".
"pastimes%5B1%5D=opera&pastimes%5B2%5D=poker&".
"pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12&".
"children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8&".
"children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO");
$obj = new stdclass;
$obj->foo = 'bar';
$obj->baz = 'boom';
VS(http_build_query($obj), "foo=bar&baz=boom");
}
function test_parse_url() {
$url = "http://username:password@hostname/path?arg=value#anchor";
VS(print_r(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");
}
function test_rawurldecode() {
VS(rawurldecode("foo%20bar%40baz"), "foo bar@baz");
VS(rawurldecode("foo+bar%40baz"), "foo+bar@baz");
}
function test_rawurlencode() {
VS(rawurlencode("foo bar@baz"), "foo%20bar%40baz");
}
function test_urldecode() {
VS(urldecode("foo+bar%40baz"), "foo bar@baz");
}
function test_urlencode() {
VS(urlencode("foo bar@baz"), "foo+bar%40baz");
}
test_base64_decode();
test_base64_encode();
test_get_headers();
test_get_meta_tags();
test_http_build_query();
test_parse_url();
test_rawurldecode();
test_rawurlencode();
test_urldecode();
test_urlencode();
+24
Ver Arquivo
@@ -0,0 +1,24 @@
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)