parent
022a41a2da
commit
ce734f671e
@ -0,0 +1,6 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
.log
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
composer.lock
|
||||
|
||||
.vscode/
|
||||
.idea
|
||||
.DS_Store
|
||||
|
||||
cache/
|
||||
*.cache
|
||||
runtime/
|
||||
.php_cs.cache
|
@ -0,0 +1,375 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\OpenApiUtil\Tests;
|
||||
|
||||
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
|
||||
use AlibabaCloud\Tea\Model;
|
||||
use AlibabaCloud\Tea\Request;
|
||||
use AlibabaCloud\Tea\Utils\Utils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class OpenApiUtilClientTest extends TestCase
|
||||
{
|
||||
public function testConvert()
|
||||
{
|
||||
$model = new MockModel();
|
||||
$model->a = 'foo';
|
||||
|
||||
$output = new MockModel();
|
||||
OpenApiUtilClient::convert($model, $output);
|
||||
$this->assertEquals($model->a, $output->a);
|
||||
}
|
||||
|
||||
public function testGetStringToSign()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->method = 'GET';
|
||||
$request->pathname = '/';
|
||||
$request->headers['accept'] = 'application/json';
|
||||
|
||||
$this->assertEquals("GET\napplication/json\n\n\n\n/", OpenApiUtilClient::getStringToSign($request));
|
||||
|
||||
$request->headers = [
|
||||
'accept' => 'application/json',
|
||||
'content-md5' => 'md5',
|
||||
'content-type' => 'application/json',
|
||||
'date' => 'date',
|
||||
];
|
||||
$this->assertEquals("GET\napplication/json\nmd5\napplication/json\ndate\n/", OpenApiUtilClient::getStringToSign($request));
|
||||
|
||||
$request->headers = [
|
||||
'accept' => 'application/json',
|
||||
'content-md5' => 'md5',
|
||||
'content-type' => 'application/json',
|
||||
'date' => 'date',
|
||||
'x-acs-custom-key' => 'any value',
|
||||
];
|
||||
$this->assertEquals("GET\napplication/json\nmd5\napplication/json\ndate\nx-acs-custom-key:any value\n/", OpenApiUtilClient::getStringToSign($request));
|
||||
|
||||
$request->query = [
|
||||
'key' => 'val ue with space',
|
||||
];
|
||||
$this->assertEquals("GET\napplication/json\nmd5\napplication/json\ndate\nx-acs-custom-key:any value\n/?key=val ue with space", OpenApiUtilClient::getStringToSign($request));
|
||||
}
|
||||
|
||||
public function testGetROASignature()
|
||||
{
|
||||
$this->assertEquals('OmuTAr79tpI6CRoAdmzKRq5lHs0=', OpenApiUtilClient::getROASignature('stringtosign', 'secret'));
|
||||
}
|
||||
|
||||
public function testToForm()
|
||||
{
|
||||
$this->assertEquals('client=test&strs.1=str1&strs.2=str2&tag.key=value', OpenApiUtilClient::toForm([
|
||||
'client' => 'test',
|
||||
'tag' => [
|
||||
'key' => 'value',
|
||||
],
|
||||
'strs' => ['str1', 'str2'],
|
||||
]));
|
||||
}
|
||||
|
||||
public function testGetTimestamp()
|
||||
{
|
||||
$date = OpenApiUtilClient::getTimestamp();
|
||||
$this->assertEquals(20, \strlen($date));
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
$model = new MockModel();
|
||||
$model->a = 'foo';
|
||||
$model->c = 'boo';
|
||||
|
||||
$array = [
|
||||
'a' => 'a',
|
||||
'b1' => [
|
||||
'a' => 'a',
|
||||
],
|
||||
'b2' => [
|
||||
'a' => 'a',
|
||||
],
|
||||
'c' => ['x', 'y', 'z'],
|
||||
'd' => [
|
||||
$model
|
||||
]
|
||||
];
|
||||
$this->assertEquals([
|
||||
'a' => 'a',
|
||||
'b1.a' => 'a',
|
||||
'b2.a' => 'a',
|
||||
'c.1' => 'x',
|
||||
'c.2' => 'y',
|
||||
'c.3' => 'z',
|
||||
'd.1.A' => 'foo',
|
||||
'd.1.b' => '',
|
||||
'd.1.c' => 'boo',
|
||||
], OpenApiUtilClient::query($array));
|
||||
}
|
||||
|
||||
public function testGetRPCSignature()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->pathname = '';
|
||||
$request->query = [
|
||||
'query' => 'test',
|
||||
'body' => 'test',
|
||||
];
|
||||
$this->assertEquals('XlUyV4sXjOuX5FnjUz9IF9tm5rU=', OpenApiUtilClient::getRPCSignature($request->query, $request->method, 'secret'));
|
||||
}
|
||||
|
||||
public function testArrayToStringWithSpecifiedStyle()
|
||||
{
|
||||
$data = ['ok', 'test', 2, 3];
|
||||
$this->assertEquals(
|
||||
'instance.1=ok&instance.2=test&instance.3=2&instance.4=3',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'repeatList'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'["ok","test",2,3]',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'json'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'ok,test,2,3',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'simple'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'ok test 2 3',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'spaceDelimited'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'ok|test|2|3',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'pipeDelimited'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
$data,
|
||||
'instance',
|
||||
'piDelimited'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
OpenApiUtilClient::arrayToStringWithSpecifiedStyle(
|
||||
null,
|
||||
'instance',
|
||||
'pipeDelimited'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseToArray()
|
||||
{
|
||||
$test = $this->parseData();
|
||||
$data = $test['data'];
|
||||
$expected = $test['expected'];
|
||||
foreach ($data as $index => $item) {
|
||||
$this->assertEquals($expected[$index], OpenApiUtilClient::parseToArray($item));
|
||||
}
|
||||
}
|
||||
|
||||
public function testParseToMap()
|
||||
{
|
||||
$test = $this->parseData();
|
||||
$data = $test['data'];
|
||||
$expected = $test['expected'];
|
||||
foreach ($data as $index => $item) {
|
||||
$this->assertEquals($expected[$index], OpenApiUtilClient::parseToMap($item));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetEndpoint()
|
||||
{
|
||||
$endpoint = 'ecs.cn-hangzhou.aliyun.cs.com';
|
||||
$useAccelerate = false;
|
||||
$endpointType = 'public';
|
||||
|
||||
$this->assertEquals('ecs.cn-hangzhou.aliyun.cs.com', OpenApiUtilClient::getEndpoint($endpoint, $useAccelerate, $endpointType));
|
||||
|
||||
$endpointType = 'internal';
|
||||
$this->assertEquals('ecs-internal.cn-hangzhou.aliyun.cs.com', OpenApiUtilClient::getEndpoint($endpoint, $useAccelerate, $endpointType));
|
||||
|
||||
$useAccelerate = true;
|
||||
$endpointType = 'accelerate';
|
||||
$this->assertEquals('oss-accelerate.aliyuncs.com', OpenApiUtilClient::getEndpoint($endpoint, $useAccelerate, $endpointType));
|
||||
}
|
||||
|
||||
public function testHexEncode()
|
||||
{
|
||||
$data = OpenApiUtilClient::hash(Utils::toBytes('test'), 'ACS3-HMAC-SHA256');
|
||||
$this->assertEquals(
|
||||
Utils::toBytes(hex2bin('9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08')),
|
||||
$data
|
||||
);
|
||||
|
||||
$data = OpenApiUtilClient::hash(Utils::toBytes('test'), 'ACS3-RSA-SHA256');
|
||||
$this->assertEquals(
|
||||
Utils::toBytes(hex2bin('9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08')),
|
||||
$data
|
||||
);
|
||||
|
||||
$data = OpenApiUtilClient::hash(Utils::toBytes('test'), 'ACS3-HMAC-SM3');
|
||||
$this->assertEquals(
|
||||
Utils::toBytes(hex2bin('55e12e91650d2fec56ec74e1d3e4ddbfce2ef3a65890c2a19ecf88a307e76a23')),
|
||||
$data
|
||||
);
|
||||
|
||||
$data = OpenApiUtilClient::hash(Utils::toBytes('test'), 'ACS3-HM-SHA256');
|
||||
$this->assertEquals('', Utils::toString($data));
|
||||
}
|
||||
|
||||
public function testGetEncodePath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'/path/%20test',
|
||||
OpenApiUtilClient::getEncodePath('/path/ test')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetEncodeParam()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'a%2Fb%2Fc%2F%20test',
|
||||
OpenApiUtilClient::getEncodeParam('a/b/c/ test')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAuthorization()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->method = '';
|
||||
$request->pathname = '';
|
||||
$request->query = [
|
||||
'test' => 'ok',
|
||||
'empty' => '',
|
||||
];
|
||||
$request->headers = [
|
||||
'x-acs-test' => 'http',
|
||||
'x-acs-TEST' => 'https',
|
||||
];
|
||||
|
||||
$res = OpenApiUtilClient::getAuthorization($request, 'ACS3-HMAC-SHA256', '55e12e91650d2fec56ec74e1d3e4ddbfce2ef3a65890c2a19ecf88a307e76a23', 'acesskey', 'secret');
|
||||
|
||||
$this->assertEquals('ACS3-HMAC-SHA256 Credential=acesskey,SignedHeaders=x-acs-test,Signature=0a0f89a45f1ec3537a2d1a1046c71b95513a8f1f02526056968da19b99a5b914', $res);
|
||||
|
||||
$request->query = null;
|
||||
|
||||
$res = OpenApiUtilClient::getAuthorization($request, 'ACS3-HMAC-SHA256', '55e12e91650d2fec56ec74e1d3e4ddbfce2ef3a65890c2a19ecf88a307e76a23', 'acesskey', 'secret');
|
||||
|
||||
$this->assertEquals('ACS3-HMAC-SHA256 Credential=acesskey,SignedHeaders=x-acs-test,Signature=af6d32deb090ae85a21d7183055cf18dca17751da96979cdf964f8f0853e9dd2', $res);
|
||||
}
|
||||
|
||||
public function testSign()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'b9ff646822f41ef647c1416fa2b8408923828abc0464af6706e18db3e8553da8',
|
||||
OpenApiUtilClient::hexEncode(OpenApiUtilClient::sign('secret', 'source', 'ACS3-HMAC-SM3'))
|
||||
);
|
||||
$this->assertEquals('1d93c62698a1c26427265668e79fac099aa26c1df873669599a2fb2f272e64c9',
|
||||
OpenApiUtilClient::hexEncode(OpenApiUtilClient::sign('secret', 'source', 'ACS3-HMAC-SHA256'))
|
||||
);
|
||||
}
|
||||
|
||||
private function parseData()
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'NotArray',
|
||||
new ParseModel([
|
||||
'str' => 'A',
|
||||
'model' => new ParseModel(['str' => 'sub model']),
|
||||
'array' => [1, 2, 3],
|
||||
]),
|
||||
[ // model item in array
|
||||
new ParseModel([
|
||||
'str' => 'A',
|
||||
]),
|
||||
],
|
||||
[ // model item in map
|
||||
'model' => new ParseModel([
|
||||
'str' => 'A',
|
||||
]),
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
['NotArray'],
|
||||
[
|
||||
'str' => 'A',
|
||||
'model' => [
|
||||
'str' => 'sub model',
|
||||
'model' => null,
|
||||
'array' => null,
|
||||
],
|
||||
'array' => [1, 2, 3],
|
||||
],
|
||||
[
|
||||
[
|
||||
'str' => 'A',
|
||||
'model' => null,
|
||||
'array' => null,
|
||||
],
|
||||
],
|
||||
[
|
||||
'model' => [
|
||||
'str' => 'A',
|
||||
'model' => null,
|
||||
'array' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class MockModel extends Model
|
||||
{
|
||||
public $a = 'A';
|
||||
|
||||
public $b = '';
|
||||
|
||||
public $c = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->_name['a'] = 'A';
|
||||
$this->_required['c'] = true;
|
||||
parent::__construct([]);
|
||||
}
|
||||
}
|
||||
|
||||
class ParseModel extends Model
|
||||
{
|
||||
public $str;
|
||||
public $model;
|
||||
public $array;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
@ -0,0 +1,8 @@
|
||||
vendor
|
||||
composer.lock
|
||||
doc
|
||||
output
|
||||
.idea
|
||||
.buildpath
|
||||
.project
|
||||
.settings
|
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//*******************************Simple Usage ***************************************************************
|
||||
|
||||
// Add Canme record
|
||||
$myDomain = '<yourDomainName>';
|
||||
$ossClient->addBucketCname($bucket, $myDomain);
|
||||
|
||||
// View cname records
|
||||
$cnameConfig = $ossClient->getBucketCname($bucket);
|
||||
Common::println("bucket $bucket cname:" . $cnameConfig->serializeToXml());
|
||||
|
||||
// Delete bucket cname
|
||||
$myDomain = '<yourDomainName>';
|
||||
$ossClient->deleteBucketCname($bucket,$myDomain);
|
||||
Common::println("bucket $bucket cname deleted");
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
addBucketCname($ossClient, $bucket);
|
||||
getBucketCname($ossClient, $bucket);
|
||||
deleteBucketCname($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set bucket cname
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function addBucketCname($ossClient, $bucket)
|
||||
{
|
||||
// Set up a custom domain name.
|
||||
$myDomain = '<yourDomainName>';
|
||||
try {
|
||||
$ossClient->addBucketCname($bucket, $myDomain);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bucket cname
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketCname($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$cnameConfig = $ossClient->getBucketCname($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($cnameConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bucket cname
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketCname($ossClient, $bucket)
|
||||
{
|
||||
$myDomain = '<yourDomainName>';
|
||||
try {
|
||||
$ossClient->deleteBucketCname($bucket, $myDomain);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\ServerSideEncryptionConfig;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// Configure Bucket encryption
|
||||
// Set Bucket's default server-side encryption method to OSS fully managed encryption (SSE-OSS).
|
||||
$config = new ServerSideEncryptionConfig("AES256");
|
||||
// Set Bucket's default server-side encryption method to KMS, and do not specify a CMK ID.
|
||||
//$config = new ServerSideEncryptionConfig("KMS");
|
||||
// Set Bucket's default server-side encryption method to KMS, and specify the CMK ID.
|
||||
//$config = new ServerSideEncryptionConfig("KMS", "your kms id");
|
||||
$ossClient->putBucketEncryption($bucket, $config);
|
||||
Common::println("bucket $bucket encryoption created");
|
||||
|
||||
$config = $ossClient->getBucketEncryption($bucket);
|
||||
Common::println("bucket $bucket encryoption:".$config->serializeToXml());
|
||||
|
||||
$config = $ossClient->deleteBucketEncryption($bucket);
|
||||
Common::println("bucket $bucket encryoption has deleted");
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
putBucketEncryption($ossClient, $bucket);
|
||||
getBucketEncryption($ossClient, $bucket);
|
||||
deleteBucketEncryption($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Configure Bucket encryption
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
|
||||
function putBucketEncryption($ossClient,$bucket){
|
||||
try {
|
||||
// Set Bucket's default server-side encryption method to OSS fully managed encryption (SSE-OSS).
|
||||
$config = new ServerSideEncryptionConfig("AES256");
|
||||
// Set Bucket's default server-side encryption method to KMS, and do not specify a CMK ID.
|
||||
//$config = new ServerSideEncryptionConfig("KMS");
|
||||
// Set Bucket's default server-side encryption method to KMS, and specify the CMK ID.
|
||||
//$config = new ServerSideEncryptionConfig("KMS", "your kms id");
|
||||
$ossClient->putBucketEncryption($bucket, $config);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bucket encryption
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
|
||||
function getBucketEncryption($ossClient,$bucket){
|
||||
try {
|
||||
$config = $ossClient->getBucketEncryption($bucket);
|
||||
print($config->getSSEAlgorithm());
|
||||
print($config->getKMSMasterKeyID());
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete Bucket encryption
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
|
||||
function deleteBucketEncryption($ossClient,$bucket){
|
||||
try {
|
||||
$ossClient->deleteBucketEncryption($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
//Set requester payment mode
|
||||
$ossClient->putBucketRequestPayment($bucket, "Requester");
|
||||
|
||||
//Get requester payment mode configuration
|
||||
$payer = $ossClient->getBucketRequestPayment($bucket);
|
||||
Common::println("bucket $bucket Payer:".$payer.PHP_EOL);
|
||||
|
||||
//Third-party paid access to Object
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
$content = "hello";
|
||||
$object = "object";
|
||||
|
||||
//PutObject interface to specify the payer
|
||||
$ossClient->putObject($bucket, $object, $content, $options);
|
||||
|
||||
// GetObject interface to specify the payer
|
||||
$ossClient->getObject($bucket, $object, $options);
|
||||
|
||||
// DeleteObject interface to specify the payer
|
||||
$ossClient->deleteObject($bucket, $object, $options);
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketRequestPayment($ossClient,$bucket);
|
||||
getBucketRequestPayment($ossClient,$bucket);
|
||||
setObjectPayment($ossClient,$bucket);
|
||||
|
||||
/**
|
||||
* Set requester payment mode
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function putBucketRequestPayment($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->putBucketRequestPayment($bucket, "Requester");
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get payment mode of bucket
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function getBucketRequestPayment($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$payer = $ossClient->getBucketRequestPayment($bucket);
|
||||
print("bucket $bucket Payer:".$payer.PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set payment mode of object
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function setObjectPayment($ossClient,$bucket){
|
||||
// Specify the payment model for the requester.
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
try {
|
||||
|
||||
$content = "hello";
|
||||
$object = "object";
|
||||
//PutObject interface to specify the payer
|
||||
$ossClient->putObject($bucket, $object, $content, $options);
|
||||
// GetObject interface to specify the payer
|
||||
$ossClient->getObject($bucket, $object, $options);
|
||||
// DeleteObject interface to specify the payer
|
||||
$ossClient->deleteObject($bucket, $object, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// Set Bucket Policy
|
||||
// Authorization strategy.
|
||||
$policy = <<< BBBB
|
||||
{
|
||||
"Version":"1",
|
||||
"Statement":[
|
||||
{
|
||||
"Action":[
|
||||
"oss:PutObject",
|
||||
"oss:GetObject"
|
||||
],
|
||||
"Effect":"Allow",
|
||||
"Resource":["acs:oss:*:*:*/user1/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
BBBB;
|
||||
$ossClient->putBucketPolicy($bucket, $policy);
|
||||
|
||||
// Get bucket pllicy
|
||||
$policy = $ossClient->getBucketPolicy($bucket);
|
||||
Common::println("bucket $bucket policy: " . $policy);
|
||||
|
||||
|
||||
// Delete bucket pllicy
|
||||
$policy = $ossClient->deleteBucketPolicy($bucket);
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketPolicy($ossClient, $bucket);
|
||||
getBucketPolicy($ossClient, $bucket);
|
||||
deleteBucketPolicy($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set Bucket Policy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function putBucketPolicy($ossClient, $bucket)
|
||||
{
|
||||
$policy = <<< BBBB
|
||||
{
|
||||
"Version":"1",
|
||||
"Statement":[
|
||||
{
|
||||
"Action":[
|
||||
"oss:PutObject",
|
||||
"oss:GetObject"
|
||||
],
|
||||
"Effect":"Allow",
|
||||
"Resource":["acs:oss:*:*:*/user1/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
BBBB;
|
||||
|
||||
try {
|
||||
$ossClient->putBucketPolicy($bucket, $policy);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Bucket Policy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function getBucketPolicy($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$policy = $ossClient->getBucketPolicy($bucket);
|
||||
print($policy);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete Bucket Policy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketPolicy($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucketPolicy($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// Set bucket tag
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
$ossClient->putBucketTags($bucket, $config);
|
||||
|
||||
// Get bucket tags
|
||||
$config = $ossClient->getBucketTags($bucket);
|
||||
Common::println("bucket $bucket tags: ".$config->serializeToXml());
|
||||
|
||||
// Delete bucket tags
|
||||
|
||||
// Delete the specified tag of the bucket.
|
||||
$tags = array();
|
||||
$tags[] = new Tag("key1", "value1");
|
||||
$tags[] = new Tag("key2", "value2");
|
||||
$ossClient->deleteBucketTags($bucket, $tags);
|
||||
|
||||
// Delete all tags in the bucket.
|
||||
$ossClient->deleteBucketTags($bucket);
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketTags($ossClient, $bucket);
|
||||
getBucketTags($ossClient, $bucket);
|
||||
deleteBucketTags($ossClient, $bucket);
|
||||
|
||||
|
||||
/**
|
||||
* Create bucket tag
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function putBucketTags($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
// 设置Bucket标签。
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
$ossClient->putBucketTags($bucket, $config);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get bucket tag
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function getBucketTags($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$config = $ossClient->getBucketTags($bucket);
|
||||
print_r($config->getTags());
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* delete bucket tag
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketTags($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
// Delete the specified tag of the bucket.
|
||||
$tags = array();
|
||||
$tags[] = new Tag("key1", "value1");
|
||||
$tags[] = new Tag("key2", "value2");
|
||||
$ossClient->deleteBucketTags($bucket, $tags);
|
||||
|
||||
// Delete all tags in the bucket.
|
||||
//$ossClient->deleteBucketTags($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// set <tran></tran>sfer acceleration
|
||||
$enabled = true; // set true to enable transfer acceleration; set false to disalbe transfer acceleration
|
||||
$ossClient->putBucketTransferAcceleration($bucket, $enabled);
|
||||
printf('putBucketTransferAcceleration SUCCESS' . "\n");
|
||||
|
||||
|
||||
// get transfer acceleration
|
||||
$result = $ossClient->getBucketTransferAcceleration($bucket);
|
||||
printf('getBucketTransferAcceleration Status:%s'."\n",$result);
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
putBucketTransferAcceleration($ossClient,$bucket);
|
||||
getBucketTransferAcceleration($bucket);
|
||||
|
||||
/**
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
* @param $enabled string
|
||||
*/
|
||||
function putBucketTransferAcceleration($ossClient, $bucket, $enabled)
|
||||
{
|
||||
try{
|
||||
$enabled = true; // set true to enable transfer acceleration; set false to disalbe transfer acceleration
|
||||
$ossClient->putBucketTransferAcceleration($bucket,$enabled);
|
||||
printf('putBucketTransferAcceleration SUCCESS' . "\n");
|
||||
} catch(OssException $e) {
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function getBucketTransferAcceleration($ossClient, $bucket)
|
||||
{
|
||||
try{
|
||||
$result = $ossClient->getBucketTransferAcceleration($bucket);
|
||||
printf('getBucketTransferAcceleration Status:%s'."\n",$result);
|
||||
} catch(OssException $e) {
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
//Set Bucket version control status
|
||||
//Set the storage space version control to enable version control (Enabled) or suspend version control (Suspended).
|
||||
$ossClient->putBucketVersioning($bucket, "Enabled");
|
||||
Common::println("bucket $bucket version Enabled");
|
||||
// show all object list
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null
|
||||
);
|
||||
$bool = true;
|
||||
while ($bool) {
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
if ($result->getIsTruncated() === 'true') {
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => $result->getNextKeyMarker(),
|
||||
OssClient::OSS_VERSION_ID_MARKER => $result->getNextVersionIdMarker()
|
||||
);
|
||||
} else {
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
|
||||
// show the prefix object
|
||||
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null,
|
||||
OssClient::OSS_PREFIX => "test"
|
||||
);
|
||||
$bool = true;
|
||||
while ($bool) {
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
if ($result->getIsTruncated() === 'true') {
|
||||
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
|
||||
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
|
||||
} else {
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
|
||||
// list the number of objects
|
||||
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null,
|
||||
OssClient::OSS_MAX_KEYS => 200
|
||||
);
|
||||
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
|
||||
// show root folder list
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null,
|
||||
OssClient::OSS_DELIMITER => "/",
|
||||
);
|
||||
$bool = true;
|
||||
while ($bool) {
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
if ($result->getIsTruncated() === 'true') {
|
||||
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
|
||||
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
|
||||
} else {
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Show subfolder objects list
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null,
|
||||
OssClient::OSS_DELIMITER => "/",
|
||||
OssClient::OSS_PREFIX => "test/",
|
||||
);
|
||||
$bool = true;
|
||||
while ($bool) {
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
if ($result->getIsTruncated() === 'true') {
|
||||
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
|
||||
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
|
||||
} else {
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
listObjectVersions($ossClient, $bucket);
|
||||
putBucketVersioning($ossClient, $bucket);
|
||||
/**
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function listObjectVersions($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$option = array(
|
||||
OssClient::OSS_KEY_MARKER => null,
|
||||
OssClient::OSS_VERSION_ID_MARKER => null,
|
||||
);
|
||||
$bool = true;
|
||||
while ($bool) {
|
||||
$result = $ossClient->listObjectVersions($bucket, $option);
|
||||
## View the version information of the listed object.
|
||||
foreach ($result->getObjectVersionList() as $key => $info) {
|
||||
Common::println("key name: " . $info->getKey());
|
||||
Common::println("versionid: " . $info->getVersionId());
|
||||
Common::println("Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
## View the version information that lists the deletion flags.
|
||||
foreach ($result->getDeleteMarkerList() as $key => $info) {
|
||||
Common::println("del_maker key name: " . $info->getKey());
|
||||
Common::println("del_maker versionid: " . $info->getVersionId());
|
||||
Common::println("del_maker Is latest: " . $info->getIsLatest());
|
||||
}
|
||||
|
||||
if ($result->getIsTruncated() === 'true') {
|
||||
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
|
||||
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
|
||||
} else {
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Enabled or Suspended bucket version
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function putBucketVersioning($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
//Set the storage space version control to enable version control (Enabled) or suspend version control (Suspended).
|
||||
$ossClient->putBucketVersioning($bucket, "Enabled");
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// Create a new compliance retention policy:
|
||||
// The specified object protection days are 30 days.
|
||||
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
|
||||
Common::println("bucket $bucket wormId: " . $wormId.PHP_EOL);
|
||||
|
||||
// Cancel an unlocked compliance retention policy
|
||||
$ossClient->abortBucketWorm($bucket);
|
||||
|
||||
//Lock compliant retention policy
|
||||
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
|
||||
$ossClient->completeBucketWorm($bucket, $wormId);
|
||||
|
||||
// Get compliant retention policy
|
||||
$config = $ossClient->getBucketWorm($bucket);
|
||||
Common::println("WormId:".$config->getWormId().PHP_EOL);
|
||||
Common::println("State:". $config->getState().PHP_EOL);
|
||||
Common::println("Day:". $config->getDay().PHP_EOL);
|
||||
|
||||
// Extend the retention days of objects
|
||||
$wormId = "<yourWormId>";
|
||||
// Extend the retention days of objects in the locked compliance retention policy to 120 days.
|
||||
$ossClient->extendBucketWorm($bucket, $wormId, 120);
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
initiateBucketWorm($ossClient, $bucket);
|
||||
abortBucketWorm($ossClient, $bucket);
|
||||
completeBucketWorm($ossClient, $bucket);
|
||||
getBucketWorm($ossClient, $bucket);
|
||||
extendBucketWorm($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set Bucket Worm Ploicy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function initiateBucketWorm($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$wormId = $ossClient->initiateBucketWorm($bucket,30);
|
||||
print("bucket $bucket wormId: " . $wormId.PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel an unlocked compliance retention policy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function abortBucketWorm($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->abortBucketWorm($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Complete Bucket Worm
|
||||
* @param $ossClient $ossClient OssClient instance
|
||||
* @param $bucket $bucket Name of the bucket to create
|
||||
*/
|
||||
function completeBucketWorm($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
|
||||
$ossClient->completeBucketWorm($bucket, $wormId);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bucket Worm
|
||||
* @param $ossClient $ossClient OssClient instance
|
||||
* @param $bucket $bucket Name of the bucket to create
|
||||
*/
|
||||
function getBucketWorm($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$config = $ossClient->getBucketWorm($bucket);
|
||||
|
||||
printf("WormId:%s\n", $config->getWormId());
|
||||
printf("State:%s\n", $config->getState());
|
||||
printf("Day:%d\n", $config->getDay());
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the retention days of objects
|
||||
* @param $ossClient $ossClient OssClient instance
|
||||
* @param $bucket $bucket Name of the bucket to create
|
||||
*/
|
||||
function extendBucketWorm($ossClient, $bucket)
|
||||
{
|
||||
$wormId = "<yourWormId>";
|
||||
try {
|
||||
$ossClient->ExtendBucketWorm($bucket, $wormId, 120);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
@ -0,0 +1,366 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
//******************************* Simple usage ***************************************************************
|
||||
|
||||
// Upload Object add tag
|
||||
$object = "b.file";
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
)
|
||||
);
|
||||
$result = $ossClient->putObject($bucket, $object, __FILE__,$options);
|
||||
Common::println("b.file is created");
|
||||
Common::println("tag is:".$result['oss-requestheaders']['x-oss-tagging']);
|
||||
|
||||
// Add object tags when uploading parts
|
||||
|
||||
$object = "b.file";
|
||||
$file = __FILE__;
|
||||
$options = array(
|
||||
OssClient::OSS_CHECK_MD5 => true,
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
),
|
||||
);
|
||||
$result = $ossClient->multiuploadFile($bucket, $object, $file, $options);
|
||||
Common::println("b.file is created");
|
||||
Common::println("tag is:".$result['oss-requestheaders']['x-oss-tagging']);
|
||||
|
||||
// get tags from object
|
||||
|
||||
$object = "a.txt";
|
||||
$result = $ossClient->getObjectTagging($bucket,$object);
|
||||
printf($object.'tags is: '.$result->serializeToXml().PHP_EOL);
|
||||
|
||||
|
||||
// Add or change object tags to uploaded objects
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
|
||||
$ossClient->putObjectTagging($bucket, $object, $config);
|
||||
// Add object tags when uploading
|
||||
$object = "a.txt";
|
||||
$filePath = "D:\\localpath\\b.txt";
|
||||
$filePath1 = "D:\\localpath\\c.txt";
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2',
|
||||
)
|
||||
);
|
||||
$position = $ossClient->appendObject($bucket, $object,'content one',0,$options);
|
||||
printf('Content one append object Success'.PHP_EOL);
|
||||
$position = $ossClient->appendObject($bucket, $object, 'content two',$position,$options);
|
||||
printf('Content two append object Success'.PHP_EOL);
|
||||
|
||||
// delete tags
|
||||
$object = "g.file";
|
||||
$ossClient->deleteObjectTagging($bucket, $object);
|
||||
printf($object.' tags has deleted'.PHP_EOL);
|
||||
|
||||
// Copy a small file
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "a.file";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject . '.copy';
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging-directive' => 'Replace',
|
||||
'x-oss-tagging'=>'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
$ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $options);
|
||||
$config = $ossClient->getObjectTagging($bucket, $toObject);
|
||||
Common::println('object tags is:'.$config->serializeToXml());
|
||||
|
||||
// Copy a large file
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "a.file";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject . '.copy';
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging'=>'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
|
||||
$part_size = 256*1024*1024;
|
||||
$objectMeta = $ossClient->getObjectMeta($fromBucket, $fromObject);
|
||||
$length = $objectMeta['content-length'];
|
||||
$upload_id = $ossClient->initiateMultipartUpload($toBucket, $toObject,$options);
|
||||
$pieces = $ossClient->generateMultiuploadParts($length, $part_size);
|
||||
$response_upload_part = array();
|
||||
$copyId = 1;
|
||||
$upload_position = 0;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece['seekTo'];
|
||||
$to_pos = (integer)$piece['length'] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
'start' => $from_pos,
|
||||
'end' => $to_pos,
|
||||
);
|
||||
$response_upload_part[] = $ossClient->uploadPartCopy( $fromBucket, $fromObject, $toBucket, $toObject, $copyId, $upload_id, $up_options);
|
||||
printf("initiateMultipartUpload, uploadPartCopy - part#{$copyId} OK\n");
|
||||
$copyId = $copyId + 1;
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $etag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $etag,
|
||||
);
|
||||
}
|
||||
$result = $ossClient->completeMultipartUpload($toBucket, $toObject, $upload_id, $upload_parts);
|
||||
$config = $ossClient->getObjectTagging($bucket, $toObject);
|
||||
Common::println($toObject.' tags is:'.$config->serializeToXml());
|
||||
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putObject($ossClient,$bucket);
|
||||
multiuploadFile($ossClient,$bucket);
|
||||
appendObject($ossClient,$bucket);
|
||||
putObjectTagging($ossClient,$bucket);
|
||||
getObjectTagging($ossClient,$bucket);
|
||||
deleteObjectTagging($ossClient,$bucket);
|
||||
copyObjectSmall($ossClient,$bucket);
|
||||
copyObjectLarge($ossClient,$bucket);
|
||||
/**
|
||||
* Upload Object add tag
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name
|
||||
*/
|
||||
function putObject($ossClient,$bucket){
|
||||
$object = "b.file";
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
try {
|
||||
// 通过简单上传的方式上传Object。
|
||||
$result = $ossClient->putObject($bucket, $object, __FILE__,$options);
|
||||
Common::println("b.file is created".PHP_EOL);
|
||||
Common::println("tag is:".$result['oss-requestheaders']['x-oss-tagging'].PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add object tags when uploading parts
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name
|
||||
*/
|
||||
function multiuploadFile($ossClient,$bucket){
|
||||
$object = "b.file";
|
||||
$file = __FILE__;
|
||||
$options = array(
|
||||
OssClient::OSS_CHECK_MD5 => true,
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $ossClient->multiuploadFile($bucket, $object, $file, $options);
|
||||
Common::println("b.file is created".PHP_EOL);
|
||||
Common::println("tag is:".$result['oss-requestheaders']['x-oss-tagging'].PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add object tags when uploading
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function appendObject($ossClient,$bucket){
|
||||
$object = "g.file";
|
||||
$content_array = array('Hello OSS', 'Hi OSS');
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2',
|
||||
));
|
||||
|
||||
try {
|
||||
$position = $ossClient->appendObject($bucket, $object, $content_array[0], 0, $options);
|
||||
printf($content_array[0].' append object Success'.PHP_EOL);
|
||||
$position = $ossClient->appendObject($bucket, $object, $content_array[1], $position);
|
||||
printf($content_array[1].' append object Success'.PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
* @throws OssException
|
||||
*/
|
||||
function putObjectTagging($ossClient,$bucket){
|
||||
$object = "g.file";
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
|
||||
try {
|
||||
$ossClient->putObjectTagging($bucket, $object, $config);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get object tags
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function getObjectTagging($ossClient,$bucket){
|
||||
$object = "g.file";
|
||||
try {
|
||||
$config = $ossClient->getObjectTagging($bucket, $object);
|
||||
printf($object." tags is:".$config->serializeToXml().PHP_EOL);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get object tags
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function deleteObjectTagging($ossClient,$bucket){
|
||||
$object = "g.file";
|
||||
try {
|
||||
$ossClient->deleteObjectTagging($bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy small files
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function copyObjectSmall($ossClient,$bucket){
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "a.file";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject . '.copy';
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging-directive' => 'Replace',
|
||||
'x-oss-tagging'=>'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
|
||||
try {
|
||||
$ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
$config = $ossClient->getObjectTagging($bucket, $toObject);
|
||||
Common::println('object tags is:'.$config->serializeToXml());
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a large file
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket bucket_name string
|
||||
*/
|
||||
function copyObjectLarge($ossClient,$bucket){
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "a.file";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject . '.copy';
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging'=>'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
|
||||
$part_size = 256*1024*1024;
|
||||
try{
|
||||
$objectMeta = $ossClient->getObjectMeta($fromBucket, $fromObject);
|
||||
$length = $objectMeta['content-length'];
|
||||
$upload_id = $ossClient->initiateMultipartUpload($toBucket, $toObject,$options);
|
||||
$pieces = $ossClient->generateMultiuploadParts($length, $part_size);
|
||||
$response_upload_part = array();
|
||||
$copyId = 1;
|
||||
$upload_position = 0;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece['seekTo'];
|
||||
$to_pos = (integer)$piece['length'] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
'start' => $from_pos,
|
||||
'end' => $to_pos,
|
||||
);
|
||||
$response_upload_part[] = $ossClient->uploadPartCopy( $fromBucket, $fromObject, $toBucket, $toObject, $copyId, $upload_id, $up_options);
|
||||
printf("initiateMultipartUpload, uploadPartCopy - part#{$copyId} OK\n");
|
||||
$copyId = $copyId + 1;
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $etag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $etag,
|
||||
);
|
||||
}
|
||||
$result = $ossClient->completeMultipartUpload($toBucket, $toObject, $upload_id, $upload_parts);
|
||||
printf('copy success'. "\n");
|
||||
} catch(OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
$config = $ossClient->getObjectTagging($bucket, $toObject);
|
||||
Common::println($toObject.' tags is:'.$config->serializeToXml());
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Cname token info class.
|
||||
*
|
||||
* Class CnameTokenInfo
|
||||
* @package OSS\Model
|
||||
*/
|
||||
class CnameTokenInfo
|
||||
{
|
||||
/**
|
||||
* Get bucket name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBucket()
|
||||
{
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCname()
|
||||
{
|
||||
return $this->cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expireTime.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExpireTime()
|
||||
{
|
||||
return $this->expireTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse cname token from the xml.
|
||||
*
|
||||
* @param string $strXml
|
||||
* @throws OssException
|
||||
* @return null
|
||||
*/
|
||||
public function parseFromXml($strXml)
|
||||
{
|
||||
$xml = simplexml_load_string($strXml);
|
||||
if (isset($xml->Bucket) ) {
|
||||
$this->bucket = strval($xml->Bucket);
|
||||
}
|
||||
if (isset($xml->Cname) ) {
|
||||
$this->cname = strval($xml->Cname);
|
||||
}
|
||||
if (isset($xml->Token) ) {
|
||||
$this->token = strval($xml->Token);
|
||||
}
|
||||
if (isset($xml->ExpireTime) ) {
|
||||
$this->expireTime = strval($xml->ExpireTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bucket name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $bucket;
|
||||
/**
|
||||
* cname
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cname;
|
||||
|
||||
/**
|
||||
* token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* expire time
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $expireTime;
|
||||
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Model;
|
||||
|
||||
/**
|
||||
* Class ObjectListInfoV2
|
||||
*
|
||||
* The class of return value of ListObjectsV2
|
||||
*
|
||||
* @package OSS\Model
|
||||
*/
|
||||
class ObjectListInfoV2
|
||||
{
|
||||
/**
|
||||
* ObjectListInfoV2 constructor.
|
||||
*
|
||||
* @param string $bucketName
|
||||
* @param string $prefix
|
||||
* @param int $maxKeys
|
||||
* @param string $delimiter
|
||||
* @param null $isTruncated
|
||||
* @param array $objectList
|
||||
* @param array $prefixList
|
||||
* @param string $continuationToken
|
||||
* @param string $nextContinuationToken
|
||||
* @param string $startAfter
|
||||
* @param int $keyCount
|
||||
*/
|
||||
public function __construct($bucketName, $prefix, $maxKeys, $delimiter, $isTruncated, array $objectList, array $prefixList, $continuationToken, $nextContinuationToken, $startAfter, $keyCount)
|
||||
{
|
||||
$this->bucketName = $bucketName;
|
||||
$this->prefix = $prefix;
|
||||
$this->maxKeys = $maxKeys;
|
||||
$this->delimiter = $delimiter;
|
||||
$this->isTruncated = $isTruncated;
|
||||
$this->objectList = $objectList;
|
||||
$this->prefixList = $prefixList;
|
||||
$this->continuationToken = $continuationToken;
|
||||
$this->nextContinuationToken = $nextContinuationToken;
|
||||
$this->startAfter = $startAfter;
|
||||
$this->keyCount = $keyCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBucketName()
|
||||
{
|
||||
return $this->bucketName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxKeys()
|
||||
{
|
||||
return $this->maxKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDelimiter()
|
||||
{
|
||||
return $this->delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsTruncated()
|
||||
{
|
||||
return $this->isTruncated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ObjectInfo list.
|
||||
*
|
||||
* @return ObjectInfo[]
|
||||
*/
|
||||
public function getObjectList()
|
||||
{
|
||||
return $this->objectList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PrefixInfo list
|
||||
*
|
||||
* @return PrefixInfo[]
|
||||
*/
|
||||
public function getPrefixList()
|
||||
{
|
||||
return $this->prefixList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContinuationToken()
|
||||
{
|
||||
return $this->continuationToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNextContinuationToken()
|
||||
{
|
||||
return $this->nextContinuationToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStartAfter()
|
||||
{
|
||||
return $this->startAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getKeyCount()
|
||||
{
|
||||
return $this->keyCount;
|
||||
}
|
||||
|
||||
private $bucketName = "";
|
||||
private $prefix = "";
|
||||
private $maxKeys = 0;
|
||||
private $delimiter = "";
|
||||
private $isTruncated = null;
|
||||
private $objectList = array();
|
||||
private $prefixList = array();
|
||||
private $nextContinuationToken = "";
|
||||
private $continuationToken = "";
|
||||
private $startAfter = "";
|
||||
private $keyCount = 0;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Model;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class TransferAccelerationConfig
|
||||
* @package OSS\Model
|
||||
*/
|
||||
class TransferAccelerationConfig implements XmlConfig
|
||||
{
|
||||
/**
|
||||
* Parse TransferAccelerationConfig from the xml.
|
||||
* @param string $strXml
|
||||
* @throws OssException
|
||||
* @return null
|
||||
*/
|
||||
public function parseFromXml($strXml)
|
||||
{
|
||||
$xml = simplexml_load_string($strXml);
|
||||
if (isset($xml->Enabled)) {
|
||||
$this->enabled = (strval($xml->Enabled) === 'TRUE' || strval($xml->Enabled) === 'true') ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the object into xml string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serializeToXml()
|
||||
{
|
||||
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><TransferAccelerationConfiguration></TransferAccelerationConfiguration>');
|
||||
if (isset($this->enabled)) {
|
||||
if($this->enabled === true){
|
||||
$xml->addChild('Enabled','true');
|
||||
} else {
|
||||
$xml->addChild('Enabled','false');
|
||||
}
|
||||
}
|
||||
return $xml->asXML();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->serializeToXml();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean enabled
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var $enabled boolean
|
||||
*/
|
||||
private $enabled = false;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\CnameTokenInfo;
|
||||
|
||||
class CreateBucketCnameTokenResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return CnameConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$info = new CnameTokenInfo();
|
||||
$info->parseFromXml($content);
|
||||
return $info;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\CnameTokenInfo;
|
||||
|
||||
class GetBucketCnameTokenResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return CnameConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$info = new CnameTokenInfo();
|
||||
$info->parseFromXml($content);
|
||||
return $info;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
use OSS\Model\TransferAccelerationConfig;
|
||||
|
||||
/**
|
||||
* Class GetBucketTransferAccelerationResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetBucketTransferAccelerationResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new TransferAccelerationConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config->getEnabled();
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Model\ObjectInfo;
|
||||
use OSS\Model\ObjectListInfoV2;
|
||||
use OSS\Model\PrefixInfo;
|
||||
|
||||
/**
|
||||
* Class ListObjectsV2Result
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ListObjectsV2Result extends Result
|
||||
{
|
||||
/**
|
||||
* Parse the xml data returned by the ListObjectsV2 interface
|
||||
*
|
||||
* return ObjectListInfoV2
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$xml = new \SimpleXMLElement($this->rawResponse->body);
|
||||
$encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : "";
|
||||
$objectList = $this->parseObjectList($xml, $encodingType);
|
||||
$prefixList = $this->parsePrefixList($xml, $encodingType);
|
||||
$bucketName = isset($xml->Name) ? strval($xml->Name) : "";
|
||||
$prefix = isset($xml->Prefix) ? strval($xml->Prefix) : "";
|
||||
$prefix = OssUtil::decodeKey($prefix, $encodingType);
|
||||
$maxKeys = isset($xml->MaxKeys) ? intval($xml->MaxKeys) : 0;
|
||||
$delimiter = isset($xml->Delimiter) ? strval($xml->Delimiter) : "";
|
||||
$delimiter = OssUtil::decodeKey($delimiter, $encodingType);
|
||||
$isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
|
||||
$continuationToken = isset($xml->ContinuationToken) ? strval($xml->ContinuationToken) : "";
|
||||
$nextContinuationToken = isset($xml->NextContinuationToken) ? strval($xml->NextContinuationToken) : "";
|
||||
$startAfter = isset($xml->StartAfter) ? strval($xml->StartAfter) : "";
|
||||
$startAfter = OssUtil::decodeKey($startAfter, $encodingType);
|
||||
$keyCount = isset($xml->KeyCount) ? intval($xml->KeyCount) : 0;
|
||||
return new ObjectListInfoV2($bucketName, $prefix, $maxKeys, $delimiter, $isTruncated, $objectList, $prefixList, $continuationToken, $nextContinuationToken, $startAfter, $keyCount);
|
||||
}
|
||||
|
||||
private function parseObjectList($xml, $encodingType)
|
||||
{
|
||||
$retList = array();
|
||||
if (isset($xml->Contents)) {
|
||||
foreach ($xml->Contents as $content) {
|
||||
$key = isset($content->Key) ? strval($content->Key) : "";
|
||||
$key = OssUtil::decodeKey($key, $encodingType);
|
||||
$lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
|
||||
$eTag = isset($content->ETag) ? strval($content->ETag) : "";
|
||||
$type = isset($content->Type) ? strval($content->Type) : "";
|
||||
$size = isset($content->Size) ? strval($content->Size) : "0";
|
||||
$storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : "";
|
||||
$retList[] = new ObjectInfo($key, $lastModified, $eTag, $type, $size, $storageClass);
|
||||
}
|
||||
}
|
||||
return $retList;
|
||||
}
|
||||
|
||||
private function parsePrefixList($xml, $encodingType)
|
||||
{
|
||||
$retList = array();
|
||||
if (isset($xml->CommonPrefixes)) {
|
||||
foreach ($xml->CommonPrefixes as $commonPrefix) {
|
||||
$prefix = isset($commonPrefix->Prefix) ? strval($commonPrefix->Prefix) : "";
|
||||
$prefix = OssUtil::decodeKey($prefix, $encodingType);
|
||||
$retList[] = new PrefixInfo($prefix);
|
||||
}
|
||||
}
|
||||
return $retList;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\AclResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class AclResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<AccessControlPolicy>
|
||||
<Owner>
|
||||
<ID>00220120222</ID>
|
||||
<DisplayName>user_example</DisplayName>
|
||||
</Owner>
|
||||
<AccessControlList>
|
||||
<Grant>public-read</Grant>
|
||||
</AccessControlList>
|
||||
</AccessControlPolicy>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<AccessControlPolicy>
|
||||
</AccessControlPolicy>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new AclResult($response);
|
||||
$this->assertEquals("public-read", $result->getData());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
try {
|
||||
new AclResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('body is null', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
try {
|
||||
new AclResult($response);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("xml format exception", $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Result\BodyResult;
|
||||
|
||||
|
||||
class BodyResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testParseValid200()
|
||||
{
|
||||
$response = new ResponseCore(array(), "hi", 200);
|
||||
$result = new BodyResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals($result->getData(), "hi");
|
||||
}
|
||||
|
||||
public function testParseInvalid404()
|
||||
{
|
||||
$response = new ResponseCore(array(), null, 200);
|
||||
$result = new BodyResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals($result->getData(), "");
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\Model\CnameConfig;
|
||||
|
||||
class BucketCnameTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $bucketName;
|
||||
private $client;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = Common::getOssClient();
|
||||
$this->bucketName = 'php-sdk-test-bucket-' . strval(rand(0, 10000));
|
||||
$this->client->createBucket($this->bucketName);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->client->deleteBucket($this->bucketName);
|
||||
}
|
||||
|
||||
public function testBucketWithoutCname()
|
||||
{
|
||||
$cnameConfig = $this->client->getBucketCname($this->bucketName);
|
||||
$this->assertEquals(0, count($cnameConfig->getCnames()));
|
||||
}
|
||||
|
||||
public function testAddCname()
|
||||
{
|
||||
$this->client->addBucketCname($this->bucketName, 'www.baidu.com');
|
||||
$this->client->addBucketCname($this->bucketName, 'www.qq.com');
|
||||
|
||||
$ret = $this->client->getBucketCname($this->bucketName);
|
||||
$this->assertEquals(2, count($ret->getCnames()));
|
||||
|
||||
// add another 2 cnames
|
||||
$this->client->addBucketCname($this->bucketName, 'www.sina.com.cn');
|
||||
$this->client->addBucketCname($this->bucketName, 'www.iqiyi.com');
|
||||
|
||||
$ret = $this->client->getBucketCname($this->bucketName);
|
||||
$cnames = $ret->getCnames();
|
||||
$cnameList = array();
|
||||
|
||||
foreach ($cnames as $c) {
|
||||
$cnameList[] = $c['Domain'];
|
||||
}
|
||||
$should = array(
|
||||
'www.baidu.com',
|
||||
'www.qq.com',
|
||||
'www.sina.com.cn',
|
||||
'www.iqiyi.com'
|
||||
);
|
||||
$this->assertEquals(4, count($cnames));
|
||||
$this->assertEquals(sort($should), sort($cnameList));
|
||||
}
|
||||
|
||||
public function testDeleteCname()
|
||||
{
|
||||
$this->client->addBucketCname($this->bucketName, 'www.baidu.com');
|
||||
$this->client->addBucketCname($this->bucketName, 'www.qq.com');
|
||||
|
||||
$ret = $this->client->getBucketCname($this->bucketName);
|
||||
$this->assertEquals(2, count($ret->getCnames()));
|
||||
|
||||
// delete one cname
|
||||
$this->client->deleteBucketCname($this->bucketName, 'www.baidu.com');
|
||||
|
||||
$ret = $this->client->getBucketCname($this->bucketName);
|
||||
$this->assertEquals(1, count($ret->getCnames()));
|
||||
$cnames = $ret->getCnames();
|
||||
$this->assertEquals('www.qq.com', $cnames[0]['Domain']);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Model\BucketInfo;
|
||||
|
||||
/**
|
||||
* Class BucketInfoTest
|
||||
* @package OSS\Tests
|
||||
*/
|
||||
class BucketInfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$bucketInfo = new BucketInfo('cn-beijing', 'name', 'today');
|
||||
$this->assertNotNull($bucketInfo);
|
||||
$this->assertEquals('cn-beijing', $bucketInfo->getLocation());
|
||||
$this->assertEquals('name', $bucketInfo->getName());
|
||||
$this->assertEquals('today', $bucketInfo->getCreateDate());
|
||||
}
|
||||
}
|
@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\Model\LiveChannelConfig;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class BucketLiveChannelTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $bucketName;
|
||||
private $client;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = Common::getOssClient();
|
||||
$this->bucketName = 'php-sdk-test-rtmp-bucket-name-' . strval(rand(0, 10000));
|
||||
$this->client->createBucket($this->bucketName);
|
||||
Common::waitMetaSync();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
////to delete created bucket
|
||||
//1. delele live channel
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName);
|
||||
if (count($list->getChannelList()) != 0)
|
||||
{
|
||||
foreach($list->getChannelList() as $list)
|
||||
{
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, $list->getName());
|
||||
}
|
||||
}
|
||||
//2. delete exsited object
|
||||
$prefix = 'live-test/';
|
||||
$delimiter = '/';
|
||||
$nextMarker = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'marker' => $nextMarker,
|
||||
);
|
||||
|
||||
try {
|
||||
$listObjectInfo = $this->client->listObjects($this->bucketName, $options);
|
||||
} catch (OssException $e) {
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
$objectList = $listObjectInfo->getObjectList(); // 文件列表
|
||||
if (!empty($objectList))
|
||||
{
|
||||
foreach($objectList as $objectInfo)
|
||||
$this->client->deleteObject($this->bucketName, $objectInfo->getKey());
|
||||
}
|
||||
//3. delete the bucket
|
||||
$this->client->deleteBucket($this->bucketName);
|
||||
}
|
||||
|
||||
public function testPutLiveChannel()
|
||||
{
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel 1',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$info = $this->client->putBucketLiveChannel($this->bucketName, 'live-1', $config);
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, 'live-1');
|
||||
|
||||
$this->assertEquals('live-1', $info->getName());
|
||||
$this->assertEquals('live channel 1', $info->getDescription());
|
||||
$this->assertEquals(1, count($info->getPublishUrls()));
|
||||
$this->assertEquals(1, count($info->getPlayUrls()));
|
||||
}
|
||||
|
||||
public function testPutLiveChannelWithDefaultParams()
|
||||
{
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel 1',
|
||||
'type' => 'HLS',
|
||||
));
|
||||
$info = $this->client->putBucketLiveChannel($this->bucketName, 'live-1', $config);
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, 'live-1');
|
||||
|
||||
$this->assertEquals('live-1', $info->getName());
|
||||
$this->assertEquals('live channel 1', $info->getDescription());
|
||||
$this->assertEquals(1, count($info->getPublishUrls()));
|
||||
$this->assertEquals(1, count($info->getPlayUrls()));
|
||||
}
|
||||
|
||||
public function testListLiveChannels()
|
||||
{
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel 1',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, 'live-1', $config);
|
||||
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel 2',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, 'live-2', $config);
|
||||
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName);
|
||||
|
||||
$this->assertEquals($this->bucketName, $list->getBucketName());
|
||||
$this->assertEquals(false, $list->getIsTruncated());
|
||||
$channels = $list->getChannelList();
|
||||
$this->assertEquals(2, count($channels));
|
||||
|
||||
$chan1 = $channels[0];
|
||||
$this->assertEquals('live-1', $chan1->getName());
|
||||
$this->assertEquals('live channel 1', $chan1->getDescription());
|
||||
$this->assertEquals(1, count($chan1->getPublishUrls()));
|
||||
$this->assertEquals(1, count($chan1->getPlayUrls()));
|
||||
|
||||
$chan2 = $channels[1];
|
||||
$this->assertEquals('live-2', $chan2->getName());
|
||||
$this->assertEquals('live channel 2', $chan2->getDescription());
|
||||
$this->assertEquals(1, count($chan2->getPublishUrls()));
|
||||
$this->assertEquals(1, count($chan2->getPlayUrls()));
|
||||
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName, array(
|
||||
'prefix' => 'live-',
|
||||
'marker' => 'live-1',
|
||||
'max-keys' => 10
|
||||
));
|
||||
$channels = $list->getChannelList();
|
||||
$this->assertEquals(1, count($channels));
|
||||
$chan2 = $channels[0];
|
||||
$this->assertEquals('live-2', $chan2->getName());
|
||||
$this->assertEquals('live channel 2', $chan2->getDescription());
|
||||
$this->assertEquals(1, count($chan2->getPublishUrls()));
|
||||
$this->assertEquals(1, count($chan2->getPlayUrls()));
|
||||
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, 'live-1');
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, 'live-2');
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName, array(
|
||||
'prefix' => 'live-'
|
||||
));
|
||||
$this->assertEquals(0, count($list->getChannelList()));
|
||||
}
|
||||
|
||||
public function testDeleteLiveChannel()
|
||||
{
|
||||
$channelName = 'live-to-delete';
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel to delete',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, $channelName, $config);
|
||||
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, $channelName);
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName, array(
|
||||
'prefix' => $channelName
|
||||
));
|
||||
|
||||
$this->assertEquals(0, count($list->getChannelList()));
|
||||
}
|
||||
|
||||
public function testSignRtmpUrl()
|
||||
{
|
||||
$channelName = '90475';
|
||||
$bucket = 'douyu';
|
||||
$now = time();
|
||||
$url = $this->client->signRtmpUrl($bucket, $channelName, 900, array(
|
||||
'params' => array(
|
||||
'playlistName' => 'playlist.m3u8'
|
||||
)
|
||||
));
|
||||
|
||||
$ret = parse_url($url);
|
||||
$this->assertEquals('rtmp', $ret['scheme']);
|
||||
parse_str($ret['query'], $query);
|
||||
|
||||
$this->assertTrue(isset($query['OSSAccessKeyId']));
|
||||
$this->assertTrue(isset($query['Signature']));
|
||||
$this->assertTrue(intval($query['Expires']) - ($now + 900) < 3);
|
||||
$this->assertEquals('playlist.m3u8', $query['playlistName']);
|
||||
}
|
||||
|
||||
public function testGetgenPreSignedRtmpUrlVsSignedRtmpUrl()
|
||||
{
|
||||
$channelName = '90475';
|
||||
$bucket = 'douyu';
|
||||
$url1 = '245';
|
||||
$url2 = '123';
|
||||
$expiration = 0;
|
||||
|
||||
do {
|
||||
$begin = time();
|
||||
$expiration = time() + 900;
|
||||
$url1 = $this->client->generatePresignedRtmpUrl($bucket, $channelName, $expiration, array(
|
||||
'params' => array(
|
||||
'playlistName' => 'playlist.m3u8'
|
||||
)
|
||||
));
|
||||
|
||||
$url2 = $this->client->signRtmpUrl($bucket, $channelName, 900, array(
|
||||
'params' => array(
|
||||
'playlistName' => 'playlist.m3u8'
|
||||
)
|
||||
));
|
||||
|
||||
$end = time();
|
||||
|
||||
if ($begin == $end)
|
||||
break;
|
||||
usleep(500000);
|
||||
} while (true);
|
||||
$this->assertEquals($url1, $url1);
|
||||
$this->assertTrue(strpos($url1, 'Expires='.$expiration) !== false);
|
||||
}
|
||||
|
||||
public function testLiveChannelInfo()
|
||||
{
|
||||
$channelName = 'live-to-put-status';
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'test live channel info',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, $channelName, $config);
|
||||
|
||||
$info = $this->client->getLiveChannelInfo($this->bucketName, $channelName);
|
||||
$this->assertEquals('test live channel info', $info->getDescription());
|
||||
$this->assertEquals('enabled', $info->getStatus());
|
||||
$this->assertEquals('HLS', $info->getType());
|
||||
$this->assertEquals(10, $info->getFragDuration());
|
||||
$this->assertEquals(5, $info->getFragCount());
|
||||
$this->assertEquals('playlist.m3u8', $info->getPlayListName());
|
||||
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, $channelName);
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName, array(
|
||||
'prefix' => $channelName
|
||||
));
|
||||
$this->assertEquals(0, count($list->getChannelList()));
|
||||
}
|
||||
|
||||
public function testPutLiveChannelStatus()
|
||||
{
|
||||
$channelName = 'live-to-put-status';
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'test live channel info',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, $channelName, $config);
|
||||
|
||||
$info = $this->client->getLiveChannelInfo($this->bucketName, $channelName);
|
||||
$this->assertEquals('test live channel info', $info->getDescription());
|
||||
$this->assertEquals('enabled', $info->getStatus());
|
||||
$this->assertEquals('HLS', $info->getType());
|
||||
$this->assertEquals(10, $info->getFragDuration());
|
||||
$this->assertEquals(5, $info->getFragCount());
|
||||
$this->assertEquals('playlist.m3u8', $info->getPlayListName());
|
||||
$status = $this->client->getLiveChannelStatus($this->bucketName, $channelName);
|
||||
$this->assertEquals('Idle', $status->getStatus());
|
||||
|
||||
|
||||
$resp = $this->client->putLiveChannelStatus($this->bucketName, $channelName, "disabled");
|
||||
$info = $this->client->getLiveChannelInfo($this->bucketName, $channelName);
|
||||
$this->assertEquals('test live channel info', $info->getDescription());
|
||||
$this->assertEquals('disabled', $info->getStatus());
|
||||
$this->assertEquals('HLS', $info->getType());
|
||||
$this->assertEquals(10, $info->getFragDuration());
|
||||
$this->assertEquals(5, $info->getFragCount());
|
||||
$this->assertEquals('playlist.m3u8', $info->getPlayListName());
|
||||
|
||||
$status = $this->client->getLiveChannelStatus($this->bucketName, $channelName);
|
||||
//getLiveChannelInfo
|
||||
$this->assertEquals('Disabled', $status->getStatus());
|
||||
|
||||
$this->client->deleteBucketLiveChannel($this->bucketName, $channelName);
|
||||
$list = $this->client->listBucketLiveChannels($this->bucketName, array(
|
||||
'prefix' => $channelName
|
||||
));
|
||||
$this->assertEquals(0, count($list->getChannelList()));
|
||||
|
||||
}
|
||||
public function testLiveChannelHistory()
|
||||
{
|
||||
$channelName = 'live-test-history';
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'test live channel info',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$this->client->putBucketLiveChannel($this->bucketName, $channelName, $config);
|
||||
|
||||
$history = $this->client->getLiveChannelHistory($this->bucketName, $channelName);
|
||||
$this->assertEquals(0, count($history->getLiveRecordList()));
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Model\CnameConfig;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class CnameConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $xml1 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BucketCnameConfiguration>
|
||||
<Cname>
|
||||
<Domain>www.foo.com</Domain>
|
||||
<Status>enabled</Status>
|
||||
<LastModified>20150101</LastModified>
|
||||
</Cname>
|
||||
<Cname>
|
||||
<Domain>bar.com</Domain>
|
||||
<Status>disabled</Status>
|
||||
<LastModified>20160101</LastModified>
|
||||
</Cname>
|
||||
</BucketCnameConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testFromXml()
|
||||
{
|
||||
$cnameConfig = new CnameConfig();
|
||||
$cnameConfig->parseFromXml($this->xml1);
|
||||
|
||||
$cnames = $cnameConfig->getCnames();
|
||||
$this->assertEquals(2, count($cnames));
|
||||
$this->assertEquals('www.foo.com', $cnames[0]['Domain']);
|
||||
$this->assertEquals('enabled', $cnames[0]['Status']);
|
||||
$this->assertEquals('20150101', $cnames[0]['LastModified']);
|
||||
|
||||
$this->assertEquals('bar.com', $cnames[1]['Domain']);
|
||||
$this->assertEquals('disabled', $cnames[1]['Status']);
|
||||
$this->assertEquals('20160101', $cnames[1]['LastModified']);
|
||||
}
|
||||
|
||||
public function testToXml()
|
||||
{
|
||||
$cnameConfig = new CnameConfig();
|
||||
$cnameConfig->addCname('www.foo.com');
|
||||
$cnameConfig->addCname('bar.com');
|
||||
|
||||
$xml = $cnameConfig->serializeToXml();
|
||||
$comp = new CnameConfig();
|
||||
$comp->parseFromXml($xml);
|
||||
|
||||
$cnames1 = $cnameConfig->getCnames();
|
||||
$cnames2 = $comp->getCnames();
|
||||
|
||||
$this->assertEquals(count($cnames1), count($cnames2));
|
||||
$this->assertEquals(count($cnames1[0]), count($cnames2[0]));
|
||||
$this->assertEquals(1, count($cnames1[0]));
|
||||
$this->assertEquals($cnames1[0]['Domain'], $cnames2[0]['Domain']);
|
||||
}
|
||||
|
||||
public function testCnameNumberLimit()
|
||||
{
|
||||
$cnameConfig = new CnameConfig();
|
||||
for ($i = 0; $i < CnameConfig::OSS_MAX_RULES; $i += 1) {
|
||||
$cnameConfig->addCname(strval($i) . '.foo.com');
|
||||
}
|
||||
try {
|
||||
$cnameConfig->addCname('www.foo.com');
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals(
|
||||
$e->getMessage(),
|
||||
"num of cname in the config exceeds self::OSS_MAX_RULES: " . strval(CnameConfig::OSS_MAX_RULES));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Model\CnameTokenInfo;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class CnameTokenInfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $xml1 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CnameToken>
|
||||
<Bucket>bucket</Bucket>
|
||||
<Cname>www.foo.com</Cname>
|
||||
<Token>1234</Token>
|
||||
<ExpireTime>20150101</ExpireTime>
|
||||
</CnameToken>
|
||||
BBBB;
|
||||
|
||||
public function testFromXml()
|
||||
{
|
||||
$info = new CnameTokenInfo();
|
||||
$info->parseFromXml($this->xml1);
|
||||
|
||||
$this->assertEquals('bucket', $info->getBucket());
|
||||
$this->assertEquals('www.foo.com', $info->getCname());
|
||||
$this->assertEquals('1234', $info->getToken());
|
||||
$this->assertEquals('20150101', $info->getExpireTime());
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/../../../autoload.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class Common
|
||||
*
|
||||
* Sample program [Samples / *. Php] Common class, used to obtain OssClient instance and other public methods
|
||||
*/
|
||||
class Common
|
||||
{
|
||||
/**
|
||||
* According to the Config configuration, get an OssClient instance
|
||||
*
|
||||
* @return OssClient An OssClient instance
|
||||
*/
|
||||
public static function getOssClient()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
getenv('OSS_ACCESS_KEY_ID'),
|
||||
getenv('OSS_ACCESS_KEY_SECRET'),
|
||||
getenv('OSS_ENDPOINT'), false);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return null;
|
||||
}
|
||||
return $ossClient;
|
||||
}
|
||||
|
||||
public static function getBucketName()
|
||||
{
|
||||
return getenv('OSS_BUCKET');
|
||||
}
|
||||
|
||||
public static function getRegion()
|
||||
{
|
||||
return getenv('OSS_REGION');
|
||||
}
|
||||
|
||||
public static function getCallbackUrl()
|
||||
{
|
||||
return getenv('OSS_CALLBACK_URL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool method, create a bucket
|
||||
*/
|
||||
public static function createBucket()
|
||||
{
|
||||
$ossClient = self::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = self::getBucketName();
|
||||
$acl = OssClient::OSS_ACL_TYPE_PUBLIC_READ;
|
||||
try {
|
||||
$ossClient->createBucket($bucket, $acl);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for bucket meta sync
|
||||
*/
|
||||
public static function waitMetaSync()
|
||||
{
|
||||
if (getenv('TRAVIS')) {
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
class ContentTypeTest extends TestOssClientBase
|
||||
{
|
||||
private function runCmd($cmd)
|
||||
{
|
||||
$output = array();
|
||||
$status = 0;
|
||||
exec($cmd . ' 2>/dev/null', $output, $status);
|
||||
|
||||
$this->assertEquals(0, $status);
|
||||
}
|
||||
|
||||
private function getContentType($bucket, $object)
|
||||
{
|
||||
$client = $this->ossClient;
|
||||
$headers = $client->getObjectMeta($bucket, $object);
|
||||
return $headers['content-type'];
|
||||
}
|
||||
|
||||
public function testByFileName()
|
||||
{
|
||||
$client = $this->ossClient;
|
||||
$bucket = $this->bucket;
|
||||
|
||||
$file = '/tmp/x.html';
|
||||
$object = 'test/x';
|
||||
$this->runCmd('touch ' . $file);
|
||||
|
||||
$client->uploadFile($bucket, $object, $file);
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('text/html', $type);
|
||||
|
||||
$file = '/tmp/x.json';
|
||||
$object = 'test/y';
|
||||
$this->runCmd('dd if=/dev/urandom of=' . $file . ' bs=1024 count=100');
|
||||
|
||||
$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('application/json', $type);
|
||||
}
|
||||
|
||||
public function testByObjectKey()
|
||||
{
|
||||
$client = $this->ossClient;
|
||||
$bucket = $this->bucket;
|
||||
|
||||
$object = "test/x.txt";
|
||||
$client->putObject($bucket, $object, "hello world");
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('text/plain', $type);
|
||||
|
||||
$file = '/tmp/x.html';
|
||||
$object = 'test/x.txt';
|
||||
$this->runCmd('touch ' . $file);
|
||||
|
||||
$client->uploadFile($bucket, $object, $file);
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('text/html', $type);
|
||||
|
||||
$file = '/tmp/x.none';
|
||||
$object = 'test/x.txt';
|
||||
$this->runCmd('touch ' . $file);
|
||||
|
||||
$client->uploadFile($bucket, $object, $file);
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('text/plain', $type);
|
||||
|
||||
$file = '/tmp/x.mp3';
|
||||
$object = 'test/y.json';
|
||||
$this->runCmd('dd if=/dev/urandom of=' . $file . ' bs=1024 count=100');
|
||||
|
||||
$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('audio/mpeg', $type);
|
||||
|
||||
$file = '/tmp/x.none';
|
||||
$object = 'test/y.json';
|
||||
$this->runCmd('dd if=/dev/urandom of=' . $file . ' bs=1024 count=100');
|
||||
|
||||
$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('application/json', $type);
|
||||
}
|
||||
|
||||
public function testByUser()
|
||||
{
|
||||
$client = $this->ossClient;
|
||||
$bucket = $this->bucket;
|
||||
|
||||
$object = "test/x.txt";
|
||||
$client->putObject($bucket, $object, "hello world", array(
|
||||
'Content-Type' => 'text/html'
|
||||
));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('text/html', $type);
|
||||
|
||||
$file = '/tmp/x.html';
|
||||
$object = 'test/x';
|
||||
$this->runCmd('touch ' . $file);
|
||||
|
||||
$client->uploadFile($bucket, $object, $file, array(
|
||||
'Content-Type' => 'application/json'
|
||||
));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('application/json', $type);
|
||||
|
||||
$file = '/tmp/x.json';
|
||||
$object = 'test/y';
|
||||
$this->runCmd('dd if=/dev/urandom of=' . $file . ' bs=1024 count=100');
|
||||
|
||||
$client->multiuploadFile($bucket, $object, $file, array(
|
||||
'partSize' => 100,
|
||||
'Content-Type' => 'audio/mpeg'
|
||||
));
|
||||
$type = $this->getContentType($bucket, $object);
|
||||
|
||||
$this->assertEquals('audio/mpeg', $type);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Result\CopyObjectResult;
|
||||
|
||||
class CopyObjectResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $body = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CopyObjectResult>
|
||||
<LastModified>Fri, 24 Feb 2012 07:18:48 GMT</LastModified>
|
||||
<ETag>"5B3C1A2E053D763E1B002CC607C5A0FE"</ETag>
|
||||
</CopyObjectResult>
|
||||
BBBB;
|
||||
|
||||
public function testNullResponse()
|
||||
{
|
||||
$response = null;
|
||||
try {
|
||||
new CopyObjectResult($response);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('raw response is null', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testOkResponse()
|
||||
{
|
||||
$header= array();
|
||||
$response = new ResponseCore($header, $this->body, 200);
|
||||
$result = new CopyObjectResult($response);
|
||||
$data = $result->getData();
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals("Fri, 24 Feb 2012 07:18:48 GMT", $data[0]);
|
||||
$this->assertEquals("\"5B3C1A2E053D763E1B002CC607C5A0FE\"", $data[1]);
|
||||
}
|
||||
|
||||
public function testFailResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 404);
|
||||
try {
|
||||
new CopyObjectResult($response);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Model\CorsConfig;
|
||||
use OSS\Model\CorsRule;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class CorsConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CORSConfiguration>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>http://www.b.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<AllowedMethod>PUT</AllowedMethod>
|
||||
<AllowedMethod>POST</AllowedMethod>
|
||||
<AllowedHeader>x-oss-test</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test3</AllowedHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test2</ExposeHeader>
|
||||
<MaxAgeSeconds>10</MaxAgeSeconds>
|
||||
</CORSRule>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>http://www.b.com</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<AllowedHeader>x-oss-test</AllowedHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<MaxAgeSeconds>110</MaxAgeSeconds>
|
||||
</CORSRule>
|
||||
</CORSConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CORSConfiguration>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>http://www.b.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<AllowedMethod>PUT</AllowedMethod>
|
||||
<AllowedMethod>POST</AllowedMethod>
|
||||
<AllowedHeader>x-oss-test</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test3</AllowedHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test2</ExposeHeader>
|
||||
<MaxAgeSeconds>10</MaxAgeSeconds>
|
||||
</CORSRule>
|
||||
</CORSConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$corsConfig->parseFromXml($this->validXml);
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($corsConfig->serializeToXml()));
|
||||
$this->assertNotNull($corsConfig->getRules());
|
||||
$rules = $corsConfig->getRules();
|
||||
$this->assertNotNull($rules[0]->getAllowedHeaders());
|
||||
$this->assertNotNull($rules[0]->getAllowedMethods());
|
||||
$this->assertNotNull($rules[0]->getAllowedOrigins());
|
||||
$this->assertNotNull($rules[0]->getExposeHeaders());
|
||||
$this->assertNotNull($rules[0]->getMaxAgeSeconds());
|
||||
}
|
||||
|
||||
public function testParseValidXml2()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$corsConfig->parseFromXml($this->validXml2);
|
||||
$this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml($corsConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
public function testCreateCorsConfigFromMoreThan10Rules()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
for ($i = 0; $i < CorsConfig::OSS_MAX_RULES; $i += 1) {
|
||||
$corsConfig->addRule($rule);
|
||||
}
|
||||
try {
|
||||
$corsConfig->addRule($rule);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals($e->getMessage(), "num of rules in the config exceeds self::OSS_MAX_RULES: " . strval(CorsConfig::OSS_MAX_RULES));
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateCorsConfigParamAbsent()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
$corsConfig->addRule($rule);
|
||||
|
||||
try {
|
||||
$xml = $corsConfig->serializeToXml();
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals($e->getMessage(), "maxAgeSeconds is not set in the Rule");
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateCorsConfigFromScratch()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
$rule->addAllowedHeader("x-oss-test");
|
||||
$rule->addAllowedHeader("x-oss-test2");
|
||||
$rule->addAllowedHeader("x-oss-test2");
|
||||
$rule->addAllowedHeader("x-oss-test3");
|
||||
$rule->addAllowedOrigin("http://www.b.com");
|
||||
$rule->addAllowedOrigin("http://www.a.com");
|
||||
$rule->addAllowedOrigin("http://www.a.com");
|
||||
$rule->addAllowedMethod("GET");
|
||||
$rule->addAllowedMethod("PUT");
|
||||
$rule->addAllowedMethod("POST");
|
||||
$rule->addExposeHeader("x-oss-test1");
|
||||
$rule->addExposeHeader("x-oss-test1");
|
||||
$rule->addExposeHeader("x-oss-test2");
|
||||
$rule->setMaxAgeSeconds(10);
|
||||
$corsConfig->addRule($rule);
|
||||
$this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml($corsConfig->serializeToXml()));
|
||||
$this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml(strval($corsConfig)));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\DeleteObjectVersionsResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class DeleteObjectVersionsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
<Deleted>
|
||||
<Key>demo.jpg</Key>
|
||||
<VersionId>CAEQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****</VersionId>
|
||||
<DeleteMarker>true</DeleteMarker>
|
||||
<DeleteMarkerVersionId>111111</DeleteMarkerVersionId>
|
||||
</Deleted>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml1 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
<Deleted>
|
||||
<Key>multipart.data</Key>
|
||||
<VersionId>CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****</VersionId>
|
||||
</Deleted>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
<Deleted>
|
||||
<Key>multipart.data</Key>
|
||||
<DeleteMarker>true</DeleteMarker>
|
||||
<DeleteMarkerVersionId>CAEQMhiBgIDXiaaB0BYiIGQzYmRkZGUxMTM1ZDRjOTZhNjk4YjRjMTAyZjhl****</DeleteMarkerVersionId>
|
||||
</Deleted>
|
||||
<Deleted>
|
||||
<Key>test.jpg</Key>
|
||||
<DeleteMarker>true</DeleteMarker>
|
||||
<DeleteMarkerVersionId>CAEQMhiBgIDB3aWB0BYiIGUzYTA3YzliMzVmNzRkZGM5NjllYTVlMjYyYWEy****</DeleteMarkerVersionId>
|
||||
</Deleted>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml3 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
<Deleted>
|
||||
<Key>multipart.data</Key>
|
||||
</Deleted>
|
||||
<Deleted>
|
||||
<Key>test.jpg</Key>
|
||||
</Deleted>
|
||||
<Deleted>
|
||||
<Key>demo.jpg</Key>
|
||||
</Deleted>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml4 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
<EncodingType>url</EncodingType>
|
||||
<Deleted>
|
||||
<Key>multipart%2F.data</Key>
|
||||
</Deleted>
|
||||
<Deleted>
|
||||
<Key>test%2F.jpg</Key>
|
||||
</Deleted>
|
||||
<Deleted>
|
||||
<Key>demo%2F.jpg</Key>
|
||||
</Deleted>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<DeleteResult>
|
||||
</DeleteResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(1, count($list));
|
||||
$this->assertEquals('demo.jpg', $list[0]->getKey());
|
||||
$this->assertEquals('CAEQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****', $list[0]->getVersionId());
|
||||
$this->assertEquals('true', $list[0]->getDeleteMarker());
|
||||
$this->assertEquals('111111', $list[0]->getDeleteMarkerVersionId());
|
||||
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(1, count($list));
|
||||
$this->assertEquals('multipart.data', $list[0]->getKey());
|
||||
$this->assertEquals('CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****', $list[0]->getVersionId());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarkerVersionId());
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(2, count($list));
|
||||
$this->assertEquals('multipart.data', $list[0]->getKey());
|
||||
$this->assertEquals('', $list[0]->getVersionId());
|
||||
$this->assertEquals('true', $list[0]->getDeleteMarker());
|
||||
$this->assertEquals('CAEQMhiBgIDXiaaB0BYiIGQzYmRkZGUxMTM1ZDRjOTZhNjk4YjRjMTAyZjhl****', $list[0]->getDeleteMarkerVersionId());
|
||||
$this->assertEquals('test.jpg', $list[1]->getKey());
|
||||
$this->assertEquals('', $list[1]->getVersionId());
|
||||
$this->assertEquals('true', $list[1]->getDeleteMarker());
|
||||
$this->assertEquals('CAEQMhiBgIDB3aWB0BYiIGUzYTA3YzliMzVmNzRkZGM5NjllYTVlMjYyYWEy****', $list[1]->getDeleteMarkerVersionId());
|
||||
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml3, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(3, count($list));
|
||||
$this->assertEquals('multipart.data', $list[0]->getKey());
|
||||
$this->assertEquals('', $list[0]->getVersionId());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarkerVersionId());
|
||||
$this->assertEquals('test.jpg', $list[1]->getKey());
|
||||
$this->assertEquals('', $list[1]->getVersionId());
|
||||
$this->assertEquals('', $list[1]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[1]->getDeleteMarkerVersionId());
|
||||
$this->assertEquals('demo.jpg', $list[2]->getKey());
|
||||
$this->assertEquals('', $list[2]->getVersionId());
|
||||
$this->assertEquals('', $list[2]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[2]->getDeleteMarkerVersionId());
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml4, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(3, count($list));
|
||||
$this->assertEquals('multipart/.data', $list[0]->getKey());
|
||||
$this->assertEquals('', $list[0]->getVersionId());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[0]->getDeleteMarkerVersionId());
|
||||
$this->assertEquals('test/.jpg', $list[1]->getKey());
|
||||
$this->assertEquals('', $list[1]->getVersionId());
|
||||
$this->assertEquals('', $list[1]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[1]->getDeleteMarkerVersionId());
|
||||
$this->assertEquals('demo/.jpg', $list[2]->getKey());
|
||||
$this->assertEquals('', $list[2]->getVersionId());
|
||||
$this->assertEquals('', $list[2]->getDeleteMarker());
|
||||
$this->assertEquals('', $list[2]->getDeleteMarkerVersionId());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(0, count($list));
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new DeleteObjectVersionsResult($response);
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(0, count($list));
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Result\ExistResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class ExistResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testParseValid200()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new ExistResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals($result->getData(), true);
|
||||
}
|
||||
|
||||
public function testParseInvalid404()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 404);
|
||||
$result = new ExistResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals($result->getData(), false);
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 300);
|
||||
try {
|
||||
new ExistResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketEncryptionResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketEncryptionResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ServerSideEncryptionRule>
|
||||
<ApplyServerSideEncryptionByDefault>
|
||||
<SSEAlgorithm>AES256</SSEAlgorithm>
|
||||
<KMSMasterKeyID></KMSMasterKeyID>
|
||||
</ApplyServerSideEncryptionByDefault>
|
||||
</ServerSideEncryptionRule>
|
||||
BBBB;
|
||||
|
||||
private $validXml1 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ServerSideEncryptionRule>
|
||||
<ApplyServerSideEncryptionByDefault>
|
||||
<SSEAlgorithm>KMS</SSEAlgorithm>
|
||||
<KMSMasterKeyID>kms-id</KMSMasterKeyID>
|
||||
</ApplyServerSideEncryptionByDefault>
|
||||
</ServerSideEncryptionRule>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ServerSideEncryptionRule>
|
||||
<ApplyServerSideEncryptionByDefault>
|
||||
<SSEAlgorithm>KMS</SSEAlgorithm>
|
||||
</ApplyServerSideEncryptionByDefault>
|
||||
</ServerSideEncryptionRule>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ServerSideEncryptionRule>
|
||||
</ServerSideEncryptionRule>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketEncryptionResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("AES256", $config->getSSEAlgorithm());
|
||||
$this->assertEquals("", $config->getKMSMasterKeyID());
|
||||
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new GetBucketEncryptionResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("KMS", $config->getSSEAlgorithm());
|
||||
$this->assertEquals("kms-id", $config->getKMSMasterKeyID());
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new GetBucketEncryptionResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("KMS", $config->getSSEAlgorithm());
|
||||
$this->assertEquals(null, $config->getKMSMasterKeyID());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new GetBucketEncryptionResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(null, $config->getSSEAlgorithm());
|
||||
$this->assertEquals(null, $config->getKMSMasterKeyID());
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new GetBucketEncryptionResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(null, $config->getSSEAlgorithm());
|
||||
$this->assertEquals(null, $config->getKMSMasterKeyID());
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketRequestPaymentResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketRequestPaymentResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<RequestPaymentConfiguration>
|
||||
<Payer>Requester</Payer>
|
||||
</RequestPaymentConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<RequestPaymentConfiguration>
|
||||
<Payer>BucketOwner</Payer>
|
||||
</RequestPaymentConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<RequestPaymentConfiguration>
|
||||
</RequestPaymentConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketRequestPaymentResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$payer = $result->getData();
|
||||
$this->assertEquals("Requester", $payer);
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new GetBucketRequestPaymentResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$payer = $result->getData();
|
||||
$this->assertEquals("BucketOwner", $payer);
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new GetBucketRequestPaymentResult($response);
|
||||
$payer = $result->getData();
|
||||
$this->assertEquals(null, $payer);
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new GetBucketRequestPaymentResult($response);
|
||||
$payer = $result->getData();
|
||||
$this->assertEquals(null, $payer);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketStatResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketStatResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<BucketStat>
|
||||
<Storage>100</Storage>
|
||||
<ObjectCount>200</ObjectCount>
|
||||
<MultipartUploadCount>10</MultipartUploadCount>
|
||||
</BucketStat>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<BucketStat>
|
||||
</BucketStat>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketStatResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$stat = $result->getData();
|
||||
$this->assertEquals(100, $stat->getStorage());
|
||||
$this->assertEquals(200, $stat->getObjectCount());
|
||||
$this->assertEquals(10, $stat->getMultipartUploadCount());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new GetBucketStatResult($response);
|
||||
$stat = $result->getData();
|
||||
$this->assertEquals(0, $stat->getStorage());
|
||||
$this->assertEquals(0, $stat->getObjectCount());
|
||||
$this->assertEquals(0, $stat->getMultipartUploadCount());
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new GetBucketStatResult($response);
|
||||
$stat = $result->getData();
|
||||
$this->assertEquals(0, $stat->getStorage());
|
||||
$this->assertEquals(0, $stat->getObjectCount());
|
||||
$this->assertEquals(0, $stat->getMultipartUploadCount());
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketTagsResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketTagsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<Tagging>
|
||||
<TagSet>
|
||||
<Tag>
|
||||
<Key>testa</Key>
|
||||
<Value>value1-test</Value>
|
||||
</Tag>
|
||||
<Tag>
|
||||
<Key>testb</Key>
|
||||
<Value>value2-test</Value>
|
||||
</Tag>
|
||||
</TagSet>
|
||||
</Tagging>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<Tagging>
|
||||
</Tagging>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<Tagging>
|
||||
<TagSet>
|
||||
</TagSet>
|
||||
</Tagging>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketTagsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(2, count($config->getTags()));
|
||||
$this->assertEquals("testa", $config->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1-test", $config->getTags()[0]->getValue());
|
||||
$this->assertEquals("testb", $config->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2-test", $config->getTags()[1]->getValue());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new GetBucketTagsResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(0, count($config->getTags()));
|
||||
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new GetBucketTagsResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(0, count($config->getTags()));
|
||||
|
||||
$response = new ResponseCore(array(), $this->invalidXml2, 200);
|
||||
$result = new GetBucketTagsResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals(0, count($config->getTags()));
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketTransferAccelerationResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketTransferAccelerationResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<TransferAccelerationConfiguration>
|
||||
<Enabled>true</Enabled>
|
||||
</TransferAccelerationConfiguration>
|
||||
BBBB;
|
||||
private $validXml1 = <<<BBBB
|
||||
<TransferAccelerationConfiguration>
|
||||
<Enabled>false</Enabled>
|
||||
</TransferAccelerationConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<TransferAccelerationConfiguration>
|
||||
</TransferAccelerationConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketTransferAccelerationResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$enabled = $result->getData();
|
||||
$this->assertEquals(true, $enabled);
|
||||
}
|
||||
|
||||
public function testParseValidXml1()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new GetBucketTransferAccelerationResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$enabled = $result->getData();
|
||||
$this->assertEquals(false, $enabled);
|
||||
}
|
||||
|
||||
public function testParseInvalidXml2()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml2, 200);
|
||||
$result = new GetBucketTransferAccelerationResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$this->assertNotNull($result->getRawResponse()->body);
|
||||
$enabled = $result->getData();
|
||||
$this->assertEquals(false, $enabled);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetBucketWormResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetBucketWormResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<WormConfiguration>
|
||||
<WormId>ID1</WormId>
|
||||
<State>Locked</State>
|
||||
<RetentionPeriodInDays>1</RetentionPeriodInDays>
|
||||
<CreationDate>2018-08-14T15:50:32</CreationDate>
|
||||
</WormConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<WormConfiguration>
|
||||
<WormId>ID2</WormId>
|
||||
<State>InProgress</State>
|
||||
<RetentionPeriodInDays>10</RetentionPeriodInDays>
|
||||
<CreationDate>2018-09-14T15:50:32</CreationDate>
|
||||
</WormConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<WormConfiguration>
|
||||
</WormConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetBucketWormResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("ID1", $config->getWormId());
|
||||
$this->assertEquals("Locked", $config->getState());
|
||||
$this->assertEquals(1, $config->getDay());
|
||||
$this->assertEquals("2018-08-14T15:50:32", $config->getCreationDate());
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new GetBucketWormResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("ID2", $config->getWormId());
|
||||
$this->assertEquals("InProgress", $config->getState());
|
||||
$this->assertEquals(10, $config->getDay());
|
||||
$this->assertEquals("2018-09-14T15:50:32", $config->getCreationDate());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new GetBucketWormResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("", $config->getWormId());
|
||||
$this->assertEquals("", $config->getState());
|
||||
$this->assertEquals(0, $config->getDay());
|
||||
$this->assertEquals("", $config->getCreationDate());
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new GetBucketWormResult($response);
|
||||
$config = $result->getData();
|
||||
$this->assertEquals("", $config->getWormId());
|
||||
$this->assertEquals("", $config->getState());
|
||||
$this->assertEquals(0, $config->getDay());
|
||||
$this->assertEquals("", $config->getCreationDate());
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Result\GetCorsResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class GetCorsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CORSConfiguration>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>http://www.b.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedOrigin>http://www.a.com</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<AllowedMethod>PUT</AllowedMethod>
|
||||
<AllowedMethod>POST</AllowedMethod>
|
||||
<AllowedHeader>x-oss-test</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test2</AllowedHeader>
|
||||
<AllowedHeader>x-oss-test3</AllowedHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<ExposeHeader>x-oss-test2</ExposeHeader>
|
||||
<MaxAgeSeconds>10</MaxAgeSeconds>
|
||||
</CORSRule>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>http://www.b.com</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<AllowedHeader>x-oss-test</AllowedHeader>
|
||||
<ExposeHeader>x-oss-test1</ExposeHeader>
|
||||
<MaxAgeSeconds>110</MaxAgeSeconds>
|
||||
</CORSRule>
|
||||
</CORSConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetCorsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$corsConfig = $result->getData();
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($corsConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 300);
|
||||
try {
|
||||
$result = new GetCorsResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LifecycleConfig;
|
||||
use OSS\Result\GetLifecycleResult;
|
||||
|
||||
class GetLifecycleResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>delete obsoleted files</ID>
|
||||
<Prefix>obsoleted/</Prefix>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Days>3</Days></Expiration>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<ID>delete temporary files</ID>
|
||||
<Prefix>temporary/</Prefix>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Date>2022-10-12T00:00:00.000Z</Date></Expiration>
|
||||
<Expiration2><Date>2022-10-12T00:00:00.000Z</Date></Expiration2>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetLifecycleResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$lifecycleConfig = $result->getData();
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($lifecycleConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 300);
|
||||
try {
|
||||
$result = new GetLifecycleResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Result\GetLoggingResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
|
||||
class GetLoggingResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BucketLoggingStatus>
|
||||
<LoggingEnabled>
|
||||
<TargetBucket>TargetBucket</TargetBucket>
|
||||
<TargetPrefix>TargetPrefix</TargetPrefix>
|
||||
</LoggingEnabled>
|
||||
</BucketLoggingStatus>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetLoggingResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$loggingConfig = $result->getData();
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($loggingConfig->serializeToXml()));
|
||||
$this->assertEquals("TargetBucket", $loggingConfig->getTargetBucket());
|
||||
$this->assertEquals("TargetPrefix", $loggingConfig->getTargetPrefix());
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 300);
|
||||
try {
|
||||
$result = new GetLoggingResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\GetRefererResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
|
||||
class GetRefererResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RefererConfiguration>
|
||||
<AllowEmptyReferer>true</AllowEmptyReferer>
|
||||
<RefererList>
|
||||
<Referer>http://www.aliyun.com</Referer>
|
||||
<Referer>https://www.aliyun.com</Referer>
|
||||
<Referer>http://www.*.com</Referer>
|
||||
<Referer>https://www.?.aliyuncs.com</Referer>
|
||||
</RefererList>
|
||||
</RefererConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetRefererResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$refererConfig = $result->getData();
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($refererConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 300);
|
||||
try {
|
||||
$result = new GetRefererResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Result\GetWebsiteResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class GetWebsiteResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<WebsiteConfiguration>
|
||||
<IndexDocument>
|
||||
<Suffix>index.html</Suffix>
|
||||
</IndexDocument>
|
||||
<ErrorDocument>
|
||||
<Key>errorDocument.html</Key>
|
||||
</ErrorDocument>
|
||||
</WebsiteConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetWebsiteResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$websiteConfig = $result->getData();
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 300);
|
||||
try {
|
||||
$result = new GetWebsiteResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\HeaderResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
/**
|
||||
* Class HeaderResultTest
|
||||
* @package OSS\Tests
|
||||
*/
|
||||
class HeaderResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetHeader()
|
||||
{
|
||||
$response = new ResponseCore(array('key' => 'value'), "", 200);
|
||||
$result = new HeaderResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertTrue(is_array($result->getData()));
|
||||
$data = $result->getData();
|
||||
$this->assertEquals($data['key'], 'value');
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Http\RequestCore_Exception;
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
|
||||
class HttpTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testResponseCore()
|
||||
{
|
||||
$res = new ResponseCore(null, "", 500);
|
||||
$this->assertFalse($res->isOK());
|
||||
$this->assertTrue($res->isOK(500));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$httpCore = new RequestCore("http://www.baidu.com");
|
||||
$httpResponse = $httpCore->send_request();
|
||||
$this->assertNotNull($httpResponse);
|
||||
}
|
||||
|
||||
public function testSetProxyAndTimeout()
|
||||
{
|
||||
$httpCore = new RequestCore("http://www.baidu.com");
|
||||
$httpCore->set_proxy("1.0.2.1:8888");
|
||||
$httpCore->connect_timeout = 1;
|
||||
try {
|
||||
$httpResponse = $httpCore->send_request();
|
||||
$this->assertTrue(false);
|
||||
} catch (RequestCore_Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetParseTrue()
|
||||
{
|
||||
$httpCore = new RequestCore("http://www.baidu.com");
|
||||
$httpCore->curlopts = array(CURLOPT_HEADER => true);
|
||||
$url = $httpCore->send_request(true);
|
||||
foreach ($httpCore->get_response_header() as $key => $value) {
|
||||
$this->assertEquals($httpCore->get_response_header($key), $value);
|
||||
}
|
||||
$this->assertNotNull($url);
|
||||
}
|
||||
|
||||
public function testParseResponse()
|
||||
{
|
||||
$httpCore = new RequestCore("http://www.baidu.com");
|
||||
$response = $httpCore->send_request();
|
||||
$parsed = $httpCore->process_response(null, $response);
|
||||
$this->assertNotNull($parsed);
|
||||
}
|
||||
|
||||
public function testExceptionGet()
|
||||
{
|
||||
$httpCore = null;
|
||||
$exception = false;
|
||||
try {
|
||||
$httpCore = new RequestCore("http://www.notexistsitexx.com");
|
||||
$httpCore->set_body("");
|
||||
$httpCore->set_method("GET");
|
||||
$httpCore->connect_timeout = 10;
|
||||
$httpCore->timeout = 10;
|
||||
$res = $httpCore->send_request();
|
||||
} catch (RequestCore_Exception $e) {
|
||||
$exception = true;
|
||||
}
|
||||
$this->assertTrue($exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Result\InitiateMultipartUploadResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class InitiateMultipartUploadResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<InitiateMultipartUploadResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
|
||||
<Bucket> multipart_upload</Bucket>
|
||||
<Key>multipart.data</Key>
|
||||
<UploadId>0004B9894A22E5B1888A1E29F8236E2D</UploadId>
|
||||
</InitiateMultipartUploadResult>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<InitiateMultipartUploadResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
|
||||
<Bucket> multipart_upload</Bucket>
|
||||
<Key>multipart.data</Key>
|
||||
</InitiateMultipartUploadResult>
|
||||
BBBB;
|
||||
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new InitiateMultipartUploadResult($response);
|
||||
$this->assertEquals("0004B9894A22E5B1888A1E29F8236E2D", $result->getData());
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
try {
|
||||
$result = new InitiateMultipartUploadResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LifecycleAction;
|
||||
use OSS\Model\LifecycleConfig;
|
||||
use OSS\Model\LifecycleRule;
|
||||
|
||||
class LifecycleConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validLifecycle = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>delete obsoleted files</ID>
|
||||
<Prefix>obsoleted/</Prefix>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Days>3</Days></Expiration>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<ID>delete temporary files</ID>
|
||||
<Prefix>temporary/</Prefix>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Date>2022-10-12T00:00:00.000Z</Date></Expiration>
|
||||
<Expiration2><Date>2022-10-12T00:00:00.000Z</Date></Expiration2>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $validLifecycle2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LifecycleConfiguration>
|
||||
<Rule><ID>delete temporary files</ID>
|
||||
<Prefix>temporary/</Prefix>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Date>2022-10-12T00:00:00.000Z</Date></Expiration>
|
||||
<Expiration2><Date>2022-10-12T00:00:00.000Z</Date></Expiration2>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $nullLifecycle = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LifecycleConfiguration/>
|
||||
BBBB;
|
||||
|
||||
public function testConstructValidConfig()
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction("Expiration", "Days", 3);
|
||||
$lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction("Expiration", "Date", '2022-10-12T00:00:00.000Z');
|
||||
$actions[] = new LifecycleAction("Expiration2", "Date", '2022-10-12T00:00:00.000Z');
|
||||
$lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
try {
|
||||
$lifecycleConfig->addRule(null);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('lifecycleRule is null', $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($this->cleanXml(strval($lifecycleConfig)), $this->cleanXml($this->validLifecycle));
|
||||
}
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$lifecycleConfig->parseFromXml($this->validLifecycle);
|
||||
$this->assertEquals($this->cleanXml($lifecycleConfig->serializeToXml()), $this->cleanXml($this->validLifecycle));
|
||||
$this->assertEquals(2, count($lifecycleConfig->getRules()));
|
||||
$rules = $lifecycleConfig->getRules();
|
||||
$this->assertEquals('delete temporary files', $rules[1]->getId());
|
||||
}
|
||||
|
||||
public function testParseValidXml2()
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$lifecycleConfig->parseFromXml($this->validLifecycle2);
|
||||
$this->assertEquals($this->cleanXml($lifecycleConfig->serializeToXml()), $this->cleanXml($this->validLifecycle2));
|
||||
$this->assertEquals(1, count($lifecycleConfig->getRules()));
|
||||
$rules = $lifecycleConfig->getRules();
|
||||
$this->assertEquals('delete temporary files', $rules[0]->getId());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$lifecycleConfig->parseFromXml($this->nullLifecycle);
|
||||
$this->assertEquals($this->cleanXml($lifecycleConfig->serializeToXml()), $this->cleanXml($this->nullLifecycle));
|
||||
$this->assertEquals(0, count($lifecycleConfig->getRules()));
|
||||
}
|
||||
|
||||
public function testLifecycleRule()
|
||||
{
|
||||
$lifecycleRule = new LifecycleRule("x", "x", "x", array('x'));
|
||||
$lifecycleRule->setId("id");
|
||||
$lifecycleRule->setPrefix("prefix");
|
||||
$lifecycleRule->setStatus("Enabled");
|
||||
$lifecycleRule->setActions(array());
|
||||
|
||||
$this->assertEquals('id', $lifecycleRule->getId());
|
||||
$this->assertEquals('prefix', $lifecycleRule->getPrefix());
|
||||
$this->assertEquals('Enabled', $lifecycleRule->getStatus());
|
||||
$this->assertEmpty($lifecycleRule->getActions());
|
||||
}
|
||||
|
||||
public function testLifecycleAction()
|
||||
{
|
||||
$action = new LifecycleAction('x', 'x', 'x');
|
||||
$this->assertEquals($action->getAction(), 'x');
|
||||
$this->assertEquals($action->getTimeSpec(), 'x');
|
||||
$this->assertEquals($action->getTimeValue(), 'x');
|
||||
$action->setAction('y');
|
||||
$action->setTimeSpec('y');
|
||||
$action->setTimeValue('y');
|
||||
$this->assertEquals($action->getAction(), 'y');
|
||||
$this->assertEquals($action->getTimeSpec(), 'y');
|
||||
$this->assertEquals($action->getTimeValue(), 'y');
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Result\ListBucketsResult;
|
||||
|
||||
class ListBucketsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListAllMyBucketsResult>
|
||||
<Owner>
|
||||
<ID>ut_test_put_bucket</ID>
|
||||
<DisplayName>ut_test_put_bucket</DisplayName>
|
||||
</Owner>
|
||||
<Buckets>
|
||||
<Bucket>
|
||||
<Location>oss-cn-hangzhou-a</Location>
|
||||
<Name>xz02tphky6fjfiuc0</Name>
|
||||
<CreationDate>2014-05-15T11:18:32.000Z</CreationDate>
|
||||
</Bucket>
|
||||
<Bucket>
|
||||
<Location>oss-cn-hangzhou-a</Location>
|
||||
<Name>xz02tphky6fjfiuc1</Name>
|
||||
<CreationDate>2014-05-15T11:18:32.000Z</CreationDate>
|
||||
</Bucket>
|
||||
</Buckets>
|
||||
</ListAllMyBucketsResult>
|
||||
BBBB;
|
||||
|
||||
private $nullXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListAllMyBucketsResult>
|
||||
<Owner>
|
||||
<ID>ut_test_put_bucket</ID>
|
||||
<DisplayName>ut_test_put_bucket</DisplayName>
|
||||
</Owner>
|
||||
<Buckets>
|
||||
</Buckets>
|
||||
</ListAllMyBucketsResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new ListBucketsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$bucketListInfo = $result->getData();
|
||||
$this->assertEquals(2, count($bucketListInfo->getBucketList()));
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->nullXml, 200);
|
||||
$result = new ListBucketsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$bucketListInfo = $result->getData();
|
||||
$this->assertEquals(0, count($bucketListInfo->getBucketList()));
|
||||
}
|
||||
|
||||
public function test403()
|
||||
{
|
||||
$errorHeader = array(
|
||||
'x-oss-request-id' => '1a2b-3c4d'
|
||||
);
|
||||
|
||||
$errorBody = <<< BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error>
|
||||
<Code>NoSuchBucket</Code>
|
||||
<Message>The specified bucket does not exist.</Message>
|
||||
<RequestId>566B870D207FB3044302EB0A</RequestId>
|
||||
<HostId>hello.oss-test.aliyun-inc.com</HostId>
|
||||
<BucketName>hello</BucketName>
|
||||
</Error>
|
||||
BBBB;
|
||||
$response = new ResponseCore($errorHeader, $errorBody, 403);
|
||||
try {
|
||||
new ListBucketsResult($response);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals(
|
||||
$e->getMessage(),
|
||||
'NoSuchBucket: The specified bucket does not exist. RequestId: 1a2b-3c4d');
|
||||
$this->assertEquals($e->getHTTPStatus(), '403');
|
||||
$this->assertEquals($e->getRequestId(), '1a2b-3c4d');
|
||||
$this->assertEquals($e->getErrorCode(), 'NoSuchBucket');
|
||||
$this->assertEquals($e->getErrorMessage(), 'The specified bucket does not exist.');
|
||||
$this->assertEquals($e->getDetails(), $errorBody);
|
||||
}
|
||||
}
|
||||
|
||||
public function testParseXml2()
|
||||
{
|
||||
$xml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListAllMyBucketsResult>
|
||||
<Owner>
|
||||
<ID>ut_test_put_bucket</ID>
|
||||
<DisplayName>ut_test_put_bucket</DisplayName>
|
||||
</Owner>
|
||||
<Buckets>
|
||||
<Bucket>
|
||||
<CreationDate>2015-12-17T18:12:43.000Z</CreationDate>
|
||||
<ExtranetEndpoint>oss-cn-shanghai.aliyuncs.com</ExtranetEndpoint>
|
||||
<IntranetEndpoint>oss-cn-shanghai-internal.aliyuncs.com</IntranetEndpoint>
|
||||
<Location>oss-cn-shanghai</Location>
|
||||
<Name>app-base-oss</Name>
|
||||
<Region>cn-shanghai</Region>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
</Bucket>
|
||||
<Bucket>
|
||||
<CreationDate>2014-12-25T11:21:04.000Z</CreationDate>
|
||||
<ExtranetEndpoint>oss-cn-hangzhou.aliyuncs.com</ExtranetEndpoint>
|
||||
<IntranetEndpoint>oss-cn-hangzhou-internal.aliyuncs.com</IntranetEndpoint>
|
||||
<Location>oss-cn-hangzhou</Location>
|
||||
<Name>atestleo23</Name>
|
||||
<Region>cn-hangzhou</Region>
|
||||
<StorageClass>IA</StorageClass>
|
||||
</Bucket>
|
||||
<Bucket>
|
||||
<CreationDate>2014-12-25T11:21:04.000Z</CreationDate>
|
||||
<Location>oss-cn-hangzhou</Location>
|
||||
<Name>atestleo23</Name>
|
||||
</Bucket>
|
||||
</Buckets>
|
||||
</ListAllMyBucketsResult>
|
||||
BBBB;
|
||||
|
||||
$response = new ResponseCore(array(), $xml, 200);
|
||||
$result = new ListBucketsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$bucketListInfo = $result->getData();
|
||||
$this->assertEquals(3, count($bucketListInfo->getBucketList()));
|
||||
$this->assertEquals("2015-12-17T18:12:43.000Z", $bucketListInfo->getBucketList()[0]->getCreateDate());
|
||||
$this->assertEquals("oss-cn-shanghai", $bucketListInfo->getBucketList()[0]->getLocation());
|
||||
$this->assertEquals("app-base-oss", $bucketListInfo->getBucketList()[0]->getName());
|
||||
$this->assertEquals("oss-cn-shanghai.aliyuncs.com", $bucketListInfo->getBucketList()[0]->getExtranetEndpoint());
|
||||
$this->assertEquals("oss-cn-shanghai-internal.aliyuncs.com", $bucketListInfo->getBucketList()[0]->getIntranetEndpoint());
|
||||
$this->assertEquals("cn-shanghai", $bucketListInfo->getBucketList()[0]->getRegion());
|
||||
$this->assertEquals("Standard", $bucketListInfo->getBucketList()[0]->getStorageClass());
|
||||
|
||||
$this->assertEquals("2014-12-25T11:21:04.000Z", $bucketListInfo->getBucketList()[1]->getCreateDate());
|
||||
$this->assertEquals("oss-cn-hangzhou", $bucketListInfo->getBucketList()[1]->getLocation());
|
||||
$this->assertEquals("atestleo23", $bucketListInfo->getBucketList()[1]->getName());
|
||||
$this->assertEquals("oss-cn-hangzhou.aliyuncs.com", $bucketListInfo->getBucketList()[1]->getExtranetEndpoint());
|
||||
$this->assertEquals("oss-cn-hangzhou-internal.aliyuncs.com", $bucketListInfo->getBucketList()[1]->getIntranetEndpoint());
|
||||
$this->assertEquals("cn-hangzhou", $bucketListInfo->getBucketList()[1]->getRegion());
|
||||
$this->assertEquals("IA", $bucketListInfo->getBucketList()[1]->getStorageClass());
|
||||
|
||||
$this->assertEquals("2014-12-25T11:21:04.000Z", $bucketListInfo->getBucketList()[2]->getCreateDate());
|
||||
$this->assertEquals("oss-cn-hangzhou", $bucketListInfo->getBucketList()[2]->getLocation());
|
||||
$this->assertEquals("atestleo23", $bucketListInfo->getBucketList()[2]->getName());
|
||||
$this->assertEquals(null, $bucketListInfo->getBucketList()[2]->getExtranetEndpoint());
|
||||
$this->assertEquals(null, $bucketListInfo->getBucketList()[2]->getIntranetEndpoint());
|
||||
$this->assertEquals(null, $bucketListInfo->getBucketList()[2]->getRegion());
|
||||
$this->assertEquals(null, $bucketListInfo->getBucketList()[2]->getStorageClass());
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\ListMultipartUploadResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
/**
|
||||
* Class ListMultipartUploadResultTest
|
||||
* @package OSS\Tests
|
||||
*/
|
||||
class ListMultipartUploadResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListMultipartUploadsResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
|
||||
<Bucket>oss-example</Bucket>
|
||||
<KeyMarker>xx</KeyMarker>
|
||||
<UploadIdMarker>3</UploadIdMarker>
|
||||
<NextKeyMarker>oss.avi</NextKeyMarker>
|
||||
<NextUploadIdMarker>0004B99B8E707874FC2D692FA5D77D3F</NextUploadIdMarker>
|
||||
<Delimiter>x</Delimiter>
|
||||
<Prefix>xx</Prefix>
|
||||
<MaxUploads>1000</MaxUploads>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<Upload>
|
||||
<Key>multipart.data</Key>
|
||||
<UploadId>0004B999EF518A1FE585B0C9360DC4C8</UploadId>
|
||||
<Initiated>2012-02-23T04:18:23.000Z</Initiated>
|
||||
</Upload>
|
||||
<Upload>
|
||||
<Key>multipart.data</Key>
|
||||
<UploadId>0004B999EF5A239BB9138C6227D69F95</UploadId>
|
||||
<Initiated>2012-02-23T04:18:23.000Z</Initiated>
|
||||
</Upload>
|
||||
<Upload>
|
||||
<Key>oss.avi</Key>
|
||||
<UploadId>0004B99B8E707874FC2D692FA5D77D3F</UploadId>
|
||||
<Initiated>2012-02-23T06:14:27.000Z</Initiated>
|
||||
</Upload>
|
||||
</ListMultipartUploadsResult>
|
||||
BBBB;
|
||||
|
||||
private $validXmlWithEncodedKey = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListMultipartUploadsResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
|
||||
<Bucket>oss-example</Bucket>
|
||||
<EncodingType>url</EncodingType>
|
||||
<KeyMarker>php%2Bkey-marker</KeyMarker>
|
||||
<UploadIdMarker>3</UploadIdMarker>
|
||||
<NextKeyMarker>php%2Bnext-key-marker</NextKeyMarker>
|
||||
<NextUploadIdMarker>0004B99B8E707874FC2D692FA5D77D3F</NextUploadIdMarker>
|
||||
<Delimiter>%2F</Delimiter>
|
||||
<Prefix>php%2Bprefix</Prefix>
|
||||
<MaxUploads>1000</MaxUploads>
|
||||
<IsTruncated>true</IsTruncated>
|
||||
<Upload>
|
||||
<Key>php%2Bkey-1</Key>
|
||||
<UploadId>0004B999EF518A1FE585B0C9360DC4C8</UploadId>
|
||||
<Initiated>2012-02-23T04:18:23.000Z</Initiated>
|
||||
</Upload>
|
||||
<Upload>
|
||||
<Key>php%2Bkey-2</Key>
|
||||
<UploadId>0004B999EF5A239BB9138C6227D69F95</UploadId>
|
||||
<Initiated>2012-02-23T04:18:23.000Z</Initiated>
|
||||
</Upload>
|
||||
<Upload>
|
||||
<Key>php%2Bkey-3</Key>
|
||||
<UploadId>0004B99B8E707874FC2D692FA5D77D3F</UploadId>
|
||||
<Initiated>2012-02-23T06:14:27.000Z</Initiated>
|
||||
</Upload>
|
||||
</ListMultipartUploadsResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new ListMultipartUploadResult($response);
|
||||
$listMultipartUploadInfo = $result->getData();
|
||||
$this->assertEquals("oss-example", $listMultipartUploadInfo->getBucket());
|
||||
$this->assertEquals("xx", $listMultipartUploadInfo->getKeyMarker());
|
||||
$this->assertEquals(3, $listMultipartUploadInfo->getUploadIdMarker());
|
||||
$this->assertEquals("oss.avi", $listMultipartUploadInfo->getNextKeyMarker());
|
||||
$this->assertEquals("0004B99B8E707874FC2D692FA5D77D3F", $listMultipartUploadInfo->getNextUploadIdMarker());
|
||||
$this->assertEquals("x", $listMultipartUploadInfo->getDelimiter());
|
||||
$this->assertEquals("xx", $listMultipartUploadInfo->getPrefix());
|
||||
$this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
|
||||
$this->assertEquals("false", $listMultipartUploadInfo->getIsTruncated());
|
||||
$uploads = $listMultipartUploadInfo->getUploads();
|
||||
$this->assertEquals("multipart.data", $uploads[0]->getKey());
|
||||
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
|
||||
$this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
|
||||
}
|
||||
|
||||
public function testParseValidXmlWithEncodedKey()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200);
|
||||
$result = new ListMultipartUploadResult($response);
|
||||
$listMultipartUploadInfo = $result->getData();
|
||||
$this->assertEquals("oss-example", $listMultipartUploadInfo->getBucket());
|
||||
$this->assertEquals("php+key-marker", $listMultipartUploadInfo->getKeyMarker());
|
||||
$this->assertEquals("php+next-key-marker", $listMultipartUploadInfo->getNextKeyMarker());
|
||||
$this->assertEquals(3, $listMultipartUploadInfo->getUploadIdMarker());
|
||||
$this->assertEquals("0004B99B8E707874FC2D692FA5D77D3F", $listMultipartUploadInfo->getNextUploadIdMarker());
|
||||
$this->assertEquals("/", $listMultipartUploadInfo->getDelimiter());
|
||||
$this->assertEquals("php+prefix", $listMultipartUploadInfo->getPrefix());
|
||||
$this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
|
||||
$this->assertEquals("true", $listMultipartUploadInfo->getIsTruncated());
|
||||
$uploads = $listMultipartUploadInfo->getUploads();
|
||||
$this->assertEquals("php+key-1", $uploads[0]->getKey());
|
||||
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
|
||||
$this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\ListObjectVersionsResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class ListObjectVersionsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ListVersionsResult>
|
||||
<Name>oss-example</Name>
|
||||
<Prefix></Prefix>
|
||||
<KeyMarker>example</KeyMarker>
|
||||
<VersionIdMarker>CAEQMxiBgICbof2D0BYiIGRhZjgwMzJiMjA3MjQ0ODE5MWYxZDYwMzJlZjU1****</VersionIdMarker>
|
||||
<MaxKeys>100</MaxKeys>
|
||||
<Delimiter></Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<DeleteMarker>
|
||||
<Key>example</Key>
|
||||
<VersionId>CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****</VersionId>
|
||||
<IsLatest>false</IsLatest>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</DeleteMarker>
|
||||
<Version>
|
||||
<Key>example</Key>
|
||||
<VersionId>CAEQMxiBgMDNoP2D0BYiIDE3MWUxNzgxZDQxNTRiODI5OGYwZGMwNGY3MzZjN****</VersionId>
|
||||
<IsLatest>false</IsLatest>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<ETag>"250F8A0AE989679A22926A875F0A2****"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>93731</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</Version>
|
||||
<Version>
|
||||
<Key>pic.jpg</Key>
|
||||
<VersionId>CAEQMxiBgMCZov2D0BYiIDY4MDllOTc2YmY5MjQxMzdiOGI3OTlhNTU0ODIx****</VersionId>
|
||||
<IsLatest>true</IsLatest>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<ETag>"3663F7B0B9D3153F884C821E7CF4****"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>574768</Size>
|
||||
<StorageClass>IA</StorageClass>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</Version>
|
||||
</ListVersionsResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml1 = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ListVersionsResult>
|
||||
<Name>oss-example</Name>
|
||||
<Prefix></Prefix>
|
||||
<KeyMarker>example</KeyMarker>
|
||||
<VersionIdMarker>CAEQMxiBgICbof2D0BYiIGRhZjgwMzJiMjA3MjQ0ODE5MWYxZDYwMzJlZjU1****</VersionIdMarker>
|
||||
<MaxKeys>100</MaxKeys>
|
||||
<Delimiter></Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<DeleteMarker>
|
||||
<Key>example</Key>
|
||||
<VersionId>CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****</VersionId>
|
||||
<IsLatest>true</IsLatest>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</DeleteMarker>
|
||||
<DeleteMarker>
|
||||
<Key>example-1</Key>
|
||||
<VersionId>CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****</VersionId>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</DeleteMarker>
|
||||
<Version>
|
||||
<Key>example-2</Key>
|
||||
<VersionId>CAEQMxiBgMDNoP2D0BYiIDE3MWUxNzgxZDQxNTRiODI5OGYwZGMwNGY3MzZjN****</VersionId>
|
||||
<LastModified>2019-04-09T07:27:28.000Z</LastModified>
|
||||
<ETag>"250F8A0AE989679A22926A875F0A2****"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>93731</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
<Owner>
|
||||
<ID>1234512528586****</ID>
|
||||
<DisplayName>12345125285864390</DisplayName>
|
||||
</Owner>
|
||||
</Version>
|
||||
</ListVersionsResult>
|
||||
BBBB;
|
||||
|
||||
private $invalidXml = <<<BBBB
|
||||
<?xml version="1.0" ?>
|
||||
<ListVersionsResult>
|
||||
</ListVersionsResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new ListObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(0, count($list->getPrefixList()));
|
||||
$this->assertEquals(1, count($list->getDeleteMarkerList()));
|
||||
$this->assertEquals(2, count($list->getObjectVersionList()));
|
||||
|
||||
$this->assertEquals('oss-example', $list->getBucketName());
|
||||
$this->assertEquals('', $list->getPrefix());
|
||||
$this->assertEquals('example', $list->getKeyMarker());
|
||||
$this->assertEquals('CAEQMxiBgICbof2D0BYiIGRhZjgwMzJiMjA3MjQ0ODE5MWYxZDYwMzJlZjU1****', $list->getVersionIdMarker());
|
||||
$this->assertEquals(100, $list->getMaxKeys());
|
||||
$this->assertEquals('', $list->getDelimiter());
|
||||
$this->assertEquals('false', $list->getIsTruncated());
|
||||
|
||||
$deleteMarkerList = $list->getDeleteMarkerList();
|
||||
$this->assertEquals('example', $deleteMarkerList[0]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****', $deleteMarkerList[0]->getVersionId());
|
||||
$this->assertEquals('false', $deleteMarkerList[0]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $deleteMarkerList[0]->getLastModified());
|
||||
|
||||
$objectVersionList = $list->getObjectVersionList();
|
||||
$this->assertEquals('example', $objectVersionList[0]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgMDNoP2D0BYiIDE3MWUxNzgxZDQxNTRiODI5OGYwZGMwNGY3MzZjN****', $objectVersionList[0]->getVersionId());
|
||||
$this->assertEquals('false', $objectVersionList[0]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $objectVersionList[0]->getLastModified());
|
||||
$this->assertEquals('"250F8A0AE989679A22926A875F0A2****"', $objectVersionList[0]->getETag());
|
||||
$this->assertEquals('Normal', $objectVersionList[0]->getType());
|
||||
$this->assertEquals(93731, $objectVersionList[0]->getSize());
|
||||
$this->assertEquals('Standard', $objectVersionList[0]->getStorageClass());
|
||||
|
||||
$this->assertEquals('pic.jpg', $objectVersionList[1]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgMCZov2D0BYiIDY4MDllOTc2YmY5MjQxMzdiOGI3OTlhNTU0ODIx****', $objectVersionList[1]->getVersionId());
|
||||
$this->assertEquals('true', $objectVersionList[1]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $objectVersionList[1]->getLastModified());
|
||||
$this->assertEquals('"3663F7B0B9D3153F884C821E7CF4****"', $objectVersionList[1]->getETag());
|
||||
$this->assertEquals('Normal', $objectVersionList[1]->getType());
|
||||
$this->assertEquals(574768, $objectVersionList[1]->getSize());
|
||||
$this->assertEquals('IA', $objectVersionList[1]->getStorageClass());
|
||||
|
||||
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new ListObjectVersionsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$list = $result->getData();
|
||||
$this->assertEquals(0, count($list->getPrefixList()));
|
||||
$this->assertEquals(2, count($list->getDeleteMarkerList()));
|
||||
$this->assertEquals(1, count($list->getObjectVersionList()));
|
||||
|
||||
$this->assertEquals('oss-example', $list->getBucketName());
|
||||
$this->assertEquals('', $list->getPrefix());
|
||||
$this->assertEquals('example', $list->getKeyMarker());
|
||||
$this->assertEquals('CAEQMxiBgICbof2D0BYiIGRhZjgwMzJiMjA3MjQ0ODE5MWYxZDYwMzJlZjU1****', $list->getVersionIdMarker());
|
||||
$this->assertEquals(100, $list->getMaxKeys());
|
||||
$this->assertEquals('', $list->getDelimiter());
|
||||
$this->assertEquals('false', $list->getIsTruncated());
|
||||
|
||||
$deleteMarkerList = $list->getDeleteMarkerList();
|
||||
$this->assertEquals('example', $deleteMarkerList[0]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****', $deleteMarkerList[0]->getVersionId());
|
||||
$this->assertEquals('true', $deleteMarkerList[0]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $deleteMarkerList[0]->getLastModified());
|
||||
|
||||
$this->assertEquals('example-1', $deleteMarkerList[1]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****', $deleteMarkerList[1]->getVersionId());
|
||||
$this->assertEquals('', $deleteMarkerList[1]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $deleteMarkerList[1]->getLastModified());
|
||||
|
||||
$objectVersionList = $list->getObjectVersionList();
|
||||
$this->assertEquals('example-2', $objectVersionList[0]->getKey());
|
||||
$this->assertEquals('CAEQMxiBgMDNoP2D0BYiIDE3MWUxNzgxZDQxNTRiODI5OGYwZGMwNGY3MzZjN****', $objectVersionList[0]->getVersionId());
|
||||
$this->assertEquals('', $objectVersionList[0]->getIsLatest());
|
||||
$this->assertEquals('2019-04-09T07:27:28.000Z', $objectVersionList[0]->getLastModified());
|
||||
$this->assertEquals('"250F8A0AE989679A22926A875F0A2****"', $objectVersionList[0]->getETag());
|
||||
$this->assertEquals('Normal', $objectVersionList[0]->getType());
|
||||
$this->assertEquals(93731, $objectVersionList[0]->getSize());
|
||||
$this->assertEquals('Standard', $objectVersionList[0]->getStorageClass());
|
||||
}
|
||||
|
||||
public function testParseNullXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 200);
|
||||
$result = new ListObjectVersionsResult($response);
|
||||
$list = $result->getData();
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testParseInvalidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->invalidXml, 200);
|
||||
$result = new ListObjectVersionsResult($response);
|
||||
$stat = $result->getData();
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Result\ListObjectsResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class ListObjectsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml1 = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<Prefix></Prefix>
|
||||
<Marker></Marker>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>/</Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<CommonPrefixes>
|
||||
<Prefix>oss-php-sdk-test/</Prefix>
|
||||
</CommonPrefixes>
|
||||
<CommonPrefixes>
|
||||
<Prefix>test/</Prefix>
|
||||
</CommonPrefixes>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<Prefix>oss-php-sdk-test/</Prefix>
|
||||
<Marker>xx</Marker>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>/</Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<Contents>
|
||||
<Key>oss-php-sdk-test/upload-test-object-name.txt</Key>
|
||||
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
|
||||
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>13115</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
<Owner>
|
||||
<ID>cname_user</ID>
|
||||
<DisplayName>cname_user</DisplayName>
|
||||
</Owner>
|
||||
</Contents>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
private $validXmlWithEncodedKey = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<EncodingType>url</EncodingType>
|
||||
<Prefix>php%2Fprefix</Prefix>
|
||||
<Marker>php%2Fmarker</Marker>
|
||||
<NextMarker>php%2Fnext-marker</NextMarker>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>%2F</Delimiter>
|
||||
<IsTruncated>true</IsTruncated>
|
||||
<Contents>
|
||||
<Key>php/a%2Bb</Key>
|
||||
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
|
||||
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>13115</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
<Owner>
|
||||
<ID>cname_user</ID>
|
||||
<DisplayName>cname_user</DisplayName>
|
||||
</Owner>
|
||||
</Contents>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml1()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new ListObjectsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(2, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(0, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('', $objectListInfo->getMarker());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('false', $objectListInfo->getIsTruncated());
|
||||
$prefixes = $objectListInfo->getPrefixList();
|
||||
$this->assertEquals('oss-php-sdk-test/', $prefixes[0]->getPrefix());
|
||||
$this->assertEquals('test/', $prefixes[1]->getPrefix());
|
||||
}
|
||||
|
||||
public function testParseValidXml2()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new ListObjectsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(1, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('oss-php-sdk-test/', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('xx', $objectListInfo->getMarker());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('false', $objectListInfo->getIsTruncated());
|
||||
$objects = $objectListInfo->getObjectList();
|
||||
$this->assertEquals('oss-php-sdk-test/upload-test-object-name.txt', $objects[0]->getKey());
|
||||
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
|
||||
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
|
||||
$this->assertEquals('Normal', $objects[0]->getType());
|
||||
$this->assertEquals(13115, $objects[0]->getSize());
|
||||
$this->assertEquals('Standard', $objects[0]->getStorageClass());
|
||||
}
|
||||
|
||||
public function testParseValidXmlWithEncodedKey()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200);
|
||||
$result = new ListObjectsResult($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(1, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('php/prefix', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('php/marker', $objectListInfo->getMarker());
|
||||
$this->assertEquals('php/next-marker', $objectListInfo->getNextMarker());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('true', $objectListInfo->getIsTruncated());
|
||||
$objects = $objectListInfo->getObjectList();
|
||||
$this->assertEquals('php/a+b', $objects[0]->getKey());
|
||||
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
|
||||
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
|
||||
$this->assertEquals('Normal', $objects[0]->getType());
|
||||
$this->assertEquals(13115, $objects[0]->getSize());
|
||||
$this->assertEquals('Standard', $objects[0]->getStorageClass());
|
||||
}
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Result\ListObjectsV2Result;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class ListObjectsV2ResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
private $validXml1 = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<Prefix></Prefix>
|
||||
<StartAfter></StartAfter>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>/</Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<CommonPrefixes>
|
||||
<Prefix>oss-php-sdk-test/</Prefix>
|
||||
</CommonPrefixes>
|
||||
<CommonPrefixes>
|
||||
<Prefix>test/</Prefix>
|
||||
</CommonPrefixes>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<Prefix>oss-php-sdk-test/</Prefix>
|
||||
<StartAfter>xx</StartAfter>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>/</Delimiter>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<Contents>
|
||||
<Key>oss-php-sdk-test/upload-test-object-name.txt</Key>
|
||||
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
|
||||
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>13115</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
</Contents>
|
||||
<KeyCount>1</KeyCount>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
private $validXmlWithEncodedKey = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult>
|
||||
<Name>testbucket-hf</Name>
|
||||
<EncodingType>url</EncodingType>
|
||||
<Prefix>php%2Fprefix</Prefix>
|
||||
<StartAfter>php%2Fmarker</StartAfter>
|
||||
<ContinuationToken>1gJiYw--</ContinuationToken>
|
||||
<NextContinuationToken>CgJiYw--</NextContinuationToken>
|
||||
<MaxKeys>1000</MaxKeys>
|
||||
<Delimiter>%2F</Delimiter>
|
||||
<IsTruncated>true</IsTruncated>
|
||||
<Contents>
|
||||
<Key>php/a%2Bb</Key>
|
||||
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
|
||||
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
|
||||
<Type>Normal</Type>
|
||||
<Size>13115</Size>
|
||||
<StorageClass>Standard</StorageClass>
|
||||
<Owner>
|
||||
<ID>cname_user</ID>
|
||||
<DisplayName>cname_user</DisplayName>
|
||||
</Owner>
|
||||
</Contents>
|
||||
<KeyCount>1</KeyCount>
|
||||
</ListBucketResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml1()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml1, 200);
|
||||
$result = new ListObjectsV2Result($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(2, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(0, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('', $objectListInfo->getStartAfter());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('false', $objectListInfo->getIsTruncated());
|
||||
$this->assertEquals(0, $objectListInfo->getKeyCount());
|
||||
$prefixes = $objectListInfo->getPrefixList();
|
||||
$this->assertEquals('oss-php-sdk-test/', $prefixes[0]->getPrefix());
|
||||
$this->assertEquals('test/', $prefixes[1]->getPrefix());
|
||||
}
|
||||
|
||||
public function testParseValidXml2()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml2, 200);
|
||||
$result = new ListObjectsV2Result($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(1, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('oss-php-sdk-test/', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('xx', $objectListInfo->getStartAfter());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('false', $objectListInfo->getIsTruncated());
|
||||
$this->assertEquals(1, $objectListInfo->getKeyCount());
|
||||
$objects = $objectListInfo->getObjectList();
|
||||
$this->assertEquals('oss-php-sdk-test/upload-test-object-name.txt', $objects[0]->getKey());
|
||||
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
|
||||
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
|
||||
$this->assertEquals('Normal', $objects[0]->getType());
|
||||
$this->assertEquals(13115, $objects[0]->getSize());
|
||||
$this->assertEquals('Standard', $objects[0]->getStorageClass());
|
||||
}
|
||||
|
||||
public function testParseValidXmlWithEncodedKey()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200);
|
||||
$result = new ListObjectsV2Result($response);
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertNotNull($result->getData());
|
||||
$this->assertNotNull($result->getRawResponse());
|
||||
$objectListInfo = $result->getData();
|
||||
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
|
||||
$this->assertEquals(1, count($objectListInfo->getObjectList()));
|
||||
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
|
||||
$this->assertEquals('php/prefix', $objectListInfo->getPrefix());
|
||||
$this->assertEquals('php/marker', $objectListInfo->getStartAfter());
|
||||
$this->assertEquals('CgJiYw--', $objectListInfo->getNextContinuationToken());
|
||||
$this->assertEquals('1gJiYw--', $objectListInfo->getContinuationToken());
|
||||
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
|
||||
$this->assertEquals('/', $objectListInfo->getDelimiter());
|
||||
$this->assertEquals('true', $objectListInfo->getIsTruncated());
|
||||
$this->assertEquals(1, $objectListInfo->getKeyCount());
|
||||
$objects = $objectListInfo->getObjectList();
|
||||
$this->assertEquals('php/a+b', $objects[0]->getKey());
|
||||
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
|
||||
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
|
||||
$this->assertEquals('Normal', $objects[0]->getType());
|
||||
$this->assertEquals(13115, $objects[0]->getSize());
|
||||
$this->assertEquals('Standard', $objects[0]->getStorageClass());
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Result\ListPartsResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
/**
|
||||
* Class ListPartsResultTest
|
||||
* @package OSS\Tests
|
||||
*/
|
||||
class ListPartsResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListPartsResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
|
||||
<Bucket>multipart_upload</Bucket>
|
||||
<Key>multipart.data</Key>
|
||||
<UploadId>0004B999EF5A239BB9138C6227D69F95</UploadId>
|
||||
<NextPartNumberMarker>5</NextPartNumberMarker>
|
||||
<MaxParts>1000</MaxParts>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<Part>
|
||||
<PartNumber>1</PartNumber>
|
||||
<LastModified>2012-02-23T07:01:34.000Z</LastModified>
|
||||
<ETag>"3349DC700140D7F86A078484278075A9"</ETag>
|
||||
<Size>6291456</Size>
|
||||
</Part>
|
||||
<Part>
|
||||
<PartNumber>2</PartNumber>
|
||||
<LastModified>2012-02-23T07:01:12.000Z</LastModified>
|
||||
<ETag>"3349DC700140D7F86A078484278075A9"</ETag>
|
||||
<Size>6291456</Size>
|
||||
</Part>
|
||||
<Part>
|
||||
<PartNumber>5</PartNumber>
|
||||
<LastModified>2012-02-23T07:02:03.000Z</LastModified>
|
||||
<ETag>"7265F4D211B56873A381D321F586E4A9"</ETag>
|
||||
<Size>1024</Size>
|
||||
</Part>
|
||||
</ListPartsResult>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new ListPartsResult($response);
|
||||
$listPartsInfo = $result->getData();
|
||||
$this->assertEquals("multipart_upload", $listPartsInfo->getBucket());
|
||||
$this->assertEquals("multipart.data", $listPartsInfo->getKey());
|
||||
$this->assertEquals("0004B999EF5A239BB9138C6227D69F95", $listPartsInfo->getUploadId());
|
||||
$this->assertEquals(5, $listPartsInfo->getNextPartNumberMarker());
|
||||
$this->assertEquals(1000, $listPartsInfo->getMaxParts());
|
||||
$this->assertEquals("false", $listPartsInfo->getIsTruncated());
|
||||
$this->assertEquals(3, count($listPartsInfo->getListPart()));
|
||||
$parts = $listPartsInfo->getListPart();
|
||||
$this->assertEquals(1, $parts[0]->getPartNumber());
|
||||
$this->assertEquals('2012-02-23T07:01:34.000Z', $parts[0]->getLastModified());
|
||||
$this->assertEquals('"3349DC700140D7F86A078484278075A9"', $parts[0]->getETag());
|
||||
$this->assertEquals(6291456, $parts[0]->getSize());
|
||||
}
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LiveChannelInfo;
|
||||
use OSS\Model\LiveChannelListInfo;
|
||||
use OSS\Model\LiveChannelConfig;
|
||||
use OSS\Model\GetLiveChannelStatus;
|
||||
use OSS\Model\GetLiveChannelHistory;
|
||||
use OSS\Model\LiveChannelHistory;
|
||||
|
||||
class LiveChannelXmlTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $config = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LiveChannelConfiguration>
|
||||
<Description>xxx</Description>
|
||||
<Status>enabled</Status>
|
||||
<Target>
|
||||
<Type>hls</Type>
|
||||
<FragDuration>1000</FragDuration>
|
||||
<FragCount>5</FragCount>
|
||||
<PlayListName>hello.m3u8</PlayListName>
|
||||
</Target>
|
||||
</LiveChannelConfiguration>
|
||||
BBBB;
|
||||
|
||||
private $info = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CreateLiveChannelResult>
|
||||
<Name>live-1</Name>
|
||||
<Description>xxx</Description>
|
||||
<PublishUrls>
|
||||
<Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/213443245345</Url>
|
||||
</PublishUrls>
|
||||
<PlayUrls>
|
||||
<Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/213443245345/播放列表.m3u8</Url>
|
||||
</PlayUrls>
|
||||
<Status>enabled</Status>
|
||||
<LastModified>2015-11-24T14:25:31.000Z</LastModified>
|
||||
</CreateLiveChannelResult>
|
||||
BBBB;
|
||||
|
||||
private $list = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ListLiveChannelResult>
|
||||
<Prefix>xxx</Prefix>
|
||||
<Marker>yyy</Marker>
|
||||
<MaxKeys>100</MaxKeys>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
<NextMarker>121312132</NextMarker>
|
||||
<LiveChannel>
|
||||
<Name>12123214323431</Name>
|
||||
<Description>xxx</Description>
|
||||
<PublishUrls>
|
||||
<Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/1</Url>
|
||||
</PublishUrls>
|
||||
<PlayUrls>
|
||||
<Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/1/播放列表.m3u8</Url>
|
||||
</PlayUrls>
|
||||
<Status>enabled</Status>
|
||||
<LastModified>2015-11-24T14:25:31.000Z</LastModified>
|
||||
</LiveChannel>
|
||||
<LiveChannel>
|
||||
<Name>432423432423</Name>
|
||||
<Description>yyy</Description>
|
||||
<PublishUrls>
|
||||
<Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/2</Url>
|
||||
</PublishUrls>
|
||||
<PlayUrls>
|
||||
<Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/2/播放列表.m3u8</Url>
|
||||
</PlayUrls>
|
||||
<Status>enabled</Status>
|
||||
<LastModified>2016-11-24T14:25:31.000Z</LastModified>
|
||||
</LiveChannel>
|
||||
</ListLiveChannelResult>
|
||||
BBBB;
|
||||
|
||||
private $status = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LiveChannelStat>
|
||||
<Status>Live</Status>
|
||||
<ConnectedTime>2016-10-20T14:25:31.000Z</ConnectedTime>
|
||||
<RemoteAddr>10.1.2.4:47745</RemoteAddr>
|
||||
<Video>
|
||||
<Width>1280</Width>
|
||||
<Height>536</Height>
|
||||
<FrameRate>24</FrameRate>
|
||||
<Bandwidth>72513</Bandwidth>
|
||||
<Codec>H264</Codec>
|
||||
</Video>
|
||||
<Audio>
|
||||
<Bandwidth>6519</Bandwidth>
|
||||
<SampleRate>44100</SampleRate>
|
||||
<Codec>AAC</Codec>
|
||||
</Audio>
|
||||
</LiveChannelStat>
|
||||
BBBB;
|
||||
|
||||
private $history = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LiveChannelHistory>
|
||||
<LiveRecord>
|
||||
<StartTime>2013-11-24T14:25:31.000Z</StartTime>
|
||||
<EndTime>2013-11-24T15:25:31.000Z</EndTime>
|
||||
<RemoteAddr>10.101.194.148:56861</RemoteAddr>
|
||||
</LiveRecord>
|
||||
<LiveRecord>
|
||||
<StartTime>2014-11-24T14:25:31.000Z</StartTime>
|
||||
<EndTime>2014-11-24T15:25:31.000Z</EndTime>
|
||||
<RemoteAddr>10.101.194.148:56862</RemoteAddr>
|
||||
</LiveRecord>
|
||||
<LiveRecord>
|
||||
<StartTime>2015-11-24T14:25:31.000Z</StartTime>
|
||||
<EndTime>2015-11-24T15:25:31.000Z</EndTime>
|
||||
<RemoteAddr>10.101.194.148:56863</RemoteAddr>
|
||||
</LiveRecord>
|
||||
</LiveChannelHistory>
|
||||
BBBB;
|
||||
|
||||
public function testLiveChannelStatus()
|
||||
{
|
||||
$stat = new GetLiveChannelStatus();
|
||||
$stat->parseFromXml($this->status);
|
||||
|
||||
$this->assertEquals('Live', $stat->getStatus());
|
||||
$this->assertEquals('2016-10-20T14:25:31.000Z', $stat->getConnectedTime());
|
||||
$this->assertEquals('10.1.2.4:47745', $stat->getRemoteAddr());
|
||||
|
||||
$this->assertEquals(1280, $stat->getVideoWidth());
|
||||
$this->assertEquals(536, $stat->getVideoHeight());
|
||||
$this->assertEquals(24, $stat->getVideoFrameRate());
|
||||
$this->assertEquals(72513, $stat->getVideoBandwidth());
|
||||
$this->assertEquals('H264', $stat->getVideoCodec());
|
||||
$this->assertEquals(6519, $stat->getAudioBandwidth());
|
||||
$this->assertEquals(44100, $stat->getAudioSampleRate());
|
||||
$this->assertEquals('AAC', $stat->getAudioCodec());
|
||||
|
||||
}
|
||||
|
||||
public function testGetLiveChannelHistory()
|
||||
{
|
||||
$history = new GetLiveChannelHistory();
|
||||
$history->parseFromXml($this->history);
|
||||
|
||||
$recordList = $history->getLiveRecordList();
|
||||
$this->assertEquals(3, count($recordList));
|
||||
|
||||
$list0 = $recordList[0];
|
||||
$this->assertEquals('2013-11-24T14:25:31.000Z', $list0->getStartTime());
|
||||
$this->assertEquals('2013-11-24T15:25:31.000Z', $list0->getEndTime());
|
||||
$this->assertEquals('10.101.194.148:56861', $list0->getRemoteAddr());
|
||||
|
||||
$list1 = $recordList[1];
|
||||
$this->assertEquals('2014-11-24T14:25:31.000Z', $list1->getStartTime());
|
||||
$this->assertEquals('2014-11-24T15:25:31.000Z', $list1->getEndTime());
|
||||
$this->assertEquals('10.101.194.148:56862', $list1->getRemoteAddr());
|
||||
|
||||
$list2 = $recordList[2];
|
||||
$this->assertEquals('2015-11-24T14:25:31.000Z', $list2->getStartTime());
|
||||
$this->assertEquals('2015-11-24T15:25:31.000Z', $list2->getEndTime());
|
||||
$this->assertEquals('10.101.194.148:56863', $list2->getRemoteAddr());
|
||||
|
||||
}
|
||||
|
||||
public function testLiveChannelConfig()
|
||||
{
|
||||
$config = new LiveChannelConfig(array('name' => 'live-1'));
|
||||
$config->parseFromXml($this->config);
|
||||
|
||||
$this->assertEquals('xxx', $config->getDescription());
|
||||
$this->assertEquals('enabled', $config->getStatus());
|
||||
$this->assertEquals('hls', $config->getType());
|
||||
$this->assertEquals(1000, $config->getFragDuration());
|
||||
$this->assertEquals(5, $config->getFragCount());
|
||||
$this->assertEquals('hello.m3u8', $config->getPlayListName());
|
||||
|
||||
$xml = $config->serializeToXml();
|
||||
$config2 = new LiveChannelConfig(array('name' => 'live-2'));
|
||||
$config2->parseFromXml($xml);
|
||||
$this->assertEquals('xxx', $config2->getDescription());
|
||||
$this->assertEquals('enabled', $config2->getStatus());
|
||||
$this->assertEquals('hls', $config2->getType());
|
||||
$this->assertEquals(1000, $config2->getFragDuration());
|
||||
$this->assertEquals(5, $config2->getFragCount());
|
||||
$this->assertEquals('hello.m3u8', $config2->getPlayListName());
|
||||
}
|
||||
|
||||
public function testLiveChannelInfo()
|
||||
{
|
||||
$info = new LiveChannelInfo(array('name' => 'live-1'));
|
||||
$info->parseFromXml($this->info);
|
||||
|
||||
$this->assertEquals('live-1', $info->getName());
|
||||
$this->assertEquals('xxx', $info->getDescription());
|
||||
$this->assertEquals('enabled', $info->getStatus());
|
||||
$this->assertEquals('2015-11-24T14:25:31.000Z', $info->getLastModified());
|
||||
$pubs = $info->getPublishUrls();
|
||||
$this->assertEquals(1, count($pubs));
|
||||
$this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/213443245345', $pubs[0]);
|
||||
|
||||
$plays = $info->getPlayUrls();
|
||||
$this->assertEquals(1, count($plays));
|
||||
$this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/213443245345/播放列表.m3u8', $plays[0]);
|
||||
}
|
||||
|
||||
public function testLiveChannelList()
|
||||
{
|
||||
$list = new LiveChannelListInfo();
|
||||
$list->parseFromXml($this->list);
|
||||
|
||||
$this->assertEquals('xxx', $list->getPrefix());
|
||||
$this->assertEquals('yyy', $list->getMarker());
|
||||
$this->assertEquals(100, $list->getMaxKeys());
|
||||
$this->assertEquals(false, $list->getIsTruncated());
|
||||
$this->assertEquals('121312132', $list->getNextMarker());
|
||||
|
||||
$channels = $list->getChannelList();
|
||||
$this->assertEquals(2, count($channels));
|
||||
|
||||
$chan1 = $channels[0];
|
||||
$this->assertEquals('12123214323431', $chan1->getName());
|
||||
$this->assertEquals('xxx', $chan1->getDescription());
|
||||
$this->assertEquals('enabled', $chan1->getStatus());
|
||||
$this->assertEquals('2015-11-24T14:25:31.000Z', $chan1->getLastModified());
|
||||
$pubs = $chan1->getPublishUrls();
|
||||
$this->assertEquals(1, count($pubs));
|
||||
$this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/1', $pubs[0]);
|
||||
|
||||
$plays = $chan1->getPlayUrls();
|
||||
$this->assertEquals(1, count($plays));
|
||||
$this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/1/播放列表.m3u8', $plays[0]);
|
||||
|
||||
$chan2 = $channels[1];
|
||||
$this->assertEquals('432423432423', $chan2->getName());
|
||||
$this->assertEquals('yyy', $chan2->getDescription());
|
||||
$this->assertEquals('enabled', $chan2->getStatus());
|
||||
$this->assertEquals('2016-11-24T14:25:31.000Z', $chan2->getLastModified());
|
||||
$pubs = $chan2->getPublishUrls();
|
||||
$this->assertEquals(1, count($pubs));
|
||||
$this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/2', $pubs[0]);
|
||||
|
||||
$plays = $chan2->getPlayUrls();
|
||||
$this->assertEquals(1, count($plays));
|
||||
$this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/2/播放列表.m3u8', $plays[0]);
|
||||
}
|
||||
|
||||
public function testLiveChannelHistory()
|
||||
{
|
||||
$xml = "<LiveRecord><StartTime>2013-11-24T14:25:31.000Z</StartTime><EndTime>2013-11-24T15:25:31.000Z</EndTime><RemoteAddr>10.101.194.148:56861</RemoteAddr></LiveRecord>";
|
||||
$history = new LiveChannelHistory();
|
||||
$history->parseFromXml($xml);
|
||||
|
||||
$this->assertEquals('2013-11-24T14:25:31.000Z', $history->getStartTime());
|
||||
$this->assertEquals('2013-11-24T15:25:31.000Z', $history->getEndTime());
|
||||
$this->assertEquals('10.101.194.148:56861', $history->getRemoteAddr());
|
||||
}
|
||||
|
||||
public function testGetLiveChannelHistorySerializeToXml()
|
||||
{
|
||||
try {
|
||||
$history = new GetLiveChannelHistory ();
|
||||
$history->serializeToXml();
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
if (strpos($e, "Not implemented.") == false)
|
||||
{
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Model\LoggingConfig;
|
||||
|
||||
class LoggingConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BucketLoggingStatus>
|
||||
<LoggingEnabled>
|
||||
<TargetBucket>TargetBucket</TargetBucket>
|
||||
<TargetPrefix>TargetPrefix</TargetPrefix>
|
||||
</LoggingEnabled>
|
||||
</BucketLoggingStatus>
|
||||
BBBB;
|
||||
|
||||
private $nullXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BucketLoggingStatus/>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$loggingConfig = new LoggingConfig();
|
||||
$loggingConfig->parseFromXml($this->validXml);
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml(strval($loggingConfig)));
|
||||
}
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$loggingConfig = new LoggingConfig('TargetBucket', 'TargetPrefix');
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($loggingConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
public function testFailedConstruct()
|
||||
{
|
||||
$loggingConfig = new LoggingConfig('TargetBucket', null);
|
||||
$this->assertEquals($this->cleanXml($this->nullXml), $this->cleanXml($loggingConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\MimeTypes;
|
||||
|
||||
class MimeTypesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetMimeType()
|
||||
{
|
||||
$this->assertEquals('application/xml', MimeTypes::getMimetype('file.xml'));
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
class ObjectAclTest extends TestOssClientBase
|
||||
{
|
||||
public function testGetSet()
|
||||
{
|
||||
$client = $this->ossClient;
|
||||
$bucket = $this->bucket;
|
||||
|
||||
$object = 'test/object-acl';
|
||||
$client->deleteObject($bucket, $object);
|
||||
$client->putObject($bucket, $object, "hello world");
|
||||
|
||||
$acl = $client->getObjectAcl($bucket, $object);
|
||||
$this->assertEquals('default', $acl);
|
||||
|
||||
$client->putObjectAcl($bucket, $object, 'public-read');
|
||||
$acl = $client->getObjectAcl($bucket, $object);
|
||||
$this->assertEquals('public-read', $acl);
|
||||
|
||||
$content = $client->getObject($bucket, $object);
|
||||
$this->assertEquals('hello world', $content);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\CnameConfig;
|
||||
use OSS\Model\CnameTokenInfo;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketCnameTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucketCname()
|
||||
{
|
||||
$bucketName = $this->bucket . '-cname';
|
||||
$client = new OssClient(
|
||||
getenv('OSS_ACCESS_KEY_ID'),
|
||||
getenv('OSS_ACCESS_KEY_SECRET'),
|
||||
"oss-ap-southeast-2.aliyuncs.com", false);
|
||||
|
||||
$client->createBucket($bucketName);
|
||||
|
||||
try {
|
||||
$info1 = $client->createBucketCnameToken($bucketName, "www.example.com");
|
||||
$this->assertEquals("www.example.com", $info1->getCname());
|
||||
$this->assertEquals($bucketName, $info1->getBucket());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$info2 = $client->getBucketCnameToken($bucketName, "www.example.com");
|
||||
$this->assertEquals("www.example.com", $info2->getCname());
|
||||
$this->assertEquals($bucketName, $info2->getBucket());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $client->addBucketCname($bucketName, "www.example.com");
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('NeedVerifyDomainOwnership', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$config = $client->getBucketCname($bucketName);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $client->deleteBucketCname($bucketName, "www.example.com");
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$client->deleteBucket($bucketName);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\CorsConfig;
|
||||
use OSS\Model\CorsRule;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketCorsTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
$rule->addAllowedHeader("x-oss-test");
|
||||
$rule->addAllowedHeader("x-oss-test2");
|
||||
$rule->addAllowedHeader("x-oss-test2");
|
||||
$rule->addAllowedHeader("x-oss-test3");
|
||||
$rule->addAllowedOrigin("http://www.b.com");
|
||||
$rule->addAllowedOrigin("http://www.a.com");
|
||||
$rule->addAllowedOrigin("http://www.a.com");
|
||||
$rule->addAllowedMethod("GET");
|
||||
$rule->addAllowedMethod("PUT");
|
||||
$rule->addAllowedMethod("POST");
|
||||
$rule->addExposeHeader("x-oss-test1");
|
||||
$rule->addExposeHeader("x-oss-test1");
|
||||
$rule->addExposeHeader("x-oss-test2");
|
||||
$rule->setMaxAgeSeconds(10);
|
||||
$corsConfig->addRule($rule);
|
||||
$rule = new CorsRule();
|
||||
$rule->addAllowedHeader("x-oss-test");
|
||||
$rule->addAllowedMethod("GET");
|
||||
$rule->addAllowedOrigin("http://www.b.com");
|
||||
$rule->addExposeHeader("x-oss-test1");
|
||||
$rule->setMaxAgeSeconds(110);
|
||||
$corsConfig->addRule($rule);
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketCors($this->bucket, $corsConfig);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(True);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$object = "cors/test.txt";
|
||||
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
|
||||
$headers = $this->ossClient->optionsObject($this->bucket, $object, "http://www.a.com", "GET", "", null);
|
||||
$this->assertNotEmpty($headers);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$corsConfig2 = $this->ossClient->getBucketCors($this->bucket);
|
||||
$this->assertNotNull($corsConfig2);
|
||||
$this->assertEquals($corsConfig->serializeToXml(), $corsConfig2->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(True);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$this->ossClient->deleteBucketCors($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(True);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$corsConfig3 = $this->ossClient->getBucketCors($this->bucket);
|
||||
$this->assertNotNull($corsConfig3);
|
||||
$this->assertNotEquals($corsConfig->serializeToXml(), $corsConfig3->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(True);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\ServerSideEncryptionConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketEncryptionTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
$config = new ServerSideEncryptionConfig("AES256");
|
||||
try {
|
||||
$this->ossClient->putBucketEncryption($this->bucket, $config);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$config2 = $this->ossClient->getBucketEncryption($this->bucket);
|
||||
$this->assertEquals($config->serializeToXml(), $config2->serializeToXml());
|
||||
$this->assertEquals("AES256", $config2->getSSEAlgorithm());
|
||||
$this->assertEquals(null, $config2->getKMSMasterKeyID());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$config = new ServerSideEncryptionConfig("KMS", "kms-id");
|
||||
try {
|
||||
$this->ossClient->putBucketEncryption($this->bucket, $config);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$config2 = $this->ossClient->getBucketEncryption($this->bucket);
|
||||
$this->assertEquals($config->serializeToXml(), $config2->serializeToXml());
|
||||
$this->assertEquals("KMS", $config2->getSSEAlgorithm());
|
||||
$this->assertEquals("kms-id", $config2->getKMSMasterKeyID());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$this->ossClient->deleteBucketEncryption($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$config2 = $this->ossClient->getBucketEncryption($this->bucket);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("NoSuchServerSideEncryptionRule", $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
class OssClientBucketInfoTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucketInfo()
|
||||
{
|
||||
try {
|
||||
$info = $this->ossClient->getBucketInfo($this->bucket);
|
||||
$this->assertEquals($this->bucket, $info->getName());
|
||||
$this->assertEquals("Standard", $info->getStorageClass());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LifecycleConfig;
|
||||
use OSS\Model\LifecycleRule;
|
||||
use OSS\Model\LifecycleAction;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketLifecycleTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction("Expiration", "Days", 3);
|
||||
$lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction("Expiration", "Date", '2022-10-12T00:00:00.000Z');
|
||||
$lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketLifecycle($this->bucket, $lifecycleConfig);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$lifecycleConfig2 = $this->ossClient->getBucketLifecycle($this->bucket);
|
||||
$this->assertEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig2->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$this->ossClient->deleteBucketLifecycle($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$lifecycleConfig3 = $this->ossClient->getBucketLifecycle($this->bucket);
|
||||
$this->assertNotEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig3->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LoggingConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketLoggingTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
$loggingConfig = new LoggingConfig($this->bucket, 'prefix');
|
||||
try {
|
||||
$this->ossClient->putBucketLogging($this->bucket, $this->bucket, 'prefix');
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$loggingConfig2 = $this->ossClient->getBucketLogging($this->bucket);
|
||||
$this->assertEquals($loggingConfig->serializeToXml(), $loggingConfig2->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$this->ossClient->deleteBucketLogging($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$loggingConfig3 = $this->ossClient->getBucketLogging($this->bucket);
|
||||
$this->assertNotEquals($loggingConfig->serializeToXml(), $loggingConfig3->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
class OssClientBucketPolicyTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
$policy_str = <<< BBBB
|
||||
{
|
||||
"Version":"1",
|
||||
"Statement":[
|
||||
{
|
||||
"Action":[
|
||||
"oss:PutObject",
|
||||
"oss:GetObject"
|
||||
],
|
||||
"Effect":"Deny",
|
||||
"Principal":["1234567890"],
|
||||
"Resource":["acs:oss:*:1234567890:*/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
BBBB;
|
||||
|
||||
try {
|
||||
$this->ossClient->deleteBucketPolicy($this->bucket);
|
||||
$policy = $this->ossClient->getBucketPolicy($this->bucket);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
$this->assertEquals("NoSuchBucketPolicy", $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketPolicy($this->bucket, $policy_str);
|
||||
$policy = $this->ossClient->getBucketPolicy($this->bucket);
|
||||
$this->assertEquals($policy_str, $policy);
|
||||
$this->ossClient->deleteBucketPolicy($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\RefererConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketRefererTest extends TestOssClientBase
|
||||
{
|
||||
|
||||
public function testBucket()
|
||||
{
|
||||
$refererConfig = new RefererConfig();
|
||||
$refererConfig->addReferer('http://www.aliyun.com');
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketReferer($this->bucket, $refererConfig);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$refererConfig2 = $this->ossClient->getBucketReferer($this->bucket);
|
||||
$this->assertEquals($refererConfig->serializeToXml(), $refererConfig2->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$nullRefererConfig = new RefererConfig();
|
||||
$nullRefererConfig->setAllowEmptyReferer(false);
|
||||
$this->ossClient->putBucketReferer($this->bucket, $nullRefererConfig);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$refererConfig3 = $this->ossClient->getBucketLogging($this->bucket);
|
||||
$this->assertNotEquals($refererConfig->serializeToXml(), $refererConfig3->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\RequestPaymentConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketRequestPaymentTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$payer = $this->ossClient->getBucketRequestPayment($this->bucket);
|
||||
$this->assertEquals("BucketOwner", $payer);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketRequestPayment($this->bucket, "Requester");
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$payer = $this->ossClient->getBucketRequestPayment($this->bucket);
|
||||
$this->assertEquals("Requester", $payer);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketRequestPayment($this->bucket, "BucketOwner");
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$payer = $this->ossClient->getBucketRequestPayment($this->bucket);
|
||||
$this->assertEquals("BucketOwner", $payer);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
class OssClientBucketStatTestTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucketStat()
|
||||
{
|
||||
try {
|
||||
$content = "hello";
|
||||
$this->ossClient->putObject($this->bucket, "name-1.txt", $content);
|
||||
$this->ossClient->putObject($this->bucket, "name-2.txt", $content);
|
||||
$this->ossClient->putObject($this->bucket, "name-3.txt", $content);
|
||||
|
||||
$object = "multipart-test.txt";
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
|
||||
Common::waitMetaSync();
|
||||
Common::waitMetaSync();
|
||||
Common::waitMetaSync();
|
||||
$stat = $this->ossClient->getBucketStat($this->bucket);
|
||||
$this->assertEquals(3, $stat->getObjectCount());
|
||||
$this->assertEquals(15, $stat->getStorage());
|
||||
$this->assertEquals(1, $stat->getMultipartUploadCount());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
class OssClientBucketStorageCapacityTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
|
||||
$this->assertEquals($storageCapacity, -1);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketStorageCapacity($this->bucket, 1000);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
|
||||
$this->assertEquals($storageCapacity, 1000);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketStorageCapacity($this->bucket, 0);
|
||||
|
||||
Common::waitMetaSync();
|
||||
|
||||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
|
||||
$this->assertEquals($storageCapacity, 0);
|
||||
|
||||
$this->ossClient->putObject($this->bucket, 'test-storage-capacity','test-content');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('Bucket storage exceed max storage capacity.',$e->getErrorMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketStorageCapacity($this->bucket, -2);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals(400, $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidArgument', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketTagsTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$config = $this->ossClient->getBucketTags($this->bucket);
|
||||
$this->assertEquals(0, count($config->getTags()));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
$config->addTag(new Tag("key3", "value3"));
|
||||
$this->ossClient->putBucketTags($this->bucket, $config);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$config2 = $this->ossClient->getBucketTags($this->bucket);
|
||||
$this->assertEquals(3, count($config2->getTags()));
|
||||
$this->assertEquals("key1", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $config2->getTags()[0]->getValue());
|
||||
$this->assertEquals("key2", $config2->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[1]->getValue());
|
||||
$this->assertEquals("key3", $config2->getTags()[2]->getKey());
|
||||
$this->assertEquals("value3", $config2->getTags()[2]->getValue());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
//del key1, key3
|
||||
$tags = array();
|
||||
$tags[] = new Tag("key1", "value1");
|
||||
$tags[] = new Tag("key3", "value3");
|
||||
|
||||
$this->ossClient->deleteBucketTags($this->bucket, $tags);
|
||||
$config2 = $this->ossClient->getBucketTags($this->bucket);
|
||||
$this->assertEquals(1, count($config2->getTags()));
|
||||
$this->assertEquals("key2", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[0]->getValue());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
//del all
|
||||
$this->ossClient->deleteBucketTags($this->bucket);
|
||||
$config2 = $this->ossClient->getBucketTags($this->bucket);
|
||||
$this->assertEquals(0, count($config2->getTags()));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketTest extends TestOssClientBase
|
||||
{
|
||||
private $standardBucket;
|
||||
private $iaBucket;
|
||||
private $archiveBucket;
|
||||
|
||||
public function testBucketWithInvalidName()
|
||||
{
|
||||
try {
|
||||
$this->ossClient->createBucket("s");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('"s"bucket name is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testBucketWithInvalidACL()
|
||||
{
|
||||
try {
|
||||
$this->ossClient->createBucket($this->bucket, "invalid");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('invalid:acl is invalid(private,public-read,public-read-write)', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testBucket()
|
||||
{
|
||||
$this->ossClient->createBucket($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
|
||||
$bucketListInfo = $this->ossClient->listBuckets();
|
||||
$this->assertNotNull($bucketListInfo);
|
||||
|
||||
$bucketList = $bucketListInfo->getBucketList();
|
||||
$this->assertTrue(is_array($bucketList));
|
||||
$this->assertGreaterThan(0, count($bucketList));
|
||||
|
||||
$this->ossClient->putBucketAcl($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
Common::waitMetaSync();
|
||||
$this->assertEquals($this->ossClient->getBucketAcl($this->bucket), OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
|
||||
$this->assertTrue($this->ossClient->doesBucketExist($this->bucket));
|
||||
$this->assertFalse($this->ossClient->doesBucketExist($this->bucket . '-notexist'));
|
||||
|
||||
$this->assertEquals($this->ossClient->getBucketLocation($this->bucket), Common::getRegion());
|
||||
|
||||
$res = $this->ossClient->getBucketMeta($this->bucket);
|
||||
$this->assertEquals('200', $res['info']['http_code']);
|
||||
$this->assertEquals(Common::getRegion(), $res['x-oss-bucket-region']);
|
||||
}
|
||||
|
||||
public function testCreateBucketWithStorageType()
|
||||
{
|
||||
$object = 'storage-object';
|
||||
|
||||
$this->ossClient->putObject($this->archiveBucket, $object,'testcontent');
|
||||
try {
|
||||
$this->ossClient->getObject($this->archiveBucket, $object);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('403', $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidObjectState', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$this->ossClient->putObject($this->iaBucket, $object,'testcontent');
|
||||
$result = $this->ossClient->getObject($this->iaBucket, $object);
|
||||
$this->assertEquals($result, 'testcontent');
|
||||
|
||||
$this->ossClient->putObject($this->bucket, $object,'testcontent');
|
||||
$result = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($result, 'testcontent');
|
||||
}
|
||||
|
||||
public function testCreateBucketWithInvalidStorageType()
|
||||
{
|
||||
try {
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => 'unknown'
|
||||
);
|
||||
$this->ossClient->createBucket('bucket-name', OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
if (strpos($e, "storage name is invalid") == false)
|
||||
{
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->iaBucket = 'ia-' . $this->bucket;
|
||||
$this->archiveBucket = 'archive-' . $this->bucket;
|
||||
$this->standardBucket = 'standard-' . $this->bucket;
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_IA
|
||||
);
|
||||
|
||||
$this->ossClient->createBucket($this->iaBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_ARCHIVE
|
||||
);
|
||||
|
||||
$this->ossClient->createBucket($this->archiveBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_STANDARD
|
||||
);
|
||||
|
||||
$this->ossClient->createBucket($this->standardBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$object = 'storage-object';
|
||||
|
||||
$this->ossClient->deleteObject($this->iaBucket, $object);
|
||||
$this->ossClient->deleteObject($this->archiveBucket, $object);
|
||||
$this->ossClient->deleteBucket($this->iaBucket);
|
||||
$this->ossClient->deleteBucket($this->archiveBucket);
|
||||
$this->ossClient->deleteBucket($this->standardBucket);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketTransferAccelerationTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketTransferAcceleration($this->bucket);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("NoSuchTransferAccelerationConfiguration", $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketTransferAcceleration($this->bucket, true);
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketTransferAcceleration($this->bucket);
|
||||
$this->assertEquals(true, $status);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketTransferAcceleration($this->bucket, false);
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketTransferAcceleration($this->bucket);
|
||||
$this->assertEquals(false, $status);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketVersioningTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketVersioning($this->bucket);
|
||||
$this->assertEquals(null, $status);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketVersioning($this->bucket, "Enabled");
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketVersioning($this->bucket);
|
||||
$this->assertEquals("Enabled", $status);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketVersioning($this->bucket, "Suspended");
|
||||
Common::waitMetaSync();
|
||||
$status = $this->ossClient->getBucketVersioning($this->bucket);
|
||||
$this->assertEquals("Suspended", $status);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\WebsiteConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketWebsiteTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
|
||||
$websiteConfig = new WebsiteConfig("index.html", "error.html");
|
||||
|
||||
try {
|
||||
$this->ossClient->putBucketWebsite($this->bucket, $websiteConfig);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$websiteConfig2 = $this->ossClient->getBucketWebsite($this->bucket);
|
||||
$this->assertEquals($websiteConfig->serializeToXml(), $websiteConfig2->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$this->ossClient->deleteBucketWebsite($this->bucket);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
try {
|
||||
Common::waitMetaSync();
|
||||
$websiteConfig3 = $this->ossClient->getBucketLogging($this->bucket);
|
||||
$this->assertNotEquals($websiteConfig->serializeToXml(), $websiteConfig3->serializeToXml());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketWormTest extends TestOssClientBase
|
||||
{
|
||||
public function testBucket()
|
||||
{
|
||||
try {
|
||||
$wormId = $this->ossClient->initiateBucketWorm($this->bucket, 30);
|
||||
$config = $this->ossClient->getBucketWorm($this->bucket);
|
||||
$this->assertEquals($wormId, $config->getWormId());
|
||||
$this->assertEquals("InProgress", $config->getState());
|
||||
$this->assertEquals(30, $config->getDay());
|
||||
$this->ossClient->abortBucketWorm($this->bucket);
|
||||
|
||||
$wormId = $this->ossClient->initiateBucketWorm($this->bucket, 60);
|
||||
$this->ossClient->completeBucketWorm($this->bucket, $wormId);
|
||||
$config = $this->ossClient->getBucketWorm($this->bucket);
|
||||
|
||||
$this->ossClient->ExtendBucketWorm($this->bucket, $wormId, 120);
|
||||
$config = $this->ossClient->getBucketWorm($this->bucket);
|
||||
$this->assertEquals($wormId, $config->getWormId());
|
||||
$this->assertEquals("Locked", $config->getState());
|
||||
$this->assertEquals(120, $config->getDay());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
|
||||
class OssClinetImageTest extends TestOssClientBase
|
||||
{
|
||||
private $bucketName;
|
||||
private $client;
|
||||
private $local_file;
|
||||
private $object;
|
||||
private $download_file;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->client = $this->ossClient;
|
||||
$this->bucketName = $this->bucket;
|
||||
$this->local_file = "example.jpg";
|
||||
$this->object = "oss-example.jpg";
|
||||
$this->download_file = "image.jpg";
|
||||
|
||||
Common::waitMetaSync();
|
||||
$this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
unlink($this->download_file);
|
||||
}
|
||||
|
||||
public function testImageResize()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/resize,m_fixed,h_100,w_100", );
|
||||
$this->check($options, 100, 100, 3267, 'jpg');
|
||||
}
|
||||
|
||||
public function testImageCrop()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/crop,w_100,h_100,x_100,y_100,r_1", );
|
||||
$this->check($options, 100, 100, 1969, 'jpg');
|
||||
}
|
||||
|
||||
public function testImageRotate()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/rotate,90", );
|
||||
$this->check($options, 267, 400, 20998, 'jpg');
|
||||
}
|
||||
|
||||
public function testImageSharpen()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/sharpen,100", );
|
||||
$this->check($options, 400, 267, 23015, 'jpg');
|
||||
}
|
||||
|
||||
public function testImageWatermark()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ", );
|
||||
$this->check($options, 400, 267, 26369, 'jpg');
|
||||
}
|
||||
|
||||
public function testImageFormat()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/format,png", );
|
||||
$this->check($options, 400, 267, 160733, 'png');
|
||||
}
|
||||
|
||||
public function testImageTofile()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
OssClient::OSS_PROCESS => "image/resize,m_fixed,w_100,h_100", );
|
||||
$this->check($options, 100, 100, 3267, 'jpg');
|
||||
}
|
||||
|
||||
public function testProcesObject()
|
||||
{
|
||||
$object = 'process-object.jpg';
|
||||
$process = 'image/resize,m_fixed,w_100,h_100'.
|
||||
'|sys/saveas'.
|
||||
',o_'.$this->base64url_encode($object).
|
||||
',b_'.$this->base64url_encode($this->bucketName);
|
||||
$result = $this->client->processObject($this->bucketName, $this->object, $process);
|
||||
$this->assertTrue(stripos($result, '"object": "process-object.jpg",') > 0);
|
||||
$this->assertTrue(stripos($result, '"status": "OK"') > 0);
|
||||
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
);
|
||||
$this->client->getObject($this->bucketName, $object, $options);
|
||||
$array = getimagesize($this->download_file);
|
||||
$this->assertEquals(100, $array[0]);
|
||||
$this->assertEquals(100, $array[1]);
|
||||
$this->assertEquals(2, $array[2]);
|
||||
|
||||
//without bucket
|
||||
$object = 'process-object-1.jpg';
|
||||
$process = 'image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ'.
|
||||
'|sys/saveas'.
|
||||
',o_'.$this->base64url_encode($object);
|
||||
$result = $this->client->processObject($this->bucketName, $this->object, $process);
|
||||
$this->assertTrue(stripos($result, '"object": "process-object-1.jpg",') > 0);
|
||||
$this->assertTrue(stripos($result, '"status": "OK"') > 0);
|
||||
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
|
||||
);
|
||||
$this->client->getObject($this->bucketName, $object, $options);
|
||||
$array = getimagesize($this->download_file);
|
||||
$this->assertEquals(400, $array[0]);
|
||||
$this->assertEquals(267, $array[1]);
|
||||
$this->assertEquals(2, $array[2]);
|
||||
}
|
||||
|
||||
private function check($options, $width, $height, $size, $type)
|
||||
{
|
||||
$this->client->getObject($this->bucketName, $this->object, $options);
|
||||
$array = getimagesize($this->download_file);
|
||||
$this->assertEquals($width, $array[0]);
|
||||
$this->assertEquals($height, $array[1]);
|
||||
$this->assertEquals($type === 'jpg' ? 2 : 3, $array[2]);//2 <=> jpg
|
||||
}
|
||||
|
||||
private function base64url_encode($data)
|
||||
{
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientListObjectsTest extends TestOssClientBase
|
||||
{
|
||||
public function testListObjectsDefault()
|
||||
{
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket);
|
||||
$objectList = $listObjectInfo->getObjectList();
|
||||
$prefixList = $listObjectInfo->getPrefixList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
$this->assertEquals((2), count($objectList));
|
||||
$this->assertEquals(4, count($prefixList));
|
||||
|
||||
$this->assertEquals('file++00', $objectList[0]->getKey());
|
||||
$this->assertEquals('file++01', $objectList[1]->getKey());
|
||||
|
||||
$this->assertEquals('folder/', $prefixList[0]->getPrefix());
|
||||
$this->assertEquals('sub++/', $prefixList[1]->getPrefix());
|
||||
$this->assertEquals('test/', $prefixList[2]->getPrefix());
|
||||
$this->assertEquals('work/', $prefixList[3]->getPrefix());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testListObjectsWithPrefix()
|
||||
{
|
||||
/**
|
||||
* List the files in your bucket.
|
||||
*/
|
||||
$prefix = 'folder/';
|
||||
$delimiter = '';
|
||||
$next_marker = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'marker' => $next_marker,
|
||||
);
|
||||
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket, $options);
|
||||
$objectList = $listObjectInfo->getObjectList();
|
||||
$prefixList = $listObjectInfo->getPrefixList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
$this->assertEquals(12, count($objectList));
|
||||
$this->assertEquals(0, count($prefixList));
|
||||
|
||||
$this->assertEquals('folder/00', $objectList[0]->getKey());
|
||||
$this->assertEquals('folder/01', $objectList[1]->getKey());
|
||||
$this->assertEquals('folder/11', $objectList[11]->getKey());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testListObjectsWithMaxKeysAndMarker()
|
||||
{
|
||||
$count = 0;
|
||||
$nextMarker = '';
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'marker' => $nextMarker,
|
||||
'max-keys' => 2,
|
||||
);
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$nextMarker = $listObjectInfo->getNextMarker();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$count += count($listObject);
|
||||
$this->assertEquals(2, count($listObject));
|
||||
if ($listObjectInfo->getIsTruncated() !== "true") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(12 + 8 + 5 + 3 + 2, $count);
|
||||
}
|
||||
|
||||
public function testListObjectsWithMarker()
|
||||
{
|
||||
$count = 0;
|
||||
$nextMarker = 'h';
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'marker' => $nextMarker,
|
||||
'max-keys' => 1,
|
||||
);
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$nextMarker = $listObjectInfo->getNextMarker();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$count += count($listObject);
|
||||
$this->assertEquals(1, count($listObject));
|
||||
if ($listObjectInfo->getIsTruncated() !== "true") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(8 + 5 + 3, $count);
|
||||
|
||||
|
||||
$nextMarker = 'h';
|
||||
|
||||
try {
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'marker' => $nextMarker,
|
||||
'max-keys' => 5,
|
||||
);
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$nextMarker = $listObjectInfo->getNextMarker();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$this->assertEquals('test/01', $nextMarker);
|
||||
$this->assertEquals(5, count($listObject));
|
||||
$this->assertEquals("true", $listObjectInfo->getIsTruncated());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
//folder
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$key = 'folder/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//test
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$key = 'test/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//work
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$key = 'work/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//sub++
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$key = 'sub++/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
|
||||
//file++
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$key = 'file++'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientListObjectsV2Test extends TestOssClientBase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
//folder
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$key = 'folder/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//test
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$key = 'test/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//work
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$key = 'work/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//sub++
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$key = 'sub++/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
|
||||
//file++
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$key = 'file++'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
public function testListObjectsDefault()
|
||||
{
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjectsV2($this->bucket);
|
||||
$objectList = $listObjectInfo->getObjectList();
|
||||
$prefixList = $listObjectInfo->getPrefixList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
$this->assertEquals((2), count($objectList));
|
||||
$this->assertEquals(4, count($prefixList));
|
||||
|
||||
$this->assertEquals('file++00', $objectList[0]->getKey());
|
||||
$this->assertEquals('file++01', $objectList[1]->getKey());
|
||||
|
||||
$this->assertEquals('folder/', $prefixList[0]->getPrefix());
|
||||
$this->assertEquals('sub++/', $prefixList[1]->getPrefix());
|
||||
$this->assertEquals('test/', $prefixList[2]->getPrefix());
|
||||
$this->assertEquals('work/', $prefixList[3]->getPrefix());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testListObjectsWithPrefix()
|
||||
{
|
||||
/**
|
||||
* List the files in your bucket.
|
||||
*/
|
||||
$prefix = 'folder/';
|
||||
$delimiter = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
);
|
||||
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjectsV2($this->bucket, $options);
|
||||
$objectList = $listObjectInfo->getObjectList();
|
||||
$prefixList = $listObjectInfo->getPrefixList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
$this->assertEquals(12, count($objectList));
|
||||
$this->assertEquals(0, count($prefixList));
|
||||
|
||||
$this->assertEquals('folder/00', $objectList[0]->getKey());
|
||||
$this->assertEquals('folder/01', $objectList[1]->getKey());
|
||||
$this->assertEquals('folder/11', $objectList[11]->getKey());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testListObjectsWithMaxKeysAndMarker()
|
||||
{
|
||||
$count = 0;
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'max-keys' => 2,
|
||||
);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
|
||||
$listObjectInfo = $this->ossClient->listObjectsV2($this->bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$options[OssClient::OSS_CONTINUATION_TOKEN] = $listObjectInfo->getNextContinuationToken();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$count += count($listObject);
|
||||
$this->assertEquals(2, count($listObject));
|
||||
if ($listObjectInfo->getIsTruncated() !== "true") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(12 + 8 + 5 + 3 + 2, $count);
|
||||
}
|
||||
|
||||
|
||||
public function testListObjectsWithStartAfter()
|
||||
{
|
||||
$count = 0;
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'start-after' => 'folder/11',
|
||||
'max-keys' => 1,
|
||||
);
|
||||
while (true) {
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjectsV2($this->bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$options[OssClient::OSS_CONTINUATION_TOKEN] = $listObjectInfo->getNextContinuationToken();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$count += count($listObject);
|
||||
$this->assertEquals(1, count($listObject));
|
||||
if ($listObjectInfo->getIsTruncated() !== "true") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(8 + 5 + 3, $count);
|
||||
$options2 = array(
|
||||
'delimiter' => '',
|
||||
'start-after' => 'folder/11',
|
||||
'max-keys' => 5,
|
||||
);
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjectsV2($this->bucket, $options2);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$this->assertEquals(5, count($listObject));
|
||||
$this->assertEquals("true", $listObjectInfo->getIsTruncated());
|
||||
}
|
||||
}
|
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssUtil;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientMultipartUploadTest extends TestOssClientBase
|
||||
{
|
||||
public function testInvalidDir()
|
||||
{
|
||||
try {
|
||||
$this->ossClient->uploadDir($this->bucket, "", "abc/ds/s/s/notexitst");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("parameter error: abc/ds/s/s/notexitst is not a directory, please check it", $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testMultipartUploadBigFile()
|
||||
{
|
||||
$bigFileName = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile.tmp";
|
||||
$localFilename = __DIR__ . DIRECTORY_SEPARATOR . "/localfile.tmp";
|
||||
OssUtil::generateFile($bigFileName, 6 * 1024 * 1024);
|
||||
$object = 'mpu/multipart-bigfile-test.tmp';
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $bigFileName, array(OssClient::OSS_PART_SIZE => 1));
|
||||
$options = array(OssClient::OSS_FILE_DOWNLOAD => $localFilename);
|
||||
$this->ossClient->getObject($this->bucket, $object, $options);
|
||||
$this->assertEquals(md5_file($bigFileName), md5_file($localFilename));
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
unlink($bigFileName);
|
||||
unlink($localFilename);
|
||||
}
|
||||
|
||||
public function testMultipartUploadBigFileWithMD5Check()
|
||||
{
|
||||
$bigFileName = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile.tmp";
|
||||
$localFilename = __DIR__ . DIRECTORY_SEPARATOR . "/localfile.tmp";
|
||||
OssUtil::generateFile($bigFileName, 6 * 1024 * 1024);
|
||||
$object = 'mpu/multipart-bigfile-test.tmp';
|
||||
$options = array(
|
||||
OssClient::OSS_CHECK_MD5 => true,
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
);
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $bigFileName, $options);
|
||||
$options = array(OssClient::OSS_FILE_DOWNLOAD => $localFilename);
|
||||
$this->ossClient->getObject($this->bucket, $object, $options);
|
||||
$this->assertEquals(md5_file($bigFileName), md5_file($localFilename));
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
unlink($bigFileName);
|
||||
unlink($localFilename);
|
||||
}
|
||||
|
||||
public function testCopyPart()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
$copiedObject = "mpu/multipart-test.txt.copied";
|
||||
$this->ossClient->putObject($this->bucket, $copiedObject, file_get_contents(__FILE__));
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$copyId = 1;
|
||||
$eTag = $this->ossClient->uploadPartCopy($this->bucket, $copiedObject, $this->bucket, $object, $copyId, $upload_id);
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->ossClient->listParts($this->bucket, $object, $upload_id);
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $object), file_get_contents(__FILE__));
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $copiedObject), file_get_contents(__FILE__));
|
||||
}
|
||||
|
||||
public function testCopyPartWithRange()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
$copiedObject = "mpu/multipart-test.txt.range.copied";
|
||||
$this->ossClient->putObject($this->bucket, $copiedObject, file_get_contents(__FILE__));
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. uploadPartCopy
|
||||
*/
|
||||
$copyId = 1;
|
||||
$options = array(
|
||||
'start' => 0,
|
||||
'end' => 3,
|
||||
);
|
||||
$eTag = $this->ossClient->uploadPartCopy($this->bucket, $copiedObject, $this->bucket, $object, $copyId, $upload_id, $options);
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->ossClient->listParts($this->bucket, $object, $upload_id);
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $copiedObject), file_get_contents(__FILE__));
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $object), '<?ph');
|
||||
}
|
||||
|
||||
public function testAbortMultipartUpload()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$part_size = 10 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = sprintf('%u',filesize($upload_file));
|
||||
$pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size);
|
||||
$response_upload_part = array();
|
||||
$upload_position = 0;
|
||||
$is_check_md5 = true;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece[OssClient::OSS_SEEK_TO];
|
||||
$to_pos = (integer)$piece[OssClient::OSS_LENGTH] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
OssClient::OSS_FILE_UPLOAD => $upload_file,
|
||||
OssClient::OSS_PART_NUM => ($i + 1),
|
||||
OssClient::OSS_SEEK_TO => $from_pos,
|
||||
OssClient::OSS_LENGTH => $to_pos - $from_pos + 1,
|
||||
OssClient::OSS_CHECK_MD5 => $is_check_md5,
|
||||
);
|
||||
if ($is_check_md5) {
|
||||
$content_md5 = OssUtil::getMd5SumForFile($upload_file, $from_pos, $to_pos);
|
||||
$up_options[OssClient::OSS_CONTENT_MD5] = $content_md5;
|
||||
}
|
||||
//2. 将每一分片上传到OSS
|
||||
try {
|
||||
$response_upload_part[] = $this->ossClient->uploadPart($this->bucket, $object, $upload_id, $up_options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $eTag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->ossClient->listParts($this->bucket, $object, $upload_id, array('max-parts' => 100));
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
$this->assertEquals(1, count($listPartsInfo->getListPart()));
|
||||
|
||||
$numOfMultipartUpload1 = 0;
|
||||
$options = null;
|
||||
try {
|
||||
$listMultipartUploadInfo = $listMultipartUploadInfo = $this->ossClient->listMultipartUploads($this->bucket, $options);
|
||||
$this->assertNotNull($listMultipartUploadInfo);
|
||||
$numOfMultipartUpload1 = count($listMultipartUploadInfo->getUploads());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->abortMultipartUpload($this->bucket, $object, $upload_id);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$numOfMultipartUpload2 = 0;
|
||||
try {
|
||||
$listMultipartUploadInfo = $listMultipartUploadInfo = $this->ossClient->listMultipartUploads($this->bucket, array('max-uploads' => 1000));
|
||||
$this->assertNotNull($listMultipartUploadInfo);
|
||||
$numOfMultipartUpload2 = count($listMultipartUploadInfo->getUploads());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertEquals($numOfMultipartUpload1 - 1, $numOfMultipartUpload2);
|
||||
}
|
||||
|
||||
public function testPutObjectByRawApis()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$part_size = 10 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = sprintf('%u',filesize($upload_file));
|
||||
$pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size);
|
||||
$response_upload_part = array();
|
||||
$upload_position = 0;
|
||||
$is_check_md5 = true;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece[OssClient::OSS_SEEK_TO];
|
||||
$to_pos = (integer)$piece[OssClient::OSS_LENGTH] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
OssClient::OSS_FILE_UPLOAD => $upload_file,
|
||||
OssClient::OSS_PART_NUM => ($i + 1),
|
||||
OssClient::OSS_SEEK_TO => $from_pos,
|
||||
OssClient::OSS_LENGTH => $to_pos - $from_pos + 1,
|
||||
OssClient::OSS_CHECK_MD5 => $is_check_md5,
|
||||
);
|
||||
if ($is_check_md5) {
|
||||
$content_md5 = OssUtil::getMd5SumForFile($upload_file, $from_pos, $to_pos);
|
||||
$up_options[OssClient::OSS_CONTENT_MD5] = $content_md5;
|
||||
}
|
||||
//2. 将每一分片上传到OSS
|
||||
try {
|
||||
$response_upload_part[] = $this->ossClient->uploadPart($this->bucket, $object, $upload_id, $up_options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $eTag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->ossClient->listParts($this->bucket, $object, $upload_id);
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
function testPutObjectsByDir()
|
||||
{
|
||||
$localDirectory = dirname(__FILE__);
|
||||
$prefix = "samples/codes";
|
||||
try {
|
||||
$this->ossClient->uploadDir($this->bucket, $prefix, $localDirectory);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e->getMessage());
|
||||
$this->assertFalse(true);
|
||||
|
||||
}
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, 'samples/codes/' . "OssClientMultipartUploadTest.php"));
|
||||
}
|
||||
|
||||
public function testPutObjectByMultipartUpload()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
$file = __FILE__;
|
||||
$options = array();
|
||||
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file, $options);
|
||||
$this->assertFalse(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutObjectByMultipartUploadWithMD5Check()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
$file = __FILE__;
|
||||
$options = array(OssClient::OSS_CHECK_MD5 => true);
|
||||
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file, $options);
|
||||
$this->assertFalse(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutObjectByMultipartUploadWithOSS_LENGTH()
|
||||
{
|
||||
$object = "mpu/multipart-test-length.txt";
|
||||
$file = __FILE__;
|
||||
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
$options = array(OssClient::OSS_LENGTH => 4, OssClient::OSS_UPLOAD_ID => $upload_id);
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file, $options);
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $object), '<?ph');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutObjectByMultipartUploadWithOSS_CONTENT_LENGTH()
|
||||
{
|
||||
$object = "mpu/multipart-test-content-length.txt";
|
||||
$file = __FILE__;
|
||||
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
$options = array(OssClient::OSS_CONTENT_LENGTH => 4, OssClient::OSS_UPLOAD_ID => $upload_id);
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file, $options);
|
||||
$this->assertEquals($this->ossClient->getObject($this->bucket, $object), '<?ph');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutObjectByMultipartUploadWithException()
|
||||
{
|
||||
$object = "mpu/multipart-test-exception.txt";
|
||||
$file = "";
|
||||
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
if (strpos($e, "parameter invalid, file is empty") == false)
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testListMultipartUploads()
|
||||
{
|
||||
$options = null;
|
||||
try {
|
||||
$listMultipartUploadInfo = $this->ossClient->listMultipartUploads($this->bucket, $options);
|
||||
$this->assertNotNull($listMultipartUploadInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCompleteMultipartUploadWithException()
|
||||
{
|
||||
$object = "mpu/multipart-test-complete.txt";
|
||||
$uploadId = "uploadId";
|
||||
try {
|
||||
$listMultipartUploadInfo = $this->ossClient->completeMultipartUpload($this->bucket, $object, $uploadId, null);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('NoSuchUpload', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCompleteMultipartUploadWithEmptyArray(){
|
||||
$object = 'multipart-test-complete.txt';
|
||||
try {
|
||||
$uploadId = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
$listMultipartUploadInfo = $this->ossClient->completeMultipartUpload($this->bucket, $object, $uploadId, array());
|
||||
var_dump($listMultipartUploadInfo);
|
||||
$this->assertNotNull($listMultipartUploadInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testCompleteMultipartUploadWithNull(){
|
||||
$object = "mpu/multipart-test.txt";
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$part_size = 5 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = sprintf('%u',filesize($upload_file));
|
||||
$pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size);
|
||||
$response_upload_part = array();
|
||||
$upload_position = 0;
|
||||
$is_check_md5 = true;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece[OssClient::OSS_SEEK_TO];
|
||||
$to_pos = (integer)$piece[OssClient::OSS_LENGTH] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
OssClient::OSS_FILE_UPLOAD => $upload_file,
|
||||
OssClient::OSS_PART_NUM => ($i + 1),
|
||||
OssClient::OSS_SEEK_TO => $from_pos,
|
||||
OssClient::OSS_LENGTH => $to_pos - $from_pos + 1,
|
||||
OssClient::OSS_CHECK_MD5 => $is_check_md5,
|
||||
);
|
||||
if ($is_check_md5) {
|
||||
$content_md5 = OssUtil::getMd5SumForFile($upload_file, $from_pos, $to_pos);
|
||||
$up_options[OssClient::OSS_CONTENT_MD5] = $content_md5;
|
||||
}
|
||||
try {
|
||||
$response_upload_part[] = $this->ossClient->uploadPart($this->bucket, $object, $upload_id, $up_options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $eTag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->ossClient->listParts($this->bucket, $object, $upload_id);
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$options['headers'] = array(
|
||||
'x-oss-forbid-overwrite' => 'false',
|
||||
'x-oss-complete-all'=> 'yes'
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, null,$options);
|
||||
var_dump($result);
|
||||
$this->assertNotNull($result);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,472 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
use OSS\Model\RestoreConfig;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
use OSS\Core\OssUtil;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientObjectRequestPaymentTest extends TestOssClientBase
|
||||
{
|
||||
private $payerClient;
|
||||
|
||||
public function testPayerClientWithoutRequester()
|
||||
{
|
||||
try {
|
||||
$this->payerClient->listObjects($this->bucket);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->createObjectDir($this->bucket, 'folder/');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->putObject($this->bucket, 'object', 'content');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->putSymlink($this->bucket, 'symlink', 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getSymlink($this->bucket, 'default-symlink');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->uploadFile($this->bucket, 'file-object', __FILE__);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->appendObject($this->bucket, 'append-object', 'content', 0);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->appendObject($this->bucket, 'append-file', __FILE__, 0);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->copyObject($this->bucket, 'default-object', $this->bucket, 'copy-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObjectMeta($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getSimplifiedObjectMeta($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->deleteObject($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObject($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->doesObjectExist($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->restoreObject($this->bucket, 'default-ia-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$this->payerClient->putObjectTagging($this->bucket, 'default-object', $config);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObjectTagging($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->deleteObjectTagging($this->bucket, 'default-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->initiateMultipartUpload($this->bucket, 'mup-object');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$uploadId= $this->ossClient->initiateMultipartUpload($this->bucket, 'mup-object');
|
||||
|
||||
try {
|
||||
$this->payerClient->listParts($this->bucket, 'mup-object', $uploadId);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->abortMultipartUpload($this->bucket, 'mup-object', $uploadId);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->listMultipartUploads($this->bucket);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->multiuploadFile($this->bucket, 'mup-file', __FILE__);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('AccessDenied', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testObjectOperationsWithRequester()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
try {
|
||||
$this->payerClient->listObjects($this->bucket, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->createObjectDir($this->bucket, 'folder/', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->putObject($this->bucket, 'object', 'content', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->putSymlink($this->bucket, 'symlink', 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getSymlink($this->bucket, 'default-symlink', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->uploadFile($this->bucket, 'file-object', __FILE__, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->appendObject($this->bucket, 'append-object', 'content', 0, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->appendObject($this->bucket, 'append-file', __FILE__, 0, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->copyObject($this->bucket, 'default-object', $this->bucket, 'copy-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObjectMeta($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getSimplifiedObjectMeta($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObject($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->putObject($this->bucket, 'test-object', 'content', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->deleteObject($this->bucket, 'test-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->doesObjectExist($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$ia_options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-storage-class' => 'Archive',
|
||||
));
|
||||
$this->ossClient->putObject($this->bucket, 'default-Archive-object', 'content', $ia_options);
|
||||
try {
|
||||
$this->payerClient->restoreObject($this->bucket, 'default-Archive-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$this->payerClient->putObjectTagging($this->bucket, 'default-object', $config, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->getObjectTagging($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->payerClient->deleteObjectTagging($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMultipartOperationsWithRequester()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
$object = "mpu/multipart-test.txt";
|
||||
/**
|
||||
* step 1. 初始化一个分块上传事件, 也就是初始化上传Multipart, 获取upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->payerClient->initiateMultipartUpload($this->bucket, $object, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* step 2. 上传分片
|
||||
*/
|
||||
$part_size = 1 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = sprintf('%u',filesize($upload_file));
|
||||
$pieces = $this->payerClient->generateMultiuploadParts($upload_filesize, $part_size);
|
||||
$response_upload_part = array();
|
||||
$upload_position = 0;
|
||||
$is_check_md5 = false;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$from_pos = $upload_position + (integer)$piece[OssClient::OSS_SEEK_TO];
|
||||
$to_pos = (integer)$piece[OssClient::OSS_LENGTH] + $from_pos - 1;
|
||||
$up_options = array(
|
||||
OssClient::OSS_FILE_UPLOAD => $upload_file,
|
||||
OssClient::OSS_PART_NUM => ($i + 1),
|
||||
OssClient::OSS_SEEK_TO => $from_pos,
|
||||
OssClient::OSS_LENGTH => $to_pos - $from_pos + 1,
|
||||
OssClient::OSS_CHECK_MD5 => $is_check_md5,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
),
|
||||
);
|
||||
|
||||
//2. 将每一分片上传到OSS
|
||||
try {
|
||||
$response_upload_part[] = $this->ossClient->uploadPart($this->bucket, $object, $upload_id, $up_options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
$upload_parts = array();
|
||||
foreach ($response_upload_part as $i => $eTag) {
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$listPartsInfo = $this->payerClient->listParts($this->bucket, $object, $upload_id, $options);
|
||||
$this->assertNotNull($listPartsInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$uploads = $this->payerClient->listMultipartUploads($this->bucket, $options);
|
||||
$this->assertNotNull($uploads);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
try {
|
||||
$this->payerClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMiscOperationsWithRequester()
|
||||
{
|
||||
//use multipart
|
||||
$options = array(
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
$bigFileName = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile.tmp";
|
||||
OssUtil::generateFile($bigFileName, 256 * 1024);
|
||||
$object = 'mpu/multipart-bigfile-test.tmp';
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $bigFileName, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
//use uploadfile
|
||||
$options = array(
|
||||
OssClient::OSS_PART_SIZE => 1024*1024,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_REQUEST_PAYER => 'requester',
|
||||
));
|
||||
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $bigFileName, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
unlink($bigFileName);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->payerClient = new OssClient(
|
||||
getenv('OSS_PAYER_ACCESS_KEY_ID'),
|
||||
getenv('OSS_PAYER_ACCESS_KEY_SECRET'),
|
||||
getenv('OSS_ENDPOINT'), false);
|
||||
|
||||
$policy = '{"Version":"1","Statement":[{"Action":["oss:*"],"Effect": "Allow",'.
|
||||
'"Principal":["' . getenv('OSS_PAYER_UID') . '"],'.
|
||||
'"Resource": ["acs:oss:*:*:' . $this->bucket . '","acs:oss:*:*:' . $this->bucket . '/*"]}]}';
|
||||
|
||||
$this->ossClient->putBucketPolicy($this->bucket, $policy);
|
||||
$this->ossClient->putBucketRequestPayment($this->bucket, 'Requester');
|
||||
$this->ossClient->putObject($this->bucket, "default-object", "");
|
||||
$this->ossClient->putSymlink($this->bucket, "default-symlink", "default-object");
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientObjectTaggingTest extends TestOssClientBase
|
||||
{
|
||||
public function testObjectTagging()
|
||||
{
|
||||
$object = "object-tagging.txt";
|
||||
$content = "hello world";
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$config = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(0, count($config->getTags()));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key1", "value1"));
|
||||
$config->addTag(new Tag("key2", "value2"));
|
||||
$config->addTag(new Tag("key3", "value3"));
|
||||
$this->ossClient->putObjectTagging($this->bucket, $object, $config);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$config2 = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(3, count($config2->getTags()));
|
||||
$this->assertEquals("key1", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $config2->getTags()[0]->getValue());
|
||||
$this->assertEquals("key2", $config2->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[1]->getValue());
|
||||
$this->assertEquals("key3", $config2->getTags()[2]->getKey());
|
||||
$this->assertEquals("value3", $config2->getTags()[2]->getValue());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->deleteObjectTagging($this->bucket, $object);
|
||||
$config2 = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(0, count($config2->getTags()));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutObjectTaggingFromHeader()
|
||||
{
|
||||
$object = "object-tagging-header.txt";
|
||||
$content = "hello world";
|
||||
|
||||
try {
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$config2 = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(3, count($config2->getTags()));
|
||||
$this->assertEquals("key1", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $config2->getTags()[0]->getValue());
|
||||
$this->assertEquals("key2", $config2->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[1]->getValue());
|
||||
$this->assertEquals("key3", $config2->getTags()[2]->getKey());
|
||||
$this->assertEquals("value3", $config2->getTags()[2]->getValue());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAppendObjectTaggingFromHeader()
|
||||
{
|
||||
$object = "append-object-tagging-header.txt";
|
||||
$content_array = array('Hello OSS', 'Hi OSS', 'OSS OK');
|
||||
|
||||
try {
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
));
|
||||
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[0], 0, $options);
|
||||
$this->assertEquals($position, strlen($content_array[0]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[1], $position);
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[2], $position, array(OssClient::OSS_LENGTH => strlen($content_array[2])));
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]) + strlen($content_array[2]));
|
||||
|
||||
$config2 = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(3, count($config2->getTags()));
|
||||
$this->assertEquals("key1", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $config2->getTags()[0]->getValue());
|
||||
$this->assertEquals("key2", $config2->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[1]->getValue());
|
||||
$this->assertEquals("key3", $config2->getTags()[2]->getKey());
|
||||
$this->assertEquals("value3", $config2->getTags()[2]->getValue());
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMultipartUploadTaggingFromHeader()
|
||||
{
|
||||
$file = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile.tmp";
|
||||
OssUtil::generateFile($file, 110 * 1024);
|
||||
|
||||
$object = "mpu-object-tagging-header.txt";
|
||||
$options = array(
|
||||
OssClient::OSS_CHECK_MD5 => true,
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'x-oss-tagging' => 'key1=value1&key2=value2&key3=value3',
|
||||
),
|
||||
);
|
||||
try {
|
||||
$this->ossClient->multiuploadFile($this->bucket, $object, $file, $options);
|
||||
|
||||
$config2 = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$this->assertEquals(3, count($config2->getTags()));
|
||||
$this->assertEquals("key1", $config2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $config2->getTags()[0]->getValue());
|
||||
$this->assertEquals("key2", $config2->getTags()[1]->getKey());
|
||||
$this->assertEquals("value2", $config2->getTags()[1]->getValue());
|
||||
$this->assertEquals("key3", $config2->getTags()[2]->getKey());
|
||||
$this->assertEquals("value3", $config2->getTags()[2]->getValue());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,781 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientObjectTest extends TestOssClientBase
|
||||
{
|
||||
|
||||
public function testGetObjectMeta()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
|
||||
try {
|
||||
$res = $this->ossClient->getObjectMeta($this->bucket, $object);
|
||||
$this->assertEquals('200', $res['info']['http_code']);
|
||||
$this->assertEquals('text/plain', $res['content-type']);
|
||||
$this->assertEquals('Accept-Encoding', $res['vary']);
|
||||
$this->assertTrue(isset($res['content-length']));
|
||||
$this->assertFalse(isset($res['content-encoding']));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
$options = array(OssClient::OSS_HEADERS => array(OssClient::OSS_ACCEPT_ENCODING => 'deflate, gzip'));
|
||||
|
||||
try {
|
||||
$res = $this->ossClient->getObjectMeta($this->bucket, $object, $options);
|
||||
$this->assertEquals('200', $res['info']['http_code']);
|
||||
$this->assertEquals('text/plain', $res['content-type']);
|
||||
$this->assertEquals('Accept-Encoding', $res['vary']);
|
||||
$this->assertFalse(isset($res['content-length']));
|
||||
$this->assertEquals('gzip', $res['content-encoding']);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetObjectWithAcceptEncoding()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$options = array(OssClient::OSS_HEADERS => array(OssClient::OSS_ACCEPT_ENCODING => 'deflate, gzip'));
|
||||
|
||||
try {
|
||||
$res = $this->ossClient->getObject($this->bucket, $object, $options);
|
||||
$this->assertEquals(file_get_contents(__FILE__), $res);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetObjectWithHeader()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$res = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_LAST_MODIFIED => "xx"));
|
||||
$this->assertEquals(file_get_contents(__FILE__), $res);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('"/ilegal.txt" object name is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetObjectWithIleggalEtag()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$res = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_ETAG => "xx"));
|
||||
$this->assertEquals(file_get_contents(__FILE__), $res);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('"/ilegal.txt" object name is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testObject()
|
||||
{
|
||||
/**
|
||||
* Upload the local variable to bucket
|
||||
*/
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
$options = array(
|
||||
OssClient::OSS_LENGTH => strlen($content),
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Expires' => 'Fri, 28 Feb 2020 05:38:42 GMT',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'Content-Disposition' => 'attachment;filename=oss_download.log',
|
||||
'Content-Language' => 'zh-CN',
|
||||
'x-oss-server-side-encryption' => 'AES256',
|
||||
'x-oss-meta-self-define-title' => 'user define meta info',
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, "stringtype", $options);
|
||||
$this->assertEquals('stringtype', $result[0]);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('objects must be array', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, "stringtype", $options);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('objects must be array', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->uploadFile($this->bucket, $object, "notexist.txt", $options);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('notexist.txt file does not exist', $e->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* GetObject to the local variable and check for match
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* GetObject first five bytes
|
||||
*/
|
||||
try {
|
||||
$options = array(OssClient::OSS_RANGE => '0-4');
|
||||
$content = $this->ossClient->getObject($this->bucket, $object, $options);
|
||||
$this->assertEquals($content, '<?php');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload the local file to object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->uploadFile($this->bucket, $object, __FILE__);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file to the local variable and check for match.
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file to the local file
|
||||
*/
|
||||
$localfile = "upload-test-object-name.txt";
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $localfile,
|
||||
);
|
||||
|
||||
try {
|
||||
$this->ossClient->getObject($this->bucket, $object, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertTrue(file_get_contents($localfile) === file_get_contents(__FILE__));
|
||||
if (file_exists($localfile)) {
|
||||
unlink($localfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file to the local file. no such key
|
||||
*/
|
||||
$localfile = "upload-test-object-name-no-such-key.txt";
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $localfile,
|
||||
);
|
||||
|
||||
try {
|
||||
$this->ossClient->getObject($this->bucket, $object . "no-such-key", $options);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
$this->assertFalse(file_exists($localfile));
|
||||
if (strpos($e, "The specified key does not exist") == false)
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file to the content. no such key
|
||||
*/
|
||||
try {
|
||||
$result = $this->ossClient->getObject($this->bucket, $object . "no-such-key");
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
if (strpos($e, "The specified key does not exist") == false)
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy object
|
||||
*/
|
||||
$to_bucket = $this->bucket;
|
||||
$to_object = $object . '.copy';
|
||||
$options = array();
|
||||
try {
|
||||
$result = $this->ossClient->copyObject($this->bucket, $object, $to_bucket, $to_object, $options);
|
||||
$this->assertFalse(empty($result));
|
||||
$this->assertEquals(strlen("2016-11-21T03:46:58.000Z"), strlen($result[0]));
|
||||
$this->assertEquals(strlen("\"5B3C1A2E053D763E1B002CC607C5A0FE\""), strlen($result[1]));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
var_dump($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $to_object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* List the files in your bucket.
|
||||
*/
|
||||
$prefix = '';
|
||||
$delimiter = '/';
|
||||
$next_marker = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'marker' => $next_marker,
|
||||
);
|
||||
|
||||
try {
|
||||
$listObjectInfo = $this->ossClient->listObjects($this->bucket, $options);
|
||||
$objectList = $listObjectInfo->getObjectList();
|
||||
$prefixList = $listObjectInfo->getPrefixList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the meta information for the file
|
||||
*/
|
||||
$from_bucket = $this->bucket;
|
||||
$from_object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$to_bucket = $from_bucket;
|
||||
$to_object = $from_object;
|
||||
$copy_options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Expires' => '2012-10-01 08:00:00',
|
||||
'Content-Disposition' => 'attachment; filename="xxxxxx"',
|
||||
),
|
||||
);
|
||||
try {
|
||||
$this->ossClient->copyObject($from_bucket, $from_object, $to_bucket, $to_object, $copy_options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta information for the file
|
||||
*/
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$objectMeta = $this->ossClient->getObjectMeta($this->bucket, $object);
|
||||
$this->assertEquals('attachment; filename="xxxxxx"', $objectMeta[strtolower('Content-Disposition')]);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete single file
|
||||
*/
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
|
||||
try {
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple files
|
||||
*/
|
||||
$object1 = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$object2 = "oss-php-sdk-test/upload-test-object-name.txt.copy";
|
||||
$list = array($object1, $object2);
|
||||
try {
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object2));
|
||||
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, $list);
|
||||
$this->assertEquals($list[0], $result[0]);
|
||||
$this->assertEquals($list[1], $result[1]);
|
||||
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, $list, array('quiet' => 'true'));
|
||||
$this->assertEquals(array(), $result);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object2));
|
||||
|
||||
$this->ossClient->putObject($this->bucket, $object, $content);
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, $list, array('quiet' => true));
|
||||
$this->assertEquals(array(), $result);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAppendObject()
|
||||
{
|
||||
$object = "oss-php-sdk-test/append-test-object-name.txt";
|
||||
$content_array = array('Hello OSS', 'Hi OSS', 'OSS OK');
|
||||
|
||||
/**
|
||||
* Append the upload string
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[0], 0);
|
||||
$this->assertEquals($position, strlen($content_array[0]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[1], $position);
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[2], $position, array(OssClient::OSS_LENGTH => strlen($content_array[2])));
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]) + strlen($content_array[2]));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the content is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, implode($content_array));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the upload of invalid local files
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, "invalid-file-path", 0);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the upload of local files
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0);
|
||||
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)));
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position);
|
||||
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__) . file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Expires' => '2012-10-01 08:00:00',
|
||||
'Content-Disposition' => 'attachment; filename="xxxxxx"',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Append upload with option
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, "Hello OSS, ", 0, $options);
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, "Hi OSS.", $position);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta information for the file
|
||||
*/
|
||||
try {
|
||||
$objectMeta = $this->ossClient->getObjectMeta($this->bucket, $object);
|
||||
$this->assertEquals('attachment; filename="xxxxxx"', $objectMeta[strtolower('Content-Disposition')]);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPutIllelObject()
|
||||
{
|
||||
$object = "/ilegal.txt";
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, "hi", null);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('"/ilegal.txt" object name is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckMD5()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
$options = array(OssClient::OSS_CHECK_MD5 => true);
|
||||
|
||||
/**
|
||||
* Upload data to start MD5
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file to start MD5
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->uploadFile($this->bucket, $object, __FILE__, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$object = "oss-php-sdk-test/append-test-object-name.txt";
|
||||
$content_array = array('Hello OSS', 'Hi OSS', 'OSS OK');
|
||||
$options = array(OssClient::OSS_CHECK_MD5 => true);
|
||||
|
||||
/**
|
||||
* Append the upload string
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[0], 0, $options);
|
||||
$this->assertEquals($position, strlen($content_array[0]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[1], $position, $options);
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]));
|
||||
$position = $this->ossClient->appendObject($this->bucket, $object, $content_array[2], $position, $options);
|
||||
$this->assertEquals($position, strlen($content_array[0]) + strlen($content_array[1]) + strlen($content_array[1]));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the content is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, implode($content_array));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append upload of local files
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0, $options);
|
||||
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)));
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position, $options);
|
||||
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__) . file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete test object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testWithInvalidBucketName()
|
||||
{
|
||||
try {
|
||||
$this->ossClient->createBucket("abcefc/", "test-key");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('"abcefc/"bucket name is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSimplifiedObjectMeta()
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
|
||||
try {
|
||||
$objectMeta = $this->ossClient->getSimplifiedObjectMeta($this->bucket, $object);
|
||||
$this->assertEquals(false, array_key_exists(strtolower('Content-Disposition'), $objectMeta));
|
||||
$this->assertEquals(strlen(file_get_contents(__FILE__)), $objectMeta[strtolower('Content-Length')]);
|
||||
$this->assertEquals(true, array_key_exists(strtolower('ETag'), $objectMeta));
|
||||
$this->assertEquals(true, array_key_exists(strtolower('Last-Modified'), $objectMeta));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testUploadStream()
|
||||
{
|
||||
$object = "oss-php-sdk-test/put-from-stream.txt";
|
||||
$options = array(OssClient::OSS_CHECK_MD5 => true);
|
||||
$handle = fopen(__FILE__, 'rb');
|
||||
/**
|
||||
* Upload data to start MD5
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->uploadStream($this->bucket, $object, $handle, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$object = "oss-php-sdk-test/put-from-stream-without-md5.txt";
|
||||
$handle = fopen(__FILE__, 'rb');
|
||||
try {
|
||||
$this->ossClient->uploadStream($this->bucket, $object, $handle);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testObjectKeyWithQuestionMark()
|
||||
{
|
||||
/**
|
||||
* Upload the local variable to bucket
|
||||
*/
|
||||
$object = "oss-php-sdk-test/??/upload-test-object-name???123??123??.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
$options = array(
|
||||
OssClient::OSS_LENGTH => strlen($content),
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Expires' => 'Fri, 28 Feb 2020 05:38:42 GMT',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'Content-Disposition' => 'attachment;filename=oss_download.log',
|
||||
'Content-Language' => 'zh-CN',
|
||||
'x-oss-server-side-encryption' => 'AES256',
|
||||
'x-oss-meta-self-define-title' => 'user define meta info',
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* GetObject to the local variable and check for match
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* GetObject first five bytes
|
||||
*/
|
||||
try {
|
||||
$options = array(OssClient::OSS_RANGE => '0-4');
|
||||
$content = $this->ossClient->getObject($this->bucket, $object, $options);
|
||||
$this->assertEquals($content, '<?php');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload the local file to object
|
||||
*/
|
||||
try {
|
||||
$this->ossClient->uploadFile($this->bucket, $object, __FILE__);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file to the local variable and check for match.
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy object
|
||||
*/
|
||||
$to_bucket = $this->bucket;
|
||||
$to_object = $object . '.copy';
|
||||
$options = array();
|
||||
try {
|
||||
$result = $this->ossClient->copyObject($this->bucket, $object, $to_bucket, $to_object, $options);
|
||||
$this->assertFalse(empty($result));
|
||||
$this->assertEquals(strlen("2016-11-21T03:46:58.000Z"), strlen($result[0]));
|
||||
$this->assertEquals(strlen("\"5B3C1A2E053D763E1B002CC607C5A0FE\""), strlen($result[1]));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
var_dump($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the replication is the same
|
||||
*/
|
||||
try {
|
||||
$content = $this->ossClient->getObject($this->bucket, $to_object);
|
||||
$this->assertEquals($content, file_get_contents(__FILE__));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
$this->ossClient->deleteObject($this->bucket, $object);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->ossClient->putObject($this->bucket, 'oss-php-sdk-test/upload-test-object-name.txt', file_get_contents(__FILE__));
|
||||
}
|
||||
}
|
@ -0,0 +1,610 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
use OSS\Model\TaggingConfig;
|
||||
use OSS\Model\Tag;
|
||||
use OSS\Model\DeleteObjectInfo;
|
||||
use OSS\Core\OssUtil;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientObjectVersioningTest extends TestOssClientBase
|
||||
{
|
||||
public function testObjectBasic()
|
||||
{
|
||||
$object = 'object';
|
||||
$content1 = 'hello';
|
||||
$content2 = 'hello world';
|
||||
$ret1 = $this->ossClient->putObject($this->bucket, $object, $content1, array(OssClient::OSS_HEADERS => array('x-oss-object-acl' => 'public-read', 'x-oss-tagging' => 'key1=value1')));
|
||||
$ret2 = $this->ossClient->putObject($this->bucket, $object, $content2, array(OssClient::OSS_HEADERS => array('x-oss-object-acl' => 'private', 'x-oss-tagging' => 'key2=value2')));
|
||||
|
||||
$this->assertTrue(isset($ret1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($ret2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
|
||||
$versionId1 = $ret1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$versionId2 = $ret2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
//get object
|
||||
$res = $this->ossClient->getObject($this->bucket, $object);
|
||||
$res1 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$res2 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
$this->assertEquals($content1, $res1);
|
||||
$this->assertEquals($content2, $res2);
|
||||
$this->assertEquals($content2, $res);
|
||||
|
||||
//meta
|
||||
$headers = $this->ossClient->getObjectMeta($this->bucket, $object);
|
||||
$headers1 = $this->ossClient->getObjectMeta($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$headers2 = $this->ossClient->getObjectMeta($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
|
||||
$this->assertTrue(isset($headers[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($headers1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($headers2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertEquals($versionId1, $headers1[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
$this->assertEquals($versionId2, $headers2[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
$this->assertEquals($versionId2, $headers[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
|
||||
|
||||
$sheaders = $this->ossClient->getSimplifiedObjectMeta($this->bucket, $object);
|
||||
$sheaders1 = $this->ossClient->getSimplifiedObjectMeta($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$sheaders2 = $this->ossClient->getSimplifiedObjectMeta($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
|
||||
$this->assertTrue(isset($sheaders[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($sheaders1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($sheaders2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertEquals($versionId1, $sheaders1[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
$this->assertEquals($versionId2, $sheaders2[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
$this->assertEquals($versionId2, $sheaders[OssClient::OSS_HEADER_VERSION_ID]);
|
||||
|
||||
//acl
|
||||
$acl = $this->ossClient->getObjectAcl($this->bucket, $object);
|
||||
$acl1 = $this->ossClient->getObjectAcl($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$acl2 = $this->ossClient->getObjectAcl($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
|
||||
$this->assertEquals('public-read', $acl1);
|
||||
$this->assertEquals('private', $acl2);
|
||||
$this->assertEquals('private', $acl);
|
||||
|
||||
$this->ossClient->putObjectAcl($this->bucket, $object, 'public-read-write', array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$acl = $this->ossClient->getObjectAcl($this->bucket, $object);
|
||||
$acl1 = $this->ossClient->getObjectAcl($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$this->assertEquals('public-read-write', $acl1);
|
||||
$this->assertEquals('private', $acl);
|
||||
|
||||
//tagging
|
||||
$tag = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$tag1 = $this->ossClient->getObjectTagging($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$tag2 = $this->ossClient->getObjectTagging($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
$this->assertEquals(1, count($tag1->getTags()));
|
||||
$this->assertEquals("key1", $tag1->getTags()[0]->getKey());
|
||||
$this->assertEquals("value1", $tag1->getTags()[0]->getValue());
|
||||
$this->assertEquals(1, count($tag2->getTags()));
|
||||
$this->assertEquals("key2", $tag2->getTags()[0]->getKey());
|
||||
$this->assertEquals("value2", $tag2->getTags()[0]->getValue());
|
||||
$this->assertEquals(1, count($tag->getTags()));
|
||||
$this->assertEquals("key2", $tag->getTags()[0]->getKey());
|
||||
$this->assertEquals("value2", $tag->getTags()[0]->getValue());
|
||||
|
||||
$config = new TaggingConfig();
|
||||
$config->addTag(new Tag("key11", "value11"));
|
||||
$this->ossClient->putObjectTagging($this->bucket, $object, $config, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$tag = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$tag1 = $this->ossClient->getObjectTagging($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$this->assertEquals(1, count($tag1->getTags()));
|
||||
$this->assertEquals("key11", $tag1->getTags()[0]->getKey());
|
||||
$this->assertEquals("value11", $tag1->getTags()[0]->getValue());
|
||||
$this->assertEquals(1, count($tag->getTags()));
|
||||
$this->assertEquals("key2", $tag->getTags()[0]->getKey());
|
||||
$this->assertEquals("value2", $tag->getTags()[0]->getValue());
|
||||
|
||||
$this->ossClient->deleteObjectTagging($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$tag = $this->ossClient->getObjectTagging($this->bucket, $object);
|
||||
$tag1 = $this->ossClient->getObjectTagging($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$this->assertEquals(0, count($tag1->getTags()));
|
||||
$this->assertEquals(1, count($tag->getTags()));
|
||||
$this->assertEquals("key2", $tag->getTags()[0]->getKey());
|
||||
$this->assertEquals("value2", $tag->getTags()[0]->getValue());
|
||||
|
||||
//delete
|
||||
$dret = $this->ossClient->deleteObject($this->bucket, $object);
|
||||
$this->assertTrue(isset($dret['x-oss-delete-marker']));
|
||||
$this->assertTrue(isset($dret['x-oss-version-id']));
|
||||
$this->assertEquals("true", $dret['x-oss-delete-marker']);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1)));
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId2)));
|
||||
|
||||
$dret1 = $this->ossClient->deleteObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$this->assertFalse(isset($dret1['x-oss-delete-marker']));
|
||||
$this->assertTrue(isset($dret1['x-oss-version-id']));
|
||||
$this->assertEquals($versionId1, $dret1['x-oss-version-id']);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1)));
|
||||
|
||||
|
||||
$dret_ = $this->ossClient->deleteObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $dret['x-oss-version-id']));
|
||||
$this->assertTrue(isset($dret_['x-oss-delete-marker']));
|
||||
$this->assertTrue(isset($dret_['x-oss-version-id']));
|
||||
$this->assertEquals($dret['x-oss-version-id'], $dret_['x-oss-version-id']);
|
||||
$this->assertTrue($this->ossClient->doesObjectExist($this->bucket, $object));
|
||||
|
||||
}
|
||||
|
||||
public function testObjectSymlink()
|
||||
{
|
||||
$object1 = 'object-target-1';
|
||||
$object2 = 'object-target-2';
|
||||
$symlink = 'object-symlink';
|
||||
$content1 = 'hello';
|
||||
$content2 = 'hello world';
|
||||
|
||||
|
||||
$ret1 = $this->ossClient->putObject($this->bucket, $object1, $content1);
|
||||
$sym1 = $this->ossClient->putSymlink($this->bucket, $symlink, $object1);
|
||||
|
||||
$ret2 = $this->ossClient->putObject($this->bucket, $object2, $content2);
|
||||
$sym2 = $this->ossClient->putSymlink($this->bucket, $symlink, $object2);
|
||||
|
||||
$this->assertTrue(isset($ret1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($ret2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
|
||||
$this->assertTrue(isset($sym1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($sym2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
|
||||
$versionId1 = $ret1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$versionId2 = $ret2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
$sym_versionId1 = $sym1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$sym_versionId2 = $sym2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
|
||||
$sym_ret = $this->ossClient->getSymlink($this->bucket, $symlink);
|
||||
$sym_ret1 = $this->ossClient->getSymlink($this->bucket, $symlink, array(OssClient::OSS_VERSION_ID => $sym_versionId1));
|
||||
$sym_ret2 = $this->ossClient->getSymlink($this->bucket, $symlink, array(OssClient::OSS_VERSION_ID => $sym_versionId2));
|
||||
|
||||
$this->assertTrue(isset($sym_ret['x-oss-version-id']));
|
||||
$this->assertTrue(isset($sym_ret1['x-oss-version-id']));
|
||||
$this->assertTrue(isset($sym_ret2['x-oss-version-id']));
|
||||
|
||||
$this->assertEquals($sym_versionId1, $sym_ret1['x-oss-version-id']);
|
||||
$this->assertEquals($sym_versionId2, $sym_ret2['x-oss-version-id']);
|
||||
$this->assertEquals($sym_versionId2, $sym_ret['x-oss-version-id']);
|
||||
|
||||
|
||||
$res = $this->ossClient->getObject($this->bucket, $symlink);
|
||||
$res1 = $this->ossClient->getObject($this->bucket, $symlink, array(OssClient::OSS_VERSION_ID => $sym_versionId1));
|
||||
$res2 = $this->ossClient->getObject($this->bucket, $symlink, array(OssClient::OSS_VERSION_ID => $sym_versionId2));
|
||||
$this->assertEquals($content1, $res1);
|
||||
$this->assertEquals($content2, $res2);
|
||||
$this->assertEquals($content2, $res);
|
||||
}
|
||||
|
||||
public function testObjectCopy()
|
||||
{
|
||||
$object = 'copy-= +object';
|
||||
$content1 = 'hello';
|
||||
$content2 = 'hello world';
|
||||
$to_bucket = $this->bucket;
|
||||
$to_object = $object . '.copy';
|
||||
$to_object1 = $object . '.copy1';
|
||||
$to_object2 = $object . '.copy2';
|
||||
|
||||
$ret1 = $this->ossClient->putObject($this->bucket, $object, $content1);
|
||||
$ret2 = $this->ossClient->putObject($this->bucket, $object, $content2);
|
||||
|
||||
$versionId1 = $ret1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$versionId2 = $ret2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
$cret = $this->ossClient->copyObject($this->bucket, $object, $to_bucket, $to_object);
|
||||
$cret1 = $this->ossClient->copyObject($this->bucket, $object, $to_bucket, $to_object1, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$cret2 = $this->ossClient->copyObject($this->bucket, $object, $to_bucket, $to_object2, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
$this->assertFalse(empty($cret1));
|
||||
$this->assertEquals(strlen("2016-11-21T03:46:58.000Z"), strlen($cret1[0]));
|
||||
$this->assertEquals(trim($ret1['etag'], '"'), trim($cret1[1], '"'));
|
||||
$this->assertTrue(isset($cret1['x-oss-version-id']));
|
||||
$this->assertEquals($versionId1, $cret1['x-oss-copy-source-version-id']);
|
||||
|
||||
$this->assertFalse(empty($cret2));
|
||||
$this->assertEquals(strlen("2016-11-21T03:46:58.000Z"), strlen($cret2[0]));
|
||||
$this->assertEquals(trim($ret2['etag'], '"'), trim($cret2[1], '"'));
|
||||
$this->assertTrue(isset($cret2['x-oss-version-id']));
|
||||
$this->assertEquals($versionId2, $cret2['x-oss-copy-source-version-id']);
|
||||
|
||||
$this->assertFalse(empty($cret));
|
||||
$this->assertEquals(strlen("2016-11-21T03:46:58.000Z"), strlen($cret[0]));
|
||||
$this->assertEquals(trim($ret2['etag'], '"'), trim($cret[1], '"'));
|
||||
$this->assertTrue(isset($cret2['x-oss-version-id']));
|
||||
$this->assertEquals($versionId2, $cret['x-oss-copy-source-version-id']);
|
||||
|
||||
$res = $this->ossClient->getObject($this->bucket, $to_object);
|
||||
$res1 = $this->ossClient->getObject($this->bucket, $to_object1);
|
||||
$res2 = $this->ossClient->getObject($this->bucket, $to_object2);
|
||||
$this->assertEquals($content1, $res1);
|
||||
$this->assertEquals($content2, $res2);
|
||||
$this->assertEquals($content2, $res);
|
||||
}
|
||||
|
||||
public function testObjectRestore()
|
||||
{
|
||||
$object = 'retore-object';
|
||||
$content1 = 'hello';
|
||||
$content2 = 'hello world';
|
||||
$ret1 = $this->ossClient->putObject($this->bucket, $object, $content1, array(OssClient::OSS_HEADERS => array('x-oss-storage-class' => 'Archive')));
|
||||
$ret2 = $this->ossClient->putObject($this->bucket, $object, $content2);
|
||||
|
||||
$versionId1 = $ret1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$versionId2 = $ret2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
try{
|
||||
$this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('403', $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidObjectState', $e->getErrorCode());
|
||||
}
|
||||
|
||||
try{
|
||||
$this->ossClient->restoreObject($this->bucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch(OssException $e){
|
||||
$this->assertEquals('400', $e->getHTTPStatus());
|
||||
$this->assertEquals('OperationNotSupported', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$result = $this->ossClient->restoreObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
common::waitMetaSync();
|
||||
$this->assertEquals('202', $result['info']['http_code']);
|
||||
|
||||
try{
|
||||
$this->ossClient->restoreObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
}catch(OssException $e){
|
||||
$this->assertEquals('409', $e->getHTTPStatus());
|
||||
$this->assertEquals('RestoreAlreadyInProgress', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testObjectMultiPart()
|
||||
{
|
||||
$object_src = 'multi-= +object.src';
|
||||
$content1 = 'hello';
|
||||
$content2 = 'hello world';
|
||||
$ret1 = $this->ossClient->putObject($this->bucket, $object_src, $content1);
|
||||
$ret2 = $this->ossClient->putObject($this->bucket, $object_src, $content2);
|
||||
|
||||
$this->assertTrue(isset($ret1[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
$this->assertTrue(isset($ret2[OssClient::OSS_HEADER_VERSION_ID]));
|
||||
|
||||
$versionId1 = $ret1[OssClient::OSS_HEADER_VERSION_ID];
|
||||
$versionId2 = $ret2[OssClient::OSS_HEADER_VERSION_ID];
|
||||
|
||||
//object
|
||||
$object = "multi-object";
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
$copyId = 1;
|
||||
$eTag = $this->ossClient->uploadPartCopy($this->bucket, $object_src, $this->bucket, $object, $copyId, $upload_id);
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
$ret = $this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts);
|
||||
|
||||
//object-1
|
||||
$object1 = "multi-object-1";
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object1);
|
||||
$copyId = 1;
|
||||
$eTag = $this->ossClient->uploadPartCopy($this->bucket, $object_src, $this->bucket, $object1, $copyId, $upload_id, array(OssClient::OSS_VERSION_ID => $versionId1));
|
||||
$upload_parts1[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
$ret1 = $this->ossClient->completeMultipartUpload($this->bucket, $object1, $upload_id, $upload_parts1);
|
||||
|
||||
//object-2
|
||||
$object2 = "multi-object-2";
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object2);
|
||||
$copyId = 1;
|
||||
$eTag = $this->ossClient->uploadPartCopy($this->bucket, $object_src, $this->bucket, $object2, $copyId, $upload_id, array(OssClient::OSS_VERSION_ID => $versionId2));
|
||||
$upload_parts2[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
$ret2 = $this->ossClient->completeMultipartUpload($this->bucket, $object2, $upload_id, $upload_parts2);
|
||||
|
||||
$res = $this->ossClient->getObject($this->bucket, $object);
|
||||
$res1 = $this->ossClient->getObject($this->bucket, $object1);
|
||||
$res2 = $this->ossClient->getObject($this->bucket, $object2);
|
||||
|
||||
$this->assertEquals($content1, $res1);
|
||||
$this->assertEquals($content2, $res2);
|
||||
$this->assertEquals($content2, $res);
|
||||
}
|
||||
|
||||
public function testObjectMisc()
|
||||
{
|
||||
//use multipart
|
||||
$options = array(
|
||||
OssClient::OSS_PART_SIZE => 1,
|
||||
);
|
||||
|
||||
$object = 'misc-object';
|
||||
|
||||
$smallFile1 = __DIR__ . DIRECTORY_SEPARATOR . "/smallfile1.tmp";
|
||||
$smallFile2 = __DIR__ . DIRECTORY_SEPARATOR . "/smallfile2.tmp";
|
||||
$bigFile1 = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile1.tmp";
|
||||
$bigFile2 = __DIR__ . DIRECTORY_SEPARATOR . "/bigfile2.tmp";
|
||||
|
||||
OssUtil::generateFile($smallFile1, 5);
|
||||
OssUtil::generateFile($smallFile2, 10);
|
||||
OssUtil::generateFile($bigFile1, 128 * 1024);
|
||||
OssUtil::generateFile($bigFile2, 256 * 1024);
|
||||
|
||||
$sret1 = $this->ossClient->multiuploadFile($this->bucket, $object, $smallFile1, $options);
|
||||
$sret2 = $this->ossClient->multiuploadFile($this->bucket, $object, $smallFile2, $options);
|
||||
$bret1 = $this->ossClient->multiuploadFile($this->bucket, $object, $bigFile1, $options);
|
||||
$bret2 = $this->ossClient->multiuploadFile($this->bucket, $object, $bigFile2, $options);
|
||||
|
||||
|
||||
$res = $this->ossClient->getObject($this->bucket, $object);
|
||||
$sres1 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $sret1['x-oss-version-id']));
|
||||
$sres2 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $sret2['x-oss-version-id']));
|
||||
$bres1 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $bret1['x-oss-version-id']));
|
||||
$bres2 = $this->ossClient->getObject($this->bucket, $object, array(OssClient::OSS_VERSION_ID => $bret2['x-oss-version-id']));
|
||||
|
||||
|
||||
$this->assertEquals(file_get_contents($smallFile1), $sres1);
|
||||
$this->assertEquals(file_get_contents($smallFile2), $sres2);
|
||||
$this->assertEquals(file_get_contents($bigFile1), $bres1);
|
||||
$this->assertEquals(file_get_contents($bigFile2), $bres2);
|
||||
$this->assertEquals(file_get_contents($bigFile2), $res);
|
||||
|
||||
|
||||
unlink($smallFile1);
|
||||
unlink($smallFile2);
|
||||
unlink($bigFile1);
|
||||
unlink($bigFile2);
|
||||
}
|
||||
|
||||
public function testListObjects()
|
||||
{
|
||||
//folder
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$key = 'folder/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->deleteObject($this->bucket, $key);
|
||||
}
|
||||
|
||||
//test
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$key = 'test/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->deleteObject($this->bucket, $key);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//work
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$key = 'work/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//sub++
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$key = 'sub++/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
//file++
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$key = 'file++'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->deleteObject($this->bucket, $key);
|
||||
}
|
||||
|
||||
//list default
|
||||
$result = $this->ossClient->listObjectVersions($this->bucket);
|
||||
$versionList = $result->getObjectVersionList();
|
||||
$deleteMarkerList = $result->getDeleteMarkerList();
|
||||
$prefixList = $result->getPrefixList();
|
||||
|
||||
$this->assertNotNull($versionList);
|
||||
$this->assertNotNull($deleteMarkerList);
|
||||
$this->assertNotNull($prefixList);
|
||||
$this->assertTrue(is_array($versionList));
|
||||
$this->assertTrue(is_array($deleteMarkerList));
|
||||
$this->assertTrue(is_array($prefixList));
|
||||
$this->assertEquals(2, count($versionList));
|
||||
$this->assertEquals(2, count($deleteMarkerList));
|
||||
$this->assertEquals(4, count($prefixList));
|
||||
|
||||
$this->assertEquals('file++00', $versionList[0]->getKey());
|
||||
$this->assertEquals('false', $versionList[0]->getIsLatest());
|
||||
$this->assertEquals('file++01', $versionList[1]->getKey());
|
||||
$this->assertEquals('false', $versionList[1]->getIsLatest());
|
||||
|
||||
$this->assertEquals('file++00', $deleteMarkerList[0]->getKey());
|
||||
$this->assertEquals('true', $deleteMarkerList[0]->getIsLatest());
|
||||
$this->assertEquals('file++01', $deleteMarkerList[1]->getKey());
|
||||
$this->assertEquals('true', $deleteMarkerList[1]->getIsLatest());
|
||||
|
||||
|
||||
$this->assertEquals('folder/', $prefixList[0]->getPrefix());
|
||||
$this->assertEquals('sub++/', $prefixList[1]->getPrefix());
|
||||
$this->assertEquals('test/', $prefixList[2]->getPrefix());
|
||||
$this->assertEquals('work/', $prefixList[3]->getPrefix());
|
||||
|
||||
//list by prefix
|
||||
$prefix = 'folder/';
|
||||
$delimiter = '';
|
||||
$next_marker = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'key-marker' => $next_marker,
|
||||
);
|
||||
|
||||
$result = $this->ossClient->listObjectVersions($this->bucket, $options);
|
||||
$versionList = $result->getObjectVersionList();
|
||||
$deleteMarkerList = $result->getDeleteMarkerList();
|
||||
$prefixList = $result->getPrefixList();
|
||||
|
||||
$this->assertEquals(24, count($versionList));
|
||||
$this->assertEquals(12, count($deleteMarkerList));
|
||||
$this->assertEquals(0, count($prefixList));
|
||||
|
||||
$this->assertEquals('folder/00', $versionList[0]->getKey());
|
||||
$this->assertEquals('folder/00', $versionList[1]->getKey());
|
||||
$this->assertEquals('folder/00', $deleteMarkerList[0]->getKey());
|
||||
$this->assertEquals('folder/01', $deleteMarkerList[1]->getKey());
|
||||
|
||||
|
||||
//max-key & key-marker & version-id-marker
|
||||
$count = 0;
|
||||
$markerCount = 0;
|
||||
$nextMarker = '';
|
||||
$nextVersionIdMarker = '';
|
||||
|
||||
while (true) {
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'key-marker' => $nextMarker,
|
||||
'max-keys' => 1,
|
||||
'version-id-marker' => $nextVersionIdMarker,
|
||||
);
|
||||
$result = $this->ossClient->listObjectVersions($this->bucket, $options);
|
||||
|
||||
$nextMarker = $result->getNextKeyMarker();
|
||||
$nextVersionIdMarker = $result->getNextVersionIdMarker();
|
||||
$count += count($result->getObjectVersionList());
|
||||
$markerCount += count($result->getDeleteMarkerList());
|
||||
$this->assertEquals(1, count($result->getObjectVersionList()) + count($result->getDeleteMarkerList()));
|
||||
if ($result->getIsTruncated() !== "true") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(12*3 + 8*3 + 5 + 3*3 + 2*2, $count + $markerCount);
|
||||
}
|
||||
|
||||
public function testDeleteObjects()
|
||||
{
|
||||
//deletes
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$key = 'deletes/'. sprintf("%02d",$i);
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
$this->ossClient->putObject($this->bucket, $key, "content");
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'delimiter' => '',
|
||||
'prefix' => 'deletes/',
|
||||
'max-keys' => 1000,
|
||||
);
|
||||
$result = $this->ossClient->listObjects($this->bucket, $options);
|
||||
$this->assertEquals(5, count($result->getObjectList()));
|
||||
|
||||
//delete without version-id
|
||||
$objects = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$key = 'deletes/'. sprintf("%02d",$i);
|
||||
$objects[] = new DeleteObjectInfo($key);
|
||||
}
|
||||
$dresult = $this->ossClient->deleteObjectVersions($this->bucket, $objects);
|
||||
$this->assertEquals(5, count($dresult));
|
||||
$this->assertEquals('deletes/00', $dresult[0]->getKey());
|
||||
$this->assertEquals('true', $dresult[0]->getDeleteMarker());
|
||||
$this->assertEquals('', $dresult[0]->getVersionId());
|
||||
$this->assertFalse(empty($dresult[0]->getDeleteMarkerVersionId()));
|
||||
|
||||
$result = $this->ossClient->listObjects($this->bucket, $options);
|
||||
$this->assertEquals(0, count($result->getObjectList()));
|
||||
|
||||
//delete by version-id
|
||||
$vresult = $this->ossClient->listObjectVersions($this->bucket, $options);
|
||||
$versions = $vresult->getObjectVersionList();
|
||||
$deleteMarkerList = $vresult->getDeleteMarkerList();
|
||||
$this->assertEquals(10, count($versions));
|
||||
$this->assertEquals(5, count($deleteMarkerList));
|
||||
|
||||
$objects = array();
|
||||
foreach ($versions as $obj) {
|
||||
$objects[] = new DeleteObjectInfo($obj->getKey(), $obj->getVersionId());
|
||||
}
|
||||
$dresult = $this->ossClient->deleteObjectVersions($this->bucket, $objects);
|
||||
$this->assertEquals(10, count($dresult));
|
||||
$this->assertEquals('deletes/00', $dresult[0]->getKey());
|
||||
$this->assertEquals('', $dresult[0]->getDeleteMarker());
|
||||
$this->assertFalse(empty($dresult[0]->getVersionId()));
|
||||
$this->assertTrue(empty($dresult[0]->getDeleteMarkerVersionId()));
|
||||
$this->assertEquals('deletes/00', $dresult[1]->getKey());
|
||||
$this->assertEquals('', $dresult[1]->getDeleteMarker());
|
||||
$this->assertFalse(empty($dresult[1]->getVersionId()));
|
||||
$this->assertTrue(empty($dresult[1]->getDeleteMarkerVersionId()));
|
||||
|
||||
|
||||
$vresult = $this->ossClient->listObjectVersions($this->bucket, $options);
|
||||
$versions = $vresult->getObjectVersionList();
|
||||
$deleteMarkerList = $vresult->getDeleteMarkerList();
|
||||
$this->assertEquals(0, count($versions));
|
||||
$this->assertEquals(5, count($deleteMarkerList));
|
||||
|
||||
$objects = array();
|
||||
foreach ($deleteMarkerList as $obj) {
|
||||
$objects[] = new DeleteObjectInfo($obj->getKey(), $obj->getVersionId());
|
||||
}
|
||||
$dresult = $this->ossClient->deleteObjectVersions($this->bucket, $objects);
|
||||
$this->assertEquals(5, count($dresult));
|
||||
$this->assertEquals('deletes/00', $dresult[0]->getKey());
|
||||
$this->assertEquals('true', $dresult[0]->getDeleteMarker());
|
||||
$this->assertFalse(empty($dresult[1]->getVersionId()));
|
||||
$this->assertFalse(empty($dresult[1]->getDeleteMarkerVersionId()));
|
||||
|
||||
$vresult = $this->ossClient->listObjectVersions($this->bucket, $options);
|
||||
$versions = $vresult->getObjectVersionList();
|
||||
$deleteMarkerList = $vresult->getDeleteMarkerList();
|
||||
$this->assertEquals(0, count($versions));
|
||||
$this->assertEquals(0, count($deleteMarkerList));
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->ossClient->putBucketVersioning($this->bucket, "Enabled");
|
||||
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (!$this->ossClient->doesBucketExist($this->bucket)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ossClient->putBucketVersioning($this->bucket, "Suspended");
|
||||
|
||||
$result = $this->ossClient->listObjectVersions(
|
||||
$this->bucket, array('max-keys' => 1000, 'delimiter' => ''));
|
||||
|
||||
$versions = $result->getObjectVersionList();
|
||||
$deleteMarkers = $result->getDeleteMarkerList();
|
||||
|
||||
foreach ($versions as $obj) {
|
||||
$options = array(
|
||||
OssClient::OSS_VERSION_ID => $obj->getVersionId(),
|
||||
);
|
||||
$this->ossClient->deleteObject($this->bucket, $obj->getKey(), $options);
|
||||
}
|
||||
|
||||
foreach ($deleteMarkers as $del) {
|
||||
$options = array(
|
||||
OssClient::OSS_VERSION_ID => $del->getVersionId(),
|
||||
);
|
||||
$this->ossClient->deleteObject($this->bucket, $del->getKey(), $options);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
use OSS\Model\RestoreConfig;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientRestoreObjectTest extends TestOssClientBase
|
||||
{
|
||||
private $iaBucket;
|
||||
private $archiveBucket;
|
||||
|
||||
public function testIARestoreObject()
|
||||
{
|
||||
$object = 'storage-object';
|
||||
|
||||
$this->ossClient->putObject($this->iaBucket, $object,'testcontent');
|
||||
try{
|
||||
$this->ossClient->restoreObject($this->iaBucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('400', $e->getHTTPStatus());
|
||||
$this->assertEquals('OperationNotSupported', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testNullObjectRestoreObject()
|
||||
{
|
||||
$object = 'null-object';
|
||||
|
||||
try{
|
||||
$this->ossClient->restoreObject($this->bucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('404', $e->getHTTPStatus());
|
||||
}
|
||||
}
|
||||
|
||||
public function testArchiveRestoreObject()
|
||||
{
|
||||
$object = 'storage-object';
|
||||
|
||||
$this->ossClient->putObject($this->archiveBucket, $object,'testcontent');
|
||||
try{
|
||||
$this->ossClient->getObject($this->archiveBucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('403', $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidObjectState', $e->getErrorCode());
|
||||
}
|
||||
$result = $this->ossClient->restoreObject($this->archiveBucket, $object);
|
||||
common::waitMetaSync();
|
||||
$this->assertEquals('202', $result['info']['http_code']);
|
||||
|
||||
try{
|
||||
$this->ossClient->restoreObject($this->archiveBucket, $object);
|
||||
}catch(OssException $e){
|
||||
$this->assertEquals('409', $e->getHTTPStatus());
|
||||
$this->assertEquals('RestoreAlreadyInProgress', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testColdArchiveRestoreObject()
|
||||
{
|
||||
$client = new OssClient(
|
||||
getenv('OSS_ACCESS_KEY_ID'),
|
||||
getenv('OSS_ACCESS_KEY_SECRET'),
|
||||
'oss-ap-southeast-1.aliyuncs.com', false);
|
||||
|
||||
$bucket = $this->bucket . 'cold-archive';
|
||||
$object = 'storage-object';
|
||||
|
||||
//create bucket
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_COLDARCHIVE
|
||||
);
|
||||
$client->createBucket($bucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
|
||||
//test with days
|
||||
$client->putObject($bucket, $object,'testcontent');
|
||||
|
||||
try{
|
||||
$client->getObject($bucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('403', $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidObjectState', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$config = new RestoreConfig(5);
|
||||
$resoptions = array(
|
||||
OssClient::OSS_RESTORE_CONFIG => $config
|
||||
);
|
||||
try{
|
||||
$client->restoreObject($bucket, $object, $resoptions);
|
||||
}catch(OssException $e){
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try{
|
||||
$client->restoreObject($bucket, $object, $resoptions);
|
||||
}catch(OssException $e){
|
||||
$this->assertEquals('409', $e->getHTTPStatus());
|
||||
$this->assertEquals('RestoreAlreadyInProgress', $e->getErrorCode());
|
||||
}
|
||||
|
||||
//test with days & tier
|
||||
$client->putObject($bucket, $object,'testcontent');
|
||||
|
||||
try{
|
||||
$client->getObject($bucket, $object);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('403', $e->getHTTPStatus());
|
||||
$this->assertEquals('InvalidObjectState', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$config = new RestoreConfig(5, "Expedited");
|
||||
$resoptions = array(
|
||||
OssClient::OSS_RESTORE_CONFIG => $config
|
||||
);
|
||||
try{
|
||||
$client->restoreObject($bucket, $object, $resoptions);
|
||||
}catch(OssException $e){
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try{
|
||||
$client->restoreObject($bucket, $object, $resoptions);
|
||||
}catch(OssException $e){
|
||||
$this->assertEquals('409', $e->getHTTPStatus());
|
||||
$this->assertEquals('RestoreAlreadyInProgress', $e->getErrorCode());
|
||||
}
|
||||
|
||||
$client->deleteObject($bucket, $object);
|
||||
$client->deleteBucket($bucket);
|
||||
}
|
||||
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->iaBucket = 'ia-' . $this->bucket;
|
||||
$this->archiveBucket = 'archive-' . $this->bucket;
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_IA
|
||||
);
|
||||
|
||||
$this->ossClient->createBucket($this->iaBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
|
||||
$options = array(
|
||||
OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_ARCHIVE
|
||||
);
|
||||
|
||||
$this->ossClient->createBucket($this->archiveBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$object = 'storage-object';
|
||||
|
||||
$this->ossClient->deleteObject($this->iaBucket, $object);
|
||||
$this->ossClient->deleteObject($this->archiveBucket, $object);
|
||||
$this->ossClient->deleteBucket($this->iaBucket);
|
||||
$this->ossClient->deleteBucket($this->archiveBucket);
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientSignatureTest extends TestOssClientBase
|
||||
{
|
||||
function testGetSignedUrlForGettingObject()
|
||||
{
|
||||
$object = "a.file";
|
||||
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
|
||||
$timeout = 3600;
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('GET');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
|
||||
$this->assertEquals(file_get_contents(__FILE__), $res->body);
|
||||
}
|
||||
|
||||
public function testGetSignedUrlForPuttingObject()
|
||||
{
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT");
|
||||
$content = file_get_contents(__FILE__);
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('PUT');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->add_header('Content-Length', strlen($content));
|
||||
$request->set_body($content);
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(),
|
||||
$request->get_response_body(), $request->get_response_code());
|
||||
$this->assertTrue($res->isOK());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSignedUrlForPuttingObjectFromFile()
|
||||
{
|
||||
$file = __FILE__;
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('PUT');
|
||||
$request->add_header('Content-Type', 'txt');
|
||||
$request->set_read_file($file);
|
||||
$request->set_read_stream_size(sprintf('%u',filesize($file)));
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(),
|
||||
$request->get_response_body(), $request->get_response_code());
|
||||
$this->assertTrue($res->isOK());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testSignedUrlWithException()
|
||||
{
|
||||
$file = __FILE__;
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "POST", $options);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
if (strpos($e, "method is invalid") == false)
|
||||
{
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testGetgenPreSignedUrlForGettingObject()
|
||||
{
|
||||
$object = "a.file";
|
||||
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
|
||||
$expires = time() + 3600;
|
||||
try {
|
||||
$signedUrl = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expires);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('GET');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
|
||||
$this->assertEquals(file_get_contents(__FILE__), $res->body);
|
||||
}
|
||||
|
||||
function testGetgenPreSignedUrlVsSignedUrl()
|
||||
{
|
||||
$object = "object-vs.file";
|
||||
$signedUrl1 = '245';
|
||||
$signedUrl2 = '123';
|
||||
$expiration = 0;
|
||||
|
||||
do {
|
||||
usleep(500000);
|
||||
$begin = time();
|
||||
$expiration = time() + 3600;
|
||||
$signedUrl1 = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expiration);
|
||||
$signedUrl2 = $this->ossClient->signUrl($this->bucket, $object, 3600);
|
||||
$end = time();
|
||||
} while ($begin != $end);
|
||||
$this->assertEquals($signedUrl1, $signedUrl2);
|
||||
$this->assertTrue(strpos($signedUrl1, 'Expires='.$expiration) !== false);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->ossClient->deleteObject($this->bucket, "a.file");
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
/**
|
||||
* 上传本地变量到bucket
|
||||
*/
|
||||
$object = "a.file";
|
||||
$content = file_get_contents(__FILE__);
|
||||
$options = array(
|
||||
OssClient::OSS_LENGTH => strlen($content),
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Expires' => 'Fri, 28 Feb 2020 05:38:42 GMT',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'Content-Disposition' => 'attachment;filename=oss_download.log',
|
||||
'Content-Encoding' => 'utf-8',
|
||||
'Content-Language' => 'zh-CN',
|
||||
'x-oss-server-side-encryption' => 'AES256',
|
||||
'x-oss-meta-self-define-title' => 'user define meta info',
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
$this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
|
||||
class OssClientTest extends TestOssClientBase
|
||||
{
|
||||
public function testConstrunct()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', 'http://oss-cn-hangzhou.aliyuncs.com');
|
||||
$this->assertFalse($ossClient->isUseSSL());
|
||||
$ossClient->setUseSSL(true);
|
||||
$this->assertTrue($ossClient->isUseSSL());
|
||||
$this->assertTrue(true);
|
||||
$this->assertEquals(3, $ossClient->getMaxRetries());
|
||||
$ossClient->setMaxTries(4);
|
||||
$this->assertEquals(4, $ossClient->getMaxRetries());
|
||||
$ossClient->setTimeout(10);
|
||||
$ossClient->setConnectTimeout(20);
|
||||
} catch (OssException $e) {
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct2()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', "", 'http://oss-cn-hangzhou.aliyuncs.com');
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("access key secret is empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct3()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient("", 'key', 'http://oss-cn-hangzhou.aliyuncs.com');
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("access key id is empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct4()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('endpoint is empty', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct5()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "123.123.123.1");
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct6()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "https://123.123.123.1");
|
||||
$this->assertTrue($ossClient->isUseSSL());
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "https://123.123.123.1:3128");
|
||||
$this->assertTrue($ossClient->isUseSSL());
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct7()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "http://123.123.123.1");
|
||||
$this->assertFalse($ossClient->isUseSSL());
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "http://123.123.123.1:3128");
|
||||
$this->assertFalse($ossClient->isUseSSL());
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct8()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "http://123.123.123.1", true);
|
||||
$ossClient->listBuckets();
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct9()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$ossClient->listBuckets();
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct10()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "http://ABC-COM.TEST.123.cn", true);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct11()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "oss-test.com\\aliyuncs.com");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('endpoint is invalid:'."oss-test.com\\aliyuncs.com", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct12()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "192.168.1.0:abc123");
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('endpoint is invalid:'."192.168.1.0:abc123", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupportPutEmptyObject()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = $this->bucket;
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret , $endpoint, false);
|
||||
$ossClient->putObject($bucket,'test_emptybody','');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
//use invalid sts-token, should fail.
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = $this->bucket;
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret , $endpoint, false, "invalid-sts-token");
|
||||
$ossClient->putObject($bucket,'test_emptybody','');
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('InvalidAccessKeyId', $e->getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateObjectDir()
|
||||
{
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = $this->bucket;
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
|
||||
try {
|
||||
$object='test-dir';
|
||||
$ossClient->createObjectDir($bucket,$object);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
try {
|
||||
$object='0';
|
||||
$ossClient->createObjectDir($bucket,$object);
|
||||
$ossClient->putObject($bucket,$object, '');
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
var_dump($e);
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetBucketCors()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$ossClient->getBucketCors($bucket);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetBucketCname()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = $this->bucket;
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$ossClient->getBucketCname($bucket);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testProxySupport()
|
||||
{
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = getenv('OSS_BUCKET') . '-proxy';
|
||||
$requestProxy = getenv('OSS_PROXY');
|
||||
$key = 'test-proxy-srv-object';
|
||||
$content = 'test-content';
|
||||
$proxys = parse_url($requestProxy);
|
||||
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false, null, $requestProxy);
|
||||
|
||||
$result = $ossClient->createBucket($bucket);
|
||||
$this->checkProxy($result, $proxys);
|
||||
|
||||
$result = $ossClient->putObject($bucket, $key, $content);
|
||||
$this->checkProxy($result, $proxys);
|
||||
$result = $ossClient->getObject($bucket, $key);
|
||||
$this->assertEquals($content, $result);
|
||||
|
||||
// list object
|
||||
$objectListInfo = $ossClient->listObjects($bucket);
|
||||
$objectList = $objectListInfo->getObjectList();
|
||||
$this->assertNotNull($objectList);
|
||||
$this->assertTrue(is_array($objectList));
|
||||
$objects = array();
|
||||
foreach ($objectList as $value) {
|
||||
$objects[] = $value->getKey();
|
||||
}
|
||||
$this->assertEquals(1, count($objects));
|
||||
$this->assertTrue(in_array($key, $objects));
|
||||
|
||||
$result = $ossClient->deleteObject($bucket, $key);
|
||||
$this->checkProxy($result,$proxys);
|
||||
|
||||
$result = $ossClient->deleteBucket($bucket);
|
||||
$this->checkProxy($result, $proxys);
|
||||
}
|
||||
|
||||
private function checkProxy($result, $proxys)
|
||||
{
|
||||
$this->assertEquals($result['info']['primary_ip'], $proxys['host']);
|
||||
$this->assertEquals($result['info']['primary_port'], $proxys['port']);
|
||||
$this->assertTrue(array_key_exists('via', $result));
|
||||
}
|
||||
|
||||
public function testIpEndpoint()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = 'sk' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = '192.168.1.1';
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
|
||||
$this->assertTrue(strpos($signedUrl, '192.168.1.1/skyranch-php-test/a.file?') != false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCnameEndpoint()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = 'sk' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = 'cname.endpoint';
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, true);
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
|
||||
$this->assertTrue(strpos($signedUrl, 'cname.endpoint/a.file?') != false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testStsToken()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = 'sk' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false, "test-token");
|
||||
$object = "a.file";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
|
||||
$this->assertTrue(strpos($signedUrl, 'security-token=test-token') != false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class OssExceptionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testOSS_exception()
|
||||
{
|
||||
try {
|
||||
throw new OssException("ERR");
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertNotNull($e);
|
||||
$this->assertEquals($e->getMessage(), "ERR");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssTrafficLimitTest extends TestOssClientBase
|
||||
{
|
||||
function testTrafficLimitInHeader()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
OssClient::OSS_TRAFFIC_LIMIT => 819200,
|
||||
));
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->putObject($this->bucket, 'default-object', 'content', $options);
|
||||
$this->assertTrue(true);
|
||||
$this->assertTrue(isset($result["x-oss-qos-delay-time"]));
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->appendObject($this->bucket, 'append-object', 'content', 0, $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->copyObject($this->bucket, 'default-object', $this->bucket, 'copy-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->getObject($this->bucket, 'default-object', $options);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
function testTrafficLimitInQuery()
|
||||
{
|
||||
$options = array(
|
||||
OssClient::OSS_TRAFFIC_LIMIT => 819200,
|
||||
);
|
||||
|
||||
$object = "get.file";
|
||||
$content = 'hello world';
|
||||
$this->ossClient->putObject($this->bucket, $object, $content);
|
||||
$timeout = 3600;
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "GET", $options);
|
||||
$this->assertTrue(stripos($signedUrl, 'x-oss-traffic-limit=819200') > 0);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('GET');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
|
||||
$this->assertEquals($content, $res->body);
|
||||
|
||||
|
||||
$object = "put.file";
|
||||
$timeout = 3600;
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
|
||||
$this->assertTrue(stripos($signedUrl, 'x-oss-traffic-limit=819200') > 0);
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('PUT');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->add_header('Content-Length', strlen($content));
|
||||
$request->set_body($content);
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(),
|
||||
$request->get_response_body(), $request->get_response_code());
|
||||
$this->assertTrue($res->isOK());
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue