晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/rainic/www/oldTZh/wp-content/plugins/digits/Twilio/Tests/Unit/Http/ |
Upload File : |
<?php
namespace Twilio\Tests\Unit\Http;
use Twilio\Exceptions\EnvironmentException;
use Twilio\Http\CurlClient;
use Twilio\Tests\Unit\UnitTest;
class CurlClientTest extends UnitTest {
public function testPreemptiveAuthorization() {
$client = new CurlClient();
$options = $client->options(
'GET',
'http://api.twilio.com',
array(),
array(),
array(),
'test-user',
'test-password'
);
$this->assertArrayHasKey(CURLOPT_HTTPHEADER, $options);
$headers = $options[CURLOPT_HTTPHEADER];
$authorization = null;
foreach ($headers as $header) {
$parse = explode(':', $header);
$headerKey = $parse[0];
if ($headerKey == 'Authorization') {
$authorization = $header;
break;
}
}
$this->assertNotNull($authorization);
$authorizationPayload = explode(' ', $authorization);
$encodedAuthorization = array_pop($authorizationPayload);
$decodedAuthorization = base64_decode($encodedAuthorization);
$this->assertEquals('test-user:test-password', $decodedAuthorization);
}
/**
* @param string $message Failure Message
* @param mixed[] $params Params with which to build the query
* @param string $expected Expected query string
* @dataProvider buildQueryProvider
*/
public function testBuildQuery($message, $params, $expected) {
$client = new CurlClient();
$actual = $client->buildQuery($params);
$this->assertEquals($expected, $actual, $message);
}
public function buildQueryProvider() {
return array(
array(
'Null Params',
null,
''
),
array(
'Empty Params',
array(),
'',
),
array(
'Single Scalar',
array('a' => 'z'),
'a=z',
),
array(
'Multiple Scalars',
array(
'a' => 'z',
'b' => 'y',
),
'a=z&b=y',
),
array(
'Type Coercion: Booleans',
array(
'a' => true,
'b' => false,
),
'a=1&b=',
),
array(
'Type Coercion: Integers',
array(
'a' => 7,
'b' => -14,
'c' => 0,
),
'a=7&b=-14&c=0',
),
array(
'Nested Arrays',
array(
'a' => array(1, 2, 3),
'b' => array('x', 'y', 'z'),
),
'a=1&a=2&a=3&b=x&b=y&b=z',
),
array(
'URL Safety',
array(
'a' => 'un$afe:// value!',
),
'a=un%24afe%3A%2F%2F+value%21',
),
array(
'Encoded Key',
array(
'StartTime>' => '2012-06-14',
),
'StartTime%3E=2012-06-14',
)
);
}
/**
* @param $method
* @param $params
* @param $expected
* @dataProvider queryStringProvider
* @throws EnvironmentException
*/
public function testQueryString($method, $params, $expected) {
$client = new CurlClient();
$actual = $client->options($method, 'url', $params);
$this->assertEquals($expected, $actual[CURLOPT_URL]);
}
public function queryStringProvider() {
$methods = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'CUSTOM');
$cases = array();
foreach ($methods as $method) {
$cases[] = array(
$method,
array(),
'url',
);
$cases[] = array(
$method,
array(
'a' => '$z',
'b' => 7,
'c' => array(1, 'x', 2),
),
'url?a=%24z&b=7&c=1&c=x&c=2',
);
}
return $cases;
}
/**
* @param mixed[] $params Parameters to post
* @param mixed[] $data Data to post
* @param string $expected Expected POSTFIELDS
* @dataProvider postFieldsProvider
* @throws EnvironmentException
*/
public function testPostFields($params, $data, $expected) {
$client = new CurlClient();
$actual = $client->options('POST', 'url', $params, $data);
$this->assertEquals($expected, $actual[CURLOPT_POSTFIELDS]);
}
public function postFieldsProvider() {
return array(
array(
array(),
array(),
'',
),
array(
array(
'a' => 'x',
),
array(
'a' => 'b',
),
'a=b'
),
array(
array(
'a' => 'x',
),
array(
'a' => 'x',
),
'a=x'
),
array(
array(
'a' => 'x',
),
array(
'a' => 'z',
'b' => 7,
'c' => array(1, 2, 3),
),
'a=z&b=7&c=1&c=2&c=3',
),
array(
'',
'a=x&b=z',
'a=x&b=z',
),
);
}
public function testPutFile() {
$client = new CurlClient();
$actual = $client->options('PUT', 'url', array(), array('a' => 1, 'b' => 2));
$this->assertNotNull($actual[CURLOPT_INFILE]);
$this->assertEquals('a=1&b=2', fread($actual[CURLOPT_INFILE], $actual[CURLOPT_INFILESIZE]));
$this->assertEquals(7, $actual[CURLOPT_INFILESIZE]);
}
/**
* @param string $message Case message, displayed on assertion error
* @param mixed[] $options Options to inject
* @param mixed[] $expected Partial array to expect
* @dataProvider userInjectedOptionsProvider
*/
public function testUserInjectedOptions($message, $options, $expected) {
$client = new CurlClient($options);
$actual = $client->options(
'GET',
'url',
array('param-key' => 'param-value'),
array('data-key' => 'data-value'),
array('header-key' => 'header-value'),
'user',
'password',
20
);
foreach ($expected as $key => $value) {
$this->assertEquals($value, $actual[$key], $message);
}
}
public function userInjectedOptionsProvider() {
return array(
array(
'No Conflict Options',
array(
CURLOPT_VERBOSE => true,
),
array(
CURLOPT_VERBOSE => true,
),
),
array(
'Options preferred over Defaults',
array(
CURLOPT_TIMEOUT => 1000,
),
array(
CURLOPT_TIMEOUT => 1000,
),
),
array(
'Required Options can not be injected',
array(
CURLOPT_HTTPGET => false,
),
array(
CURLOPT_HTTPGET => true,
),
),
array(
'Injected URL decorated with Query String',
array(
CURLOPT_URL => 'user-provided-url',
),
array(
CURLOPT_URL => 'user-provided-url?param-key=param-value',
),
),
array(
'Injected Headers are additive',
array(
CURLOPT_HTTPHEADER => array(
'injected-key: injected-value',
),
),
array(
CURLOPT_HTTPHEADER => array(
'injected-key: injected-value',
'header-key: header-value',
'Authorization: Basic ' . base64_encode('user:password'),
),
),
),
);
}
}